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

Tomas Härdin tomas.hardin
Tue Sep 28 14:59:13 CEST 2010


On Tue, 2010-09-28 at 00:22 +0200, Michael Niedermayer wrote:
> On Mon, Sep 27, 2010 at 09:59:40AM +0200, Tomas H?rdin wrote:
> > On Sat, 2010-09-25 at 05:22 +0200, Michael Niedermayer wrote:
> > > > +
> > > > +/**
> > > > + * Read and checksum the next packet header
> > > > + *
> > > > + * @param[out] header the read packet header
> > > > + * @param[out] format context dependent format information
> > > > + * @return the size of the payload following the header or < 0 on failure
> > > > + */
> > > > +static int get_packet_header(AVFormatContext *s, uint8_t *header, uint32_t *format)
> > > > +{
> > > > +    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;
> > > > +    }
> > > 
> > > searching for the next matching ident instead of failing would make sense
> > 
> > I had thought of that, but forgot to implement it. Updated patch
> > attached. I tested it by corrupting a bunch of idents in my test files.
> > Worked great, except for the obvious packet loss artifacts.
> > 
> > Both patches attached since I rebased against the latest revision.
> > 
> > /Tomas
> [...]
> > +static int lxf_read_packet(AVFormatContext *s, AVPacket *pkt)
> > +{
> > +    LXFDemuxContext *lxf = s->priv_data;
> > +    ByteIOContext   *pb  = s->pb;
> > +    uint8_t header[LXF_PACKET_HEADER_SIZE], *buf;
> > +    int ret, stream, format;
> > +    AVStream *ast = NULL;
> > +
> > +    if ((ret = get_packet_header(s, header, &format)) < 0)
> > +        return ret;
> > +
> > +    av_log(s, AV_LOG_DEBUG, "got %d B packet\n", ret);
> > +
> > +    if ((stream = AV_RL32(&header[16])) == 1 && !(ast = s->streams[stream])) {
> > +        av_log(s, AV_LOG_ERROR, "got audio packet without having an audio stream\n");
> > +        return -1;
> > +    }
> > +
> > +    //make sure the data fits in the de-planerization buffer
> > +    if (ast && ret > LXF_MAX_AUDIO_PACKET) {
> > +        av_log(s, AV_LOG_ERROR, "audio packet too large (%i > %i)\n",
> > +            ret, LXF_MAX_AUDIO_PACKET);
> > +        return -1;
> > +    }
> > +
> > +    if (av_new_packet(pkt, ret))
> > +        return AVERROR_IO;
> > +
> > +    //read non-20-bit audio data into lxf->temp so we can deplanarize it
> > +    buf = ast && ast->codec->codec_id != CODEC_ID_PCM_LXF ? lxf->temp : pkt->data;
> > +
> > +    if (get_buffer(pb, buf, ret) != ret) {
> > +        av_free_packet(pkt);
> > +        return AVERROR_IO;
> > +    }
> > +
> 
> > +    pkt->stream_index = stream;
> 
> this isnt checked for validity

I was unsure whether streams with indices above 1 were legal. It seems
they aren't (the file's header is a "stream" with index 2 though). I
made the muxer return AVERROR(EAGAIN). I chose not to risk a url_fskip()
since the data following the header could be anything. The demuxer
re-syncs itself on the next call.

Again, I hacked the file and put some bogus values in to see whether the
demuxer would take it. It did, ignoring such data.

New patch attached. I also rolled size and ret together in
get_packet_header().

> [...]
> >  allcodecs.c |    1 +
> >  avcodec.h   |    5 +++--
> >  pcm.c       |   26 +++++++++++++++++++++++++-
> >  3 files changed, 29 insertions(+), 3 deletions(-)
> > 02b2b0f0730e657212c3ea98c89783be3f6854cf  pcm_lxf2.patch
> 
> looks ok

Cool. Maybe later I'll submit patches for planar 24-bit and 32-bit audio
which more demuxers might be able to make use of.

/Tomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: lxfdec7.patch
Type: text/x-patch
Size: 14683 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100928/b710f8f9/attachment.bin>
-------------- 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/20100928/b710f8f9/attachment.pgp>



More information about the ffmpeg-devel mailing list