summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Almer <jamrial@gmail.com>2021-06-18 18:57:38 -0300
committerJames Almer <jamrial@gmail.com>2021-06-21 15:03:52 -0300
commit7b9610ebd81a49af01e57652bae0bee88271e50c (patch)
treeec29b4bafb3425ce5def29bae1e71aa38afbfda5
parenta4fb03563ab918bf9641365d08b4363590ced1eb (diff)
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@gmail.com>
-rw-r--r--libavcodec/decode.c11
-rw-r--r--libavcodec/internal.h5
2 files changed, 14 insertions, 2 deletions
diff --git a/libavcodec/decode.c b/libavcodec/decode.c
index 44f0b11546..95ad295342 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)
@@ -487,11 +489,13 @@ static inline int decode_simple_internal(AVCodecContext *avctx, AVFrame *frame,
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)
@@ -533,7 +537,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);
@@ -1494,6 +1499,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;
frame->pkt_pos = pkt->pos;
frame->pkt_duration = pkt->duration;
@@ -1519,6 +1525,7 @@ int ff_decode_frame_props(AVCodecContext *avctx, AVFrame *frame)
} 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 975ec0ba30..586819cd1b 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