On Wed, Apr 27, 2011 at 05:19:25PM -0700, Aℓex Converse wrote:
> It's a little ugly but without chain demux it isn't something we can
> do particularly cleanly. This is similar to how we do LATM.
> 
> Let me know if you think the git metadata should be different.

> Ported-by: Alex Converse <[email protected]>
> ---
>  libavcodec/Makefile    |    1 +
>  libavcodec/allcodecs.c |    1 +
>  libavcodec/avcodec.h   |    1 +
>  libavcodec/s302m.c     |  142 
> ++++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/mpegts.c   |    1 +
>  5 files changed, 146 insertions(+), 0 deletions(-)
>  create mode 100644 libavcodec/s302m.c

This is missing a version bump and a changelog entry.

> --- /dev/null
> +++ b/libavcodec/s302m.c
> @@ -0,0 +1,142 @@
> +/*
> + * SMPTE 302M decoder
> + * Copyright (c) 2008 Laurent Aimar <[email protected]>
> + * Copyright (c) 2009 Baptiste Coudurier <[email protected]>
> + *
> + * This file is part of FFmpeg.

Ahem...

> +static int s302m_parse_frame_header(AVCodecContext *avctx, const uint8_t 
> *buf, int buf_size)

nit: long line

> +    if (AES3_HEADER_LEN + frame_size != buf_size || bits > 24) {
> +        av_log(avctx, AV_LOG_ERROR, "frame has invalid header\n");
> +        return -1;

AVERROR_INVALIDDATA?

> +    avctx->channels = channels;
> +    avctx->sample_rate = 48000;
> +    avctx->bit_rate = 48000*avctx->channels*(avctx->bits_per_coded_sample+4) 
> +
> +        
> 32*(48000/(buf_size*8/(avctx->channels*(avctx->bits_per_coded_sample+4))));

nit: Align the '=' and please give the operators some room to breathe.

> +static int s302m_decode_frame(AVCodecContext *avctx,
> +                              void *data, int *data_size,
> +                              AVPacket *avpkt)
> +{
> +    const uint8_t *buf = avpkt->data;
> +    int frame_size, buf_size = avpkt->size;

nit: align

> +    frame_size = s302m_parse_frame_header(avctx, buf, buf_size);
> +    if (frame_size < 0)
> +        return -1;

AVERROR_INVALIDDATA?

> +    if (*data_size < 4*buf_size*8/(avctx->bits_per_coded_sample+4))
> +        return -1;

nit: Please give the operators some room to breathe.

> +    if (avctx->bits_per_coded_sample == 24) {
> +        uint32_t *o = data;
> +        for (; buf_size > 6; buf_size -= 7) {
> +            *o++ = (av_reverse[buf[2]]      << 24) |
> +                   (av_reverse[buf[1]]      << 16) |
> +                   (av_reverse[buf[0]]      <<  8);
> +            *o++ = (av_reverse[buf[6]&0xf0] << 28) |
> +                   (av_reverse[buf[5]]      << 20) |
> +                   (av_reverse[buf[4]]      << 12) |
> +                   (av_reverse[buf[3]&0x0f] <<  8);
> +            buf += 7;
> +        }
> +        *data_size = (uint8_t*)o - (uint8_t*)data;
> +    } else if (avctx->bits_per_coded_sample == 20) {
> +        uint32_t *o = data;
> +        for (; buf_size > 5; buf_size -= 6) {
> +            *o++ = (av_reverse[buf[2]&0xf0] << 28) |
> +                   (av_reverse[buf[1]]      << 20) |
> +                   (av_reverse[buf[0]]      << 12);
> +            *o++ = (av_reverse[buf[5]&0xf0] << 28) |
> +                   (av_reverse[buf[4]]      << 20) |
> +                   (av_reverse[buf[3]]      << 12);
> +            buf += 6;
> +        }
> +        *data_size = (uint8_t*)o - (uint8_t*)data;
> +    } else {
> +        uint16_t *o = data;
> +        for (; buf_size > 4; buf_size -= 5) {
> +            *o++ = (av_reverse[buf[1]]      <<  8) |
> +                    av_reverse[buf[0]];
> +            *o++ = (av_reverse[buf[4]&0xf0] << 12) |
> +                   (av_reverse[buf[3]]      <<  4) |
> +                    av_reverse[buf[2]&0x0f];
> +            buf += 5;
> +        }
> +        *data_size = (uint8_t*)o - (uint8_t*)data;

nit: Please give the '&' some room to breathe.

> +AVCodec ff_s302m_decoder = {
> +    "s302m",
> +    AVMEDIA_TYPE_AUDIO,
> +    CODEC_ID_S302M,
> +    0,
> +    NULL,
> +    NULL,
> +    NULL,
> +    s302m_decode_frame,
> +    .long_name= NULL_IF_CONFIG_SMALL("SMPTE 302M"),
> +};

Please assign the struct members explicitly.

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to