diff options
author | Aman Gupta <aman@tmm1.net> | 2018-03-06 13:07:32 -0800 |
---|---|---|
committer | Aman Gupta <aman@tmm1.net> | 2018-03-07 16:22:47 -0800 |
commit | 2a0eb8685728ccb260e42f60e1dbefe47ababbc3 (patch) | |
tree | f84f97754d63a1bbf77baccc9520e5b8d24dff41 /libavcodec/mediacodecdec.c | |
parent | 840f6eb77aed6c9dc2eff1a89add3611ec305262 (diff) | |
download | ffmpeg-2a0eb8685728ccb260e42f60e1dbefe47ababbc3.tar.gz |
avcodec/mediacodecdec: add delay_flush option
The default behavior of the mediacodec decoder before this commit
was to delay flushes until all pending hardware frames were
returned to the decoder. This was useful for certain types of
applications, but was unexpected behavior for others.
The new default behavior with this commit is now to execute
flushes immediately to invalidate all pending frames. The old
behavior can be enabled by setting delay_flush=1.
With the new behavior, video players implementing seek can simply
call flush on the decoder without having to worry about whether
they have one or more mediacodec frames still buffered in their
rendering pipeline. Previously, all these frames had to be
explictly freed (or rendered) before the seek/flush would execute.
The new behavior matches the behavior of all other lavc decoders,
reducing the amount of special casing required when using the
mediacodec decoder.
Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Matthieu Bouron <matthieu.bouron@gmail.com>
Diffstat (limited to 'libavcodec/mediacodecdec.c')
-rw-r--r-- | libavcodec/mediacodecdec.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 0fe14846c3..89d2421ae9 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -41,10 +41,14 @@ typedef struct MediaCodecH264DecContext { + AVClass *avclass; + MediaCodecDecContext *ctx; AVPacket buffered_pkt; + int delay_flush; + } MediaCodecH264DecContext; static av_cold int mediacodec_decode_close(AVCodecContext *avctx) @@ -366,6 +370,8 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx) goto done; } + s->ctx->delay_flush = s->delay_flush; + if ((ret = ff_mediacodec_dec_init(avctx, s->ctx, codec_mime, format)) < 0) { s->ctx = NULL; goto done; @@ -485,12 +491,30 @@ static const AVCodecHWConfigInternal *mediacodec_hw_configs[] = { NULL }; +#define OFFSET(x) offsetof(MediaCodecH264DecContext, x) +#define VD AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM +static const AVOption ff_mediacodec_vdec_options[] = { + { "delay_flush", "Delay flush until hw output buffers are returned to the decoder", + OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD }, + { NULL } +}; + +#define DECLARE_MEDIACODEC_VCLASS(short_name) \ +static const AVClass ff_##short_name##_mediacodec_dec_class = { \ + .class_name = #short_name "_mediacodec", \ + .item_name = av_default_item_name, \ + .option = ff_mediacodec_vdec_options, \ + .version = LIBAVUTIL_VERSION_INT, \ +}; + #define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf) \ +DECLARE_MEDIACODEC_VCLASS(short_name) \ AVCodec ff_##short_name##_mediacodec_decoder = { \ .name = #short_name "_mediacodec", \ .long_name = NULL_IF_CONFIG_SMALL(full_name " Android MediaCodec decoder"), \ .type = AVMEDIA_TYPE_VIDEO, \ .id = codec_id, \ + .priv_class = &ff_##short_name##_mediacodec_dec_class, \ .priv_data_size = sizeof(MediaCodecH264DecContext), \ .init = mediacodec_decode_init, \ .receive_frame = mediacodec_receive_frame, \ |