[FFmpeg-devel] [PATCH] mmaldec: Add mpeg2 decoding support

Julian Scheel julian at jusst.de
Wed Oct 21 16:29:19 CEST 2015


Am 21.10.2015 um 16:09 schrieb Hendrik Leppkes:
> On Wed, Oct 21, 2015 at 3:54 PM, Julian Scheel <julian at jusst.de> wrote:
>> Register mmaldec as mpeg2 decoder. Supporting mpeg2 in mmaldec is just a
>> matter of setting the correct MMAL_ENCODING on the input port. To ease the
>> addition of further supported mmal codecs a macro is introduced to generate
>> the decoder and decoder class structs.
>>
>> Signed-off-by: Julian Scheel <julian at jusst.de>
>> ---
>>   configure              |  3 +++
>>   libavcodec/Makefile    |  1 +
>>   libavcodec/allcodecs.c |  2 ++
>>   libavcodec/mmaldec.c   | 71 +++++++++++++++++++++++++++++++++-----------------
>>   4 files changed, 53 insertions(+), 24 deletions(-)
>>
>> diff --git a/configure b/configure
>> index 1bbaf7f..a38b290 100755
>> --- a/configure
>> +++ b/configure
>> @@ -2481,6 +2481,9 @@ mpeg2_d3d11va_hwaccel_deps="d3d11va"
>>   mpeg2_d3d11va_hwaccel_select="mpeg2video_decoder"
>>   mpeg2_dxva2_hwaccel_deps="dxva2"
>>   mpeg2_dxva2_hwaccel_select="mpeg2video_decoder"
>> +mpeg2_mmal_decoder_deps="mmal"
>> +mpeg2_mmal_hwaccel_deps="mmal"
>> +mpeg2_mmal_decoder_select="mpeg2video_decoder"
>>   mpeg2_qsv_hwaccel_deps="libmfx"
>>   mpeg2_qsv_hwaccel_select="qsvdec_mpeg2"
>>   mpeg2_vaapi_hwaccel_deps="vaapi"
>> diff --git a/libavcodec/Makefile b/libavcodec/Makefile
>> index af93f8a..f85fc18 100644
>> --- a/libavcodec/Makefile
>> +++ b/libavcodec/Makefile
>> @@ -370,6 +370,7 @@ OBJS-$(CONFIG_MPEG1VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
>>   OBJS-$(CONFIG_MPEG1VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
>>   OBJS-$(CONFIG_MPEG2VIDEO_DECODER)      += mpeg12dec.o mpeg12.o mpeg12data.o
>>   OBJS-$(CONFIG_MPEG2VIDEO_ENCODER)      += mpeg12enc.o mpeg12.o
>> +OBJS-$(CONFIG_MPEG2_MMAL_DECODER)      += mmaldec.o
>>   OBJS-$(CONFIG_MPEG2_QSV_DECODER)       += qsvdec_mpeg2.o
>>   OBJS-$(CONFIG_MPEG2_QSV_ENCODER)       += qsvenc_mpeg2.o
>>   OBJS-$(CONFIG_MPEG4_DECODER)           += xvididct.o
>> diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
>> index d62bec7..7279620 100644
>> --- a/libavcodec/allcodecs.c
>> +++ b/libavcodec/allcodecs.c
>> @@ -97,6 +97,7 @@ void avcodec_register_all(void)
>>       REGISTER_HWACCEL(MPEG2_XVMC,        mpeg2_xvmc);
>>       REGISTER_HWACCEL(MPEG2_D3D11VA,     mpeg2_d3d11va);
>>       REGISTER_HWACCEL(MPEG2_DXVA2,       mpeg2_dxva2);
>> +    REGISTER_HWACCEL(MPEG2_MMAL,        mpeg2_mmal);
>>       REGISTER_HWACCEL(MPEG2_QSV,         mpeg2_qsv);
>>       REGISTER_HWACCEL(MPEG2_VAAPI,       mpeg2_vaapi);
>>       REGISTER_HWACCEL(MPEG2_VDPAU,       mpeg2_vdpau);
>> @@ -238,6 +239,7 @@ void avcodec_register_all(void)
>>       REGISTER_DECODER(MPEG_VDPAU,        mpeg_vdpau);
>>       REGISTER_DECODER(MPEG1_VDPAU,       mpeg1_vdpau);
>>   #endif
>> +    REGISTER_DECODER(MPEG2_MMAL,        mpeg2_mmal);
>>       REGISTER_DECODER(MPEG2_CRYSTALHD,   mpeg2_crystalhd);
>>       REGISTER_DECODER(MPEG2_QSV,         mpeg2_qsv);
>>       REGISTER_DECODER(MSA1,              msa1);
>> diff --git a/libavcodec/mmaldec.c b/libavcodec/mmaldec.c
>> index 13cc191..7db90d2 100644
>> --- a/libavcodec/mmaldec.c
>> +++ b/libavcodec/mmaldec.c
>> @@ -350,7 +350,17 @@ static av_cold int ffmmal_init_decoder(AVCodecContext *avctx)
>>
>>       format_in = decoder->input[0]->format;
>>       format_in->type = MMAL_ES_TYPE_VIDEO;
>> -    format_in->encoding = MMAL_ENCODING_H264;
>> +    switch (avctx->codec_id) {
>> +        case AV_CODEC_ID_MPEG2VIDEO:
>> +            format_in->encoding = MMAL_ENCODING_MP2V;
>> +            av_log(avctx, AV_LOG_ERROR, "Use MP2V encoding!\n");
>> +            break;
>> +        case AV_CODEC_ID_H264:
>> +        default:
>> +            format_in->encoding = MMAL_ENCODING_H264;
>> +            av_log(avctx, AV_LOG_ERROR, "Use H264 encoding!\n");
>> +            break;
>> +    }
>
> These log messages are probably not meant to be in there anymore, not
> as error anyway? :)

Gah, you're right of course. I'll send v2.

>>       format_in->es->video.width = FFALIGN(avctx->width, 32);
>>       format_in->es->video.height = FFALIGN(avctx->height, 16);
>>       format_in->es->video.crop.width = avctx->width;
>> @@ -766,31 +776,44 @@ AVHWAccel ff_h264_mmal_hwaccel = {
>>       .pix_fmt    = AV_PIX_FMT_MMAL,
>>   };
>>
>> +AVHWAccel ff_mpeg2_mmal_hwaccel = {
>> +    .name       = "mpeg2_mmal",
>> +    .type       = AVMEDIA_TYPE_VIDEO,
>> +    .id         = AV_CODEC_ID_MPEG2VIDEO,
>> +    .pix_fmt    = AV_PIX_FMT_MMAL,
>> +};
>> +
>>   static const AVOption options[]={
>>       {"extra_buffers", "extra buffers", offsetof(MMALDecodeContext, extra_buffers), AV_OPT_TYPE_INT, {.i64 = 10}, 0, 256, 0},
>>       {NULL}
>>   };
>>
>> -static const AVClass ffmmaldec_class = {
>> -    .class_name = "mmaldec",
>> -    .option     = options,
>> -    .version    = LIBAVUTIL_VERSION_INT,
>> -};
>> -
>> -AVCodec ff_h264_mmal_decoder = {
>> -    .name           = "h264_mmal",
>> -    .long_name      = NULL_IF_CONFIG_SMALL("h264 (mmal)"),
>> -    .type           = AVMEDIA_TYPE_VIDEO,
>> -    .id             = AV_CODEC_ID_H264,
>> -    .priv_data_size = sizeof(MMALDecodeContext),
>> -    .init           = ffmmal_init_decoder,
>> -    .close          = ffmmal_close_decoder,
>> -    .decode         = ffmmal_decode,
>> -    .flush          = ffmmal_flush,
>> -    .priv_class     = &ffmmaldec_class,
>> -    .capabilities   = AV_CODEC_CAP_DELAY,
>> -    .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS,
>> -    .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_MMAL,
>> -                                                     AV_PIX_FMT_YUV420P,
>> -                                                     AV_PIX_FMT_NONE},
>> -};
>> +#define FFMMAL_DEC_CLASS(NAME) \
>> +    static const AVClass ffmmal_##NAME##_dec_class = { \
>> +        .class_name = "mmal_" #NAME "_dec", \
>> +        .option     = options, \
>> +        .version    = LIBAVUTIL_VERSION_INT, \
>> +    };
>> +
>> +#define FFMMAL_DEC(NAME, ID) \
>> +    FFMMAL_DEC_CLASS(NAME) \
>> +    AVCodec ff_##NAME##_mmal_decoder = { \
>> +        .name           = #NAME "_mmal", \
>> +        .long_name      = NULL_IF_CONFIG_SMALL(#NAME " (mmal)"), \
>> +        .type           = AVMEDIA_TYPE_VIDEO, \
>> +        .id             = ID, \
>> +        .priv_data_size = sizeof(MMALDecodeContext), \
>> +        .init           = ffmmal_init_decoder, \
>> +        .close          = ffmmal_close_decoder, \
>> +        .decode         = ffmmal_decode, \
>> +        .flush          = ffmmal_flush, \
>> +        .priv_class     = &ffmmal_##NAME##_dec_class, \
>> +        .capabilities   = AV_CODEC_CAP_DELAY, \
>> +        .caps_internal  = FF_CODEC_CAP_SETS_PKT_DTS, \
>> +        .pix_fmts       = (const enum AVPixelFormat[]) { AV_PIX_FMT_MMAL, \
>> +                                                         AV_PIX_FMT_YUV420P, \
>> +                                                         AV_PIX_FMT_NONE}, \
>> +    };
>> +
>> +FFMMAL_DEC(h264, AV_CODEC_ID_H264)
>> +FFMMAL_DEC(mpeg2, AV_CODEC_ID_MPEG2VIDEO)
>> --
>> 2.6.0
>>
>>
>> _______________________________________________
>> ffmpeg-devel mailing list
>> ffmpeg-devel at ffmpeg.org
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>




More information about the ffmpeg-devel mailing list