[FFmpeg-devel] [PATCH] DTS-HD demuxer

Michael Niedermayer michaelni at gmx.at
Tue Oct 9 00:12:37 CEST 2012


On Mon, Oct 08, 2012 at 10:00:37AM +0000, Paul B Mahol wrote:
> Signed-off-by: Paul B Mahol <onemda at gmail.com>
> ---
>  configure                |   1 +
>  doc/general.texi         |   1 +
>  libavformat/Makefile     |   1 +
>  libavformat/allformats.c |   1 +
>  libavformat/dtshddec.c   | 137 +++++++++++++++++++++++++++++++++++++++++++++++
>  5 files changed, 141 insertions(+)
>  create mode 100644 libavformat/dtshddec.c
> 
> diff --git a/configure b/configure
> index 85fab2d..9b724e7 100755
> --- a/configure
> +++ b/configure
> @@ -1798,6 +1798,7 @@ asf_stream_muxer_select="asf_muxer"
>  avisynth_demuxer_deps="avisynth"
>  dirac_demuxer_select="dirac_parser"
>  dts_demuxer_select="dca_parser"
> +dtshd_demuxer_select="dca_parser"
>  eac3_demuxer_select="ac3_parser"
>  f4v_muxer_select="mov_muxer"
>  flac_demuxer_select="flac_parser"
> diff --git a/doc/general.texi b/doc/general.texi
> index 9cba7bb..7f50c11 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -287,6 +287,7 @@ library:
>  @item raw Dirac                 @tab X @tab X
>  @item raw DNxHD                 @tab X @tab X
>  @item raw DTS                   @tab X @tab X
> + at item raw DTS-HD                @tab   @tab X
>  @item raw E-AC-3                @tab X @tab X
>  @item raw FLAC                  @tab X @tab X
>  @item raw GSM                   @tab   @tab X
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 1fd616b..6f8a9fa 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -80,6 +80,7 @@ OBJS-$(CONFIG_DIRAC_MUXER)               += rawenc.o
>  OBJS-$(CONFIG_DNXHD_DEMUXER)             += dnxhddec.o rawdec.o
>  OBJS-$(CONFIG_DNXHD_MUXER)               += rawenc.o
>  OBJS-$(CONFIG_DSICIN_DEMUXER)            += dsicin.o
> +OBJS-$(CONFIG_DTSHD_DEMUXER)             += dtshddec.o
>  OBJS-$(CONFIG_DTS_DEMUXER)               += dtsdec.o rawdec.o
>  OBJS-$(CONFIG_DTS_MUXER)                 += rawenc.o
>  OBJS-$(CONFIG_DV_DEMUXER)                += dv.o
> diff --git a/libavformat/allformats.c b/libavformat/allformats.c
> index f1e8edc..00f11f4 100644
> --- a/libavformat/allformats.c
> +++ b/libavformat/allformats.c
> @@ -88,6 +88,7 @@ void av_register_all(void)
>      REGISTER_MUXDEMUX (DNXHD, dnxhd);
>      REGISTER_DEMUXER  (DSICIN, dsicin);
>      REGISTER_MUXDEMUX (DTS, dts);
> +    REGISTER_DEMUXER  (DTSHD, dtshd);
>      REGISTER_MUXDEMUX (DV, dv);
>      REGISTER_DEMUXER  (DXA, dxa);
>      REGISTER_DEMUXER  (EA, ea);
> diff --git a/libavformat/dtshddec.c b/libavformat/dtshddec.c
> new file mode 100644
> index 0000000..e9e0984
> --- /dev/null
> +++ b/libavformat/dtshddec.c
> @@ -0,0 +1,137 @@
> +/*
> + * Raw DTS-HD demuxer
> + * Copyright (c) 2012 Paul B Mahol
> + *
> + * 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 "libavutil/dict.h"
> +#include "avformat.h"
> +
> +#define AUPR_HDR 0x415550522D484452
> +#define AUPRINFO 0x41555052494E464F
> +#define BITSHVTB 0x4249545348565442
> +#define BLACKOUT 0x424C41434B4F5554
> +#define BRANCHPT 0x4252414E43485054
> +#define BUILDVER 0x4255494C44564552
> +#define CORESSMD 0x434F524553534D44
> +#define DTSHDHDR 0x4454534844484452
> +#define EXTSS_MD 0x45585453535f4d44
> +#define FILEINFO 0x46494C45494E464F
> +#define NAVI_TBL 0x4E4156492D54424C
> +#define STRMDATA 0x5354524D44415441
> +#define TIMECODE 0x54494D45434F4445
> +
> +typedef struct DTSHDDemuxContext {
> +    uint64_t    left;
> +} DTSHDDemuxContext;
> +
> +static int dtshd_probe(AVProbeData *p)
> +{
> +    if (AV_RB64(p->buf) == DTSHDHDR)
> +        return AVPROBE_SCORE_MAX;
> +    return 0;
> +}
> +
> +static int dtshd_read_header(AVFormatContext *s)
> +{
> +    DTSHDDemuxContext *dtshd = s->priv_data;
> +    AVIOContext *pb = s->pb;
> +    uint64_t chunk_type, chunk_size;
> +    AVStream *st;
> +    int ret;
> +    char *value;
> +
> +    st = avformat_new_stream(s, NULL);
> +    if (!st)
> +        return AVERROR(ENOMEM);
> +    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
> +    st->codec->codec_id   = AV_CODEC_ID_DTS;
> +    st->need_parsing      = AVSTREAM_PARSE_FULL_RAW;
> +
> +    while (!url_feof(pb)) {
> +        chunk_type = avio_rb64(pb);
> +        chunk_size = avio_rb64(pb);
> +
> +        if (chunk_size < 4) {
> +            av_log(s, AV_LOG_ERROR, "chunk size too small\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +        if (chunk_size > ((uint64_t)1 << 61)) {
> +            av_log(s, AV_LOG_ERROR, "chunk size too big\n");
> +            return AVERROR_INVALIDDATA;
> +        }
> +
> +        switch (chunk_type) {
> +        case STRMDATA:
> +            dtshd->left = chunk_size;
> +            return 0;
> +            break;
> +        case FILEINFO:
> +            value = av_malloc(chunk_size);
> +            if (!value) {
> +                avio_skip(pb, chunk_size);
> +                break;
> +            }
> +            avio_read(pb, value, chunk_size);
> +            value[chunk_size - 1] = 0;

consider a 32bit system
int and size_t are 32bit
chunk_size is larger, lets assume its (1<<32)+123

malloc will only see 123 but
value[chunk_size - 1] = 0; will see (1<<32)+123-1

except that the patch LGTM

thanks

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Republics decline into democracies and democracies degenerate into
despotisms. -- Aristotle
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121009/baab6575/attachment.asc>


More information about the ffmpeg-devel mailing list