[FFmpeg-devel] [PATCH] Demuxer for Leitch/Harris' VR native stream format (LXF)
Michael Niedermayer
michaelni
Thu Sep 2 17:13:59 CEST 2010
On Fri, Aug 27, 2010 at 05:00:39PM +0200, Tomas H?rdin wrote:
> Hi
>
> Attached you'll find a demuxer for the format used by Leitch's video
> servers. It's called the "VR native stream format", but more commonly
> known as LXF for some reason. AFAICT it appears to be memory dumps from
> said hardware.
>
> The demuxer is based mostly off of my own reverse engineering efforts
> and some documentation for a related API to fill in the gaps. I might
> post my results on the wiki if anyone's interested (I need an account
> first though).
>
> Some limitations and quirks:
>
> * VBI data is not handled, but skipped. I'm not sure how it should be
> implemented. I also have no samples with such data
does any of our demuxers support returning VBI data?
[...]
> * Audio is stored in a planar fashion and is always 48 kHz. The audio
> data is de-planerized by the demuxer
this needs a FIXME comment so we can remove it once we support planar
audio or you can implement planar audio if you like ...
>
> * 16-, 20-, 24- and 32-bit PCM is supported. I doubt there are any files
> in the wild with any other sample depths. 20-bit PCM is in-place
> expanded to 24-bit by the demuxer (the top 4 MSBs are copied to the
> bottom 4 LSBs)
this should probably be handeld similar to CODEC_ID_PCM_DVD
>
> * It is possible for a packet to not contain data for all channels (it
> uses a bitmask). In that case I'm not sure how to behave - probably
> output silence for those channels
do you have a sample that uses this feature?
>
> * No support for seeking. Using pkt->pos would probably work for seeking
> backwards
>
> * The format supports B-frames but the demuxer does not. So far I have
> not received a sample the uses them, and the documentation regarding
> them is limited
>
> I uploaded a sample to the FTP in /MPlayer/incoming/lxf called
> 1sec-dv25.lxf. I contains one seconds of PAl DV25 video and 48 kHz
> 16-bit stereo PCM audio. I'm waiting for an OK to upload some MPEG-2
> samples with 4-channel 20-bit and 24-bit audio as well. I have no NTSC
> samples.
>
> I bumped the minor version, added a Changelog entry and an entry in the
> table in docs/general.texi. I also copied the copyright boilerplate and
> added put my name in it.
>
> I ran make test just in case, which of course worked fine.
>
> /Tomas
> Changelog | 1
> doc/general.texi | 2
> libavformat/Makefile | 1
> libavformat/allformats.c | 1
> libavformat/avformat.h | 2
> libavformat/lxfdec.c | 335 +++++++++++++++++++++++++++++++++++++++++++++++
> 6 files changed, 341 insertions(+), 1 deletion(-)
> 63ec225c19f00fbd918bba0b1f6941f63bb6826b lxfdec.patch
> diff --git a/Changelog b/Changelog
> index 59d4339..f8ec194 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -33,6 +33,7 @@ version <next>:
> - Apple HTTP Live Streaming demuxer
> - a64 codec
> - MMS-HTTP support
> +- Demuxer for Leitch/Harris' VR native stream format (LXF)
>
>
> version 0.6:
> diff --git a/doc/general.texi b/doc/general.texi
> index b775e68..522dccd 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 X @tab
> + @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 5c1aaac..3d52bc7 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -103,6 +103,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) += raw.o
> OBJS-$(CONFIG_M4V_MUXER) += raw.o
> OBJS-$(CONFIG_MATROSKA_DEMUXER) += matroskadec.o matroska.o \
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index 6e73e82..8767ebd 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -109,6 +109,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 b95aaa4..f8d866f 100644
> --- a/libavformat/avformat.h
> +++ b/libavformat/avformat.h
> @@ -22,7 +22,7 @@
> #define AVFORMAT_AVFORMAT_H
>
> #define LIBAVFORMAT_VERSION_MAJOR 52
> -#define LIBAVFORMAT_VERSION_MINOR 78
> +#define LIBAVFORMAT_VERSION_MINOR 79
> #define LIBAVFORMAT_VERSION_MICRO 3
>
> #define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
> diff --git a/libavformat/lxfdec.c b/libavformat/lxfdec.c
> new file mode 100644
> index 0000000..de6894c
> --- /dev/null
> +++ b/libavformat/lxfdec.c
> @@ -0,0 +1,335 @@
> +/*
> + * 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
> + int bps; //bits per sample (<= bits_per_coded_sample)
> + uint8_t temp[LXF_MAX_AUDIO_PACKET]; //temp buffer for de-planarizing the audio data
> + int num_frames; //used to calculate duration
> + int frame_number;
> +} LXFDemuxContext;
> +
> +static int lxf_probe(AVProbeData *p)
> +{
> + if (p->buf_size < LXF_IDENT_LENGTH)
> + return 0;
unneeded
> +
> + if (!memcmp(p->buf, LXF_IDENT, LXF_IDENT_LENGTH))
> + return AVPROBE_SCORE_MAX;
> +
> + return 0;
> +}
> +
> +//returns zero if checksum is OK, non-zero otherwise
doxy
> +static int check_checksum(unsigned char *header)
> +{
> + int x, sum = 0;
> +
> + for (x = 0; x < LXF_PACKET_HEADER_SIZE; x += 4)
> + sum += AV_RL32(&header[x]);
> +
> + return sum;
unsigned sum, signed numbers have undefined overflow in C IIRC and
if one is picky
> +}
> +
> +//returns number of bits set in value
> +static int num_set_bits(uint32_t value) {
> + int ret;
> +
> + for(ret = 0; value; ret += (value & 1), value >>= 1);
> +
> + return ret;
> +}
if we dont have a population count function yet, than one should be added
to some header in libavutil
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Everything should be made as simple as possible, but not simpler.
-- Albert Einstein
-------------- 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/20100902/55153ccd/attachment.pgp>
More information about the ffmpeg-devel
mailing list