[FFmpeg-devel] [PATCH 1/4] avcodec/mediacodecdec: Add operating_rate option

Zhao Zhili quinkblack at foxmail.com
Wed Nov 6 14:31:00 EET 2024


From: Zhao Zhili <zhilizhao at tencent.com>

The codec wants to know whether the usecase is realtime playback
or full-speed transcoding, or playback at a higher speed. The codec
runs faster when operating_rate higher than framerate.
---
 libavcodec/mediacodecdec.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index cc55b306bd..4937828f21 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -57,6 +57,8 @@ typedef struct MediaCodecH264DecContext {
     int amlogic_mpeg2_api23_workaround;
 
     int use_ndk_codec;
+    // Ref. MediaFormat KEY_OPERATING_RATE
+    int operating_rate;
 } MediaCodecH264DecContext;
 
 static av_cold int mediacodec_decode_close(AVCodecContext *avctx)
@@ -441,6 +443,8 @@ static av_cold int mediacodec_decode_init(AVCodecContext *avctx)
         ff_AMediaFormat_setInt32(format, "channel-count", avctx->ch_layout.nb_channels);
         ff_AMediaFormat_setInt32(format, "sample-rate", avctx->sample_rate);
     }
+    if (s->operating_rate > 0)
+        ff_AMediaFormat_setInt32(format, "operating-rate", s->operating_rate);
 
     s->ctx = av_mallocz(sizeof(*s->ctx));
     if (!s->ctx) {
@@ -599,6 +603,8 @@ static const AVOption ff_mediacodec_vdec_options[] = {
                      OFFSET(delay_flush), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, VD },
     { "ndk_codec", "Use MediaCodec from NDK",
                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VD },
+    { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
+            OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, VD },
     { NULL }
 };
 
@@ -662,6 +668,8 @@ DECLARE_MEDIACODEC_VDEC(av1, "AV1", AV_CODEC_ID_AV1, NULL)
 static const AVOption ff_mediacodec_adec_options[] = {
     { "ndk_codec", "Use MediaCodec from NDK",
                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, AD },
+    { "operating_rate", "The desired operating rate that the codec will need to operate at, zero for unspecified",
+            OFFSET(operating_rate), AV_OPT_TYPE_INT, {.i64 = 0}, 0, INT_MAX, AD },
     { NULL }
 };
 
-- 
2.46.0



More information about the ffmpeg-devel mailing list