[FFmpeg-devel] [PATCH] VC-1 SP/MP test bitstreams demuxer

Michael Niedermayer michaelni
Sat Jan 26 17:49:04 CET 2008


On Sat, Jan 26, 2008 at 05:46:01PM +0200, Kostya wrote:
> $subj, taken from 2006 SoC project and updated for current API.

> Index: libavformat/vc1test.c
> ===================================================================
> --- libavformat/vc1test.c	(revision 0)
> +++ libavformat/vc1test.c	(revision 0)
[...]
> +/**
> + * @file vc1test.c
> + * VC1 test bitstreams file demuxer
> + * by Konstantin Shishkov
> + * Format specified in SMPTE standard 421 Annex L
> + */
> +
> +#include "avformat.h"
> +
> +typedef struct VC1testDemuxContext {
> +    int frame_count;
> +    int current_frame;
> +    uint8_t struct_c[4];
> +    uint32_t width, height;
> +    int fps;
> +    int stream_index;
> +} VC1testDemuxContext;
> +

> +static int vc1t_probe(AVProbeData *p)
> +{

> +    if (p->buf_size < 9*4)
> +        return 0;

unneeded


> +
> +    if (p->buf[3] != 0xC5)
> +        return 0;
> +
> +    if (AV_RL32(&p->buf[4]) != 4)
> +        return 0;

these 2 if() can be merged


> +
> +    return AVPROBE_SCORE_MAX;
> +}
> +

> +static int vc1t_read_header(AVFormatContext *s,
> +                           AVFormatParameters *ap)
> +{
> +    VC1testDemuxContext *vcd = (VC1testDemuxContext *)s->priv_data;
> +    ByteIOContext *pb = s->pb;
> +    AVStream *st;
> +    uint32_t value;
> +
> +    value = get_le32(pb);
> +

> +    if((value >> 24) != 0xC5){
> +        av_log(s, AV_LOG_ERROR, "Not a VC1 Simple/Main profile bitstream!\n");
> +        return -1;
> +    }

whats this check good for?


> +    vcd->frame_count = value & 0xFFFFFF;

get_le24(pb);


> +    vcd->current_frame = 0;
> +

> +    value = get_le32(pb);
> +    if(value != 4){

the assignment is redundant


> +        av_log(s, AV_LOG_ERROR, "Not a VC1 Simple/Main profile bitstream!\n");
> +        return -1;
> +    }

again whats this good for? the user will notice if it fails ...


> +
> +    get_buffer(pb, vcd->struct_c, 4);

please read in extradata directly, no redundant copies ...


> +
> +    //profile = vcd->struct_c
> +    vcd->height = get_le32(pb);
> +    vcd->width = get_le32(pb);

no copies, store it where it belongs


> +
> +    value = get_le32(pb);
> +    if(value != 0xC){
> +        av_log(s, AV_LOG_ERROR, "Not a VC1 Simple/Main profile bitstream!\n");
> +        return -1;
> +    }
> +

> +    value = get_le32(pb);
> +    value = get_le32(pb);

nonsense assignment


> +    vcd->fps = get_le32(pb);
> +
> +    /* init video codec */
> +    st = av_new_stream(s, 0);
> +    if (!st)
> +        return -1;
> +
> +    st->codec->width = vcd->width;
> +    st->codec->height = vcd->height;
> +    st->codec->codec_type = CODEC_TYPE_VIDEO;
> +    st->codec->codec_id = CODEC_ID_WMV3;
> +
> +    st->codec->extradata = av_malloc(4);
> +    st->codec->extradata_size = 4;
> +    memcpy(st->codec->extradata, vcd->struct_c, 4);
> +    av_set_pts_info(st, 33, 1, vcd->fps);

a local varaible is sufficient for fps


> +    vcd->stream_index = st->index;

this is 0 so you dont need the variable


> +
> +    return 0;
> +}
> +

> +static int vc1t_read_packet(AVFormatContext *s,
> +                           AVPacket *pkt)
> +{
> +    VC1testDemuxContext *vcd = (VC1testDemuxContext *)s->priv_data;
> +    ByteIOContext *pb = s->pb;
> +    int ret = 0;
> +    uint32_t value;
> +    int frame_size;
> +
> +    if (vcd->current_frame >= vcd->frame_count)
> +        return AVERROR_IO;

and what happens after this? EOF? if so i dont think this check is needed


> +
> +    value = get_le32(pb);
> +    frame_size = value & 0xFFFFFF;

get_le24()


> +    value = get_le32(pb);
> +    if (av_new_packet(pkt, frame_size))
> +        return AVERROR_NOMEM;
> +
> +    ret = get_buffer(pb, pkt->data, frame_size);

av_get_packet()

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

Democracy is the form of government in which you can choose your dictator
-------------- 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/20080126/ebe0c9ff/attachment.pgp>



More information about the ffmpeg-devel mailing list