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

Michael Niedermayer michaelni
Sat Sep 25 05:22:51 CEST 2010


On Wed, Sep 15, 2010 at 03:16:44PM +0200, Tomas H?rdin wrote:
> On Mon, 2010-09-13 at 22:06 +0200, Michael Niedermayer wrote:
> > On Mon, Sep 13, 2010 at 08:44:00PM +0100, M?ns Rullg?rd wrote:
> > > Michael Niedermayer <michaelni at gmx.at> writes:
> > > 
> > > > 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
> > > >
> > > >> 
> > > >> 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])
> > > 
> > > You are right.  Should we change it?
> > 
> > i do not know, but at least we should make sure all implementations of AV_R*
> > are consistent in terms of signedness
> 
> I went with a double cast to eliminate the split seek and guarantee that
> they are added together correctly.
> 
> I decided to give the CODEC_ID_PCM_LXF idea a try. Two patches attached:
> one adds a new PCM decoder called "pcm_lxf", which performs both
> unpacking and de-planerization. The other patch is a demuxer that makes
> use of this decoder, which made the code a bit simpler.
> 
> I also cleaned up the code a bit more, especially regarding handling the
> four supported bit depths. It also makes use of av_popcount() now.
> 
> /Tomas

>  Changelog                |    1 
>  doc/general.texi         |    2 
>  libavformat/Makefile     |    1 
>  libavformat/allformats.c |    1 
>  libavformat/avformat.h   |    4 
>  libavformat/lxfdec.c     |  320 +++++++++++++++++++++++++++++++++++++++++++++++
>  6 files changed, 327 insertions(+), 2 deletions(-)
> 3ddced6788bd3a2f817c816d18e0c682347e7834  lxfdec5.patch
> diff --git a/Changelog b/Changelog
> index 503ac43..d7d012c 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -36,6 +36,7 @@ version <next>:
>  - G.722 ADPCM audio decoder
>  - R10k video decoder
>  - ocv_smooth filter
> +- Demuxer for Leitch/Harris' VR native stream format (LXF)
>  
>  
>  version 0.6:
> diff --git a/doc/general.texi b/doc/general.texi
> index 9a3200f..3cb1eea 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -114,6 +114,8 @@ library:
>      @tab A format used by libvpx
>  @item LMLM4                     @tab   @tab X
>      @tab Used by Linux Media Labs MPEG-4 PCI boards
> + at item LXF                       @tab   @tab X
> +    @tab VR native stream format, used by Leitch/Harris' video servers.
>  @item Matroska                  @tab X @tab X
>  @item Matroska audio            @tab X @tab
>  @item MAXIS XA                  @tab   @tab X
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 50ff5de..dfeede7 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -105,6 +105,7 @@ OBJS-$(CONFIG_ISS_DEMUXER)               += iss.o
>  OBJS-$(CONFIG_IV8_DEMUXER)               += iv8.o
>  OBJS-$(CONFIG_IVF_DEMUXER)               += ivfdec.o riff.o
>  OBJS-$(CONFIG_LMLM4_DEMUXER)             += lmlm4.o
> +OBJS-$(CONFIG_LXF_DEMUXER)               += lxfdec.o
>  OBJS-$(CONFIG_M4V_DEMUXER)               += m4vdec.o rawdec.o
>  OBJS-$(CONFIG_M4V_MUXER)                 += rawenc.o
>  OBJS-$(CONFIG_MATROSKA_DEMUXER)          += matroskadec.o matroska.o \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index f9407f0..f9e1fb3 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -110,6 +110,7 @@ void av_register_all(void)
>      REGISTER_DEMUXER  (IV8, iv8);
>      REGISTER_DEMUXER  (IVF, ivf);
>      REGISTER_DEMUXER  (LMLM4, lmlm4);
> +    REGISTER_DEMUXER  (LXF, lxf);
>      REGISTER_MUXDEMUX (M4V, m4v);
>      REGISTER_MUXER    (MD5, md5);
>      REGISTER_MUXDEMUX (MATROSKA, matroska);
> diff --git a/libavformat/avformat.h b/libavformat/avformat.h
> index 0520530..362a056 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -22,8 +22,8 @@
>  #define AVFORMAT_AVFORMAT_H
>  
>  #define LIBAVFORMAT_VERSION_MAJOR 52
> -#define LIBAVFORMAT_VERSION_MINOR 78
> -#define LIBAVFORMAT_VERSION_MICRO  5
> +#define LIBAVFORMAT_VERSION_MINOR 79
> +#define LIBAVFORMAT_VERSION_MICRO  0
>  
>  #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
>                                                 LIBAVFORMAT_VERSION_MINOR, \
> diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c
> new file mode 100644
> index 0000000..3667b69
> --- /dev/null
> +++ b/libavformat/lxfdec.c
> @@ -0,0 +1,320 @@
> +/*
> + * LXF demuxer
> + * Copyright (c) 2010 Tomas H?rdin
> + *
> + * This file is part of FFmpeg.
> + *
> + * FFmpeg is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * FFmpeg is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with FFmpeg; if not, write to the Free Software
> + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
> + */
> +
> +#include "libavutil/intreadwrite.h"
> +#include "avformat.h"
> +#include "riff.h"
> +
> +#define LXF_PACKET_HEADER_SIZE  60
> +#define LXF_HEADER_DATA_SIZE    120
> +#define LXF_IDENT               "LEITCH\0"
> +#define LXF_IDENT_LENGTH        8
> +#define LXF_SAMPLERATE          48000
> +#define LXF_MAX_AUDIO_PACKET    (8008*15*4)     //15-channel 32-bit NTSC audio frame
> +
> +static const AVCodecTag lxf_tags[] = {
> +    { CODEC_ID_MJPEG,       0 },
> +    { CODEC_ID_MPEG1VIDEO,  1 },
> +    { CODEC_ID_MPEG2VIDEO,  2 },    //MpMl, 4:2:0
> +    { CODEC_ID_MPEG2VIDEO,  3 },    //MpPl, 4:2:2
> +    { CODEC_ID_DVVIDEO,     4 },    //DV25
> +    { CODEC_ID_DVVIDEO,     5 },    //DVCPRO
> +    { CODEC_ID_DVVIDEO,     6 },    //DVCPRO50
> +    { CODEC_ID_RAWVIDEO,    7 },    //PIX_FMT_ARGB, where alpha is used for chroma keying
> +    { CODEC_ID_RAWVIDEO,    8 },    //16-bit chroma key
> +    { CODEC_ID_MPEG2VIDEO,  9 },    //4:2:2 CBP ("Constrained Bytes per Gop")
> +    { CODEC_ID_NONE,        0 },
> +};
> +
> +typedef struct {
> +    int channels;                       //number of audio channels. 0 -> no audio
> +    uint8_t temp[LXF_MAX_AUDIO_PACKET]; //temp buffer for de-planarizing the audio data
> +    int frame_number;
> +} LXFDemuxContext;
> +
> +static int lxf_probe(AVProbeData *p)
> +{
> +    if (!memcmp(p->buf, LXF_IDENT, LXF_IDENT_LENGTH))
> +        return AVPROBE_SCORE_MAX;
> +
> +    return 0;
> +}
> +
> +/**
> + * Verify the checksum of an LXF packet header
> + *
> + * @param[in] header the packet header to check
> + * @return zero if the checksum is OK, non-zero otherwise
> + */
> +static int check_checksum(const uint8_t *header)
> +{
> +    int x;
> +    uint32_t sum = 0;
> +
> +    for (x = 0; x < LXF_PACKET_HEADER_SIZE; x += 4)
> +        sum += AV_RL32(&header[x]);
> +
> +    return sum;
> +}
> +
> +/**
> + * 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

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

Complexity theory is the science of finding the exact solution to an
approximation. Benchmarking OTOH is finding an approximation of the exact
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100925/af64e67d/attachment.pgp>



More information about the ffmpeg-devel mailing list