History

avcodec/decode: Set KEY flag+pict_type generically for intra-only codecs

This commit is the analog of 3f11eac75741888c7b2b6f93c458766f2613bab5 for decoding: It sets the AV_FRAME_FLAG_KEY and (for video decoders) also pict_type to AV_PICTURE_TYPE_I. It furthermore stops setting audio frames as always being key frames -- it is wrong for e.g. TrueHD/MLP. The latter also affects TAK and DFPWM. The change already improves output for several decoders where it has been forgotten to set e.g. pict_type like speedhq, wnv1 or tiff. The latter is the reason for the change to the exif-image-tiff FATE test reference file.

Andreas Rheinhardt committed 2 years ago

Commit eee88ba1 parent 41fc62f3 files · +42 −6Browse files

Unified · Split

3 files
  1. libavcodec/decode.c +27 −2
  2. libavcodec/pthread_frame.c +14 −3
  3. tests/ref/fate/exif-image-tiff +1 −1
libavcodec/decode.c+27−2
@@ -57,6 +57,20 @@ · 56 unmodified lines
57typedef struct DecodeContext {57typedef struct DecodeContext {
58 AVCodecInternal avci;58 AVCodecInternal avci;
59 59
60 /**
61 * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
62 * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
63 * to set the flag generically.
64 */
65 int intra_only_flag;
66
67 /**
68 * This is set to AV_PICTURE_TYPE_I for intra only video decoders
69 * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
70 * the AVFrame's pict_type before the decoder receives it.
71 */
72 enum AVPictureType initial_pict_type;
73
60 /* to prevent infinite loop on errors when draining */74 /* to prevent infinite loop on errors when draining */
61 int nb_draining_errors;75 int nb_draining_errors;
62 76
@@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca · 319 unmodified lines
382static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)396static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
383{397{
384 AVCodecInternal *avci = avctx->internal;398 AVCodecInternal *avci = avctx->internal;
399 DecodeContext *dc = decode_ctx(avci);
385 AVPacket *const pkt = avci->in_pkt;400 AVPacket *const pkt = avci->in_pkt;
386 const FFCodec *const codec = ffcodec(avctx->codec);401 const FFCodec *const codec = ffcodec(avctx->codec);
387 int got_frame, consumed;402 int got_frame, consumed;
@@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, · 21 unmodified lines
409 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {424 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
410 consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);425 consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
411 } else {426 } else {
427 frame->pict_type = dc->initial_pict_type;
428 frame->flags |= dc->intra_only_flag;
412 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);429 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
413 430
414 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))431 if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
@@ -598,6 +615,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 183 unmodified lines
598 av_assert0(!frame->buf[0]);615 av_assert0(!frame->buf[0]);
599 616
600 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {617 if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
618 frame->pict_type = dc->initial_pict_type;
619 frame->flags |= dc->intra_only_flag;
601 ret = codec->cb.receive_frame(avctx, frame);620 ret = codec->cb.receive_frame(avctx, frame);
602 emms_c();621 emms_c();
603 if (!ret) {622 if (!ret) {
@@ -627,8 +646,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 23 unmodified lines
627 frame->width = avctx->width;646 frame->width = avctx->width;
628 if (!frame->height)647 if (!frame->height)
629 frame->height = avctx->height;648 frame->height = avctx->height;
630 } else649 }
631 frame->flags |= AV_FRAME_FLAG_KEY;
632 650
633 ret = fill_frame_props(avctx, frame);651 ret = fill_frame_props(avctx, frame);
634 if (ret < 0) {652 if (ret < 0) {
@@ -1794,6 +1812,13 @@ int ff_decode_preinit(AVCodecContext *avctx) · 1159 unmodified lines
1794 DecodeContext *dc = decode_ctx(avci);1812 DecodeContext *dc = decode_ctx(avci);
1795 int ret = 0;1813 int ret = 0;
1796 1814
1815 dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
1816 if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
1817 dc->intra_only_flag = AV_FRAME_FLAG_KEY;
1818 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
1819 dc->initial_pict_type = AV_PICTURE_TYPE_I;
1820 }
1821
1797 /* if the decoder init function was already called previously,1822 /* if the decoder init function was already called previously,
1798 * free the already allocated subtitle_header before overwriting it */1823 * free the already allocated subtitle_header before overwriting it */
1799 av_freep(&avctx->subtitle_header);1824 av_freep(&avctx->subtitle_header);
libavcodec/pthread_frame.c+14−3
@@ -22,13 +22,11 @@ · 21 unmodified lines
22 * @see doc/multithreading.txt22 * @see doc/multithreading.txt
23 */23 */
24 24
25#include "config.h"
26
27#include <stdatomic.h>25#include <stdatomic.h>
28#include <stdint.h>
29 26
30#include "avcodec.h"27#include "avcodec.h"
31#include "avcodec_internal.h"28#include "avcodec_internal.h"
29#include "codec_desc.h"
32#include "codec_internal.h"30#include "codec_internal.h"
33#include "decode.h"31#include "decode.h"
34#include "hwaccel_internal.h"32#include "hwaccel_internal.h"
@@ -108,6 +106,10 @@ typedef struct PerThreadContext { · 73 unmodified lines
108 int hwaccel_threadsafe;106 int hwaccel_threadsafe;
109 107
110 atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.108 atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.
109
110 /// The following two fields have the same semantics as the DecodeContext field
111 int intra_only_flag;
112 enum AVPictureType initial_pict_type;
111} PerThreadContext;113} PerThreadContext;
112 114
113/**115/**
@@ -220,6 +222,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg) · 106 unmodified lines
220 222
221 av_frame_unref(p->frame);223 av_frame_unref(p->frame);
222 p->got_frame = 0;224 p->got_frame = 0;
225 p->frame->pict_type = p->initial_pict_type;
226 p->frame->flags |= p->intra_only_flag;
223 p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);227 p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
224 228
225 if ((p->result < 0 || !p->got_frame) && p->frame->buf[0])229 if ((p->result < 0 || !p->got_frame) && p->frame->buf[0])
@@ -763,6 +767,13 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, · 537 unmodified lines
763 AVCodecContext *copy;767 AVCodecContext *copy;
764 int err;768 int err;
765 769
770 p->initial_pict_type = AV_PICTURE_TYPE_NONE;
771 if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
772 p->intra_only_flag = AV_FRAME_FLAG_KEY;
773 if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
774 p->initial_pict_type = AV_PICTURE_TYPE_I;
775 }
776
766 atomic_init(&p->state, STATE_INPUT_READY);777 atomic_init(&p->state, STATE_INPUT_READY);
767 778
768 copy = av_memdup(avctx, sizeof(*avctx));779 copy = av_memdup(avctx, sizeof(*avctx));
tests/ref/fate/exif-image-tiff+1−1
@@ -20,7 +20,7 @@ crop_left=0 · 19 unmodified lines
20crop_right=020crop_right=0
21pix_fmt=rgb2421pix_fmt=rgb24
22sample_aspect_ratio=1:122sample_aspect_ratio=1:1
23pict_type=?23pict_type=I
24interlaced_frame=024interlaced_frame=0
25top_field_first=025top_field_first=0
26repeat_pict=026repeat_pict=0

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t