[FFmpeg-cvslog] avcodec/decode: add an internal codec flag to signal a decoder sets all output frame properties
James Almer
git at videolan.org
Wed Jun 23 21:14:32 EEST 2021
ffmpeg | branch: release/4.4 | James Almer <jamrial at gmail.com> | Fri Jun 18 18:57:38 2021 -0300| [28e803d63797d95c285832c6adfad2b9c4dce3d8] | committer: James Almer
avcodec/decode: add an internal codec flag to signal a decoder sets all output frame properties
Decoders like cuviddec ignore and overwrite all the properties set by the generic
code as derived from AVCodecInternal.last_pkt_props. This flag ensures libavcodec
will not store and potentially queue input packets that ultimately will not be used.
Signed-off-by: James Almer <jamrial at gmail.com>
(cherry picked from commit 7b9610ebd81a49af01e57652bae0bee88271e50c)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=28e803d63797d95c285832c6adfad2b9c4dce3d8
---
libavcodec/decode.c | 11 +++++++++--
libavcodec/internal.h | 5 +++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 5c57868568..1126b06882 100644
--- a/libavcodec/decode.c
+++ b/libavcodec/decode.c
@@ -233,9 +233,11 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt)
if (ret < 0)
return ret;
+ if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
ret = extract_packet_props(avctx->internal, pkt);
if (ret < 0)
goto finish;
+ }
ret = apply_param_change(avctx, pkt);
if (ret < 0)
@@ -502,11 +504,13 @@ FF_ENABLE_DEPRECATION_WARNINGS
pkt->data += consumed;
pkt->size -= consumed;
- avci->last_pkt_props->size -= consumed; // See extract_packet_props() comment.
pkt->pts = AV_NOPTS_VALUE;
pkt->dts = AV_NOPTS_VALUE;
+ if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
+ avci->last_pkt_props->size -= consumed; // See extract_packet_props() comment.
avci->last_pkt_props->pts = AV_NOPTS_VALUE;
avci->last_pkt_props->dts = AV_NOPTS_VALUE;
+ }
}
if (got_frame)
@@ -548,7 +552,8 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame)
if (ret == AVERROR_EOF)
avci->draining_done = 1;
- if (IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props))
+ if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS) &&
+ IS_EMPTY(avci->last_pkt_props) && av_fifo_size(avci->pkt_props) >= sizeof(*avci->last_pkt_props))
av_fifo_generic_read(avci->pkt_props,
avci->last_pkt_props, sizeof(*avci->last_pkt_props), NULL);
@@ -1742,6 +1747,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
{ AV_PKT_DATA_S12M_TIMECODE, AV_FRAME_DATA_S12M_TIMECODE },
};
+ if (!(avctx->codec->caps_internal & FF_CODEC_CAP_SETS_FRAME_PROPS)) {
frame->pts = pkt->pts;
#if FF_API_PKT_PTS
FF_DISABLE_DEPRECATION_WARNINGS
@@ -1772,6 +1778,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
} else {
frame->flags = (frame->flags & ~AV_FRAME_FLAG_DISCARD);
}
+ }
frame->reordered_opaque = avctx->reordered_opaque;
if (frame->color_primaries == AVCOL_PRI_UNSPECIFIED)
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index b57b996816..d889c1883e 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -78,6 +78,11 @@
* Codec handles avctx->thread_count == 0 (auto) internally.
*/
#define FF_CODEC_CAP_AUTO_THREADS (1 << 7)
+/**
+ * Codec handles output frame properties internally instead of letting the
+ * internal logic derive them from AVCodecInternal.last_pkt_props.
+ */
+#define FF_CODEC_CAP_SETS_FRAME_PROPS (1 << 8)
/**
* AVCodec.codec_tags termination value
More information about the ffmpeg-cvslog
mailing list