1 /*
2 * Copyright (C) 2005 Michael Ahlberg, Måns Rullgård
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
23 */
24
25 #include <stdlib.h>
26
30
33
41
43 {
44 int i, cnum,
h, m,
s, ms, keylen = strlen(
key);
46
48 return 0;
49
50 if (keylen <= 10) {
51 if (sscanf(
val,
"%02d:%02d:%02d.%03d", &
h, &m, &
s, &ms) < 4)
52 return 0;
53
55 ms + 1000 * (
s + 60 * (m + 60 *
h)),
61 break;
62 }
63 if (!chapter)
64 return 0;
65
67 } else
68 return 0;
69
70 return 1;
71 }
72
74 const uint8_t *buf,
int size)
75 {
77
78 if (updates > 0) {
80 }
81
82 return updates;
83 }
84
85 /**
86 * This function temporarily modifies the (const qualified) input buffer
87 * and reverts its changes before return. The input buffer needs to have
88 * at least one byte of padding.
89 */
91 const uint8_t *buf, uint32_t
size,
92 int *updates, int parse_picture)
93 {
94 char *t = (
char*)buf, *v = memchr(t,
'=',
size);
95 int tl, vl;
96 char backup;
97
98 if (!v)
99 return 0;
100
101 tl = v - t;
103 v++;
104
105 if (!tl || !vl)
106 return 0;
107
108 t[tl] = 0;
109
110 backup = v[vl];
111 v[vl] = 0;
112
113 /* The format in which the pictures are stored is the FLAC format.
114 * Xiph says: "The binary FLAC picture structure is base64 encoded
115 * and placed within a VorbisComment with the tag name
116 * 'METADATA_BLOCK_PICTURE'. This is the preferred and
117 * recommended way of embedding cover art within VorbisComments."
118 */
119 if (!
av_strcasecmp(t,
"METADATA_BLOCK_PICTURE") && parse_picture) {
122
123 if (!pict) {
125 goto end;
126 }
133 goto end;
134 }
136 (*updates)++;
140 }
141 end:
142 t[tl] = '=';
143 v[vl] = backup;
144
145 return 0;
146 }
147
149 const uint8_t *buf,
int size,
150 int parse_picture)
151 {
152 const uint8_t *p = buf;
153 const uint8_t *end = buf +
size;
154 int updates = 0;
155 unsigned n;
157
158 /* must have vendor_length and user_comment_list_length */
161
162 s = bytestream_get_le32(&p);
163
164 if (end - p - 4 <
s ||
s < 0)
166
168
169 n = bytestream_get_le32(&p);
170
171 while (end - p >= 4 && n > 0) {
172 s = bytestream_get_le32(&p);
173
174 if (end - p <
s ||
s < 0)
175 break;
176
181 n--;
182 }
183
184 if (p != end)
187 if (n > 0)
189 "truncated comment header, %i comments not found\n", n);
190
192
193 return updates;
194 }
195
196 /*
197 * Parse the vorbis header
198 *
199 * Vorbis Identification header from Vorbis_I_spec.html#vorbis-spec-codec
200 * [vorbis_version] = read 32 bits as unsigned integer | Not used
201 * [audio_channels] = read 8 bit integer as unsigned | Used
202 * [audio_sample_rate] = read 32 bits as unsigned integer | Used
203 * [bitrate_maximum] = read 32 bits as signed integer | Not used yet
204 * [bitrate_nominal] = read 32 bits as signed integer | Not used yet
205 * [bitrate_minimum] = read 32 bits as signed integer | Used as bitrate
206 * [blocksize_0] = read 4 bits as unsigned integer | Not Used
207 * [blocksize_1] = read 4 bits as unsigned integer | Not Used
208 * [framing_flag] = read one bit | Not Used
209 */
210
217 };
218
221 uint8_t **buf)
222 {
224 int buf_len;
225 unsigned char *ptr;
226
228 buf_len =
len +
len / 255 + 64;
229
230 if (*buf)
232
234 if (!ptr)
236 memset(*buf, '0円', buf_len);
237
238 ptr[0] = 2;
242 for (
i = 0;
i < 3;
i++) {
246 }
248 return err;
250 }
251
253 {
254 struct ogg *
ogg =
s->priv_data;
260 for (
i = 0;
i < 3;
i++)
262 }
263 }
264
266 {
267 struct ogg *
ogg =
s->priv_data;
271
273 return 0;
274
275 /* New metadata packet; release old data. */
281
282 /* Update the metadata if possible. */
286 /* Send an empty dictionary to indicate that metadata has been cleared. */
287 } else {
290 }
291
293 }
294
296 {
297 struct ogg *
ogg =
s->priv_data;
302
307 }
308
310
311 if (!(pkt_type & 1))
313
314 if (os->
psize < 1 || pkt_type > 5)
316
317 if (priv->
packet[pkt_type >> 1])
319 if (pkt_type > 1 && !priv->
packet[0] || pkt_type > 3 && !priv->
packet[1])
321
322 priv->
len[pkt_type >> 1] = os->
psize;
324 if (!priv->
packet[pkt_type >> 1])
327 const uint8_t *p = os->
buf + os->
pstart + 7;
/* skip "001円vorbis" tag */
328 unsigned blocksize, bs0, bs1;
329 int srate;
331
334
335 if (bytestream_get_le32(&p) != 0) /* vorbis_version */
337
343 }
345 srate = bytestream_get_le32(&p);
346 p += 4; // skip maximum bitrate
348 p += 4; // skip minimum bitrate
349
350 blocksize = bytestream_get_byte(&p);
351 bs0 = blocksize & 15;
352 bs1 = blocksize >> 4;
353
354 if (bs0 > bs1)
356 if (bs0 < 6 || bs1 > 13)
358
359 if (bytestream_get_byte(&p) != 1) /* framing_flag */
361
364
365 if (srate > 0) {
368 }
371 unsigned new_len;
372
376
377 // drop all metadata we parsed and which is not required by libvorbis
379 if (new_len >= 16 && new_len < os->psize) {
381 priv->
packet[1][new_len - 1] = 1;
382 priv->
len[1] = new_len;
383 }
384 }
385 } else {
387
390
395 }
397
403 }
404 }
405
406 return 1;
407 }
408
410 {
411 struct ogg *
ogg =
s->priv_data;
415
418
419 /* first packet handling
420 * here we parse the duration of each packet in the first page and compare
421 * the total duration to the page granule to find the encoder delay and
422 * set the first timestamp */
425 uint8_t *last_pkt = os->
buf + os->
pstart;
426 uint8_t *next_pkt = last_pkt;
427
434 return 0;
438 }
440 last_pkt = next_pkt = next_pkt + os->
psize;
441 for (; seg < os->
nsegs; seg++) {
446 break;
450 }
452 last_pkt = next_pkt + os->
segments[seg];
453 }
455 }
458
459 if (!os->
granule &&
duration)
//hack to deal with broken files (Ticket3710)
461
465 s->streams[idx]->duration -=
s->streams[idx]->start_time;
466 }
469 }
470
471 /* parse packet duration */
476 return 0;
480 }
482 }
483
484 /* final packet handling
485 * here we save the pts of the first packet in the final page, sum up all
486 * packet durations in the final page except for the last one, and compare
487 * to the page granule to find the duration of the final packet */
492 }
498 }
500 }
501
502 return 0;
503 }
504
506 .
magic =
"001円vorbis",
507 .magicsize = 7,
511 .nb_header = 3,
512 };