Signed-off-by: Justin Ruggles <justin.ruggles@gmail.com>
Paul B Mahol authored on 2011/12/10 13:53:30... | ... |
@@ -25,6 +25,7 @@ |
25 | 25 |
#include "rawdec.h" |
26 | 26 |
#include "oggdec.h" |
27 | 27 |
#include "vorbiscomment.h" |
28 |
+#include "libavcodec/bytestream.h" |
|
28 | 29 |
|
29 | 30 |
static int flac_read_header(AVFormatContext *s, |
30 | 31 |
AVFormatParameters *ap) |
... | ... |
@@ -54,6 +55,7 @@ static int flac_read_header(AVFormatContext *s, |
54 | 54 |
switch (metadata_type) { |
55 | 55 |
/* allocate and read metadata block for supported types */ |
56 | 56 |
case FLAC_METADATA_TYPE_STREAMINFO: |
57 |
+ case FLAC_METADATA_TYPE_CUESHEET: |
|
57 | 58 |
case FLAC_METADATA_TYPE_VORBIS_COMMENT: |
58 | 59 |
buffer = av_mallocz(metadata_size + FF_INPUT_BUFFER_PADDING_SIZE); |
59 | 60 |
if (!buffer) { |
... | ... |
@@ -96,6 +98,31 @@ static int flac_read_header(AVFormatContext *s, |
96 | 96 |
if (si.samples > 0) |
97 | 97 |
st->duration = si.samples; |
98 | 98 |
} |
99 |
+ } else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) { |
|
100 |
+ uint8_t isrc[13]; |
|
101 |
+ uint64_t start; |
|
102 |
+ const uint8_t *offset; |
|
103 |
+ int i, j, chapters, track, ti; |
|
104 |
+ if (metadata_size < 431) |
|
105 |
+ return AVERROR_INVALIDDATA; |
|
106 |
+ offset = buffer + 395; |
|
107 |
+ chapters = bytestream_get_byte(&offset) - 1; |
|
108 |
+ if (chapters <= 0) |
|
109 |
+ return AVERROR_INVALIDDATA; |
|
110 |
+ for (i = 0; i < chapters; i++) { |
|
111 |
+ if (offset + 36 - buffer > metadata_size) |
|
112 |
+ return AVERROR_INVALIDDATA; |
|
113 |
+ start = bytestream_get_be64(&offset); |
|
114 |
+ track = bytestream_get_byte(&offset); |
|
115 |
+ bytestream_get_buffer(&offset, isrc, 12); |
|
116 |
+ isrc[12] = 0; |
|
117 |
+ offset += 14; |
|
118 |
+ ti = bytestream_get_byte(&offset); |
|
119 |
+ if (ti <= 0) return AVERROR_INVALIDDATA; |
|
120 |
+ for (j = 0; j < ti; j++) |
|
121 |
+ offset += 12; |
|
122 |
+ avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc); |
|
123 |
+ } |
|
99 | 124 |
} else { |
100 | 125 |
/* STREAMINFO must be the first block */ |
101 | 126 |
if (!found_streaminfo) { |