[FFmpeg-devel] [PATCH] imx/d-10 remove klv bitstream filter

Michael Niedermayer michaelni
Mon May 11 03:07:32 CEST 2009


On Sat, May 09, 2009 at 07:33:46PM -0700, Baptiste Coudurier wrote:
> Hi,
> 
> $subject, and remove the check for d-10 in mpeg2 decoder which will no
> longer be needed.
> 
> -- 
> Baptiste COUDURIER                              GnuPG Key Id: 0x5C1ABAAA
> Key fingerprint                 8D77134D20CC9220201FC5DB0AC9325C5C1ABAAA
> FFmpeg maintainer                                  http://www.ffmpeg.org
[...]
> +static int imx_remove_klv(AVBitStreamFilterContext *bsfc, AVCodecContext *avctx, const char *args,
> +                          uint8_t **poutbuf, int *poutbuf_size,
> +                          const uint8_t *buf, int buf_size, int keyframe)
> +{
> +    /* MXF essence element key */
> +    static const uint8_t d10_klv_header[15] = { 0x06,0x0e,0x2b,0x34,0x01,0x02,0x01,0x01,0x0d,0x01,0x03,0x01,0x05,0x01,0x01 };
> +    const uint8_t *bufp = buf;
> +
> +    if (avctx->codec_id != CODEC_ID_MPEG2VIDEO) {
> +        av_log(avctx, AV_LOG_ERROR, "imx bitstream filter only applies to mpeg2video codec\n");
> +        return 0;
> +    }
> +
> +    if (buf_size < 17) {
> +        av_log(avctx, AV_LOG_ERROR, "wrong packet size\n");
> +        return -1;
> +    }
> +
> +    if (!memcmp(buf, d10_klv_header, 15)) {
> +        int64_t frame_size;
> +        bufp += 16;
> +        if ((frame_size = klv_decode_ber_length(&bufp)) < 0) {
> +            av_log(avctx, AV_LOG_ERROR, "error decoding klv length\n");
> +            return -1;
> +        }
> +        if (bufp - buf + frame_size > buf_size) {
> +            av_log(avctx, AV_LOG_ERROR, "wrong frame size\n");
> +            return -1;
> +        }
> +        *poutbuf = av_malloc(frame_size);
> +        if (!*poutbuf)
> +            return AVERROR(ENOMEM);
> +        memcpy(*poutbuf, bufp, frame_size);

frame_size is int64_t, av_malloc() takes unsigned int and memcpy takes
size_t
this is a risky combination i think if int64_t does not fit in int but
in size_t
av_malloc*() really should take size_t as well

also we should maybe extend the API so that a bitstream filter knows
if it can saftely change the content of the input buffer and thus avoid
a malloc&copy

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20090511/ab2c28af/attachment.pgp>



More information about the ffmpeg-devel mailing list