1 /*
2 * Raw FLAC demuxer
3 * Copyright (c) 2001 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
30
32 {
33 int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
37 if (!st)
42 /* the parameters will be extracted from the compressed bitstream */
43
44 /* if fLaC marker is not found, assume there is no header */
47 return 0;
48 }
49
50 /* process metadata blocks */
54 &metadata_size);
55 switch (metadata_type) {
56 /* allocate and read metadata block for supported types */
62 if (!buffer) {
64 }
65 if (
avio_read(s->
pb, buffer, metadata_size) != metadata_size) {
67 }
68 break;
69 /* skip metadata block for unsupported types */
70 default:
72 if (ret < 0)
74 }
75
77 uint32_t samplerate;
78 uint64_t samples;
79
80 /* STREAMINFO can only occur once */
81 if (found_streaminfo) {
83 }
86 }
87 found_streaminfo = 1;
91
92 /* get sample rate and sample count from STREAMINFO header;
93 * other parameters will be extracted by the parser */
96
97 /* set time base and duration */
98 if (samplerate > 0) {
100 if (samples > 0)
102 }
107 int i, chapters, track, ti;
108 if (metadata_size < 431)
110 offset = buffer + 395;
111 chapters = bytestream_get_byte(&offset) - 1;
112 if (chapters <= 0)
114 for (i = 0; i < chapters; i++) {
115 if (offset + 36 - buffer > metadata_size)
117 start = bytestream_get_be64(&offset);
118 track = bytestream_get_byte(&offset);
120 isrc[12] = 0;
121 offset += 14;
122 ti = bytestream_get_byte(&offset);
124 offset += ti * 12;
126 }
131 if (ret < 0) {
134 }
135 } else {
136 /* STREAMINFO must be the first block */
137 if (!found_streaminfo) {
139 }
140 /* process supported blocks other than STREAMINFO */
143
145 if (ret < 0) {
147 } else if (ret > 0) {
149 }
150
151 /* parse the channels mask if present */
153 if (chmask) {
155 if (!mask || mask & ~0x3ffffULL) {
157 "Invalid value of WAVEFORMATEXTENSIBLE_CHANNEL_MASK\n");
158 } else {
161 }
162 }
163 }
165 }
166 }
167
169 if (ret < 0)
171
172 return 0;
173
174 fail:
177 }
178
180 {
182 return 0;
184 }
185
187 int64_t *ppos, int64_t pos_limit)
188 {
194
197
200 if (!parser){
202 }
204
205 for (;;){
207 if (ret < 0){
209 continue;
210 else
211 break;
212 }
217
222 // seeking may not have started from beginning of a frame
223 // calculate frame start position from next frame backwards
226 break;
227 }
228 }
229 }
232 }
233
242 .extensions = "flac",
244 };