1 /*
2 * ADP demuxer
3 * Copyright (c) 2013 James Almer
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #include "libavutil/channel_layout.h"
23 #include "libavutil/intreadwrite.h"
24 #include "avformat.h"
25 #include "internal.h"
26
adp_probe(const AVProbeData * p)27 static int adp_probe(const AVProbeData *p)
28 {
29 int i, changes = 0;
30 uint8_t last = 0;
31
32 if (p->buf_size < 32)
33 return 0;
34
35 for (i = 0; i < p->buf_size - 3; i+=32) {
36 if (p->buf[i] != p->buf[i+2] || p->buf[i+1] != p->buf[i+3])
37 return 0;
38 if (p->buf[i] != last)
39 changes++;
40 last = p->buf[i];
41 }
42 if (changes <= 1)
43 return 0;
44
45 return p->buf_size < 260 ? 1 : AVPROBE_SCORE_MAX / 4;
46 }
47
adp_read_header(AVFormatContext * s)48 static int adp_read_header(AVFormatContext *s)
49 {
50 AVStream *st;
51
52 st = avformat_new_stream(s, NULL);
53 if (!st)
54 return AVERROR(ENOMEM);
55
56 st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
57 st->codecpar->codec_id = AV_CODEC_ID_ADPCM_DTK;
58 st->codecpar->channel_layout = AV_CH_LAYOUT_STEREO;
59 st->codecpar->channels = 2;
60 st->codecpar->sample_rate = 48000;
61 st->start_time = 0;
62 if (s->pb->seekable & AVIO_SEEKABLE_NORMAL)
63 st->duration = av_get_audio_frame_duration2(st->codecpar, avio_size(s->pb));
64
65 avpriv_set_pts_info(st, 64, 1, st->codecpar->sample_rate);
66
67 return 0;
68 }
69
adp_read_packet(AVFormatContext * s,AVPacket * pkt)70 static int adp_read_packet(AVFormatContext *s, AVPacket *pkt)
71 {
72 int ret, size = 1024;
73
74 if (avio_feof(s->pb))
75 return AVERROR_EOF;
76
77 ret = av_get_packet(s->pb, pkt, size);
78 if (ret < 0)
79 return ret;
80
81 pkt->stream_index = 0;
82
83 return ret;
84 }
85
86 AVInputFormat ff_adp_demuxer = {
87 .name = "adp",
88 .long_name = NULL_IF_CONFIG_SMALL("ADP"),
89 .read_probe = adp_probe,
90 .read_header = adp_read_header,
91 .read_packet = adp_read_packet,
92 .extensions = "adp,dtk",
93 };
94