1 /*
2 * RIFF demuxing functions and data
3 * Copyright (c) 2000 Fabrice Bellard
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
31
33 {
AV_CODEC_ID_AC3, { 0x2C, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA } },
34 {
AV_CODEC_ID_ATRAC3P, { 0xBF, 0xAA, 0x23, 0xE9, 0x58, 0xCB, 0x71, 0x44, 0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62 } },
35 {
AV_CODEC_ID_EAC3, { 0xAF, 0x87, 0xFB, 0xA7, 0x02, 0x2D, 0xFB, 0x42, 0xA4, 0xD4, 0x05, 0xCD, 0x93, 0x84, 0x3B, 0xDD } },
36 {
AV_CODEC_ID_MP2, { 0x2B, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA } },
38 };
39
41 {
42 av_assert0(
sizeof(*g) == 16);
//compiler will optimize this out
43 if (
avio_read(s, *g,
sizeof(*g)) < (
int)
sizeof(*g))
44 memset(*g, 0, sizeof(*g));
45 }
46
48 {
49 int i;
54 }
55
56 /* We could be given one of the three possible structures here:
57 * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
58 * is an expansion of the previous one with the fields added
59 * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
60 * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
61 * an openended structure.
62 */
63
65 {
68 if (bps)
70
72
74 if (!memcmp(subformat + 4,
79 } else {
85 }
86 }
87
89 {
91
98 if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
100 } else
102 if (id == 0xFFFE) {
104 } else {
108 }
109 if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */
111 size -= 18;
112 cbSize =
FFMIN(size, cbSize);
113 if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
115 cbSize -= 22;
116 size -= 22;
117 }
118 if (cbSize > 0) {
123 size -= cbSize;
124 }
125
126 /* It is possible for the chunk to contain garbage at the end */
127 if (size > 0)
129 }
134 }
136 /* Channels and sample_rate values are those prior to applying SBR
137 * and/or PS. */
140 }
141 /* override bits_per_coded_sample for G.726 */
144
145 return 0;
146 }
147
149 {
152 if (id <= 0)
154
159
163 }
164
166 {
167 int tag1;
180 return tag1;
181 }
182
184 {
187
190
192 cur <= end - 8 /* = tag + size */) {
193 uint32_t chunk_code;
194 int64_t chunk_size;
195 char key[5] = { 0 };
197
201 if (chunk_code || chunk_size) {
204 }
206 }
207 if (chunk_size > end ||
208 end - chunk_size < cur ||
209 chunk_size == UINT_MAX) {
213 if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) {
216 }
217 }
218
219 chunk_size += (chunk_size & 1);
220
221 if (!chunk_code) {
222 if (chunk_size)
227 }
228 continue;
229 }
230
232 if (!value) {
234 "out of memory, unable to read INFO tag\n");
236 }
237
239
240 if (
avio_read(pb, value, chunk_size) != chunk_size) {
242 "premature end of file while reading INFO tag\n");
243 }
244
246 }
247
248 return 0;
249 }