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 {
34 av_assert0(
sizeof(*g) == 16);
//compiler will optimize this out
35 if (
avio_read(s, *g,
sizeof(*g)) < (
int)
sizeof(*g)) {
36 memset(*g, 0, sizeof(*g));
38 }
39 return 0;
40 }
41
43 {
44 int i;
49 }
50
51 /* We could be given one of the three possible structures here:
52 * WAVEFORMAT, PCMWAVEFORMAT or WAVEFORMATEX. Each structure
53 * is an expansion of the previous one with the fields added
54 * at the bottom. PCMWAVEFORMAT adds 'WORD wBitsPerSample' and
55 * WAVEFORMATEX adds 'WORD cbSize' and basically makes itself
56 * an openended structure.
57 */
58
60 {
63 if (bps)
65
67
69 if (!memcmp(subformat + 4,
74 } else {
80 }
81 }
82
83 /* "big_endian" values are needed for RIFX file format */
85 {
87
88 if (size < 14)
90
92 if (!big_endian) {
98 } else {
104 }
105 if (size == 14) { /* We're dealing with plain vanilla WAVEFORMAT */
107 } else {
108 if (!big_endian) {
110 } else {
112 }
113 }
114 if (id == 0xFFFE) {
116 } else {
120 }
121 if (size >= 18) { /* We're obviously dealing with WAVEFORMATEX */
123 if (big_endian) {
126 }
127 size -= 18;
128 cbSize =
FFMIN(size, cbSize);
129 if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
131 cbSize -= 22;
132 size -= 22;
133 }
134 if (cbSize > 0) {
138 size -= cbSize;
139 }
140
141 /* It is possible for the chunk to contain garbage at the end */
142 if (size > 0)
144 }
149 }
151 /* Channels and sample_rate values are those prior to applying SBR
152 * and/or PS. */
155 }
156 /* override bits_per_coded_sample for G.726 */
159
160 return 0;
161 }
162
164 {
167 if (id <= 0)
169
174
178 }
179
181 {
182 int tag1;
195 return tag1;
196 }
197
199 {
202
205
207 cur <= end - 8 /* = tag + size */) {
208 uint32_t chunk_code;
209 int64_t chunk_size;
210 char key[5] = { 0 };
212
216 if (chunk_code || chunk_size) {
219 }
221 }
222 if (chunk_size > end ||
223 end - chunk_size < cur ||
224 chunk_size == UINT_MAX) {
228 if (chunk_size > end || end - chunk_size < cur || chunk_size == UINT_MAX) {
231 }
232 }
233
234 chunk_size += (chunk_size & 1);
235
236 if (!chunk_code) {
237 if (chunk_size)
242 }
243 continue;
244 }
245
247 if (!value) {
249 "out of memory, unable to read INFO tag\n");
251 }
252
254
255 if (
avio_read(pb, value, chunk_size) != chunk_size) {
257 "premature end of file while reading INFO tag\n");
258 }
259
261 }
262
263 return 0;
264 }