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

Paul B Mahol onemda at gmail.com
Sun Oct 7 21:24:03 CEST 2012


On 10/7/12, Michael Niedermayer <michaelni at gmx.at> wrote:
> On Sun, Oct 07, 2012 at 09:41:43AM +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   | 129
>> +++++++++++++++++++++++++++++++++++++++++++++++
>>  5 files changed, 133 insertions(+)
>>  create mode 100644 libavformat/dtshddec.c
>>
>> diff --git a/configure b/configure
>> index 11519cd..3f21e77 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 198c9ee..5dd8bf8 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 9481d2b..f113433 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 36b6988..8656de1 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..51464ce
>> --- /dev/null
>> +++ b/libavformat/dtshddec.c
>> @@ -0,0 +1,129 @@
>> +/*
>> + * 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 ((p->buf_size >= 8) &&
>> +        AV_RB64(p->buf) == DTSHDHDR)
>> +        return AVPROBE_SCORE_MAX;
>
> the buf_size check is unneeded
>
>
>> +    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);
>> +
>> +        switch (chunk_type) {
>> +        case STRMDATA:
>> +            dtshd->left = chunk_size;
>> +            return 0;
>> +            break;
>> +        case FILEINFO:
>> +            value = av_malloc(chunk_size);
>
> chunk_size is uint64_t the av_malloc argument is size_t
> later could be a smaller data type
>
>
>> +            if (!value) {
>> +                avio_skip(pb, chunk_size);
>> +                break;
>> +            }
>> +            avio_read(pb, value, chunk_size);
>
>> +            value[chunk_size] = 0;
>
> that writes the 0 after the array
>
>
>
>> +            av_dict_set(&s->metadata, "fileinfo", value,
>> +                        AV_DICT_DONT_STRDUP_VAL);
>> +            break;
>> +        default:
>> +            ret = avio_skip(pb, chunk_size);
>
> this would allow seeking backward and causing a infinite loop

Than I will make demuxer fail for any value bigger than 2^63.


More information about the ffmpeg-devel mailing list