avcodec/mediacodecdec: Add operating_rate option

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.

Signed-off-by: Zhao Zhili <zhilizhao@tencent.com>
This commit is contained in:
Zhao Zhili 2024-11-06 20:31:00 +08:00
parent a8375346eb
commit 46ad1abd36
1 changed files with 8 additions and 0 deletions

View File

@ -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 }
};