diff mbox series

[FFmpeg-devel,2/7] avcodec/mediacodecenc: make each encoder has its own option

Message ID tencent_BB49731B885693EDF36175D12915EEA24505@qq.com
State New
Headers show
Series [FFmpeg-devel,1/7] avcodec/mediacodecenc: add bitrate_mode option | expand

Checks

Context Check Description
andriy/configure_x86 warning Failed to apply patch
yinshiyou/configure_loongarch64 warning Failed to apply patch

Commit Message

zhilizhao(赵志立) Dec. 4, 2022, 5:12 p.m. UTC
From: Zhao Zhili <zhilizhao@tencent.com>

---
 libavcodec/mediacodecenc.c | 42 ++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 18 deletions(-)

Comments

Steven Liu Dec. 5, 2022, 4:23 a.m. UTC | #1
Zhao Zhili <quinkblack@foxmail.com> 于2022年12月5日周一 01:13写道:
>
> From: Zhao Zhili <zhilizhao@tencent.com>
>
> ---
>  libavcodec/mediacodecenc.c | 42 ++++++++++++++++++++++----------------
>  1 file changed, 24 insertions(+), 18 deletions(-)
>
> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
> index c8d8f84e46..c28cce56c6 100644
> --- a/libavcodec/mediacodecenc.c
> +++ b/libavcodec/mediacodecenc.c
> @@ -495,29 +495,27 @@ static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = {
>
>  #define OFFSET(x) offsetof(MediaCodecEncContext, x)
>  #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
> -static const AVOption common_options[] = {
> -    { "ndk_codec", "Use MediaCodec from NDK",
> -                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
> -    { "codec_name", "Select codec by name",
> -                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
> -    { "bitrate_mode", "Bitrate control method",
> -                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },
> -    { "cq", "Constant quality mode",
> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },
> -    { "vbr", "Variable bitrate mode",
> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },
> -    { "cbr", "Constant bitrate mode",
> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },
> -    { "cbr_fd", "Constant bitrate mode with frame drops",
> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },
> -    { NULL },
> -};
> +#define COMMON_OPTION                                                                                       \
> +    { "ndk_codec", "Use MediaCodec from NDK",                                                               \
> +                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },                      \
> +    { "codec_name", "Select codec by name",                                                                 \
> +                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },                                      \
> +    { "bitrate_mode", "Bitrate control method",                                                             \
> +                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },  \
> +    { "cq", "Constant quality mode",                                                                        \
> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },             \
> +    { "vbr", "Variable bitrate mode",                                                                       \
> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },            \
> +    { "cbr", "Constant bitrate mode",                                                                       \
> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },            \
> +    { "cbr_fd", "Constant bitrate mode with frame drops",                                                   \
> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },         \

Why don't merge 1/7 and 2/7 into one step?
>
>  #define MEDIACODEC_ENCODER_CLASS(name)              \
>  static const AVClass name ## _mediacodec_class = {  \
>      .class_name = #name "_mediacodec",              \
>      .item_name  = av_default_item_name,             \
> -    .option     = common_options,                   \
> +    .option     = name ## _options,                 \
>      .version    = LIBAVUTIL_VERSION_INT,            \
>  };                                                  \
>
> @@ -542,9 +540,17 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = {              \
>  };                                                                      \
>
>  #if CONFIG_H264_MEDIACODEC_ENCODER
> +static const AVOption h264_options[] = {
> +    COMMON_OPTION
> +    { NULL, }
> +};
>  DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
>  #endif
>
>  #if CONFIG_HEVC_MEDIACODEC_ENCODER
> +static const AVOption hevc_options[] = {
> +    COMMON_OPTION
> +    { NULL, }
> +};
>  DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
>  #endif
> --
> 2.25.1
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
zhilizhao(赵志立) Dec. 5, 2022, 5:29 a.m. UTC | #2
> On Dec 5, 2022, at 12:23, Steven Liu <lingjiujianke@gmail.com> wrote:
> 
> Zhao Zhili <quinkblack@foxmail.com> 于2022年12月5日周一 01:13写道:
>> 
>> From: Zhao Zhili <zhilizhao@tencent.com>
>> 
>> ---
>> libavcodec/mediacodecenc.c | 42 ++++++++++++++++++++++----------------
>> 1 file changed, 24 insertions(+), 18 deletions(-)
>> 
>> diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
>> index c8d8f84e46..c28cce56c6 100644
>> --- a/libavcodec/mediacodecenc.c
>> +++ b/libavcodec/mediacodecenc.c
>> @@ -495,29 +495,27 @@ static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = {
>> 
>> #define OFFSET(x) offsetof(MediaCodecEncContext, x)
>> #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
>> -static const AVOption common_options[] = {
>> -    { "ndk_codec", "Use MediaCodec from NDK",
>> -                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
>> -    { "codec_name", "Select codec by name",
>> -                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
>> -    { "bitrate_mode", "Bitrate control method",
>> -                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },
>> -    { "cq", "Constant quality mode",
>> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },
>> -    { "vbr", "Variable bitrate mode",
>> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },
>> -    { "cbr", "Constant bitrate mode",
>> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },
>> -    { "cbr_fd", "Constant bitrate mode with frame drops",
>> -                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },
>> -    { NULL },
>> -};
>> +#define COMMON_OPTION                                                                                       \
>> +    { "ndk_codec", "Use MediaCodec from NDK",                                                               \
>> +                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },                      \
>> +    { "codec_name", "Select codec by name",                                                                 \
>> +                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },                                      \
>> +    { "bitrate_mode", "Bitrate control method",                                                             \
>> +                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },  \
>> +    { "cq", "Constant quality mode",                                                                        \
>> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },             \
>> +    { "vbr", "Variable bitrate mode",                                                                       \
>> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },            \
>> +    { "cbr", "Constant bitrate mode",                                                                       \
>> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },            \
>> +    { "cbr_fd", "Constant bitrate mode with frame drops",                                                   \
>> +                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },         \
> 
> Why don't merge 1/7 and 2/7 into one step?

I’m waiting for someone to ask the question :)

Patch 3/7 can be simplified to passthrough an opaque int
value to MediaFormat, without those AV_OPT_TYPE_CONST,
enum MediaCodecAvcLevel and enum MediaCodecHevcLevel, then
patch 2/7 is unnecessary.

I’d like to ask: do you like to drop those AV_OPT_TYPE_CONST,
or keep them as patch 3/7 currently do?

After a second thought, patch 2/7 is future proof. I will
reorder patch 1/7 and 2/7.

>> 
>> #define MEDIACODEC_ENCODER_CLASS(name)              \
>> static const AVClass name ## _mediacodec_class = {  \
>>     .class_name = #name "_mediacodec",              \
>>     .item_name  = av_default_item_name,             \
>> -    .option     = common_options,                   \
>> +    .option     = name ## _options,                 \
>>     .version    = LIBAVUTIL_VERSION_INT,            \
>> };                                                  \
>> 
>> @@ -542,9 +540,17 @@ const FFCodec ff_ ## short_name ## _mediacodec_encoder = {              \
>> };                                                                      \
>> 
>> #if CONFIG_H264_MEDIACODEC_ENCODER
>> +static const AVOption h264_options[] = {
>> +    COMMON_OPTION
>> +    { NULL, }
>> +};
>> DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
>> #endif
>> 
>> #if CONFIG_HEVC_MEDIACODEC_ENCODER
>> +static const AVOption hevc_options[] = {
>> +    COMMON_OPTION
>> +    { NULL, }
>> +};
>> DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
>> #endif
>> --
>> 2.25.1
>> 
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>> 
>> To unsubscribe, visit link above, or email
>> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
> 
> 
>
diff mbox series

Patch

diff --git a/libavcodec/mediacodecenc.c b/libavcodec/mediacodecenc.c
index c8d8f84e46..c28cce56c6 100644
--- a/libavcodec/mediacodecenc.c
+++ b/libavcodec/mediacodecenc.c
@@ -495,29 +495,27 @@  static const AVCodecHWConfigInternal *const mediacodec_hw_configs[] = {
 
 #define OFFSET(x) offsetof(MediaCodecEncContext, x)
 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
-static const AVOption common_options[] = {
-    { "ndk_codec", "Use MediaCodec from NDK",
-                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },
-    { "codec_name", "Select codec by name",
-                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },
-    { "bitrate_mode", "Bitrate control method",
-                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },
-    { "cq", "Constant quality mode",
-                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },
-    { "vbr", "Variable bitrate mode",
-                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },
-    { "cbr", "Constant bitrate mode",
-                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },
-    { "cbr_fd", "Constant bitrate mode with frame drops",
-                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },
-    { NULL },
-};
+#define COMMON_OPTION                                                                                       \
+    { "ndk_codec", "Use MediaCodec from NDK",                                                               \
+                    OFFSET(use_ndk_codec), AV_OPT_TYPE_BOOL, {.i64 = -1}, -1, 1, VE },                      \
+    { "codec_name", "Select codec by name",                                                                 \
+                    OFFSET(name), AV_OPT_TYPE_STRING, {0}, 0, 0, VE },                                      \
+    { "bitrate_mode", "Bitrate control method",                                                             \
+                    OFFSET(bitrate_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "bitrate_mode" },  \
+    { "cq", "Constant quality mode",                                                                        \
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CQ}, 0, 0, VE, "bitrate_mode" },             \
+    { "vbr", "Variable bitrate mode",                                                                       \
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_VBR}, 0, 0, VE, "bitrate_mode" },            \
+    { "cbr", "Constant bitrate mode",                                                                       \
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR}, 0, 0, VE, "bitrate_mode" },            \
+    { "cbr_fd", "Constant bitrate mode with frame drops",                                                   \
+                    0, AV_OPT_TYPE_CONST, {.i64 = BITRATE_MODE_CBR_FD}, 0, 0, VE, "bitrate_mode" },         \
 
 #define MEDIACODEC_ENCODER_CLASS(name)              \
 static const AVClass name ## _mediacodec_class = {  \
     .class_name = #name "_mediacodec",              \
     .item_name  = av_default_item_name,             \
-    .option     = common_options,                   \
+    .option     = name ## _options,                 \
     .version    = LIBAVUTIL_VERSION_INT,            \
 };                                                  \
 
@@ -542,9 +540,17 @@  const FFCodec ff_ ## short_name ## _mediacodec_encoder = {              \
 };                                                                      \
 
 #if CONFIG_H264_MEDIACODEC_ENCODER
+static const AVOption h264_options[] = {
+    COMMON_OPTION
+    { NULL, }
+};
 DECLARE_MEDIACODEC_ENCODER(h264, "H.264", AV_CODEC_ID_H264)
 #endif
 
 #if CONFIG_HEVC_MEDIACODEC_ENCODER
+static const AVOption hevc_options[] = {
+    COMMON_OPTION
+    { NULL, }
+};
 DECLARE_MEDIACODEC_ENCODER(hevc, "H.265", AV_CODEC_ID_HEVC)
 #endif