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
5757 typedef struct DecodeContext {
5858 AVCodecInternal avci;
5959
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+
6074 /* to prevent infinite loop on errors when draining */
6175 int nb_draining_errors;
6276
@@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca · 319 unmodified lines
382396 static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
383397 {
384398 AVCodecInternal *avci = avctx->internal;
399+ DecodeContext *dc = decode_ctx(avci);
385400 AVPacket *const pkt = avci->in_pkt;
386401 const FFCodec *const codec = ffcodec(avctx->codec);
387402 int got_frame, consumed;
@@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, · 21 unmodified lines
409424 if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
410425 consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
411426 } else {
427+ frame->pict_type = dc->initial_pict_type;
428+ frame->flags |= dc->intra_only_flag;
412429 consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
413430
414431 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
598615 av_assert0(!frame->buf[0]);
599616
600617 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;
601620 ret = codec->cb.receive_frame(avctx, frame);
602621 emms_c();
603622 if (!ret) {
@@ -627,8 +646,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) · 23 unmodified lines
627646 frame->width = avctx->width;
628647 if (!frame->height)
629648 frame->height = avctx->height;
630− } else
631− frame->flags |= AV_FRAME_FLAG_KEY;
649+ }
632650
633651 ret = fill_frame_props(avctx, frame);
634652 if (ret < 0) {
@@ -1794,6 +1812,13 @@ int ff_decode_preinit(AVCodecContext *avctx) · 1159 unmodified lines
17941812 DecodeContext *dc = decode_ctx(avci);
17951813 int ret = 0;
17961814
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+
17971822 /* if the decoder init function was already called previously,
17981823 * free the already allocated subtitle_header before overwriting it */
17991824 av_freep(&avctx->subtitle_header);
libavcodec/pthread_frame.c+14−3
@@ -22,13 +22,11 @@ · 21 unmodified lines
2222 * @see doc/multithreading.txt
2323 */
2424
25−#include "config.h"
26−
2725 #include <stdatomic.h>
28−#include <stdint.h>
2926
3027 #include "avcodec.h"
3128 #include "avcodec_internal.h"
29+#include "codec_desc.h"
3230 #include "codec_internal.h"
3331 #include "decode.h"
3432 #include "hwaccel_internal.h"
@@ -108,6 +106,10 @@ typedef struct PerThreadContext { · 73 unmodified lines
108106 int hwaccel_threadsafe;
109107
110108 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;
111113 } PerThreadContext;
112114
113115 /**
@@ -220,6 +222,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg) · 106 unmodified lines
220222
221223 av_frame_unref(p->frame);
222224 p->got_frame = 0;
225+ p->frame->pict_type = p->initial_pict_type;
226+ p->frame->flags |= p->intra_only_flag;
223227 p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
224228
225229 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
763767 AVCodecContext *copy;
764768 int err;
765769
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+
766777 atomic_init(&p->state, STATE_INPUT_READY);
767778
768779 copy = av_memdup(avctx, sizeof(*avctx));
tests/ref/fate/exif-image-tiff+1−1
@@ -20,7 +20,7 @@ crop_left=0 · 19 unmodified lines
2020 crop_right=0
2121 pix_fmt=rgb24
2222 sample_aspect_ratio=1:1
23−pict_type=?
23+pict_type=I
2424 interlaced_frame=0
2525 top_field_first=0
2626 repeat_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