[FFmpeg-devel] [PATCH] Demuxer for Leitch/Harris' VR native stream format (LXF)

Tomas Härdin tomas.hardin
Tue Sep 14 07:47:36 CEST 2010


On Mon, 2010-09-13 at 20:33 +0200, Michael Niedermayer wrote:
> On Mon, Sep 13, 2010 at 10:56:43AM +0100, M?ns Rullg?rd wrote:
> > Tomas H?rdin <tomas.hardin at codemill.se> writes:
> [...]
> > >> > +//reads and checksums packet header. returns format and size of payload
> > >> > +static int get_packet_header(AVFormatContext *s, unsigned char *header,
> > >> > +                             uint32_t *format)
> > >> > +{
> > >> > +    LXFDemuxContext *lxf = s->priv_data;
> > >> > +    ByteIOContext   *pb  = s->pb;
> > >> > +    int size, track_size, samples;
> > >> > +    AVStream *st;
> > >> > +
> > >> > +    if (get_buffer(pb, header, LXF_PACKET_HEADER_SIZE) != LXF_PACKET_HEADER_SIZE)
> > >> > +        return AVERROR(EIO);
> > >> > +
> > >> > +    if (memcmp(header, LXF_IDENT, LXF_IDENT_LENGTH)) {
> > >> > +        av_log(s, AV_LOG_ERROR, "packet ident mismatch - out of sync?\n");
> > >> > +        return -1;
> > >> > +    }
> > >> > +
> > >> > +    if (check_checksum(header))
> > >> > +        av_log(s, AV_LOG_ERROR, "checksum error\n");
> > >> > +
> > >> > +    *format = AV_RL32(&header[32]);
> > >> > +    size    = AV_RL32(&header[36]);
> > >> > +
> > >> > +    //type
> > >> > +    switch (AV_RL32(&header[16])) {
> > >> > +    case 0:
> > >> > +        //video
> > >> > +        //skip VBI data and metadata
> > >> > +        url_fskip(pb, AV_RL32(&header[44]) + AV_RL32(&header[52]));
> > >> 
> > >> cant this lead to a backward seek and thus infinite loop ?
> > >
> > > Yes, assuming AV_RL32() returns signed. Fixed by casting to uint32_t and
> > > splitting up into two skips.
> 
> split is ugly

Yes, I realized that after I posted the patch. A solution I considered
uses a somewhat ugly double-cast:

url_fskip(pb, (int64_t)(uint32_t)AV_RL32(&header[44]) +
              (int64_t)(uint32_t)AV_RL32(&header[52]));

Maybe that's better in the end though.

> > 
> > AV_RL32() returns an unsigned value.
> 
> maybe it should but i dont think it does
> 
> #   define AV_RL32(x)                           \
>     ((((const uint8_t*)(x))[3] << 24) |         \
>      (((const uint8_t*)(x))[2] << 16) |         \
>      (((const uint8_t*)(x))[1] <<  8) |         \
>       ((const uint8_t*)(x))[0])

If it did then the above code would be a little prettier.

/Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100914/b10272a0/attachment.pgp>



More information about the ffmpeg-devel mailing list