From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
To: ffmpeg-devel@ffmpeg.org
Cc: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Subject: [FFmpeg-devel] [PATCH 3/4] avcodec/decode: Set KEY flag+pict_type generically for intra-only codecs
Date: Thu, 9 May 2024 04:04:42 +0200
Message-ID: <GV1P250MB07371C1E0C33E95C5433E4EA8FE62@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <GV1P250MB0737230EFB1A8FE7E765AE5E8FE62@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM>
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.
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
libavcodec/decode.c | 29 +++++++++++++++++++++++++++--
libavcodec/pthread_frame.c | 17 ++++++++++++++---
tests/ref/fate/exif-image-tiff | 2 +-
3 files changed, 42 insertions(+), 6 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index d031b1ca17..0ca5344ef5 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -57,6 +57,20 @@
typedef struct DecodeContext {
AVCodecInternal avci;
+ /**
+ * This is set to AV_FRAME_FLAG_KEY for decoders of intra-only formats
+ * (those whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set)
+ * to set the flag generically.
+ */
+ int intra_only_flag;
+
+ /**
+ * This is set to AV_PICTURE_TYPE_I for intra only video decoders
+ * and to AV_PICTURE_TYPE_NONE for other decoders. It is used to set
+ * the AVFrame's pict_type before the decoder receives it.
+ */
+ enum AVPictureType initial_pict_type;
+
/* to prevent infinite loop on errors when draining */
int nb_draining_errors;
@@ -382,6 +396,7 @@ static int discard_samples(AVCodecContext *avctx, AVFrame *frame, int64_t *disca
static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame, int64_t *discarded_samples)
{
AVCodecInternal *avci = avctx->internal;
+ DecodeContext *dc = decode_ctx(avci);
AVPacket *const pkt = avci->in_pkt;
const FFCodec *const codec = ffcodec(avctx->codec);
int got_frame, consumed;
@@ -409,6 +424,8 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
if (HAVE_THREADS && avctx->active_thread_type & FF_THREAD_FRAME) {
consumed = ff_thread_decode_frame(avctx, frame, &got_frame, pkt);
} else {
+ frame->pict_type = dc->initial_pict_type;
+ frame->flags |= dc->intra_only_flag;
consumed = codec->cb.decode(avctx, frame, &got_frame, pkt);
if (!(codec->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS))
@@ -597,6 +614,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
av_assert0(!frame->buf[0]);
if (codec->cb_type == FF_CODEC_CB_TYPE_RECEIVE_FRAME) {
+ frame->pict_type = dc->initial_pict_type;
+ frame->flags |= dc->intra_only_flag;
ret = codec->cb.receive_frame(avctx, frame);
emms_c();
if (!ret) {
@@ -626,8 +645,7 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
frame->width = avctx->width;
if (!frame->height)
frame->height = avctx->height;
- } else
- frame->flags |= AV_FRAME_FLAG_KEY;
+ }
ret = fill_frame_props(avctx, frame);
if (ret < 0) {
@@ -1793,6 +1811,13 @@ int ff_decode_preinit(AVCodecContext *avctx)
DecodeContext *dc = decode_ctx(avci);
int ret = 0;
+ dc->initial_pict_type = AV_PICTURE_TYPE_NONE;
+ if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
+ dc->intra_only_flag = AV_FRAME_FLAG_KEY;
+ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
+ dc->initial_pict_type = AV_PICTURE_TYPE_I;
+ }
+
/* if the decoder init function was already called previously,
* free the already allocated subtitle_header before overwriting it */
av_freep(&avctx->subtitle_header);
diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c
index 67f09c1f48..982e4a64c5 100644
--- a/libavcodec/pthread_frame.c
+++ b/libavcodec/pthread_frame.c
@@ -22,13 +22,11 @@
* @see doc/multithreading.txt
*/
-#include "config.h"
-
#include <stdatomic.h>
-#include <stdint.h>
#include "avcodec.h"
#include "avcodec_internal.h"
+#include "codec_desc.h"
#include "codec_internal.h"
#include "decode.h"
#include "hwaccel_internal.h"
@@ -108,6 +106,10 @@ typedef struct PerThreadContext {
int hwaccel_threadsafe;
atomic_int debug_threads; ///< Set if the FF_DEBUG_THREADS option is set.
+
+ /// The following two fields have the same semantics as the DecodeContext field
+ int intra_only_flag;
+ enum AVPictureType initial_pict_type;
} PerThreadContext;
/**
@@ -220,6 +222,8 @@ static attribute_align_arg void *frame_worker_thread(void *arg)
av_frame_unref(p->frame);
p->got_frame = 0;
+ p->frame->pict_type = p->initial_pict_type;
+ p->frame->flags |= p->intra_only_flag;
p->result = codec->cb.decode(avctx, p->frame, &p->got_frame, p->avpkt);
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,
AVCodecContext *copy;
int err;
+ p->initial_pict_type = AV_PICTURE_TYPE_NONE;
+ if (avctx->codec_descriptor->props & AV_CODEC_PROP_INTRA_ONLY) {
+ p->intra_only_flag = AV_FRAME_FLAG_KEY;
+ if (avctx->codec_type == AVMEDIA_TYPE_VIDEO)
+ p->initial_pict_type = AV_PICTURE_TYPE_I;
+ }
+
atomic_init(&p->state, STATE_INPUT_READY);
copy = av_memdup(avctx, sizeof(*avctx));
diff --git a/tests/ref/fate/exif-image-tiff b/tests/ref/fate/exif-image-tiff
index 887c039df9..f5ff4dc16c 100644
--- a/tests/ref/fate/exif-image-tiff
+++ b/tests/ref/fate/exif-image-tiff
@@ -20,7 +20,7 @@ crop_left=0
crop_right=0
pix_fmt=rgb24
sample_aspect_ratio=1:1
-pict_type=?
+pict_type=I
interlaced_frame=0
top_field_first=0
repeat_pict=0
--
2.40.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
next prev parent reply other threads:[~2024-05-09 2:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 1:52 [FFmpeg-devel] [PATCH 1/5] avcodec/mlpdec: Set AV_FRAME_FLAG_KEY explicitly Andreas Rheinhardt
2024-05-09 2:04 ` [FFmpeg-devel] [PATCH 2/4] avcodec/codec_desc, jvdec: JV is not intra-only Andreas Rheinhardt
2024-05-09 2:04 ` Andreas Rheinhardt [this message]
2024-05-13 8:28 ` [FFmpeg-devel] [PATCH 3/4] avcodec/decode: Set KEY flag+pict_type generically for intra-only codecs Tomas Härdin
2024-05-13 8:54 ` Andreas Rheinhardt
2024-05-13 15:52 ` Tomas Härdin
2024-05-13 15:55 ` Andreas Rheinhardt
2024-05-13 17:02 ` Tomas Härdin
2024-05-09 2:04 ` [FFmpeg-devel] [PATCH 4/4] avcodec: Remove redundant setting of AV_FRAME_FLAG_KEY, AV_PICTURE_TYPE_I Andreas Rheinhardt
2024-05-10 18:05 ` [FFmpeg-devel] [PATCH 5/6] avcodec/yop: Add missing AV_CODEC_CAP_DR1 Andreas Rheinhardt
2024-05-10 18:06 ` [FFmpeg-devel] [PATCH 6/6] avcodec/codec_desc: Mark AVRN, TGQ, PhotoCD, VBN as intra-only Andreas Rheinhardt
2024-05-17 15:34 ` [FFmpeg-devel] [PATCH 1/5] avcodec/mlpdec: Set AV_FRAME_FLAG_KEY explicitly Andreas Rheinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=GV1P250MB07371C1E0C33E95C5433E4EA8FE62@GV1P250MB0737.EURP250.PROD.OUTLOOK.COM \
--to=andreas.rheinhardt@outlook.com \
--cc=ffmpeg-devel@ffmpeg.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git