Line | Branch | Exec | Source |
---|---|---|---|
1 | /* | ||
2 | * MD STUDIO audio demuxer | ||
3 | * | ||
4 | * Copyright (c) 2009 Benjamin Larsson | ||
5 | * | ||
6 | * This file is part of FFmpeg. | ||
7 | * | ||
8 | * FFmpeg is free software; you can redistribute it and/or | ||
9 | * modify it under the terms of the GNU Lesser General Public | ||
10 | * License as published by the Free Software Foundation; either | ||
11 | * version 2.1 of the License, or (at your option) any later version. | ||
12 | * | ||
13 | * FFmpeg is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
16 | * Lesser General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU Lesser General Public | ||
19 | * License along with FFmpeg; if not, write to the Free Software | ||
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
21 | */ | ||
22 | |||
23 | #include "libavutil/channel_layout.h" | ||
24 | #include "libavutil/intreadwrite.h" | ||
25 | #include "avformat.h" | ||
26 | #include "avio_internal.h" | ||
27 | #include "demux.h" | ||
28 | #include "internal.h" | ||
29 | #include "pcm.h" | ||
30 | |||
31 | #define AT1_SU_SIZE 212 | ||
32 | |||
33 | 7186 | static int aea_read_probe(const AVProbeData *p) | |
34 | { | ||
35 |
2/2✓ Branch 0 taken 3985 times.
✓ Branch 1 taken 3201 times.
|
7186 | if (p->buf_size <= 2048+AT1_SU_SIZE) |
36 | 3985 | return 0; | |
37 | |||
38 | /* Magic is '00 08 00 00' in little-endian*/ | ||
39 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 3197 times.
|
3201 | if (AV_RL32(p->buf)==0x800) { |
40 | 4 | int ch, block_size, score = 0; | |
41 | 4 | ch = p->buf[264]; | |
42 | |||
43 |
2/4✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
|
4 | if (ch != 1 && ch != 2) |
44 | ✗ | return 0; | |
45 | |||
46 | 4 | block_size = ch * AT1_SU_SIZE; | |
47 | /* Check so that the redundant bsm bytes and info bytes are valid | ||
48 | * the block size mode bytes have to be the same | ||
49 | * the info bytes have to be the same | ||
50 | */ | ||
51 |
2/2✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
|
16 | for (int i = 2048 + block_size; i + block_size <= p->buf_size; i += block_size) { |
52 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
|
12 | if (AV_RN16(p->buf+i) != AV_RN16(p->buf+i+AT1_SU_SIZE)) |
53 | ✗ | return 0; | |
54 | 12 | score++; | |
55 | } | ||
56 | 4 | return FFMIN(AVPROBE_SCORE_MAX / 4 + score, AVPROBE_SCORE_MAX); | |
57 | } | ||
58 | 3197 | return 0; | |
59 | } | ||
60 | |||
61 | 6 | static int aea_read_header(AVFormatContext *s) | |
62 | { | ||
63 | 6 | AVStream *st = avformat_new_stream(s, NULL); | |
64 | char title[256 + 1]; | ||
65 | int channels, ret; | ||
66 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (!st) |
67 | ✗ | return AVERROR(ENOMEM); | |
68 | |||
69 | /* Read the title, parse the number of channels and skip to pos 2048(0x800) */ | ||
70 | 6 | avio_rl32(s->pb); // magic | |
71 | 6 | ret = ffio_read_size(s->pb, title, sizeof(title) - 1); | |
72 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
|
6 | if (ret < 0) |
73 | ✗ | return ret; | |
74 | 6 | title[sizeof(title) - 1] = '\0'; | |
75 |
1/2✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
|
6 | if (title[0] != '\0') |
76 | 6 | av_dict_set(&st->metadata, "title", title, 0); | |
77 | 6 | avio_rl32(s->pb); // Block count | |
78 | 6 | channels = avio_r8(s->pb); | |
79 | 6 | avio_skip(s->pb, 1783); | |
80 | |||
81 | |||
82 | 6 | st->codecpar->codec_type = AVMEDIA_TYPE_AUDIO; | |
83 | 6 | st->codecpar->codec_id = AV_CODEC_ID_ATRAC1; | |
84 | 6 | st->codecpar->sample_rate = 44100; | |
85 | 6 | st->codecpar->bit_rate = 146000 * channels; | |
86 | |||
87 |
2/4✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
|
6 | if (channels != 1 && channels != 2) { |
88 | ✗ | av_log(s, AV_LOG_ERROR, "Channels %d not supported!\n", channels); | |
89 | ✗ | return AVERROR_INVALIDDATA; | |
90 | } | ||
91 | |||
92 | 6 | av_channel_layout_default(&st->codecpar->ch_layout, channels); | |
93 | |||
94 | 6 | st->codecpar->block_align = AT1_SU_SIZE * st->codecpar->ch_layout.nb_channels; | |
95 | 6 | avpriv_set_pts_info(st, 64, 1, 44100); | |
96 | 6 | return 0; | |
97 | } | ||
98 | |||
99 | 3605 | static int aea_read_packet(AVFormatContext *s, AVPacket *pkt) | |
100 | { | ||
101 | 3605 | return av_get_packet(s->pb, pkt, s->streams[0]->codecpar->block_align); | |
102 | } | ||
103 | |||
104 | const FFInputFormat ff_aea_demuxer = { | ||
105 | .p.name = "aea", | ||
106 | .p.long_name = NULL_IF_CONFIG_SMALL("MD STUDIO audio"), | ||
107 | .p.flags = AVFMT_GENERIC_INDEX, | ||
108 | .p.extensions = "aea", | ||
109 | .read_probe = aea_read_probe, | ||
110 | .read_header = aea_read_header, | ||
111 | .read_packet = aea_read_packet, | ||
112 | .read_seek = ff_pcm_read_seek, | ||
113 | }; | ||
114 |