diff mbox

[FFmpeg-devel,7/7] avcodec/mediacodecdec: factorize codec declarations

Message ID 20180303001300.4291-7-matthieu.bouron@gmail.com
State New
Headers show

Commit Message

Matthieu Bouron March 3, 2018, 12:13 a.m. UTC
---
 libavcodec/mediacodecdec.c | 116 ++++++++++-----------------------------------
 1 file changed, 24 insertions(+), 92 deletions(-)

Comments

Aman Karmani March 3, 2018, 12:24 a.m. UTC | #1
On Fri, Mar 2, 2018 at 4:13 PM, Matthieu Bouron <matthieu.bouron@gmail.com>
wrote:

> ---
>  libavcodec/mediacodecdec.c | 116 ++++++++++--------------------
> ---------------
>  1 file changed, 24 insertions(+), 92 deletions(-)
>
> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> index 4579da1fa5..5e9714ee6e 100644
> --- a/libavcodec/mediacodecdec.c
> +++ b/libavcodec/mediacodecdec.c
> @@ -485,112 +485,44 @@ static const AVCodecHWConfigInternal
> *mediacodec_hw_configs[] = {
>      NULL
>  };
>
> +#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
>                       \
> +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_data_size = sizeof(MediaCodecH264DecContext),
>                       \
> +    .init           = mediacodec_decode_init,
>                       \
> +    .receive_frame  = mediacodec_receive_frame,
>                       \
> +    .flush          = mediacodec_decode_flush,
>                      \
> +    .close          = mediacodec_decode_close,
>                      \
> +    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE, \
> +    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>                      \
> +    .bsfs           = bsf,
>                      \
> +    .hw_configs     = mediacodec_hw_configs,
>                      \
> +    .wrapper_name   = "mediacodec",
>                       \
> +};
>                      \
> +
>  #if CONFIG_H264_MEDIACODEC_DECODER
> -AVCodec ff_h264_mediacodec_decoder = {
> -    .name           = "h264_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_H264,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .bsfs           = "h264_mp4toannexb",
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264,
> "h264_mp4toannexb")
>  #endif
>
>  #if CONFIG_HEVC_MEDIACODEC_DECODER
> -AVCodec ff_hevc_mediacodec_decoder = {
> -    .name           = "hevc_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_HEVC,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .bsfs           = "hevc_mp4toannexb",
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC,
> "hevc_mp4toannexb")
>  #endif
>
>  #if CONFIG_MPEG2_MEDIACODEC_DECODER
> -AVCodec ff_mpeg2_mediacodec_decoder = {
> -    .name           = "mpeg2_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_MPEG2VIDEO,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(mpeg2, "MPEG-2", AV_CODEC_ID_MPEG2VIDEO, NULL)
>  #endif
>
>  #if CONFIG_MPEG4_MEDIACODEC_DECODER
> -AVCodec ff_mpeg4_mediacodec_decoder = {
> -    .name           = "mpeg4_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_MPEG4,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4, NULL)
>  #endif
>
>  #if CONFIG_VP8_MEDIACODEC_DECODER
> -AVCodec ff_vp8_mediacodec_decoder = {
> -    .name           = "vp8_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_VP8,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL)
>  #endif
>
>  #if CONFIG_VP9_MEDIACODEC_DECODER
> -AVCodec ff_vp9_mediacodec_decoder = {
> -    .name           = "vp9_mediacodec",
> -    .long_name      = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec
> decoder"),
> -    .type           = AVMEDIA_TYPE_VIDEO,
> -    .id             = AV_CODEC_ID_VP9,
> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> -    .init           = mediacodec_decode_init,
> -    .receive_frame  = mediacodec_receive_frame,
> -    .flush          = mediacodec_decode_flush,
> -    .close          = mediacodec_decode_close,
> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> AV_CODEC_CAP_HARDWARE,
> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> -    .hw_configs     = mediacodec_hw_configs,
> -    .wrapper_name   = "mediacodec",
> -};
> +DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL)
>  #endif
>

Patchset LGTM. Nice cleanups, and works as expected on my device.

Aman


> --
> 2.16.2
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
Aman Karmani March 3, 2018, 2:28 a.m. UTC | #2
On Fri, Mar 2, 2018 at 4:24 PM, Aman Gupta <ffmpeg@tmm1.net> wrote:

>
>
> On Fri, Mar 2, 2018 at 4:13 PM, Matthieu Bouron <matthieu.bouron@gmail.com
> > wrote:
>
>> ---
>>  libavcodec/mediacodecdec.c | 116 ++++++++++--------------------
>> ---------------
>>  1 file changed, 24 insertions(+), 92 deletions(-)
>>
>> diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
>> index 4579da1fa5..5e9714ee6e 100644
>> --- a/libavcodec/mediacodecdec.c
>> +++ b/libavcodec/mediacodecdec.c
>> @@ -485,112 +485,44 @@ static const AVCodecHWConfigInternal
>> *mediacodec_hw_configs[] = {
>>      NULL
>>  };
>>
>> +#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
>>                         \
>> +AVCodec ff_##short_name##_mediacodec_decoder = {
>>                        \
>> +    .name           = #short_name "_mediacodec",
>>                        \
>> +    .long_name      = NULL_IF_CONFIG_SMALL(full_name "Android MediaCodec
>> decoder"),            \
>>
>
Need a space in here between full_name and "Android"



> +    .type           = AVMEDIA_TYPE_VIDEO,
>>                       \
>> +    .id             = codec_id,
>>                       \
>> +    .priv_data_size = sizeof(MediaCodecH264DecContext),
>>                         \
>> +    .init           = mediacodec_decode_init,
>>                       \
>> +    .receive_frame  = mediacodec_receive_frame,
>>                       \
>> +    .flush          = mediacodec_decode_flush,
>>                        \
>> +    .close          = mediacodec_decode_close,
>>                        \
>> +    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE, \
>> +    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>>                        \
>> +    .bsfs           = bsf,
>>                        \
>> +    .hw_configs     = mediacodec_hw_configs,
>>                        \
>> +    .wrapper_name   = "mediacodec",
>>                       \
>> +};
>>                        \
>> +
>>  #if CONFIG_H264_MEDIACODEC_DECODER
>> -AVCodec ff_h264_mediacodec_decoder = {
>> -    .name           = "h264_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_H264,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .bsfs           = "h264_mp4toannexb",
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264,
>> "h264_mp4toannexb")
>>  #endif
>>
>>  #if CONFIG_HEVC_MEDIACODEC_DECODER
>> -AVCodec ff_hevc_mediacodec_decoder = {
>> -    .name           = "hevc_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_HEVC,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .bsfs           = "hevc_mp4toannexb",
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC,
>> "hevc_mp4toannexb")
>>  #endif
>>
>>  #if CONFIG_MPEG2_MEDIACODEC_DECODER
>> -AVCodec ff_mpeg2_mediacodec_decoder = {
>> -    .name           = "mpeg2_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_MPEG2VIDEO,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(mpeg2, "MPEG-2", AV_CODEC_ID_MPEG2VIDEO, NULL)
>>  #endif
>>
>>  #if CONFIG_MPEG4_MEDIACODEC_DECODER
>> -AVCodec ff_mpeg4_mediacodec_decoder = {
>> -    .name           = "mpeg4_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_MPEG4,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4, NULL)
>>  #endif
>>
>>  #if CONFIG_VP8_MEDIACODEC_DECODER
>> -AVCodec ff_vp8_mediacodec_decoder = {
>> -    .name           = "vp8_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_VP8,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL)
>>  #endif
>>
>>  #if CONFIG_VP9_MEDIACODEC_DECODER
>> -AVCodec ff_vp9_mediacodec_decoder = {
>> -    .name           = "vp9_mediacodec",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec
>> decoder"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_VP9,
>> -    .priv_data_size = sizeof(MediaCodecH264DecContext),
>> -    .init           = mediacodec_decode_init,
>> -    .receive_frame  = mediacodec_receive_frame,
>> -    .flush          = mediacodec_decode_flush,
>> -    .close          = mediacodec_decode_close,
>> -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
>> AV_CODEC_CAP_HARDWARE,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .hw_configs     = mediacodec_hw_configs,
>> -    .wrapper_name   = "mediacodec",
>> -};
>> +DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL)
>>  #endif
>>
>
> Patchset LGTM. Nice cleanups, and works as expected on my device.
>
> Aman
>
>
>> --
>> 2.16.2
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>>
>
>
Matthieu Bouron March 3, 2018, 1:12 p.m. UTC | #3
On Fri, Mar 02, 2018 at 04:24:24PM -0800, Aman Gupta wrote:
> On Fri, Mar 2, 2018 at 4:13 PM, Matthieu Bouron <matthieu.bouron@gmail.com>
> wrote:
> 
> > ---
> >  libavcodec/mediacodecdec.c | 116 ++++++++++--------------------
> > ---------------
> >  1 file changed, 24 insertions(+), 92 deletions(-)
> >
> > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > index 4579da1fa5..5e9714ee6e 100644
> > --- a/libavcodec/mediacodecdec.c
> > +++ b/libavcodec/mediacodecdec.c
> > @@ -485,112 +485,44 @@ static const AVCodecHWConfigInternal
> > *mediacodec_hw_configs[] = {
> >      NULL
> >  };
> >
> > +#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
> >                       \
> > +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_data_size = sizeof(MediaCodecH264DecContext),
> >                       \
> > +    .init           = mediacodec_decode_init,
> >                       \
> > +    .receive_frame  = mediacodec_receive_frame,
> >                       \
> > +    .flush          = mediacodec_decode_flush,
> >                      \
> > +    .close          = mediacodec_decode_close,
> >                      \
> > +    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE, \
> > +    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> >                      \
> > +    .bsfs           = bsf,
> >                      \
> > +    .hw_configs     = mediacodec_hw_configs,
> >                      \
> > +    .wrapper_name   = "mediacodec",
> >                       \
> > +};
> >                      \
> > +
> >  #if CONFIG_H264_MEDIACODEC_DECODER
> > -AVCodec ff_h264_mediacodec_decoder = {
> > -    .name           = "h264_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_H264,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .bsfs           = "h264_mp4toannexb",
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264,
> > "h264_mp4toannexb")
> >  #endif
> >
> >  #if CONFIG_HEVC_MEDIACODEC_DECODER
> > -AVCodec ff_hevc_mediacodec_decoder = {
> > -    .name           = "hevc_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_HEVC,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .bsfs           = "hevc_mp4toannexb",
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC,
> > "hevc_mp4toannexb")
> >  #endif
> >
> >  #if CONFIG_MPEG2_MEDIACODEC_DECODER
> > -AVCodec ff_mpeg2_mediacodec_decoder = {
> > -    .name           = "mpeg2_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_MPEG2VIDEO,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(mpeg2, "MPEG-2", AV_CODEC_ID_MPEG2VIDEO, NULL)
> >  #endif
> >
> >  #if CONFIG_MPEG4_MEDIACODEC_DECODER
> > -AVCodec ff_mpeg4_mediacodec_decoder = {
> > -    .name           = "mpeg4_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_MPEG4,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4, NULL)
> >  #endif
> >
> >  #if CONFIG_VP8_MEDIACODEC_DECODER
> > -AVCodec ff_vp8_mediacodec_decoder = {
> > -    .name           = "vp8_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_VP8,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL)
> >  #endif
> >
> >  #if CONFIG_VP9_MEDIACODEC_DECODER
> > -AVCodec ff_vp9_mediacodec_decoder = {
> > -    .name           = "vp9_mediacodec",
> > -    .long_name      = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec
> > decoder"),
> > -    .type           = AVMEDIA_TYPE_VIDEO,
> > -    .id             = AV_CODEC_ID_VP9,
> > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > -    .init           = mediacodec_decode_init,
> > -    .receive_frame  = mediacodec_receive_frame,
> > -    .flush          = mediacodec_decode_flush,
> > -    .close          = mediacodec_decode_close,
> > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > AV_CODEC_CAP_HARDWARE,
> > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > -    .hw_configs     = mediacodec_hw_configs,
> > -    .wrapper_name   = "mediacodec",
> > -};
> > +DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL)
> >  #endif
> >
> 
> Patchset LGTM. Nice cleanups, and works as expected on my device.

I will push the patchset in a few hours (with the space between full_name
and "Android" added).

Thanks,

[...]
Matthieu Bouron March 3, 2018, 9:09 p.m. UTC | #4
On Sat, Mar 03, 2018 at 02:12:32PM +0100, Matthieu Bouron wrote:
> On Fri, Mar 02, 2018 at 04:24:24PM -0800, Aman Gupta wrote:
> > On Fri, Mar 2, 2018 at 4:13 PM, Matthieu Bouron <matthieu.bouron@gmail.com>
> > wrote:
> > 
> > > ---
> > >  libavcodec/mediacodecdec.c | 116 ++++++++++--------------------
> > > ---------------
> > >  1 file changed, 24 insertions(+), 92 deletions(-)
> > >
> > > diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
> > > index 4579da1fa5..5e9714ee6e 100644
> > > --- a/libavcodec/mediacodecdec.c
> > > +++ b/libavcodec/mediacodecdec.c
> > > @@ -485,112 +485,44 @@ static const AVCodecHWConfigInternal
> > > *mediacodec_hw_configs[] = {
> > >      NULL
> > >  };
> > >
> > > +#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)
> > >                       \
> > > +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_data_size = sizeof(MediaCodecH264DecContext),
> > >                       \
> > > +    .init           = mediacodec_decode_init,
> > >                       \
> > > +    .receive_frame  = mediacodec_receive_frame,
> > >                       \
> > > +    .flush          = mediacodec_decode_flush,
> > >                      \
> > > +    .close          = mediacodec_decode_close,
> > >                      \
> > > +    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE, \
> > > +    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > >                      \
> > > +    .bsfs           = bsf,
> > >                      \
> > > +    .hw_configs     = mediacodec_hw_configs,
> > >                      \
> > > +    .wrapper_name   = "mediacodec",
> > >                       \
> > > +};
> > >                      \
> > > +
> > >  #if CONFIG_H264_MEDIACODEC_DECODER
> > > -AVCodec ff_h264_mediacodec_decoder = {
> > > -    .name           = "h264_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_H264,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .bsfs           = "h264_mp4toannexb",
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264,
> > > "h264_mp4toannexb")
> > >  #endif
> > >
> > >  #if CONFIG_HEVC_MEDIACODEC_DECODER
> > > -AVCodec ff_hevc_mediacodec_decoder = {
> > > -    .name           = "hevc_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_HEVC,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .bsfs           = "hevc_mp4toannexb",
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC,
> > > "hevc_mp4toannexb")
> > >  #endif
> > >
> > >  #if CONFIG_MPEG2_MEDIACODEC_DECODER
> > > -AVCodec ff_mpeg2_mediacodec_decoder = {
> > > -    .name           = "mpeg2_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_MPEG2VIDEO,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(mpeg2, "MPEG-2", AV_CODEC_ID_MPEG2VIDEO, NULL)
> > >  #endif
> > >
> > >  #if CONFIG_MPEG4_MEDIACODEC_DECODER
> > > -AVCodec ff_mpeg4_mediacodec_decoder = {
> > > -    .name           = "mpeg4_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_MPEG4,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4, NULL)
> > >  #endif
> > >
> > >  #if CONFIG_VP8_MEDIACODEC_DECODER
> > > -AVCodec ff_vp8_mediacodec_decoder = {
> > > -    .name           = "vp8_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_VP8,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL)
> > >  #endif
> > >
> > >  #if CONFIG_VP9_MEDIACODEC_DECODER
> > > -AVCodec ff_vp9_mediacodec_decoder = {
> > > -    .name           = "vp9_mediacodec",
> > > -    .long_name      = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec
> > > decoder"),
> > > -    .type           = AVMEDIA_TYPE_VIDEO,
> > > -    .id             = AV_CODEC_ID_VP9,
> > > -    .priv_data_size = sizeof(MediaCodecH264DecContext),
> > > -    .init           = mediacodec_decode_init,
> > > -    .receive_frame  = mediacodec_receive_frame,
> > > -    .flush          = mediacodec_decode_flush,
> > > -    .close          = mediacodec_decode_close,
> > > -    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING |
> > > AV_CODEC_CAP_HARDWARE,
> > > -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
> > > -    .hw_configs     = mediacodec_hw_configs,
> > > -    .wrapper_name   = "mediacodec",
> > > -};
> > > +DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL)
> > >  #endif
> > >
> > 
> > Patchset LGTM. Nice cleanups, and works as expected on my device.
> 
> I will push the patchset in a few hours (with the space between full_name
> and "Android" added).

Patchset applied.
diff mbox

Patch

diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c
index 4579da1fa5..5e9714ee6e 100644
--- a/libavcodec/mediacodecdec.c
+++ b/libavcodec/mediacodecdec.c
@@ -485,112 +485,44 @@  static const AVCodecHWConfigInternal *mediacodec_hw_configs[] = {
     NULL
 };
 
+#define DECLARE_MEDIACODEC_VDEC(short_name, full_name, codec_id, bsf)                          \
+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_data_size = sizeof(MediaCodecH264DecContext),                                        \
+    .init           = mediacodec_decode_init,                                                  \
+    .receive_frame  = mediacodec_receive_frame,                                                \
+    .flush          = mediacodec_decode_flush,                                                 \
+    .close          = mediacodec_decode_close,                                                 \
+    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE, \
+    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,                                               \
+    .bsfs           = bsf,                                                                     \
+    .hw_configs     = mediacodec_hw_configs,                                                   \
+    .wrapper_name   = "mediacodec",                                                            \
+};                                                                                             \
+
 #if CONFIG_H264_MEDIACODEC_DECODER
-AVCodec ff_h264_mediacodec_decoder = {
-    .name           = "h264_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("H.264 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_H264,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .bsfs           = "h264_mp4toannexb",
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(h264, "H.264", AV_CODEC_ID_H264, "h264_mp4toannexb")
 #endif
 
 #if CONFIG_HEVC_MEDIACODEC_DECODER
-AVCodec ff_hevc_mediacodec_decoder = {
-    .name           = "hevc_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("H.265 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_HEVC,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .bsfs           = "hevc_mp4toannexb",
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(hevc, "H.265", AV_CODEC_ID_HEVC, "hevc_mp4toannexb")
 #endif
 
 #if CONFIG_MPEG2_MEDIACODEC_DECODER
-AVCodec ff_mpeg2_mediacodec_decoder = {
-    .name           = "mpeg2_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-2 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_MPEG2VIDEO,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(mpeg2, "MPEG-2", AV_CODEC_ID_MPEG2VIDEO, NULL)
 #endif
 
 #if CONFIG_MPEG4_MEDIACODEC_DECODER
-AVCodec ff_mpeg4_mediacodec_decoder = {
-    .name           = "mpeg4_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("MPEG-4 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_MPEG4,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(mpeg4, "MPEG-4", AV_CODEC_ID_MPEG4, NULL)
 #endif
 
 #if CONFIG_VP8_MEDIACODEC_DECODER
-AVCodec ff_vp8_mediacodec_decoder = {
-    .name           = "vp8_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("VP8 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_VP8,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(vp8, "VP8", AV_CODEC_ID_VP8, NULL)
 #endif
 
 #if CONFIG_VP9_MEDIACODEC_DECODER
-AVCodec ff_vp9_mediacodec_decoder = {
-    .name           = "vp9_mediacodec",
-    .long_name      = NULL_IF_CONFIG_SMALL("VP9 Android MediaCodec decoder"),
-    .type           = AVMEDIA_TYPE_VIDEO,
-    .id             = AV_CODEC_ID_VP9,
-    .priv_data_size = sizeof(MediaCodecH264DecContext),
-    .init           = mediacodec_decode_init,
-    .receive_frame  = mediacodec_receive_frame,
-    .flush          = mediacodec_decode_flush,
-    .close          = mediacodec_decode_close,
-    .capabilities   = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_HARDWARE,
-    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
-    .hw_configs     = mediacodec_hw_configs,
-    .wrapper_name   = "mediacodec",
-};
+DECLARE_MEDIACODEC_VDEC(vp9, "VP9", AV_CODEC_ID_VP9, NULL)
 #endif