[FFmpeg-devel] [PATCH] rl2 format demuxer
    Michael Niedermayer 
    michaelni
       
    Sun Mar 16 22:56:23 CET 2008
    
    
  
On Sun, Mar 16, 2008 at 03:21:15PM +0100, Sascha Sommer wrote:
[...]
> +/**
> + * read rl2 header data and setup the avstreams
> + * @param s demuxer context
> + * @param ap format parameters
> + * @return 0 on success, AVERROR otherwise
> + */
> +static int rl2_read_header(AVFormatContext *s,
> +                            AVFormatParameters *ap)
> +{
> +    ByteIOContext *pb = s->pb;
> +    AVStream *st;
> +    unsigned int frame_count;
> +    unsigned int audio_frame_counter = 0;
> +    unsigned int video_frame_counter = 0;
> +    unsigned int back_size;
> +    int data_size;
> +    unsigned short encoding_method; 
> +    unsigned short sound_rate;
> +    unsigned short rate;
> +    unsigned short channels;
> +    unsigned short def_sound_size;
> +    unsigned int signature;
> +    unsigned int pts_den = 11025; /* video only case */
> +    unsigned int pts_num = 1103; 
> +    unsigned int* chunk_offset;
> +    int* chunk_size;
> +    int* audio_size;
> +    int i;
> +    int ret = 0;
> +    
trailing whitespace ...
[...]
> +    chunk_size = av_malloc(frame_count * sizeof(uint32_t));
> +    audio_size = av_malloc(frame_count * sizeof(uint32_t));
> +    chunk_offset = av_malloc(frame_count * sizeof(uint32_t));
> +
> +    if(!chunk_size || !audio_size || !chunk_offset)
> +        return AVERROR(ENOMEM);
memleak
> +
> +    /** read offset and size tables */
> +    for(i=0; i < frame_count;i++)
> +        chunk_size[i] = get_le32(pb);
> +    for(i=0; i < frame_count;i++)
> +        chunk_offset[i] = get_le32(pb);
> +    for(i=0; i < frame_count;i++)
> +        audio_size[i] = get_le32(pb) & 0xFFFF;
> +
> +    /** build the sample index */
> +    for(i=0;i<frame_count;i++){
> +        if(audio_size[i] < 0 || chunk_size[i] < 0 ||
> +             audio_size[i] > chunk_size[i]){
> +            ret = AVERROR_INVALIDDATA;
> +            break;
> +        }
audio_size[i] < 0 is impossible
[...]
> +    int stream_id = -1;
> +
> +    /** check if there is a valid video entry that can be used */
> +    if(rl2->index_pos[0] < s->streams[0]->nb_index_entries)
> +        stream_id = 0;
> +
> +    /** check if there is a valid audio entry that can be used */
> +    if(s->nb_streams && rl2->index_pos[1] < s->streams[1]->nb_index_entries){
> +        /** prefer the entry with the lowest position */
> +        if(!stream_id){
> +            stream_id = s->streams[0]->index_entries[ rl2->index_pos[0] ].pos > 
> +                s->streams[1]->index_entries[ rl2->index_pos[1] ].pos;
> +        }else
> +            stream_id = 1;
> +    }
s->nb_streams should be 1 or 2 so the check is not too usefull.
pos= INT64_MAX;
for(i=0; i<s->nb_streams; i++){
    if(   rl2->index_pos[i] < s->streams[i]->nb_index_entries
       && s->streams[i]->index_entries[ rl2->index_pos[i] ].pos < pos){
        sample = &s->streams[i]->index_entries[ rl2->index_pos[i] ];
        pos= sample->pos;
        stream_id= i;
    }
}
[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
No great genius has ever existed without some touch of madness. -- Aristotle
-------------- 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/20080316/fff18a50/attachment.pgp>
    
    
More information about the ffmpeg-devel
mailing list