Mercurial > libavformat.hg
annotate matroskadec.c @ 3648:07f046bf6849 libavformat
matroskadec: move declaration to upper block
author | aurel |
---|---|
date | Tue, 05 Aug 2008 00:40:49 +0000 |
parents | 98eb4eb368fa |
children | 71da9d010bae |
rev | line source |
---|---|
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2 * Matroska file demuxer (no muxer yet) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
3 * Copyright (c) 2003-2004 The ffmpeg Project |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
4 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
5 * This file is part of FFmpeg. |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
6 * |
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
11 * |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
16 * |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
1358
0899bfe4105c
Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents:
1332
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
896
edbe5c3717f9
Update licensing information: The FSF changed postal address.
diego
parents:
887
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
20 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
21 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
22 /** |
2175
9438e2e7faf2
Fix @file in matroskadec.c, it was still matroska.c
reimar
parents:
2147
diff
changeset
|
23 * @file matroskadec.c |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
24 * Matroska file demuxer |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
25 * by Ronald Bultje <rbultje@ronald.bitfreak.net> |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
26 * with a little help from Moritz Bunkus <moritz@bunkus.org> |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
27 * Specs available on the matroska project page: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
28 * http://www.matroska.org/. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
29 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
30 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
31 #include "avformat.h" |
1897
abbc781d608a
use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents:
1832
diff
changeset
|
32 /* For codec_get_id(). */ |
1172
6a5e58d2114b
move common stuff from avienc.c and wav.c to new file riff.c
mru
parents:
1169
diff
changeset
|
33 #include "riff.h" |
3601 | 34 #include "isom.h" |
2142
3aa1f0f698de
split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents:
2023
diff
changeset
|
35 #include "matroska.h" |
3201 | 36 #include "libavcodec/mpeg4audio.h" |
3286 | 37 #include "libavutil/intfloat_readwrite.h" |
3628
5f2e1da55755
matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents:
3601
diff
changeset
|
38 #include "libavutil/avstring.h" |
3281 | 39 #include "libavutil/lzo.h" |
3293 | 40 #ifdef CONFIG_ZLIB |
41 #include <zlib.h> | |
42 #endif | |
3298
edabe3db2b6e
matroskadec: add support for bzlib compressed tracks
aurel
parents:
3294
diff
changeset
|
43 #ifdef CONFIG_BZLIB |
edabe3db2b6e
matroskadec: add support for bzlib compressed tracks
aurel
parents:
3294
diff
changeset
|
44 #include <bzlib.h> |
edabe3db2b6e
matroskadec: add support for bzlib compressed tracks
aurel
parents:
3294
diff
changeset
|
45 #endif |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
46 |
3632 | 47 typedef enum { |
48 EBML_NONE, | |
49 EBML_UINT, | |
50 EBML_FLOAT, | |
51 EBML_STR, | |
52 EBML_UTF8, | |
53 EBML_BIN, | |
54 EBML_NEST, | |
55 EBML_PASS, | |
56 EBML_STOP, | |
57 } EbmlType; | |
58 | |
59 typedef const struct EbmlSyntax { | |
60 uint32_t id; | |
61 EbmlType type; | |
62 int list_elem_size; | |
63 int data_offset; | |
64 union { | |
65 uint64_t u; | |
66 double f; | |
67 const char *s; | |
68 const struct EbmlSyntax *n; | |
69 } def; | |
70 } EbmlSyntax; | |
71 | |
72 typedef struct { | |
73 int nb_elem; | |
74 void *elem; | |
75 } EbmlList; | |
76 | |
77 typedef struct { | |
78 int size; | |
79 uint8_t *data; | |
80 int64_t pos; | |
81 } EbmlBin; | |
82 | |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
83 typedef struct { |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
84 uint64_t version; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
85 uint64_t max_size; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
86 uint64_t id_length; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
87 char *doctype; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
88 uint64_t doctype_version; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
89 } Ebml; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
90 |
3642 | 91 typedef struct { |
92 uint64_t algo; | |
93 EbmlBin settings; | |
94 } MatroskaTrackCompression; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
95 |
3642 | 96 typedef struct { |
97 uint64_t scope; | |
98 uint64_t type; | |
99 MatroskaTrackCompression compression; | |
100 } MatroskaTrackEncoding; | |
101 | |
102 typedef struct { | |
103 double frame_rate; | |
104 uint64_t display_width; | |
105 uint64_t display_height; | |
106 uint64_t pixel_width; | |
107 uint64_t pixel_height; | |
108 uint64_t fourcc; | |
109 } MatroskaTrackVideo; | |
2147 | 110 |
3642 | 111 typedef struct { |
112 double samplerate; | |
113 double out_samplerate; | |
114 uint64_t bitdepth; | |
115 uint64_t channels; | |
2147 | 116 |
3642 | 117 /* real audio header (extracted from extradata) */ |
118 int coded_framesize; | |
119 int sub_packet_h; | |
120 int frame_size; | |
121 int sub_packet_size; | |
122 int sub_packet_cnt; | |
123 int pkt_cnt; | |
124 uint8_t *buf; | |
125 } MatroskaTrackAudio; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
126 |
3642 | 127 typedef struct { |
128 uint64_t num; | |
129 uint64_t type; | |
130 char *codec_id; | |
131 EbmlBin codec_priv; | |
132 char *language; | |
3408
da09478c97ce
matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents:
3407
diff
changeset
|
133 double time_scale; |
1912 | 134 uint64_t default_duration; |
3630 | 135 uint64_t flag_default; |
3642 | 136 MatroskaTrackVideo video; |
137 MatroskaTrackAudio audio; | |
138 EbmlList encodings; | |
3634
f206f746ff61
matroskadec: store an AVStream pointer instead of a stream index
aurel
parents:
3633
diff
changeset
|
139 |
f206f746ff61
matroskadec: store an AVStream pointer instead of a stream index
aurel
parents:
3633
diff
changeset
|
140 AVStream *stream; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
141 } MatroskaTrack; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
142 |
3637 | 143 typedef struct { |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
144 char *filename; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
145 char *mime; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
146 EbmlBin bin; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
147 } MatroskaAttachement; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
148 |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
149 typedef struct { |
3639 | 150 uint64_t start; |
151 uint64_t end; | |
152 uint64_t uid; | |
153 char *title; | |
154 } MatroskaChapter; | |
155 | |
156 typedef struct { | |
3637 | 157 uint64_t track; |
158 uint64_t pos; | |
159 } MatroskaIndexPos; | |
160 | |
161 typedef struct { | |
162 uint64_t time; | |
163 EbmlList pos; | |
164 } MatroskaIndex; | |
165 | |
3644 | 166 typedef struct { |
167 uint64_t id; | |
168 uint64_t pos; | |
169 } MatroskaSeekhead; | |
170 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
171 typedef struct MatroskaLevel { |
2147 | 172 uint64_t start; |
173 uint64_t length; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
174 } MatroskaLevel; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
175 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
176 typedef struct MatroskaDemuxContext { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
177 AVFormatContext *ctx; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
178 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
179 /* ebml stuff */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
180 int num_levels; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
181 MatroskaLevel levels[EBML_MAX_DEPTH]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
182 int level_up; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
183 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
184 /* timescale in the file */ |
3641 | 185 uint64_t time_scale; |
186 double duration; | |
187 char *title; | |
3642 | 188 EbmlList tracks; |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
189 EbmlList attachments; |
3639 | 190 EbmlList chapters; |
3637 | 191 EbmlList index; |
3644 | 192 EbmlList seekhead; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
193 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
194 /* num_streams is the number of streams that av_new_stream() was called |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
195 * for ( = that are available to the calling program). */ |
2147 | 196 int num_streams; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
197 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
198 /* cache for ID peeking */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
199 uint32_t peek_id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
200 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
201 /* byte position of the segment inside the stream */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
202 offset_t segment_start; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
203 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
204 /* The packet queue. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
205 AVPacket **packets; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
206 int num_packets; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
207 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
208 /* have we already parse metadata/cues/clusters? */ |
2147 | 209 int metadata_parsed; |
210 int index_parsed; | |
211 int done; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
212 |
2014
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
213 /* What to skip before effectively reading a packet. */ |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
214 int skip_to_keyframe; |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
215 AVStream *skip_to_stream; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
216 } MatroskaDemuxContext; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
217 |
3413
b7f86452706e
matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents:
3409
diff
changeset
|
218 #define ARRAY_SIZE(x) (sizeof(x)/sizeof(*x)) |
b7f86452706e
matroskadec: move ARRAY_SIZE() macro at top of the file
aurel
parents:
3409
diff
changeset
|
219 |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
220 static EbmlSyntax ebml_header[] = { |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
221 { EBML_ID_EBMLREADVERSION, EBML_UINT, 0, offsetof(Ebml,version), {.u=EBML_VERSION} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
222 { EBML_ID_EBMLMAXSIZELENGTH, EBML_UINT, 0, offsetof(Ebml,max_size), {.u=8} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
223 { EBML_ID_EBMLMAXIDLENGTH, EBML_UINT, 0, offsetof(Ebml,id_length), {.u=4} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
224 { EBML_ID_DOCTYPE, EBML_STR, 0, offsetof(Ebml,doctype), {.s="(none)"} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
225 { EBML_ID_DOCTYPEREADVERSION, EBML_UINT, 0, offsetof(Ebml,doctype_version), {.u=1} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
226 { EBML_ID_EBMLVERSION, EBML_NONE }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
227 { EBML_ID_DOCTYPEVERSION, EBML_NONE }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
228 { EBML_ID_VOID, EBML_NONE }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
229 { 0 } |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
230 }; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
231 |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
232 static EbmlSyntax ebml_syntax[] = { |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
233 { EBML_ID_HEADER, EBML_NEST, 0, 0, {.n=ebml_header} }, |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
234 { 0 } |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
235 }; |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
236 |
3641 | 237 static EbmlSyntax matroska_info[] = { |
238 { MATROSKA_ID_TIMECODESCALE, EBML_UINT, 0, offsetof(MatroskaDemuxContext,time_scale), {.u=1000000} }, | |
239 { MATROSKA_ID_DURATION, EBML_FLOAT, 0, offsetof(MatroskaDemuxContext,duration) }, | |
240 { MATROSKA_ID_TITLE, EBML_UTF8, 0, offsetof(MatroskaDemuxContext,title) }, | |
241 { MATROSKA_ID_WRITINGAPP, EBML_NONE }, | |
242 { MATROSKA_ID_MUXINGAPP, EBML_NONE }, | |
243 { MATROSKA_ID_DATEUTC, EBML_NONE }, | |
244 { MATROSKA_ID_SEGMENTUID, EBML_NONE }, | |
245 { EBML_ID_VOID, EBML_NONE }, | |
246 { 0 } | |
247 }; | |
248 | |
3642 | 249 static EbmlSyntax matroska_track_video[] = { |
250 { MATROSKA_ID_VIDEOFRAMERATE, EBML_FLOAT,0, offsetof(MatroskaTrackVideo,frame_rate) }, | |
251 { MATROSKA_ID_VIDEODISPLAYWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_width) }, | |
252 { MATROSKA_ID_VIDEODISPLAYHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,display_height) }, | |
253 { MATROSKA_ID_VIDEOPIXELWIDTH, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_width) }, | |
254 { MATROSKA_ID_VIDEOPIXELHEIGHT, EBML_UINT, 0, offsetof(MatroskaTrackVideo,pixel_height) }, | |
255 { MATROSKA_ID_VIDEOCOLORSPACE, EBML_UINT, 0, offsetof(MatroskaTrackVideo,fourcc) }, | |
256 { MATROSKA_ID_VIDEOFLAGINTERLACED,EBML_NONE }, | |
257 { MATROSKA_ID_VIDEOSTEREOMODE, EBML_NONE }, | |
258 { MATROSKA_ID_VIDEOASPECTRATIO, EBML_NONE }, | |
259 { EBML_ID_VOID, EBML_NONE }, | |
260 { 0 } | |
261 }; | |
262 | |
263 static EbmlSyntax matroska_track_audio[] = { | |
264 { MATROSKA_ID_AUDIOSAMPLINGFREQ, EBML_FLOAT,0, offsetof(MatroskaTrackAudio,samplerate), {.f=8000.0} }, | |
265 { MATROSKA_ID_AUDIOOUTSAMPLINGFREQ,EBML_FLOAT,0,offsetof(MatroskaTrackAudio,out_samplerate) }, | |
266 { MATROSKA_ID_AUDIOBITDEPTH, EBML_UINT, 0, offsetof(MatroskaTrackAudio,bitdepth) }, | |
267 { MATROSKA_ID_AUDIOCHANNELS, EBML_UINT, 0, offsetof(MatroskaTrackAudio,channels), {.u=1} }, | |
268 { EBML_ID_VOID, EBML_NONE }, | |
269 { 0 } | |
270 }; | |
271 | |
272 static EbmlSyntax matroska_track_encoding_compression[] = { | |
273 { MATROSKA_ID_ENCODINGCOMPALGO, EBML_UINT, 0, offsetof(MatroskaTrackCompression,algo), {.u=0} }, | |
274 { MATROSKA_ID_ENCODINGCOMPSETTINGS,EBML_BIN, 0, offsetof(MatroskaTrackCompression,settings) }, | |
275 { EBML_ID_VOID, EBML_NONE }, | |
276 { 0 } | |
277 }; | |
278 | |
279 static EbmlSyntax matroska_track_encoding[] = { | |
280 { MATROSKA_ID_ENCODINGSCOPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,scope), {.u=1} }, | |
281 { MATROSKA_ID_ENCODINGTYPE, EBML_UINT, 0, offsetof(MatroskaTrackEncoding,type), {.u=0} }, | |
282 { MATROSKA_ID_ENCODINGCOMPRESSION,EBML_NEST, 0, offsetof(MatroskaTrackEncoding,compression), {.n=matroska_track_encoding_compression} }, | |
283 { EBML_ID_VOID, EBML_NONE }, | |
284 { 0 } | |
285 }; | |
286 | |
287 static EbmlSyntax matroska_track_encodings[] = { | |
288 { MATROSKA_ID_TRACKCONTENTENCODING, EBML_NEST, sizeof(MatroskaTrackEncoding), offsetof(MatroskaTrack,encodings), {.n=matroska_track_encoding} }, | |
289 { EBML_ID_VOID, EBML_NONE }, | |
290 { 0 } | |
291 }; | |
292 | |
293 static EbmlSyntax matroska_track[] = { | |
294 { MATROSKA_ID_TRACKNUMBER, EBML_UINT, 0, offsetof(MatroskaTrack,num) }, | |
295 { MATROSKA_ID_TRACKTYPE, EBML_UINT, 0, offsetof(MatroskaTrack,type) }, | |
296 { MATROSKA_ID_CODECID, EBML_STR, 0, offsetof(MatroskaTrack,codec_id) }, | |
297 { MATROSKA_ID_CODECPRIVATE, EBML_BIN, 0, offsetof(MatroskaTrack,codec_priv) }, | |
298 { MATROSKA_ID_TRACKLANGUAGE, EBML_UTF8, 0, offsetof(MatroskaTrack,language), {.s="eng"} }, | |
299 { MATROSKA_ID_TRACKDEFAULTDURATION, EBML_UINT, 0, offsetof(MatroskaTrack,default_duration) }, | |
300 { MATROSKA_ID_TRACKTIMECODESCALE, EBML_FLOAT,0, offsetof(MatroskaTrack,time_scale), {.f=1.0} }, | |
301 { MATROSKA_ID_TRACKFLAGDEFAULT, EBML_UINT, 0, offsetof(MatroskaTrack,flag_default), {.u=1} }, | |
302 { MATROSKA_ID_TRACKVIDEO, EBML_NEST, 0, offsetof(MatroskaTrack,video), {.n=matroska_track_video} }, | |
303 { MATROSKA_ID_TRACKAUDIO, EBML_NEST, 0, offsetof(MatroskaTrack,audio), {.n=matroska_track_audio} }, | |
304 { MATROSKA_ID_TRACKCONTENTENCODINGS,EBML_NEST, 0, 0, {.n=matroska_track_encodings} }, | |
305 { MATROSKA_ID_TRACKUID, EBML_NONE }, | |
306 { MATROSKA_ID_TRACKNAME, EBML_NONE }, | |
307 { MATROSKA_ID_TRACKFLAGENABLED, EBML_NONE }, | |
308 { MATROSKA_ID_TRACKFLAGFORCED, EBML_NONE }, | |
309 { MATROSKA_ID_TRACKFLAGLACING, EBML_NONE }, | |
310 { MATROSKA_ID_CODECNAME, EBML_NONE }, | |
311 { MATROSKA_ID_CODECDECODEALL, EBML_NONE }, | |
312 { MATROSKA_ID_CODECINFOURL, EBML_NONE }, | |
313 { MATROSKA_ID_CODECDOWNLOADURL, EBML_NONE }, | |
314 { MATROSKA_ID_TRACKMINCACHE, EBML_NONE }, | |
315 { MATROSKA_ID_TRACKMAXCACHE, EBML_NONE }, | |
316 { EBML_ID_VOID, EBML_NONE }, | |
317 { 0 } | |
318 }; | |
319 | |
320 static EbmlSyntax matroska_tracks[] = { | |
321 { MATROSKA_ID_TRACKENTRY, EBML_NEST, sizeof(MatroskaTrack), offsetof(MatroskaDemuxContext,tracks), {.n=matroska_track} }, | |
322 { EBML_ID_VOID, EBML_NONE }, | |
323 { 0 } | |
324 }; | |
325 | |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
326 static EbmlSyntax matroska_attachment[] = { |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
327 { MATROSKA_ID_FILENAME, EBML_UTF8, 0, offsetof(MatroskaAttachement,filename) }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
328 { MATROSKA_ID_FILEMIMETYPE, EBML_STR, 0, offsetof(MatroskaAttachement,mime) }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
329 { MATROSKA_ID_FILEDATA, EBML_BIN, 0, offsetof(MatroskaAttachement,bin) }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
330 { MATROSKA_ID_FILEUID, EBML_NONE }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
331 { EBML_ID_VOID, EBML_NONE }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
332 { 0 } |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
333 }; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
334 |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
335 static EbmlSyntax matroska_attachments[] = { |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
336 { MATROSKA_ID_ATTACHEDFILE, EBML_NEST, sizeof(MatroskaAttachement), offsetof(MatroskaDemuxContext,attachments), {.n=matroska_attachment} }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
337 { EBML_ID_VOID, EBML_NONE }, |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
338 { 0 } |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
339 }; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
340 |
3639 | 341 static EbmlSyntax matroska_chapter_display[] = { |
342 { MATROSKA_ID_CHAPSTRING, EBML_UTF8, 0, offsetof(MatroskaChapter,title) }, | |
343 { EBML_ID_VOID, EBML_NONE }, | |
344 { 0 } | |
345 }; | |
346 | |
347 static EbmlSyntax matroska_chapter_entry[] = { | |
348 { MATROSKA_ID_CHAPTERTIMESTART, EBML_UINT, 0, offsetof(MatroskaChapter,start), {.u=AV_NOPTS_VALUE} }, | |
349 { MATROSKA_ID_CHAPTERTIMEEND, EBML_UINT, 0, offsetof(MatroskaChapter,end), {.u=AV_NOPTS_VALUE} }, | |
350 { MATROSKA_ID_CHAPTERUID, EBML_UINT, 0, offsetof(MatroskaChapter,uid) }, | |
351 { MATROSKA_ID_CHAPTERDISPLAY, EBML_NEST, 0, 0, {.n=matroska_chapter_display} }, | |
352 { MATROSKA_ID_CHAPTERFLAGHIDDEN, EBML_NONE }, | |
353 { EBML_ID_VOID, EBML_NONE }, | |
354 { 0 } | |
355 }; | |
356 | |
357 static EbmlSyntax matroska_chapter[] = { | |
358 { MATROSKA_ID_CHAPTERATOM, EBML_NEST, sizeof(MatroskaChapter), offsetof(MatroskaDemuxContext,chapters), {.n=matroska_chapter_entry} }, | |
359 { MATROSKA_ID_EDITIONUID, EBML_NONE }, | |
360 { MATROSKA_ID_EDITIONFLAGHIDDEN, EBML_NONE }, | |
361 { MATROSKA_ID_EDITIONFLAGDEFAULT, EBML_NONE }, | |
362 { EBML_ID_VOID, EBML_NONE }, | |
363 { 0 } | |
364 }; | |
365 | |
366 static EbmlSyntax matroska_chapters[] = { | |
367 { MATROSKA_ID_EDITIONENTRY, EBML_NEST, 0, 0, {.n=matroska_chapter} }, | |
368 { EBML_ID_VOID, EBML_NONE }, | |
369 { 0 } | |
370 }; | |
371 | |
3637 | 372 static EbmlSyntax matroska_index_pos[] = { |
373 { MATROSKA_ID_CUETRACK, EBML_UINT, 0, offsetof(MatroskaIndexPos,track) }, | |
374 { MATROSKA_ID_CUECLUSTERPOSITION, EBML_UINT, 0, offsetof(MatroskaIndexPos,pos) }, | |
375 { EBML_ID_VOID, EBML_NONE }, | |
376 { 0 } | |
377 }; | |
378 | |
379 static EbmlSyntax matroska_index_entry[] = { | |
380 { MATROSKA_ID_CUETIME, EBML_UINT, 0, offsetof(MatroskaIndex,time) }, | |
381 { MATROSKA_ID_CUETRACKPOSITION, EBML_NEST, sizeof(MatroskaIndexPos), offsetof(MatroskaIndex,pos), {.n=matroska_index_pos} }, | |
382 { EBML_ID_VOID, EBML_NONE }, | |
383 { 0 } | |
384 }; | |
385 | |
386 static EbmlSyntax matroska_index[] = { | |
387 { MATROSKA_ID_POINTENTRY, EBML_NEST, sizeof(MatroskaIndex), offsetof(MatroskaDemuxContext,index), {.n=matroska_index_entry} }, | |
388 { EBML_ID_VOID, EBML_NONE }, | |
389 { 0 } | |
390 }; | |
391 | |
3638 | 392 static EbmlSyntax matroska_tags[] = { |
393 { EBML_ID_VOID, EBML_NONE }, | |
394 { 0 } | |
395 }; | |
396 | |
3644 | 397 static EbmlSyntax matroska_seekhead_entry[] = { |
398 { MATROSKA_ID_SEEKID, EBML_UINT, 0, offsetof(MatroskaSeekhead,id) }, | |
399 { MATROSKA_ID_SEEKPOSITION, EBML_UINT, 0, offsetof(MatroskaSeekhead,pos), {.u=-1} }, | |
400 { EBML_ID_VOID, EBML_NONE }, | |
401 { 0 } | |
402 }; | |
403 | |
404 static EbmlSyntax matroska_seekhead[] = { | |
405 { MATROSKA_ID_SEEKENTRY, EBML_NEST, sizeof(MatroskaSeekhead), offsetof(MatroskaDemuxContext,seekhead), {.n=matroska_seekhead_entry} }, | |
406 { EBML_ID_VOID, EBML_NONE }, | |
407 { 0 } | |
408 }; | |
409 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
410 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
411 * The first few functions handle EBML file parsing. The rest |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
412 * is the document interpretation. Matroska really just is a |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
413 * EBML file. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
414 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
415 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
416 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
417 * Return: the amount of levels in the hierarchy that the |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
418 * current element lies higher than the previous one. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
419 * The opposite isn't done - that's auto-done using master |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
420 * element reading. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
421 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
422 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
423 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
424 ebml_read_element_level_up (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
425 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
426 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
427 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
428 int num = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
429 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
430 while (matroska->num_levels > 0) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
431 MatroskaLevel *level = &matroska->levels[matroska->num_levels - 1]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
432 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
433 if (pos >= level->start + level->length) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
434 matroska->num_levels--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
435 num++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
436 } else { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
437 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
438 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
439 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
440 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
441 return num; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
442 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
443 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
444 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
445 * Read: an "EBML number", which is defined as a variable-length |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
446 * array of bytes. The first byte indicates the length by giving a |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
447 * number of 0-bits followed by a one. The position of the first |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
448 * "one" bit inside the first byte indicates the length of this |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
449 * number. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
450 * Returns: num. of bytes read. < 0 on error. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
451 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
452 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
453 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
454 ebml_read_num (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
455 int max_size, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
456 uint64_t *number) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
457 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
458 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
459 int len_mask = 0x80, read = 1, n = 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
460 int64_t total = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
461 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
462 /* the first byte tells us the length in bytes - get_byte() can normally |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
463 * return 0, but since that's not a valid first ebmlID byte, we can |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
464 * use it safely here to catch EOS. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
465 if (!(total = get_byte(pb))) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
466 /* we might encounter EOS here */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
467 if (!url_feof(pb)) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
468 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
469 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 470 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
471 pos, pos); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
472 } |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
473 return AVERROR(EIO); /* EOS or actual I/O error */ |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
474 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
475 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
476 /* get the length of the EBML number */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
477 while (read <= max_size && !(total & len_mask)) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
478 read++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
479 len_mask >>= 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
480 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
481 if (read > max_size) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
482 offset_t pos = url_ftell(pb) - 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
483 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 484 "Invalid EBML number size tag 0x%02x at pos %"PRIu64" (0x%"PRIx64")\n", |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
485 (uint8_t) total, pos, pos); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
486 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
487 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
488 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
489 /* read out length */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
490 total &= ~len_mask; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
491 while (n++ < read) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
492 total = (total << 8) | get_byte(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
493 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
494 *number = total; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
495 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
496 return read; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
497 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
498 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
499 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
500 * Read: the element content data ID. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
501 * Return: the number of bytes read or < 0 on error. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
502 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
503 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
504 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
505 ebml_read_element_id (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
506 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
507 int *level_up) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
508 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
509 int read; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
510 uint64_t total; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
511 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
512 /* if we re-call this, use our cached ID */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
513 if (matroska->peek_id != 0) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
514 if (level_up) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
515 *level_up = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
516 *id = matroska->peek_id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
517 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
518 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
519 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
520 /* read out the "EBML number", include tag in ID */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
521 if ((read = ebml_read_num(matroska, 4, &total)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
522 return read; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
523 *id = matroska->peek_id = total | (1 << (read * 7)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
524 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
525 /* level tracking */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
526 if (level_up) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
527 *level_up = ebml_read_element_level_up(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
528 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
529 return read; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
530 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
531 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
532 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
533 * Read: element content length. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
534 * Return: the number of bytes read or < 0 on error. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
535 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
536 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
537 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
538 ebml_read_element_length (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
539 uint64_t *length) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
540 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
541 /* clear cache since we're now beyond that data point */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
542 matroska->peek_id = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
543 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
544 /* read out the "EBML number", include tag in ID */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
545 return ebml_read_num(matroska, 8, length); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
546 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
547 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
548 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
549 * Return: the ID of the next element, or 0 on error. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
550 * Level_up contains the amount of levels that this |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
551 * next element lies higher than the previous one. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
552 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
553 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
554 static uint32_t |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
555 ebml_peek_id (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
556 int *level_up) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
557 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
558 uint32_t id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
559 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
560 if (ebml_read_element_id(matroska, &id, level_up) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
561 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
562 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
563 return id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
564 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
565 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
566 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
567 * Seek to a given offset. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
568 * 0 is success, -1 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
569 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
570 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
571 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
572 ebml_read_seek (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
573 offset_t offset) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
574 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
575 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
576 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
577 /* clear ID cache, if any */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
578 matroska->peek_id = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
579 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
580 return (url_fseek(pb, offset, SEEK_SET) == offset) ? 0 : -1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
581 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
582 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
583 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
584 * Skip the next element. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
585 * 0 is success, -1 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
586 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
587 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
588 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
589 ebml_read_skip (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
590 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
591 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
592 uint32_t id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
593 uint64_t length; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
594 int res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
595 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
596 if ((res = ebml_read_element_id(matroska, &id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
597 (res = ebml_read_element_length(matroska, &length)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
598 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
599 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
600 url_fskip(pb, length); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
601 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
602 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
603 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
604 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
605 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
606 * Read the next element as an unsigned int. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
607 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
608 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
609 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
610 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
611 ebml_read_uint (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
612 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
613 uint64_t *num) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
614 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
615 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
616 int n = 0, size, res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
617 uint64_t rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
618 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
619 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
620 (res = ebml_read_element_length(matroska, &rlength)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
621 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
622 size = rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
623 if (size < 1 || size > 8) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
624 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
625 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 626 "Invalid uint element size %d at position %"PRId64" (0x%"PRIx64")\n", |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
627 size, pos, pos); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
628 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
629 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
630 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
631 /* big-endian ordening; build up number */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
632 *num = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
633 while (n++ < size) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
634 *num = (*num << 8) | get_byte(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
635 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
636 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
637 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
638 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
639 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
640 * Read the next element as a signed int. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
641 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
642 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
643 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
644 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
645 ebml_read_sint (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
646 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
647 int64_t *num) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
648 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
649 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
650 int size, n = 1, negative = 0, res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
651 uint64_t rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
652 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
653 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
654 (res = ebml_read_element_length(matroska, &rlength)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
655 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
656 size = rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
657 if (size < 1 || size > 8) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
658 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
659 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 660 "Invalid sint element size %d at position %"PRId64" (0x%"PRIx64")\n", |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
661 size, pos, pos); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
662 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
663 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
664 if ((*num = get_byte(pb)) & 0x80) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
665 negative = 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
666 *num &= ~0x80; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
667 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
668 while (n++ < size) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
669 *num = (*num << 8) | get_byte(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
670 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
671 /* make signed */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
672 if (negative) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
673 *num = *num - (1LL << ((8 * size) - 1)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
674 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
675 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
676 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
677 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
678 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
679 * Read the next element as a float. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
680 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
681 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
682 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
683 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
684 ebml_read_float (MatroskaDemuxContext *matroska, |
887 | 685 uint32_t *id, |
686 double *num) | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
687 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
688 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
689 int size, res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
690 uint64_t rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
691 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
692 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
693 (res = ebml_read_element_length(matroska, &rlength)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
694 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
695 size = rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
696 |
824 | 697 if (size == 4) { |
698 *num= av_int2flt(get_be32(pb)); | |
699 } else if(size==8){ | |
700 *num= av_int2dbl(get_be64(pb)); | |
701 } else{ | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
702 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
703 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 704 "Invalid float element size %d at position %"PRIu64" (0x%"PRIx64")\n", |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
705 size, pos, pos); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
706 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
707 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
708 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
709 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
710 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
711 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
712 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
713 * Read the next element as an ASCII string. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
714 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
715 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
716 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
717 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
718 ebml_read_ascii (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
719 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
720 char **str) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
721 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
722 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
723 int size, res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
724 uint64_t rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
725 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
726 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
727 (res = ebml_read_element_length(matroska, &rlength)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
728 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
729 size = rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
730 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
731 /* ebml strings are usually not 0-terminated, so we allocate one |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
732 * byte more, read the string and NULL-terminate it ourselves. */ |
639 | 733 if (size < 0 || !(*str = av_malloc(size + 1))) { |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
734 av_log(matroska->ctx, AV_LOG_ERROR, "Memory allocation failed\n"); |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2264
diff
changeset
|
735 return AVERROR(ENOMEM); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
736 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
737 if (get_buffer(pb, (uint8_t *) *str, size) != size) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
738 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
739 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 740 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); |
3416 | 741 av_free(*str); |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
742 return AVERROR(EIO); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
743 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
744 (*str)[size] = '\0'; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
745 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
746 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
747 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
748 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
749 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
750 * Read the next element as a UTF-8 string. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
751 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
752 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
753 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
754 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
755 ebml_read_utf8 (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
756 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
757 char **str) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
758 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
759 return ebml_read_ascii(matroska, id, str); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
760 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
761 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
762 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
763 * Read the next element, but only the header. The contents |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
764 * are supposed to be sub-elements which can be read separately. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
765 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
766 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
767 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
768 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
769 ebml_read_master (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
770 uint32_t *id) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
771 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
772 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
773 uint64_t length; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
774 MatroskaLevel *level; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
775 int res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
776 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
777 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
778 (res = ebml_read_element_length(matroska, &length)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
779 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
780 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
781 /* protect... (Heaven forbids that the '>' is true) */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
782 if (matroska->num_levels >= EBML_MAX_DEPTH) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
783 av_log(matroska->ctx, AV_LOG_ERROR, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
784 "File moves beyond max. allowed depth (%d)\n", EBML_MAX_DEPTH); |
2276
3c1e2d519277
Replace all occurrences of AVERROR_NOTSUPP with AVERROR(ENOSYS).
takis
parents:
2274
diff
changeset
|
785 return AVERROR(ENOSYS); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
786 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
787 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
788 /* remember level */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
789 level = &matroska->levels[matroska->num_levels++]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
790 level->start = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
791 level->length = length; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
792 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
793 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
794 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
795 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
796 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
797 * Read the next element as binary data. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
798 * 0 is success, < 0 is failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
799 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
800 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
801 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
802 ebml_read_binary (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
803 uint32_t *id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
804 uint8_t **binary, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
805 int *size) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
806 { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
807 ByteIOContext *pb = matroska->ctx->pb; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
808 uint64_t rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
809 int res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
810 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
811 if ((res = ebml_read_element_id(matroska, id, NULL)) < 0 || |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
812 (res = ebml_read_element_length(matroska, &rlength)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
813 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
814 *size = rlength; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
815 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
816 if (!(*binary = av_malloc(*size))) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
817 av_log(matroska->ctx, AV_LOG_ERROR, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
818 "Memory allocation error\n"); |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2264
diff
changeset
|
819 return AVERROR(ENOMEM); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
820 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
821 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
822 if (get_buffer(pb, *binary, *size) != *size) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
823 offset_t pos = url_ftell(pb); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
824 av_log(matroska->ctx, AV_LOG_ERROR, |
881 | 825 "Read error at pos. %"PRIu64" (0x%"PRIx64")\n", pos, pos); |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
826 return AVERROR(EIO); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
827 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
828 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
829 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
830 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
831 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
832 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
833 * Read signed/unsigned "EBML" numbers. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
834 * Return: number of bytes processed, < 0 on error. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
835 * XXX: use ebml_read_num(). |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
836 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
837 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
838 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
839 matroska_ebmlnum_uint (uint8_t *data, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
840 uint32_t size, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
841 uint64_t *num) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
842 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
843 int len_mask = 0x80, read = 1, n = 1, num_ffs = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
844 uint64_t total; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
845 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
846 if (size <= 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
847 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
848 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
849 total = data[0]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
850 while (read <= 8 && !(total & len_mask)) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
851 read++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
852 len_mask >>= 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
853 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
854 if (read > 8) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
855 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
856 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
857 if ((total &= (len_mask - 1)) == len_mask - 1) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
858 num_ffs++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
859 if (size < read) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
860 return AVERROR_INVALIDDATA; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
861 while (n < read) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
862 if (data[n] == 0xff) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
863 num_ffs++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
864 total = (total << 8) | data[n]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
865 n++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
866 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
867 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
868 if (read == num_ffs) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
869 *num = (uint64_t)-1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
870 else |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
871 *num = total; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
872 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
873 return read; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
874 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
875 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
876 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
877 * Same as above, but signed. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
878 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
879 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
880 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
881 matroska_ebmlnum_sint (uint8_t *data, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
882 uint32_t size, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
883 int64_t *num) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
884 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
885 uint64_t unum; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
886 int res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
887 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
888 /* read as unsigned number first */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
889 if ((res = matroska_ebmlnum_uint(data, size, &unum)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
890 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
891 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
892 /* make signed (weird way) */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
893 if (unum == (uint64_t)-1) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
894 *num = INT64_MAX; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
895 else |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
896 *num = unum - ((1LL << ((7 * res) - 1)) - 1); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
897 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
898 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
899 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
900 |
2011 | 901 |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
902 static MatroskaTrack * |
2011 | 903 matroska_find_track_by_num (MatroskaDemuxContext *matroska, |
904 int num) | |
905 { | |
3642 | 906 MatroskaTrack *tracks = matroska->tracks.elem; |
2011 | 907 int i; |
908 | |
3642 | 909 for (i=0; i < matroska->tracks.nb_elem; i++) |
910 if (tracks[i].num == num) | |
911 return &tracks[i]; | |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
912 |
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
913 av_log(matroska->ctx, AV_LOG_ERROR, "Invalid track number %d\n", num); |
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
914 return NULL; |
2011 | 915 } |
916 | |
917 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
918 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
919 * Put one packet in an application-supplied AVPacket struct. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
920 * Returns 0 on success or -1 on failure. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
921 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
922 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
923 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
924 matroska_deliver_packet (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
925 AVPacket *pkt) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
926 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
927 if (matroska->num_packets > 0) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
928 memcpy(pkt, matroska->packets[0], sizeof(AVPacket)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
929 av_free(matroska->packets[0]); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
930 if (matroska->num_packets > 1) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
931 memmove(&matroska->packets[0], &matroska->packets[1], |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
932 (matroska->num_packets - 1) * sizeof(AVPacket *)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
933 matroska->packets = |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
934 av_realloc(matroska->packets, (matroska->num_packets - 1) * |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
935 sizeof(AVPacket *)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
936 } else { |
1530 | 937 av_freep(&matroska->packets); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
938 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
939 matroska->num_packets--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
940 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
941 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
942 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
943 return -1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
944 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
945 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
946 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
947 * Put a packet into our internal queue. Will be delivered to the |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
948 * user/application during the next get_packet() call. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
949 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
950 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
951 static void |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
952 matroska_queue_packet (MatroskaDemuxContext *matroska, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
953 AVPacket *pkt) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
954 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
955 matroska->packets = |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
956 av_realloc(matroska->packets, (matroska->num_packets + 1) * |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
957 sizeof(AVPacket *)); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
958 matroska->packets[matroska->num_packets] = pkt; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
959 matroska->num_packets++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
960 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
961 |
2871
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
962 /* |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
963 * Free all packets in our internal queue. |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
964 */ |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
965 static void |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
966 matroska_clear_queue (MatroskaDemuxContext *matroska) |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
967 { |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
968 if (matroska->packets) { |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
969 int n; |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
970 for (n = 0; n < matroska->num_packets; n++) { |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
971 av_free_packet(matroska->packets[n]); |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
972 av_free(matroska->packets[n]); |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
973 } |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
974 av_free(matroska->packets); |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
975 matroska->packets = NULL; |
2881 | 976 matroska->num_packets = 0; |
2871
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
977 } |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
978 } |
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
979 |
1904
df5fe029a504
reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents:
1903
diff
changeset
|
980 |
df5fe029a504
reorder pts of packets from tracks using V_MPEG* codecs
aurel
parents:
1903
diff
changeset
|
981 /* |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
982 * Autodetecting... |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
983 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
984 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
985 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
986 matroska_probe (AVProbeData *p) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
987 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
988 uint64_t total = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
989 int len_mask = 0x80, size = 1, n = 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
990 uint8_t probe_data[] = { 'm', 'a', 't', 'r', 'o', 's', 'k', 'a' }; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
991 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
992 /* ebml header? */ |
2185 | 993 if (AV_RB32(p->buf) != EBML_ID_HEADER) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
994 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
995 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
996 /* length of header */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
997 total = p->buf[4]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
998 while (size <= 8 && !(total & len_mask)) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
999 size++; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1000 len_mask >>= 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1001 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1002 if (size > 8) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1003 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1004 total &= (len_mask - 1); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1005 while (n < size) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1006 total = (total << 8) | p->buf[4 + n++]; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1007 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1008 /* does the probe data contain the whole header? */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1009 if (p->buf_size < 4 + size + total) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1010 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1011 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1012 /* the header must contain the document type 'matroska'. For now, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1013 * we don't parse the whole header but simply check for the |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1014 * availability of that array of characters inside the header. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1015 * Not fully fool-proof, but good enough. */ |
1828 | 1016 for (n = 4 + size; n <= 4 + size + total - sizeof(probe_data); n++) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1017 if (!memcmp (&p->buf[n], probe_data, sizeof(probe_data))) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1018 return AVPROBE_SCORE_MAX; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1019 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1020 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1021 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1022 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1023 /* |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1024 * From here on, it's all XML-style DTD stuff... Needs no comments. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1025 */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1026 |
3632 | 1027 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, |
1028 void *data, uint32_t expected_id, int once); | |
1029 | |
1030 static int ebml_parse_elem(MatroskaDemuxContext *matroska, | |
1031 EbmlSyntax *syntax, void *data) | |
1032 { | |
1033 uint32_t id = syntax->id; | |
1034 EbmlBin *bin; | |
1035 int res; | |
1036 | |
1037 data = (char *)data + syntax->data_offset; | |
1038 if (syntax->list_elem_size) { | |
1039 EbmlList *list = data; | |
1040 list->elem = av_realloc(list->elem, (list->nb_elem+1)*syntax->list_elem_size); | |
1041 data = (char*)list->elem + list->nb_elem*syntax->list_elem_size; | |
1042 memset(data, 0, syntax->list_elem_size); | |
1043 list->nb_elem++; | |
1044 } | |
1045 bin = data; | |
1046 | |
1047 switch (syntax->type) { | |
1048 case EBML_UINT: return ebml_read_uint (matroska, &id, data); | |
1049 case EBML_FLOAT: return ebml_read_float(matroska, &id, data); | |
1050 case EBML_STR: | |
1051 case EBML_UTF8: av_free(*(char **)data); | |
1052 return ebml_read_ascii(matroska, &id, data); | |
1053 case EBML_BIN: av_free(bin->data); | |
1054 bin->pos = url_ftell(matroska->ctx->pb); | |
1055 return ebml_read_binary(matroska, &id, &bin->data, | |
1056 &bin->size); | |
1057 case EBML_NEST: if ((res=ebml_read_master(matroska, &id)) < 0) | |
1058 return res; | |
1059 if (id == MATROSKA_ID_SEGMENT) | |
1060 matroska->segment_start = url_ftell(matroska->ctx->pb); | |
1061 return ebml_parse(matroska, syntax->def.n, data, 0, 0); | |
1062 case EBML_PASS: return ebml_parse(matroska, syntax->def.n, data, 0, 1); | |
1063 case EBML_STOP: *(int *)data = 1; return 1; | |
1064 default: return ebml_read_skip(matroska); | |
1065 } | |
1066 } | |
1067 | |
1068 static int ebml_parse_id(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, | |
1069 uint32_t id, void *data) | |
1070 { | |
1071 int i; | |
1072 for (i=0; syntax[i].id; i++) | |
1073 if (id == syntax[i].id) | |
1074 break; | |
1075 if (!syntax[i].id) | |
1076 av_log(matroska->ctx, AV_LOG_INFO, "Unknown entry 0x%X\n", id); | |
1077 return ebml_parse_elem(matroska, &syntax[i], data); | |
1078 } | |
1079 | |
1080 static int ebml_parse(MatroskaDemuxContext *matroska, EbmlSyntax *syntax, | |
1081 void *data, uint32_t expected_id, int once) | |
1082 { | |
1083 int i, res = 0; | |
1084 uint32_t id = 0; | |
1085 | |
1086 for (i=0; syntax[i].id; i++) | |
1087 switch (syntax[i].type) { | |
1088 case EBML_UINT: | |
1089 *(uint64_t *)((char *)data+syntax[i].data_offset) = syntax[i].def.u; | |
1090 break; | |
1091 case EBML_FLOAT: | |
1092 *(double *)((char *)data+syntax[i].data_offset) = syntax[i].def.f; | |
1093 break; | |
1094 case EBML_STR: | |
1095 case EBML_UTF8: | |
1096 *(char **)((char *)data+syntax[i].data_offset) = av_strdup(syntax[i].def.s); | |
1097 break; | |
1098 } | |
1099 | |
1100 if (expected_id) { | |
1101 res = ebml_read_master(matroska, &id); | |
1102 if (id != expected_id) | |
1103 return AVERROR_INVALIDDATA; | |
1104 if (id == MATROSKA_ID_SEGMENT) | |
1105 matroska->segment_start = url_ftell(matroska->ctx->pb); | |
1106 } | |
1107 | |
1108 while (!res) { | |
1109 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { | |
1110 res = AVERROR(EIO); | |
1111 break; | |
1112 } else if (matroska->level_up) { | |
1113 matroska->level_up--; | |
1114 break; | |
1115 } | |
1116 | |
1117 res = ebml_parse_id(matroska, syntax, id, data); | |
1118 if (once) | |
1119 break; | |
1120 | |
1121 | |
1122 if (matroska->level_up) { | |
1123 matroska->level_up--; | |
1124 break; | |
1125 } | |
1126 } | |
1127 | |
1128 return res; | |
1129 } | |
1130 | |
1131 static void ebml_free(EbmlSyntax *syntax, void *data) | |
1132 { | |
1133 int i, j; | |
1134 for (i=0; syntax[i].id; i++) { | |
1135 void *data_off = (char *)data + syntax[i].data_offset; | |
1136 switch (syntax[i].type) { | |
1137 case EBML_STR: | |
1138 case EBML_UTF8: av_freep(data_off); break; | |
1139 case EBML_BIN: av_freep(&((EbmlBin *)data_off)->data); break; | |
1140 case EBML_NEST: | |
1141 if (syntax[i].list_elem_size) { | |
1142 EbmlList *list = data_off; | |
1143 char *ptr = list->elem; | |
1144 for (j=0; j<list->nb_elem; j++, ptr+=syntax[i].list_elem_size) | |
1145 ebml_free(syntax[i].def.n, ptr); | |
1146 av_free(list->elem); | |
1147 } else | |
1148 ebml_free(syntax[i].def.n, data_off); | |
1149 default: break; | |
1150 } | |
1151 } | |
1152 } | |
1153 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1154 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1155 matroska_parse_info (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1156 { |
3641 | 1157 int res = ebml_parse(matroska, matroska_info, matroska, MATROSKA_ID_INFO, 0); |
1158 | |
1159 if (matroska->duration) | |
1160 matroska->ctx->duration = matroska->duration * matroska->time_scale | |
1161 * 1000 / AV_TIME_BASE; | |
1162 if (matroska->title) | |
1163 strncpy(matroska->ctx->title, matroska->title, | |
1164 sizeof(matroska->ctx->title)-1); | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1165 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1166 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1167 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1168 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1169 static int |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1170 matroska_decode_buffer(uint8_t** buf, int* buf_size, MatroskaTrack *track) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1171 { |
3642 | 1172 MatroskaTrackEncoding *encodings = track->encodings.elem; |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1173 uint8_t* data = *buf; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1174 int isize = *buf_size; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1175 uint8_t* pkt_data = NULL; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1176 int pkt_size = isize; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1177 int result = 0; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1178 int olen; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1179 |
3642 | 1180 switch (encodings[0].compression.algo) { |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1181 case MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP: |
3642 | 1182 return encodings[0].compression.settings.size; |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1183 case MATROSKA_TRACK_ENCODING_COMP_LZO: |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1184 do { |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1185 olen = pkt_size *= 3; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1186 pkt_data = av_realloc(pkt_data, |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1187 pkt_size+LZO_OUTPUT_PADDING); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1188 result = lzo1x_decode(pkt_data, &olen, data, &isize); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1189 } while (result==LZO_OUTPUT_FULL && pkt_size<10000000); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1190 if (result) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1191 goto failed; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1192 pkt_size -= olen; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1193 break; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1194 #ifdef CONFIG_ZLIB |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1195 case MATROSKA_TRACK_ENCODING_COMP_ZLIB: { |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1196 z_stream zstream = {0}; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1197 if (inflateInit(&zstream) != Z_OK) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1198 return -1; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1199 zstream.next_in = data; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1200 zstream.avail_in = isize; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1201 do { |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1202 pkt_size *= 3; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1203 pkt_data = av_realloc(pkt_data, pkt_size); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1204 zstream.avail_out = pkt_size - zstream.total_out; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1205 zstream.next_out = pkt_data + zstream.total_out; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1206 result = inflate(&zstream, Z_NO_FLUSH); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1207 } while (result==Z_OK && pkt_size<10000000); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1208 pkt_size = zstream.total_out; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1209 inflateEnd(&zstream); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1210 if (result != Z_STREAM_END) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1211 goto failed; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1212 break; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1213 } |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1214 #endif |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1215 #ifdef CONFIG_BZLIB |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1216 case MATROSKA_TRACK_ENCODING_COMP_BZLIB: { |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1217 bz_stream bzstream = {0}; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1218 if (BZ2_bzDecompressInit(&bzstream, 0, 0) != BZ_OK) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1219 return -1; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1220 bzstream.next_in = data; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1221 bzstream.avail_in = isize; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1222 do { |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1223 pkt_size *= 3; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1224 pkt_data = av_realloc(pkt_data, pkt_size); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1225 bzstream.avail_out = pkt_size - bzstream.total_out_lo32; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1226 bzstream.next_out = pkt_data + bzstream.total_out_lo32; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1227 result = BZ2_bzDecompress(&bzstream); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1228 } while (result==BZ_OK && pkt_size<10000000); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1229 pkt_size = bzstream.total_out_lo32; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1230 BZ2_bzDecompressEnd(&bzstream); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1231 if (result != BZ_STREAM_END) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1232 goto failed; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1233 break; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1234 } |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1235 #endif |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1236 } |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1237 |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1238 *buf = pkt_data; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1239 *buf_size = pkt_size; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1240 return 0; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1241 failed: |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1242 av_free(pkt_data); |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1243 return -1; |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1244 } |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1245 |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
1246 static int |
3642 | 1247 matroska_parse_tracks (MatroskaDemuxContext *matroska) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1248 { |
3642 | 1249 MatroskaTrack *tracks; |
1250 int i, res; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1251 |
3642 | 1252 res = ebml_parse(matroska, matroska_tracks, matroska, MATROSKA_ID_TRACKS, 0); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1253 |
3642 | 1254 tracks = matroska->tracks.elem; |
1255 for (i=0; i<matroska->tracks.nb_elem; i++) { | |
1256 MatroskaTrack *track = &tracks[i]; | |
1257 EbmlList *encodings_list = &tracks->encodings; | |
1258 MatroskaTrackEncoding *encodings = encodings_list->elem; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1259 |
3642 | 1260 if (track->type != MATROSKA_TRACK_TYPE_VIDEO && |
1261 track->type != MATROSKA_TRACK_TYPE_AUDIO && | |
1262 track->type != MATROSKA_TRACK_TYPE_SUBTITLE) { | |
1263 av_log(matroska->ctx, AV_LOG_INFO, | |
1264 "Unknown or unsupported track type %"PRIu64"\n", | |
1265 track->type); | |
1266 continue; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1267 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1268 |
3642 | 1269 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { |
1270 if (!track->default_duration) | |
1271 track->default_duration = 1000000000/track->video.frame_rate; | |
1272 if (!track->video.display_width) | |
1273 track->video.display_width = track->video.pixel_width; | |
1274 if (!track->video.display_height) | |
1275 track->video.display_height = track->video.pixel_height; | |
1276 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { | |
1277 if (!track->audio.out_samplerate) | |
1278 track->audio.out_samplerate = track->audio.samplerate; | |
1279 } | |
1280 if (encodings_list->nb_elem > 1) { | |
1281 av_log(matroska->ctx, AV_LOG_ERROR, | |
1282 "Multiple combined encodings no supported"); | |
1283 } else if (encodings_list->nb_elem == 1) { | |
1284 if (encodings[0].type || | |
1285 (encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_HEADERSTRIP && | |
3293 | 1286 #ifdef CONFIG_ZLIB |
3642 | 1287 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_ZLIB && |
3293 | 1288 #endif |
3298
edabe3db2b6e
matroskadec: add support for bzlib compressed tracks
aurel
parents:
3294
diff
changeset
|
1289 #ifdef CONFIG_BZLIB |
3642 | 1290 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_BZLIB && |
3298
edabe3db2b6e
matroskadec: add support for bzlib compressed tracks
aurel
parents:
3294
diff
changeset
|
1291 #endif |
3642 | 1292 encodings[0].compression.algo != MATROSKA_TRACK_ENCODING_COMP_LZO)) { |
1293 encodings[0].scope = 0; | |
1294 av_log(matroska->ctx, AV_LOG_ERROR, | |
1295 "Unsupported encoding type"); | |
1296 } else if (track->codec_priv.size && encodings[0].scope&2) { | |
1297 uint8_t *codec_priv = track->codec_priv.data; | |
1298 int offset = matroska_decode_buffer(&track->codec_priv.data, | |
1299 &track->codec_priv.size, | |
1300 track); | |
1301 if (offset < 0) { | |
1302 track->codec_priv.data = NULL; | |
1303 track->codec_priv.size = 0; | |
1304 av_log(matroska->ctx, AV_LOG_ERROR, | |
1305 "Failed to decode codec private data\n"); | |
1306 } else if (offset > 0) { | |
1307 track->codec_priv.data = av_malloc(track->codec_priv.size + offset); | |
1308 memcpy(track->codec_priv.data, | |
1309 encodings[0].compression.settings.data, offset); | |
1310 memcpy(track->codec_priv.data+offset, codec_priv, | |
1311 track->codec_priv.size); | |
1312 track->codec_priv.size += offset; | |
3279 | 1313 } |
3642 | 1314 if (codec_priv != track->codec_priv.data) |
1315 av_free(codec_priv); | |
3408
da09478c97ce
matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents:
3407
diff
changeset
|
1316 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1317 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1318 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1319 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1320 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1321 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1322 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1323 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1324 matroska_parse_index (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1325 { |
3637 | 1326 return ebml_parse(matroska, matroska_index, matroska, MATROSKA_ID_CUES, 0); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1327 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1328 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1329 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1330 matroska_parse_metadata (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1331 { |
3638 | 1332 return ebml_parse(matroska, matroska_tags, matroska, MATROSKA_ID_TAGS, 0); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1333 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1334 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1335 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1336 matroska_parse_seekhead (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1337 { |
3644 | 1338 return ebml_parse(matroska, matroska_seekhead, matroska, MATROSKA_ID_SEEKHEAD, 0); |
1339 } | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1340 |
3644 | 1341 static void |
1342 matroska_execute_seekhead(MatroskaDemuxContext *matroska) | |
1343 { | |
1344 EbmlList *seekhead_list = &matroska->seekhead; | |
1345 MatroskaSeekhead *seekhead = seekhead_list->elem; | |
1346 uint32_t peek_id_cache = matroska->peek_id; | |
1347 uint32_t level_up = matroska->level_up; | |
1348 offset_t before_pos = url_ftell(matroska->ctx->pb); | |
1349 MatroskaLevel level; | |
1350 uint32_t id; | |
1351 int i, res; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1352 |
3644 | 1353 for (i=0; i<seekhead_list->nb_elem; i++) { |
1354 if (seekhead[i].pos <= before_pos | |
1355 || seekhead[i].id == MATROSKA_ID_SEEKHEAD | |
1356 || seekhead[i].id == MATROSKA_ID_CLUSTER) | |
1357 continue; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1358 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1359 /* seek */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1360 if (ebml_read_seek(matroska, |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1361 seekhead[i].pos+matroska->segment_start) < 0) |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1362 continue; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1363 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1364 /* we don't want to lose our seekhead level, so we add |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1365 * a dummy. This is a crude hack. */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1366 if (matroska->num_levels == EBML_MAX_DEPTH) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1367 av_log(matroska->ctx, AV_LOG_INFO, |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1368 "Max EBML element depth (%d) reached, " |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1369 "cannot parse further.\n", EBML_MAX_DEPTH); |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1370 break; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1371 } |
885 | 1372 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1373 level.start = 0; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1374 level.length = (uint64_t)-1; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1375 matroska->levels[matroska->num_levels] = level; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1376 matroska->num_levels++; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1377 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1378 /* check ID */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1379 if (!(id = ebml_peek_id (matroska, |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1380 &matroska->level_up))) |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1381 goto finish; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1382 if (id != seekhead[i].id) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1383 av_log(matroska->ctx, AV_LOG_INFO, |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1384 "We looked for ID=0x%x but got " |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1385 "ID=0x%x (pos=%"PRIu64")", |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1386 (int)seekhead[i].id, id, seekhead[i].pos + |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1387 matroska->segment_start); |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1388 goto finish; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1389 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1390 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1391 /* read master + parse */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1392 switch (id) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1393 case MATROSKA_ID_CUES: |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1394 if (!(res = matroska_parse_index(matroska)) || |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1395 url_feof(matroska->ctx->pb)) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1396 matroska->index_parsed = 1; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1397 res = 0; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1398 } |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1399 break; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1400 case MATROSKA_ID_TAGS: |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1401 if (!(res = matroska_parse_metadata(matroska)) || |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1402 url_feof(matroska->ctx->pb)) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1403 matroska->metadata_parsed = 1; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1404 res = 0; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1405 } |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1406 break; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1407 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1408 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1409 finish: |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1410 /* remove dummy level */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1411 while (matroska->num_levels) { |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1412 uint64_t length = matroska->levels[--matroska->num_levels].length; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1413 if (length == (uint64_t)-1) |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1414 break; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1415 } |
3644 | 1416 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1417 |
3646
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1418 /* seek back */ |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1419 ebml_read_seek(matroska, before_pos); |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1420 matroska->peek_id = peek_id_cache; |
370243aa26c0
matroskadec: cosmetics: indentation of matroska_execute_seekhead()
aurel
parents:
3645
diff
changeset
|
1421 matroska->level_up = level_up; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1422 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1423 |
2973 | 1424 static int |
1425 matroska_parse_attachments(AVFormatContext *s) | |
1426 { | |
1427 MatroskaDemuxContext *matroska = s->priv_data; | |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1428 EbmlList *attachements_list = &matroska->attachments; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1429 MatroskaAttachement *attachements; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1430 int i, j, res; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1431 |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1432 res = ebml_parse(matroska, matroska_attachments, matroska, MATROSKA_ID_ATTACHMENTS, 0); |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1433 |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1434 attachements = attachements_list->elem; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1435 for (j=0; j<attachements_list->nb_elem; j++) { |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1436 if (!(attachements[j].filename && attachements[j].mime && |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1437 attachements[j].bin.data && attachements[j].bin.size > 0)) { |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1438 av_log(matroska->ctx, AV_LOG_ERROR, "incomplete attachment\n"); |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1439 } else { |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1440 AVStream *st = av_new_stream(s, matroska->num_streams++); |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1441 if (st == NULL) |
2973 | 1442 break; |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1443 st->filename = av_strdup(attachements[j].filename); |
2973 | 1444 st->codec->codec_id = CODEC_ID_NONE; |
1445 st->codec->codec_type = CODEC_TYPE_ATTACHMENT; | |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1446 st->codec->extradata = av_malloc(attachements[j].bin.size); |
2973 | 1447 if(st->codec->extradata == NULL) |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1448 break; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1449 st->codec->extradata_size = attachements[j].bin.size; |
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1450 memcpy(st->codec->extradata, attachements[j].bin.data, attachements[j].bin.size); |
2973 | 1451 |
1452 for (i=0; ff_mkv_mime_tags[i].id != CODEC_ID_NONE; i++) { | |
3640
122a7c807f80
matroskadec: use generic parser to parse attachments
aurel
parents:
3639
diff
changeset
|
1453 if (!strncmp(ff_mkv_mime_tags[i].str, attachements[j].mime, |
2973 | 1454 strlen(ff_mkv_mime_tags[i].str))) { |
1455 st->codec->codec_id = ff_mkv_mime_tags[i].id; | |
1456 break; | |
1457 } | |
1458 } | |
1459 } | |
1460 } | |
1461 | |
1462 return res; | |
1463 } | |
1464 | |
3315 | 1465 static int |
1466 matroska_parse_chapters(AVFormatContext *s) | |
1467 { | |
1468 MatroskaDemuxContext *matroska = s->priv_data; | |
3639 | 1469 EbmlList *chapters_list = &matroska->chapters; |
1470 MatroskaChapter *chapters; | |
1471 int i, res; | |
1472 | |
1473 res = ebml_parse(matroska, matroska_chapters, matroska, MATROSKA_ID_CHAPTERS, 0); | |
1474 | |
1475 chapters = chapters_list->elem; | |
1476 for (i=0; i<chapters_list->nb_elem; i++) | |
1477 if (chapters[i].start != AV_NOPTS_VALUE && chapters[i].uid) | |
1478 ff_new_chapter(s, chapters[i].uid, (AVRational){1, 1000000000}, | |
1479 chapters[i].start, chapters[i].end, | |
1480 chapters[i].title); | |
3315 | 1481 |
1482 return res; | |
1483 } | |
1484 | |
1468 | 1485 static int |
1486 matroska_aac_profile (char *codec_id) | |
1487 { | |
1488 static const char *aac_profiles[] = { | |
1489 "MAIN", "LC", "SSR" | |
1490 }; | |
1491 int profile; | |
1492 | |
1493 for (profile=0; profile<ARRAY_SIZE(aac_profiles); profile++) | |
1494 if (strstr(codec_id, aac_profiles[profile])) | |
1495 break; | |
1496 return profile + 1; | |
1497 } | |
1498 | |
1499 static int | |
1500 matroska_aac_sri (int samplerate) | |
1501 { | |
1502 int sri; | |
1503 | |
3201 | 1504 for (sri=0; sri<ARRAY_SIZE(ff_mpeg4audio_sample_rates); sri++) |
1505 if (ff_mpeg4audio_sample_rates[sri] == samplerate) | |
1468 | 1506 break; |
1507 return sri; | |
1508 } | |
1509 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1510 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1511 matroska_read_header (AVFormatContext *s, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1512 AVFormatParameters *ap) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1513 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1514 MatroskaDemuxContext *matroska = s->priv_data; |
3648 | 1515 MatroskaTrack *tracks; |
3637 | 1516 EbmlList *index_list; |
1517 MatroskaIndex *index; | |
1518 int i, j, last_level, res = 0; | |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1519 Ebml ebml = { 0 }; |
3648 | 1520 AVStream *st; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1521 uint32_t id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1522 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1523 matroska->ctx = s; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1524 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1525 /* First read the EBML header. */ |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1526 if (ebml_parse(matroska, ebml_syntax, &ebml, 0, 1) |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1527 || ebml.version > EBML_VERSION || ebml.max_size > sizeof(uint64_t) |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1528 || ebml.id_length > sizeof(uint32_t) || strcmp(ebml.doctype, "matroska") |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1529 || ebml.doctype_version > 2) { |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1530 av_log(matroska->ctx, AV_LOG_ERROR, |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1531 "EBML header using unsupported features\n" |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1532 "(EBML version %"PRIu64", doctype %s, doc version %"PRIu64")\n", |
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1533 ebml.version, ebml.doctype, ebml.doctype_version); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1534 return AVERROR_NOFMT; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1535 } |
3633
7a44217312bb
matroskadec: use generic ebml parser to parse ebml header
aurel
parents:
3632
diff
changeset
|
1536 ebml_free(ebml_syntax, &ebml); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1537 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1538 /* The next thing is a segment. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1539 while (1) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1540 if (!(id = ebml_peek_id(matroska, &last_level))) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
1541 return AVERROR(EIO); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1542 if (id == MATROSKA_ID_SEGMENT) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1543 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1544 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1545 /* oi! */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1546 av_log(matroska->ctx, AV_LOG_INFO, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1547 "Expected a Segment ID (0x%x), but received 0x%x!\n", |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1548 MATROSKA_ID_SEGMENT, id); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1549 if ((res = ebml_read_skip(matroska)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1550 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1551 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1552 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1553 /* We now have a Matroska segment. |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1554 * Seeks are from the beginning of the segment, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1555 * after the segment ID/length. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1556 if ((res = ebml_read_master(matroska, &id)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1557 return res; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
1558 matroska->segment_start = url_ftell(s->pb); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1559 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1560 matroska->time_scale = 1000000; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1561 /* we've found our segment, start reading the different contents in here */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1562 while (res == 0) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1563 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
1564 res = AVERROR(EIO); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1565 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1566 } else if (matroska->level_up) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1567 matroska->level_up--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1568 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1569 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1570 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1571 switch (id) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1572 /* stream info */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1573 case MATROSKA_ID_INFO: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1574 res = matroska_parse_info(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1575 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1576 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1577 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1578 /* track info headers */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1579 case MATROSKA_ID_TRACKS: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1580 res = matroska_parse_tracks(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1581 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1582 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1583 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1584 /* stream index */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1585 case MATROSKA_ID_CUES: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1586 if (!matroska->index_parsed) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1587 res = matroska_parse_index(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1588 } else |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1589 res = ebml_read_skip(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1590 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1591 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1592 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1593 /* metadata */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1594 case MATROSKA_ID_TAGS: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1595 if (!matroska->metadata_parsed) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1596 res = matroska_parse_metadata(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1597 } else |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1598 res = ebml_read_skip(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1599 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1600 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1601 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1602 /* file index (if seekable, seek to Cues/Tags to parse it) */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1603 case MATROSKA_ID_SEEKHEAD: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1604 res = matroska_parse_seekhead(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1605 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1606 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1607 |
2973 | 1608 case MATROSKA_ID_ATTACHMENTS: { |
1609 res = matroska_parse_attachments(s); | |
1610 break; | |
1611 } | |
1612 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1613 case MATROSKA_ID_CLUSTER: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1614 /* Do not read the master - this will be done in the next |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1615 * call to matroska_read_packet. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1616 res = 1; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1617 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1618 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1619 |
3315 | 1620 case MATROSKA_ID_CHAPTERS: { |
1621 res = matroska_parse_chapters(s); | |
1622 break; | |
1623 } | |
1624 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1625 default: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1626 av_log(matroska->ctx, AV_LOG_INFO, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1627 "Unknown matroska file header ID 0x%x\n", id); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1628 /* fall-through */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1629 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1630 case EBML_ID_VOID: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1631 res = ebml_read_skip(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1632 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1633 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1634 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1635 if (matroska->level_up) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1636 matroska->level_up--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1637 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1638 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1639 } |
3644 | 1640 matroska_execute_seekhead(matroska); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1641 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1642 /* Have we found a cluster? */ |
3647 | 1643 if (ebml_peek_id(matroska, NULL) != MATROSKA_ID_CLUSTER) |
1644 return -1; | |
1645 | |
1646 { | |
3648 | 1647 tracks = matroska->tracks.elem; |
3642 | 1648 for (i=0; i < matroska->tracks.nb_elem; i++) { |
1649 MatroskaTrack *track = &tracks[i]; | |
1455
e0e7ac1b8601
Ensure codec_id = CODEC_ID_NONE for unknown codecs (don't reuse previous one).
aurel
parents:
1454
diff
changeset
|
1650 enum CodecID codec_id = CODEC_ID_NONE; |
1468 | 1651 uint8_t *extradata = NULL; |
1024 | 1652 int extradata_size = 0; |
1531 | 1653 int extradata_offset = 0; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1654 |
2244 | 1655 /* Apply some sanity checks. */ |
1656 if (track->codec_id == NULL) | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1657 continue; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1658 |
2905
616fb87724b5
Make ff_mkv_codec_tags lie entirely in .rodata section.
aurel
parents:
2881
diff
changeset
|
1659 for(j=0; ff_mkv_codec_tags[j].id != CODEC_ID_NONE; j++){ |
2142
3aa1f0f698de
split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents:
2023
diff
changeset
|
1660 if(!strncmp(ff_mkv_codec_tags[j].str, track->codec_id, |
3aa1f0f698de
split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents:
2023
diff
changeset
|
1661 strlen(ff_mkv_codec_tags[j].str))){ |
3aa1f0f698de
split some common code from the mkv demuxer that will be useful to the muxer
aurel
parents:
2023
diff
changeset
|
1662 codec_id= ff_mkv_codec_tags[j].id; |
1024 | 1663 break; |
1664 } | |
1665 } | |
1666 | |
3635 | 1667 st = track->stream = av_new_stream(s, matroska->num_streams++); |
1668 if (st == NULL) | |
1669 return AVERROR(ENOMEM); | |
1670 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1671 /* Set the FourCC from the CodecID. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1672 /* This is the MS compatibility mode which stores a |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1673 * BITMAPINFOHEADER in the CodecPrivate. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1674 if (!strcmp(track->codec_id, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1675 MATROSKA_CODEC_ID_VIDEO_VFW_FOURCC) && |
3642 | 1676 (track->codec_priv.size >= 40) && |
1677 (track->codec_priv.data != NULL)) { | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1678 /* Offset of biCompression. Stored in LE. */ |
3642 | 1679 track->video.fourcc = AV_RL32(track->codec_priv.data + 16); |
1680 codec_id = codec_get_id(codec_bmp_tags, track->video.fourcc); | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1681 |
1024 | 1682 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1683 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1684 /* This is the MS compatibility mode which stores a |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1685 * WAVEFORMATEX in the CodecPrivate. */ |
885 | 1686 else if (!strcmp(track->codec_id, |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1687 MATROSKA_CODEC_ID_AUDIO_ACM) && |
3642 | 1688 (track->codec_priv.size >= 18) && |
1689 (track->codec_priv.data != NULL)) { | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1690 /* Offset of wFormatTag. Stored in LE. */ |
3642 | 1691 uint16_t tag = AV_RL16(track->codec_priv.data); |
1897
abbc781d608a
use codec_get_id() instead of deprecated codec_get_[bmp/wav]_id()
aurel
parents:
1832
diff
changeset
|
1692 codec_id = codec_get_id(codec_wav_tags, tag); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1693 |
1024 | 1694 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1695 |
3601 | 1696 if (!strcmp(track->codec_id, "V_QUICKTIME") && |
3642 | 1697 (track->codec_priv.size >= 86) && |
1698 (track->codec_priv.data != NULL)) { | |
1699 track->video.fourcc = AV_RL32(track->codec_priv.data); | |
1700 codec_id=codec_get_id(codec_movvideo_tags, track->video.fourcc); | |
3601 | 1701 } |
1702 | |
3642 | 1703 else if (codec_id == CODEC_ID_AAC && !track->codec_priv.size) { |
1468 | 1704 int profile = matroska_aac_profile(track->codec_id); |
3642 | 1705 int sri = matroska_aac_sri(track->audio.samplerate); |
1468 | 1706 extradata = av_malloc(5); |
1707 if (extradata == NULL) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2264
diff
changeset
|
1708 return AVERROR(ENOMEM); |
1468 | 1709 extradata[0] = (profile << 3) | ((sri&0x0E) >> 1); |
3642 | 1710 extradata[1] = ((sri&0x01) << 7) | (track->audio.channels<<3); |
1468 | 1711 if (strstr(track->codec_id, "SBR")) { |
3642 | 1712 sri = matroska_aac_sri(track->audio.out_samplerate); |
1468 | 1713 extradata[2] = 0x56; |
1714 extradata[3] = 0xE5; | |
1715 extradata[4] = 0x80 | (sri<<3); | |
1716 extradata_size = 5; | |
1717 } else { | |
1718 extradata_size = 2; | |
1719 } | |
1720 } | |
1721 | |
1534 | 1722 else if (codec_id == CODEC_ID_TTA) { |
1723 ByteIOContext b; | |
1724 extradata_size = 30; | |
1725 extradata = av_mallocz(extradata_size); | |
1726 if (extradata == NULL) | |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2264
diff
changeset
|
1727 return AVERROR(ENOMEM); |
1534 | 1728 init_put_byte(&b, extradata, extradata_size, 1, |
1729 NULL, NULL, NULL, NULL); | |
3009 | 1730 put_buffer(&b, "TTA1", 4); |
1534 | 1731 put_le16(&b, 1); |
3642 | 1732 put_le16(&b, track->audio.channels); |
1733 put_le16(&b, track->audio.bitdepth); | |
1734 put_le32(&b, track->audio.out_samplerate); | |
1735 put_le32(&b, matroska->ctx->duration * track->audio.out_samplerate); | |
1534 | 1736 } |
1737 | |
1531 | 1738 else if (codec_id == CODEC_ID_RV10 || codec_id == CODEC_ID_RV20 || |
1739 codec_id == CODEC_ID_RV30 || codec_id == CODEC_ID_RV40) { | |
1740 extradata_offset = 26; | |
3642 | 1741 track->codec_priv.size -= extradata_offset; |
1531 | 1742 } |
1743 | |
2144 | 1744 else if (codec_id == CODEC_ID_RA_144) { |
3642 | 1745 track->audio.out_samplerate = 8000; |
1746 track->audio.channels = 1; | |
2144 | 1747 } |
1748 | |
1749 else if (codec_id == CODEC_ID_RA_288 || | |
1750 codec_id == CODEC_ID_COOK || | |
1751 codec_id == CODEC_ID_ATRAC3) { | |
1752 ByteIOContext b; | |
1753 | |
3642 | 1754 init_put_byte(&b, track->codec_priv.data,track->codec_priv.size, |
1755 0, NULL, NULL, NULL, NULL); | |
2144 | 1756 url_fskip(&b, 24); |
3642 | 1757 track->audio.coded_framesize = get_be32(&b); |
2144 | 1758 url_fskip(&b, 12); |
3642 | 1759 track->audio.sub_packet_h = get_be16(&b); |
1760 track->audio.frame_size = get_be16(&b); | |
1761 track->audio.sub_packet_size = get_be16(&b); | |
1762 track->audio.buf = av_malloc(track->audio.frame_size * track->audio.sub_packet_h); | |
2144 | 1763 if (codec_id == CODEC_ID_RA_288) { |
3642 | 1764 st->codec->block_align = track->audio.coded_framesize; |
1765 track->codec_priv.size = 0; | |
2144 | 1766 } else { |
3642 | 1767 st->codec->block_align = track->audio.sub_packet_size; |
2144 | 1768 extradata_offset = 78; |
3642 | 1769 track->codec_priv.size -= extradata_offset; |
2144 | 1770 } |
1771 } | |
1772 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1773 if (codec_id == CODEC_ID_NONE) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1774 av_log(matroska->ctx, AV_LOG_INFO, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1775 "Unknown/unsupported CodecID %s.\n", |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1776 track->codec_id); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1777 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1778 |
3408
da09478c97ce
matroskadec: read TrackTimecodeScale and set timebase accordingly
aurel
parents:
3407
diff
changeset
|
1779 av_set_pts_info(st, 64, matroska->time_scale*track->time_scale, 1000*1000*1000); /* 64 bit pts in ns */ |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1780 |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1781 st->codec->codec_id = codec_id; |
2009 | 1782 st->start_time = 0; |
2238
98ac80739c58
properly set AVStream.language according to Matroska track header
aurel
parents:
2202
diff
changeset
|
1783 if (strcmp(track->language, "und")) |
3628
5f2e1da55755
matroskadec: use more robust av_strlcpy() instead of strcpy()
aurel
parents:
3601
diff
changeset
|
1784 av_strlcpy(st->language, track->language, 4); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1785 |
3630 | 1786 if (track->flag_default) |
3120
ea5623a8efde
Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents:
3009
diff
changeset
|
1787 st->disposition |= AV_DISPOSITION_DEFAULT; |
ea5623a8efde
Add 'disposition' bitfield to AVStream and use it for both muxing and demuxing
eugeni
parents:
3009
diff
changeset
|
1788 |
1454 | 1789 if (track->default_duration) |
1790 av_reduce(&st->codec->time_base.num, &st->codec->time_base.den, | |
2389
cde14f83579b
Don't pre-scale default_duration to avoid precision loss in fps calculation.
aurel
parents:
2388
diff
changeset
|
1791 track->default_duration, 1000000000, 30000); |
1454 | 1792 |
692
b0144ebc71dd
H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents:
652
diff
changeset
|
1793 if(extradata){ |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1794 st->codec->extradata = extradata; |
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1795 st->codec->extradata_size = extradata_size; |
3642 | 1796 } else if(track->codec_priv.data && track->codec_priv.size > 0){ |
1797 st->codec->extradata = av_malloc(track->codec_priv.size); | |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1798 if(st->codec->extradata == NULL) |
2273
7eb456c4ed8a
Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents:
2264
diff
changeset
|
1799 return AVERROR(ENOMEM); |
3642 | 1800 st->codec->extradata_size = track->codec_priv.size; |
1801 memcpy(st->codec->extradata, | |
1802 track->codec_priv.data + extradata_offset, | |
1803 track->codec_priv.size); | |
692
b0144ebc71dd
H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents:
652
diff
changeset
|
1804 } |
b0144ebc71dd
H.264 and Vorbis support in matroska patch by (M«©ns Rullg«©rd |mru inprovide com)
michael
parents:
652
diff
changeset
|
1805 |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1806 if (track->type == MATROSKA_TRACK_TYPE_VIDEO) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1807 st->codec->codec_type = CODEC_TYPE_VIDEO; |
3642 | 1808 st->codec->codec_tag = track->video.fourcc; |
1809 st->codec->width = track->video.pixel_width; | |
1810 st->codec->height = track->video.pixel_height; | |
1021 | 1811 av_reduce(&st->codec->sample_aspect_ratio.num, |
1812 &st->codec->sample_aspect_ratio.den, | |
3642 | 1813 st->codec->height * track->video.display_width, |
1814 st->codec-> width * track->video.display_height, | |
1021 | 1815 255); |
2023 | 1816 st->need_parsing = AVSTREAM_PARSE_HEADERS; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1817 } else if (track->type == MATROSKA_TRACK_TYPE_AUDIO) { |
820
feca73904e67
changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents:
775
diff
changeset
|
1818 st->codec->codec_type = CODEC_TYPE_AUDIO; |
3642 | 1819 st->codec->sample_rate = track->audio.out_samplerate; |
1820 st->codec->channels = track->audio.channels; | |
1025
95e8458ae120
duration and subitle fix from the patch by Steve Lhomme
michael
parents:
1024
diff
changeset
|
1821 } else if (track->type == MATROSKA_TRACK_TYPE_SUBTITLE) { |
95e8458ae120
duration and subitle fix from the patch by Steve Lhomme
michael
parents:
1024
diff
changeset
|
1822 st->codec->codec_type = CODEC_TYPE_SUBTITLE; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1823 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1824 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1825 /* What do we do with private data? E.g. for Vorbis. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1826 } |
1465
1dccf2603e1d
Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents:
1459
diff
changeset
|
1827 res = 0; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1828 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1829 |
3637 | 1830 index_list = &matroska->index; |
1831 index = index_list->elem; | |
1832 for (i=0; i<index_list->nb_elem; i++) { | |
1833 EbmlList *pos_list = &index[i].pos; | |
1834 MatroskaIndexPos *pos = pos_list->elem; | |
1835 for (j=0; j<pos_list->nb_elem; j++) { | |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1836 MatroskaTrack *track = matroska_find_track_by_num(matroska, |
3637 | 1837 pos[j].track); |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1838 if (track && track->stream) |
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1839 av_add_index_entry(track->stream, |
3637 | 1840 pos[j].pos + matroska->segment_start, |
1841 index[i].time*matroska->time_scale/AV_TIME_BASE, | |
2202 | 1842 0, 0, AVINDEX_KEYFRAME); |
2012 | 1843 } |
1844 } | |
1845 | |
1465
1dccf2603e1d
Better way to detect cluster (fix files encoded with Haali's muxer).
aurel
parents:
1459
diff
changeset
|
1846 return res; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1847 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1848 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1849 static int |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
1850 matroska_parse_block(MatroskaDemuxContext *matroska, uint8_t *data, int size, |
1914 | 1851 int64_t pos, uint64_t cluster_time, uint64_t duration, |
3631 | 1852 int is_keyframe) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1853 { |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1854 MatroskaTrack *track; |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
1855 int res = 0; |
2013
fc0b19650faa
add an intermediate variable (prepare for next patch)
aurel
parents:
2012
diff
changeset
|
1856 AVStream *st; |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1857 AVPacket *pkt; |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
1858 uint8_t *origdata = data; |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1859 int16_t block_time; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1860 uint32_t *lace_size = NULL; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1861 int n, flags, laces = 0; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1862 uint64_t num; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1863 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1864 /* first byte(s): tracknum */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1865 if ((n = matroska_ebmlnum_uint(data, size, &num)) < 0) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1866 av_log(matroska->ctx, AV_LOG_ERROR, "EBML block data error\n"); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1867 av_free(origdata); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1868 return res; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1869 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1870 data += n; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1871 size -= n; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1872 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1873 /* fetch track from num */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1874 track = matroska_find_track_by_num(matroska, num); |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1875 if (size <= 3 || !track || !track->stream) { |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1876 av_log(matroska->ctx, AV_LOG_INFO, |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1877 "Invalid stream %"PRIu64" or size %u\n", num, size); |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1878 av_free(origdata); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1879 return res; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1880 } |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1881 st = track->stream; |
2013
fc0b19650faa
add an intermediate variable (prepare for next patch)
aurel
parents:
2012
diff
changeset
|
1882 if (st->discard >= AVDISCARD_ALL) { |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1883 av_free(origdata); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1884 return res; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1885 } |
1914 | 1886 if (duration == AV_NOPTS_VALUE) |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
1887 duration = track->default_duration / matroska->time_scale; |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1888 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1889 /* block_time (relative to cluster time) */ |
2185 | 1890 block_time = AV_RB16(data); |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1891 data += 2; |
2188 | 1892 flags = *data++; |
1893 size -= 3; | |
1831 | 1894 if (is_keyframe == -1) |
2415
3aa642c08cde
SimpleBlock keyframe flag is the most significant bit
conrad
parents:
2390
diff
changeset
|
1895 is_keyframe = flags & 0x80 ? PKT_FLAG_KEY : 0; |
2014
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1896 |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1897 if (matroska->skip_to_keyframe) { |
2870
d2c5c911280d
fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents:
2805
diff
changeset
|
1898 if (!is_keyframe || st != matroska->skip_to_stream) { |
d2c5c911280d
fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents:
2805
diff
changeset
|
1899 av_free(origdata); |
2014
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1900 return res; |
2870
d2c5c911280d
fix memory leak (patch by Gabriel Fort«± gforte _at_ wyplay _dot_ com)
aurel
parents:
2805
diff
changeset
|
1901 } |
2014
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1902 matroska->skip_to_keyframe = 0; |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1903 } |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
1904 |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1905 switch ((flags & 0x06) >> 1) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1906 case 0x0: /* no lacing */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1907 laces = 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1908 lace_size = av_mallocz(sizeof(int)); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1909 lace_size[0] = size; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1910 break; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1911 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1912 case 0x1: /* xiph lacing */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1913 case 0x2: /* fixed-size lacing */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1914 case 0x3: /* EBML lacing */ |
3391 | 1915 assert(size>0); // size <=3 is checked before size-=3 above |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1916 laces = (*data) + 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1917 data += 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1918 size -= 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1919 lace_size = av_mallocz(laces * sizeof(int)); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1920 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1921 switch ((flags & 0x06) >> 1) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1922 case 0x1: /* xiph lacing */ { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1923 uint8_t temp; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1924 uint32_t total = 0; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1925 for (n = 0; res == 0 && n < laces - 1; n++) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1926 while (1) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1927 if (size == 0) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1928 res = -1; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1929 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1930 } |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1931 temp = *data; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1932 lace_size[n] += temp; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1933 data += 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1934 size -= 1; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1935 if (temp != 0xff) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1936 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1937 } |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1938 total += lace_size[n]; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1939 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1940 lace_size[n] = size - total; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1941 break; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1942 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1943 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1944 case 0x2: /* fixed-size lacing */ |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1945 for (n = 0; n < laces; n++) |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1946 lace_size[n] = size / laces; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1947 break; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1948 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1949 case 0x3: /* EBML lacing */ { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1950 uint32_t total; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1951 n = matroska_ebmlnum_uint(data, size, &num); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1952 if (n < 0) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1953 av_log(matroska->ctx, AV_LOG_INFO, |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1954 "EBML block data error\n"); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1955 break; |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1956 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1957 data += n; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1958 size -= n; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1959 total = lace_size[0] = num; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1960 for (n = 1; res == 0 && n < laces - 1; n++) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1961 int64_t snum; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1962 int r; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1963 r = matroska_ebmlnum_sint (data, size, &snum); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1964 if (r < 0) { |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1965 av_log(matroska->ctx, AV_LOG_INFO, |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1966 "EBML block data error\n"); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1967 break; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1968 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1969 data += r; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1970 size -= r; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1971 lace_size[n] = lace_size[n - 1] + snum; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1972 total += lace_size[n]; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1973 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1974 lace_size[n] = size - total; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1975 break; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
1976 } |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1977 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1978 break; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1979 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1980 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1981 if (res == 0) { |
1911 | 1982 uint64_t timecode = AV_NOPTS_VALUE; |
1983 | |
2364
7c31128b23f8
ensure that negative block_time are properly checked
aurel
parents:
2276
diff
changeset
|
1984 if (cluster_time != (uint64_t)-1 |
7c31128b23f8
ensure that negative block_time are properly checked
aurel
parents:
2276
diff
changeset
|
1985 && (block_time >= 0 || cluster_time >= -block_time)) |
1911 | 1986 timecode = cluster_time + block_time; |
1987 | |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
1988 for (n = 0; n < laces; n++) { |
2657 | 1989 if (st->codec->codec_id == CODEC_ID_RA_288 || |
1990 st->codec->codec_id == CODEC_ID_COOK || | |
1991 st->codec->codec_id == CODEC_ID_ATRAC3) { | |
1992 int a = st->codec->block_align; | |
3642 | 1993 int sps = track->audio.sub_packet_size; |
1994 int cfs = track->audio.coded_framesize; | |
1995 int h = track->audio.sub_packet_h; | |
1996 int y = track->audio.sub_packet_cnt; | |
1997 int w = track->audio.frame_size; | |
2657 | 1998 int x; |
1999 | |
3642 | 2000 if (!track->audio.pkt_cnt) { |
2657 | 2001 if (st->codec->codec_id == CODEC_ID_RA_288) |
2002 for (x=0; x<h/2; x++) | |
3642 | 2003 memcpy(track->audio.buf+x*2*w+y*cfs, |
2657 | 2004 data+x*cfs, cfs); |
2005 else | |
2006 for (x=0; x<w/sps; x++) | |
3642 | 2007 memcpy(track->audio.buf+sps*(h*x+((h+1)/2)*(y&1)+(y>>1)), data+x*sps, sps); |
2657 | 2008 |
3642 | 2009 if (++track->audio.sub_packet_cnt >= h) { |
2010 track->audio.sub_packet_cnt = 0; | |
2011 track->audio.pkt_cnt = h*w / a; | |
2144 | 2012 } |
2657 | 2013 } |
3642 | 2014 while (track->audio.pkt_cnt) { |
2145 | 2015 pkt = av_mallocz(sizeof(AVPacket)); |
2657 | 2016 av_new_packet(pkt, a); |
3642 | 2017 memcpy(pkt->data, track->audio.buf |
2018 + a * (h*w / a - track->audio.pkt_cnt--), a); | |
2657 | 2019 pkt->pos = pos; |
3634
f206f746ff61
matroskadec: store an AVStream pointer instead of a stream index
aurel
parents:
3633
diff
changeset
|
2020 pkt->stream_index = st->index; |
2145 | 2021 matroska_queue_packet(matroska, pkt); |
2144 | 2022 } |
2657 | 2023 } else { |
3642 | 2024 MatroskaTrackEncoding *encodings = track->encodings.elem; |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
2025 int offset = 0, pkt_size = lace_size[n]; |
3281 | 2026 uint8_t *pkt_data = data; |
2027 | |
3642 | 2028 if (encodings && encodings->scope & 1) { |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
2029 offset = matroska_decode_buffer(&pkt_data, &pkt_size, |
3636
1f8f906eb49e
matroskadec: return pointer instead of index in matroska_find_track_by_num()
aurel
parents:
3635
diff
changeset
|
2030 track); |
3494
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
2031 if (offset < 0) |
8bf1a8e12b43
matroskadec: move buffer decoding code to a separate function
aurel
parents:
3493
diff
changeset
|
2032 continue; |
3279 | 2033 } |
2034 | |
2657 | 2035 pkt = av_mallocz(sizeof(AVPacket)); |
2036 /* XXX: prevent data copy... */ | |
3281 | 2037 if (av_new_packet(pkt, pkt_size+offset) < 0) { |
3415 | 2038 av_free(pkt); |
2657 | 2039 res = AVERROR(ENOMEM); |
2040 n = laces-1; | |
2041 break; | |
2042 } | |
3279 | 2043 if (offset) |
3642 | 2044 memcpy (pkt->data, encodings->compression.settings.data, offset); |
3281 | 2045 memcpy (pkt->data+offset, pkt_data, pkt_size); |
2657 | 2046 |
3493 | 2047 if (pkt_data != data) |
2048 av_free(pkt_data); | |
2049 | |
2657 | 2050 if (n == 0) |
2051 pkt->flags = is_keyframe; | |
3634
f206f746ff61
matroskadec: store an AVStream pointer instead of a stream index
aurel
parents:
3633
diff
changeset
|
2052 pkt->stream_index = st->index; |
2657 | 2053 |
2054 pkt->pts = timecode; | |
2055 pkt->pos = pos; | |
2056 pkt->duration = duration; | |
2057 | |
2058 matroska_queue_packet(matroska, pkt); | |
2059 } | |
2060 | |
2061 if (timecode != AV_NOPTS_VALUE) | |
2062 timecode = duration ? timecode + duration : AV_NOPTS_VALUE; | |
1830
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2063 data += lace_size[n]; |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2064 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2065 } |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2066 |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2067 av_free(lace_size); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2068 av_free(origdata); |
ae69f36fe685
cosmetics: fix indentation of the new matroska_parse_block() function
aurel
parents:
1829
diff
changeset
|
2069 return res; |
1829
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2070 } |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2071 |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2072 static int |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2073 matroska_parse_blockgroup (MatroskaDemuxContext *matroska, |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2074 uint64_t cluster_time) |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2075 { |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2076 int res = 0; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2077 uint32_t id; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2078 int is_keyframe = PKT_FLAG_KEY, last_num_packets = matroska->num_packets; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2079 uint64_t duration = AV_NOPTS_VALUE; |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2080 uint8_t *data; |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2081 int size = 0; |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2082 int64_t pos = 0; |
1829
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2083 |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2084 av_log(matroska->ctx, AV_LOG_DEBUG, "parsing blockgroup...\n"); |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2085 |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2086 while (res == 0) { |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2087 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
2088 res = AVERROR(EIO); |
1829
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2089 break; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2090 } else if (matroska->level_up) { |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2091 matroska->level_up--; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2092 break; |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2093 } |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2094 |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2095 switch (id) { |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2096 /* one block inside the group. Note, block parsing is one |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2097 * of the harder things, so this code is a bit complicated. |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2098 * See http://www.matroska.org/ for documentation. */ |
bf82ef5c32b4
split a matroska_parse_block() function from matroska_parse_blockgroup()
aurel
parents:
1828
diff
changeset
|
2099 case MATROSKA_ID_BLOCK: { |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
2100 pos = url_ftell(matroska->ctx->pb); |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2101 res = ebml_read_binary(matroska, &id, &data, &size); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2102 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2103 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2104 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2105 case MATROSKA_ID_BLOCKDURATION: { |
1456 | 2106 if ((res = ebml_read_uint(matroska, &id, &duration)) < 0) |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2107 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2108 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2109 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2110 |
1902
4225f8dc0098
check if current block contains a B frame and gives this info to parse_block()
aurel
parents:
1901
diff
changeset
|
2111 case MATROSKA_ID_BLOCKREFERENCE: { |
4225f8dc0098
check if current block contains a B frame and gives this info to parse_block()
aurel
parents:
1901
diff
changeset
|
2112 int64_t num; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2113 /* We've found a reference, so not even the first frame in |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2114 * the lace is a key frame. */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2115 is_keyframe = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2116 if (last_num_packets != matroska->num_packets) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2117 matroska->packets[last_num_packets]->flags = 0; |
1902
4225f8dc0098
check if current block contains a B frame and gives this info to parse_block()
aurel
parents:
1901
diff
changeset
|
2118 if ((res = ebml_read_sint(matroska, &id, &num)) < 0) |
4225f8dc0098
check if current block contains a B frame and gives this info to parse_block()
aurel
parents:
1901
diff
changeset
|
2119 break; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2120 break; |
1902
4225f8dc0098
check if current block contains a B frame and gives this info to parse_block()
aurel
parents:
1901
diff
changeset
|
2121 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2122 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2123 default: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2124 av_log(matroska->ctx, AV_LOG_INFO, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2125 "Unknown entry 0x%x in blockgroup data\n", id); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2126 /* fall-through */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2127 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2128 case EBML_ID_VOID: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2129 res = ebml_read_skip(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2130 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2131 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2132 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2133 if (matroska->level_up) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2134 matroska->level_up--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2135 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2136 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2137 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2138 |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2139 if (res) |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2140 return res; |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2141 |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2142 if (size > 0) |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2143 res = matroska_parse_block(matroska, data, size, pos, cluster_time, |
3631 | 2144 duration, is_keyframe); |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2145 |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2146 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2147 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2148 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2149 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2150 matroska_parse_cluster (MatroskaDemuxContext *matroska) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2151 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2152 int res = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2153 uint32_t id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2154 uint64_t cluster_time = 0; |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2155 uint8_t *data; |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2156 int64_t pos; |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2157 int size; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2158 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2159 av_log(matroska->ctx, AV_LOG_DEBUG, |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
2160 "parsing cluster at %"PRId64"\n", url_ftell(matroska->ctx->pb)); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2161 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2162 while (res == 0) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2163 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
2164 res = AVERROR(EIO); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2165 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2166 } else if (matroska->level_up) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2167 matroska->level_up--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2168 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2169 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2170 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2171 switch (id) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2172 /* cluster timecode */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2173 case MATROSKA_ID_CLUSTERTIMECODE: { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2174 uint64_t num; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2175 if ((res = ebml_read_uint(matroska, &id, &num)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2176 break; |
1035 | 2177 cluster_time = num; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2178 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2179 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2180 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2181 /* a group of blocks inside a cluster */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2182 case MATROSKA_ID_BLOCKGROUP: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2183 if ((res = ebml_read_master(matroska, &id)) < 0) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2184 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2185 res = matroska_parse_blockgroup(matroska, cluster_time); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2186 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2187 |
1831 | 2188 case MATROSKA_ID_SIMPLEBLOCK: |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
2189 pos = url_ftell(matroska->ctx->pb); |
1901
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2190 res = ebml_read_binary(matroska, &id, &data, &size); |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2191 if (res == 0) |
3f05dc37b4ec
extract ebml_read_binary() out of matroska_parse_block()
aurel
parents:
1900
diff
changeset
|
2192 res = matroska_parse_block(matroska, data, size, pos, |
1914 | 2193 cluster_time, AV_NOPTS_VALUE, |
3631 | 2194 -1); |
1831 | 2195 break; |
2196 | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2197 default: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2198 av_log(matroska->ctx, AV_LOG_INFO, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2199 "Unknown entry 0x%x in cluster data\n", id); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2200 /* fall-through */ |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2201 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2202 case EBML_ID_VOID: |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2203 res = ebml_read_skip(matroska); |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2204 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2205 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2206 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2207 if (matroska->level_up) { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2208 matroska->level_up--; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2209 break; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2210 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2211 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2212 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2213 return res; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2214 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2215 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2216 static int |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2217 matroska_read_packet (AVFormatContext *s, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2218 AVPacket *pkt) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2219 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2220 MatroskaDemuxContext *matroska = s->priv_data; |
2143
a3d59411106f
fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents:
2142
diff
changeset
|
2221 int res; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2222 uint32_t id; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2223 |
1899 | 2224 /* Read stream until we have a packet queued. */ |
2225 while (matroska_deliver_packet(matroska, pkt)) { | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2226 |
1900 | 2227 /* Have we already reached the end? */ |
2228 if (matroska->done) | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
2229 return AVERROR(EIO); |
1900 | 2230 |
2143
a3d59411106f
fix an infinite loop in case one cluster is not enough to demux a packet
aurel
parents:
2142
diff
changeset
|
2231 res = 0; |
1900 | 2232 while (res == 0) { |
2233 if (!(id = ebml_peek_id(matroska, &matroska->level_up))) { | |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2273
diff
changeset
|
2234 return AVERROR(EIO); |
1900 | 2235 } else if (matroska->level_up) { |
2236 matroska->level_up--; | |
2237 break; | |
2238 } | |
2239 | |
2240 switch (id) { | |
2241 case MATROSKA_ID_CLUSTER: | |
2242 if ((res = ebml_read_master(matroska, &id)) < 0) | |
2243 break; | |
2244 if ((res = matroska_parse_cluster(matroska)) == 0) | |
2245 res = 1; /* Parsed one cluster, let's get out. */ | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2246 break; |
1900 | 2247 |
2248 default: | |
2249 case EBML_ID_VOID: | |
2250 res = ebml_read_skip(matroska); | |
2251 break; | |
2252 } | |
2253 | |
2254 if (matroska->level_up) { | |
2255 matroska->level_up--; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2256 break; |
1900 | 2257 } |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2258 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2259 |
1900 | 2260 if (res == -1) |
2261 matroska->done = 1; | |
1899 | 2262 } |
2263 | |
2264 return 0; | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2265 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2266 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2267 static int |
2012 | 2268 matroska_read_seek (AVFormatContext *s, int stream_index, int64_t timestamp, |
2269 int flags) | |
2270 { | |
2271 MatroskaDemuxContext *matroska = s->priv_data; | |
2272 AVStream *st = s->streams[stream_index]; | |
2273 int index; | |
2274 | |
2275 /* find index entry */ | |
2276 index = av_index_search_timestamp(st, timestamp, flags); | |
2277 if (index < 0) | |
2278 return 0; | |
2279 | |
2872 | 2280 matroska_clear_queue(matroska); |
2281 | |
2012 | 2282 /* do the seek */ |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2657
diff
changeset
|
2283 url_fseek(s->pb, st->index_entries[index].pos, SEEK_SET); |
2014
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
2284 matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY); |
de75a5a81f28
add support for seeking to a keyframe instead of a random frame
aurel
parents:
2013
diff
changeset
|
2285 matroska->skip_to_stream = st; |
2012 | 2286 matroska->peek_id = 0; |
3462 | 2287 av_update_cur_dts(s, st, st->index_entries[index].timestamp); |
2012 | 2288 return 0; |
2289 } | |
2290 | |
2291 static int | |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2292 matroska_read_close (AVFormatContext *s) |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2293 { |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2294 MatroskaDemuxContext *matroska = s->priv_data; |
3642 | 2295 MatroskaTrack *tracks = matroska->tracks.elem; |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2296 int n = 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2297 |
2871
b2f261fccb0b
move internal queue freeing code in its own function
aurel
parents:
2870
diff
changeset
|
2298 matroska_clear_queue(matroska); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2299 |
3642 | 2300 for (n=0; n < matroska->tracks.nb_elem; n++) |
2301 if (tracks[n].type == MATROSKA_TRACK_TYPE_AUDIO) | |
2302 av_free(tracks[n].audio.buf); | |
2303 ebml_free(matroska_tracks, matroska); | |
3637 | 2304 ebml_free(matroska_index, matroska); |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2305 |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2306 return 0; |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2307 } |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2308 |
1169 | 2309 AVInputFormat matroska_demuxer = { |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2310 "matroska", |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3422
diff
changeset
|
2311 NULL_IF_CONFIG_SMALL("Matroska file format"), |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2312 sizeof(MatroskaDemuxContext), |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2313 matroska_probe, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2314 matroska_read_header, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2315 matroska_read_packet, |
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2316 matroska_read_close, |
2012 | 2317 matroska_read_seek, |
380
9416dc106e06
matroska demuxer by ("Ronald S. Bultje" <R dot S dot Bultje at students dot uu dot nl>)
michael
parents:
diff
changeset
|
2318 }; |