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
78 /* STREAMINFO can only occur once */
79 if (found_streaminfo) {
81 }
84 }
85 found_streaminfo = 1;
88 buffer = NULL;
89
90 /* get codec params from STREAMINFO header */
92
93 /* set time base and duration */
94 if (si.samplerate > 0) {
96 if (si.samples > 0)
98 }
103 int i, chapters, track, ti;
104 if (metadata_size < 431)
106 offset = buffer + 395;
107 chapters = bytestream_get_byte(&offset) - 1;
108 if (chapters <= 0)
110 for (i = 0; i < chapters; i++) {
111 if (offset + 36 - buffer > metadata_size)
113 start = bytestream_get_be64(&offset);
114 track = bytestream_get_byte(&offset);
116 isrc[12] = 0;
117 offset += 14;
118 ti = bytestream_get_byte(&offset);
120 offset += ti * 12;
122 }
127 if (ret < 0) {
130 }
131 } else {
132 /* STREAMINFO must be the first block */
133 if (!found_streaminfo) {
135 }
136 /* process supported blocks other than STREAMINFO */
140 }
141 }
143 }
144 }
145
146 return 0;
147
148 fail:
151 }
152
154 {
156 return 0;
158 }
159
167 .extensions = "flac",
169 };