[FFmpeg-devel] [PATCH 2/2] ADP demuxer

Michael Niedermayer michaelni at gmx.at
Wed Apr 24 00:54:24 CEST 2013


On Sat, Apr 20, 2013 at 08:12:24PM -0300, James Almer wrote:
> 
> Signed-off-by: James Almer <jamrial at gmail.com>
> ---
>  Changelog                |  1 +
>  doc/general.texi         |  2 ++
>  libavformat/Makefile     |  1 +
>  libavformat/adp.c        | 85 ++++++++++++++++++++++++++++++++++++++++++++++++
>  libavformat/allformats.c |  1 +
>  libavformat/version.h    |  2 +-
>  6 files changed, 91 insertions(+), 1 deletion(-)
>  create mode 100644 libavformat/adp.c
> 
> diff --git a/Changelog b/Changelog
> index 967792c..dfa1819 100644
> --- a/Changelog
> +++ b/Changelog
> @@ -29,6 +29,7 @@ version <next>:
>    become the default at the next libavformat major bump.
>  - decent native animated GIF encoding
>  - ADPCM DTK decoder
> +- ADP demuxer
>  
>  
>  version 1.2:
> diff --git a/doc/general.texi b/doc/general.texi
> index 215abe6..6bb3603 100644
> --- a/doc/general.texi
> +++ b/doc/general.texi
> @@ -147,6 +147,8 @@ library:
>      @tab Multimedia format used in game Heart Of Darkness.
>  @item Apple HTTP Live Streaming @tab   @tab X
>  @item Artworx Data Format       @tab   @tab X
> + at item ADP                       @tab   @tab X
> +    @tab Audio format used on the Nintendo Gamecube.
>  @item AFC                       @tab   @tab X
>      @tab Audio format used on the Nintendo Gamecube.
>  @item ASF                       @tab X @tab X
> diff --git a/libavformat/Makefile b/libavformat/Makefile
> index 470e7f3..26c0944 100644
> --- a/libavformat/Makefile
> +++ b/libavformat/Makefile
> @@ -55,6 +55,7 @@ OBJS-$(CONFIG_AC3_DEMUXER)               += ac3dec.o rawdec.o
>  OBJS-$(CONFIG_AC3_MUXER)                 += rawenc.o
>  OBJS-$(CONFIG_ACT_DEMUXER)               += act.o
>  OBJS-$(CONFIG_ADF_DEMUXER)               += bintext.o sauce.o
> +OBJS-$(CONFIG_ADP_DEMUXER)               += adp.o
>  OBJS-$(CONFIG_ADX_DEMUXER)               += adxdec.o
>  OBJS-$(CONFIG_ADX_MUXER)                 += rawenc.o
>  OBJS-$(CONFIG_ADTS_MUXER)                += adtsenc.o
> diff --git a/libavformat/adp.c b/libavformat/adp.c
> new file mode 100644
> index 0000000..ad80cdb
> --- /dev/null
> +++ b/libavformat/adp.c
> @@ -0,0 +1,85 @@
> +/*
> + * ADP demuxer
> + * Copyright (c) 2013 James Almer
> + *
> + * 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/channel_layout.h"
> +#include "libavutil/intreadwrite.h"
> +#include "avformat.h"
> +#include "internal.h"
> +
> +static int adp_probe(AVProbeData *p)
> +{
> +    if (p->buf[0] == p->buf[2] && p->buf[1] == p->buf[3]) {
> +        if (p->buf_size < 260)
> +            return AVPROBE_SCORE_MAX / 4 - 1;

return 0 or 1 here IMHO
just a single frame is very odd and doesnt look like a correct file


> +        else if (p->buf[256] == p->buf[258] && p->buf[257] == p->buf[259])
> +            return AVPROBE_SCORE_MAX / 4;
> +    }
> +    return 0;
> +}
> +
> +static int adp_read_header(AVFormatContext *s)
> +{
> +    AVStream *st;
> +
> +    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_ADPCM_DTK;
> +    st->codec->channel_layout = AV_CH_LAYOUT_STEREO;
> +    st->codec->channels       = 2;
> +    st->codec->sample_rate    = 48000;
> +    st->start_time            = 0;

> +    if (s->pb->seekable)
> +        st->duration          = avio_size(s->pb) / 32 * 28;

Is this check needed ?
avio_size() should harmlessly fail if the protocal cant seek


> +
> +    avpriv_set_pts_info(st, 64, 1, st->codec->sample_rate);
> +
> +    return 0;
> +}
> +
> +static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
> +{
> +    int ret, size = 1024;
> +
> +    if (url_feof(s->pb))
> +        return AVERROR_EOF;
> +
> +    ret = av_get_packet(s->pb, pkt, size);
> +    pkt->stream_index = 0;
> +
> +    if (ret != size) {
> +        av_free_packet(pkt);
> +        ret = AVERROR(EIO);
> +    }
> +
> +    return ret;
> +}
> +
> +AVInputFormat ff_adp_demuxer = {
> +    .name           = "adp",
> +    .long_name      = NULL_IF_CONFIG_SMALL("ADP"),
> +    .read_probe     = adp_probe,
> +    .read_header    = adp_read_header,
> +    .read_packet    = adp_read_packet,
> +    .extensions     = "adp,dtk",
> +};

does seeking work with this demuxer ?
(also see AVFMT_GENERIC_INDEX)

No more comments from me, rest looks good, feel free to ask for a
merge once all dependancies are ready too

[...]

-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

I am the wisest man alive, for I know one thing, and that is that I know
nothing. -- Socrates
-------------- 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/20130424/80258769/attachment.asc>


More information about the ffmpeg-devel mailing list