Mercurial > libavformat.hg
annotate mov.c @ 130:f607ed6aa365 libavformat
* support for AAC audio (esds decoding - using extradata)
* using MOV_atom_t instead of 3 args
* chunk parsers ordered alphabeticaly
author | kabi |
---|---|
date | Mon, 12 May 2003 10:59:18 +0000 |
parents | b1843685a8f7 |
children | 5bb5f3d201d6 |
rev | line source |
---|---|
0 | 1 /* |
2 * MOV decoder. | |
3 * Copyright (c) 2001 Fabrice Bellard. | |
4 * | |
5 * This library is free software; you can redistribute it and/or | |
6 * modify it under the terms of the GNU Lesser General Public | |
7 * License as published by the Free Software Foundation; either | |
8 * version 2 of the License, or (at your option) any later version. | |
9 * | |
10 * This library is distributed in the hope that it will be useful, | |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 * Lesser General Public License for more details. | |
14 * | |
15 * You should have received a copy of the GNU Lesser General Public | |
16 * License along with this library; if not, write to the Free Software | |
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
18 */ | |
19 #include "avformat.h" | |
20 #include "avi.h" | |
21 | |
22 #ifdef CONFIG_ZLIB | |
23 #include <zlib.h> | |
24 #endif | |
25 | |
26 /* | |
27 * First version by Francois Revol revol@free.fr | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
28 * |
0 | 29 * Features and limitations: |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
30 * - reads most of the QT files I have (at least the structure), |
0 | 31 * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement. |
32 * FIXED, Francois Revol, 07/17/2002 | |
33 * - ffmpeg has nearly none of the usual QuickTime codecs, | |
34 * although I succesfully dumped raw and mp3 audio tracks off .mov files. | |
35 * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html | |
36 * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes | |
37 * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at | |
38 * http://mpeg.telecomitalialab.com/faq.htm | |
39 * - the code is quite ugly... maybe I won't do it recursive next time :-) | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
40 * |
0 | 41 * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/ |
42 * when coding this :) (it's a writer anyway) | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
43 * |
0 | 44 * Reference documents: |
45 * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt | |
46 * Apple: | |
47 * http://developer.apple.com/techpubs/quicktime/qtdevdocs/QTFF/qtff.html | |
48 * http://developer.apple.com/techpubs/quicktime/qtdevdocs/PDF/QTFileFormat.pdf | |
49 * QuickTime is a trademark of Apple (AFAIK :)) | |
50 */ | |
51 | |
52 //#define DEBUG | |
53 | |
54 /* allows chunk splitting - should work now... */ | |
55 /* in case you can't read a file, try commenting */ | |
56 #define MOV_SPLIT_CHUNKS | |
57 | |
58 /* some streams in QT (and in MP4 mostly) aren't either video nor audio */ | |
59 /* so we first list them as this, then clean up the list of streams we give back, */ | |
60 /* getting rid of these */ | |
121 | 61 #define CODEC_TYPE_MOV_OTHER (enum CodecType) 2 |
0 | 62 |
63 static const CodecTag mov_video_tags[] = { | |
64 /* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */ | |
65 /* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */ | |
66 /* { CODEC_ID_H263, MKTAG('Y', 'u', 'v', '2') }, *//* Uncompressed YUV422 */ | |
101
0865b0aaa2af
QT AVID 4CCs patch by ("Sebastien Bechet" <s dot bechet at av7 dot net>) (not tested)
mmu_man
parents:
85
diff
changeset
|
67 /* { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'U', 'I') }, *//* YUV with alpha-channel (AVID Uncompressed) */ |
0 | 68 /* Graphics */ |
69 /* Animation */ | |
70 /* Apple video */ | |
71 /* Kodak Photo CD */ | |
72 { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */ | |
73 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */ | |
74 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */ | |
75 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'b') }, /* Motion-JPEG (format B) */ | |
101
0865b0aaa2af
QT AVID 4CCs patch by ("Sebastien Bechet" <s dot bechet at av7 dot net>) (not tested)
mmu_man
parents:
85
diff
changeset
|
76 { CODEC_ID_MJPEG, MKTAG('A', 'V', 'D', 'J') }, /* MJPEG with alpha-channel (AVID JFIF meridien compressed) */ |
0865b0aaa2af
QT AVID 4CCs patch by ("Sebastien Bechet" <s dot bechet at av7 dot net>) (not tested)
mmu_man
parents:
85
diff
changeset
|
77 /* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */ |
0 | 78 /* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */ |
79 /* Sorenson video */ | |
80 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */ | |
81 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */ | |
82 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/ | |
129 | 83 { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') }, /* Sorenson Video v3 */ |
0 | 84 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, |
85 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ | |
86 /* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */ | |
87 { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */ | |
88 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */ | |
89 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', 'p') }, /* DV PAL */ | |
101
0865b0aaa2af
QT AVID 4CCs patch by ("Sebastien Bechet" <s dot bechet at av7 dot net>) (not tested)
mmu_man
parents:
85
diff
changeset
|
90 /* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */ |
124 | 91 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
92 { CODEC_ID_NONE, 0 }, |
0 | 93 }; |
94 | |
95 static const CodecTag mov_audio_tags[] = { | |
96 /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */ | |
97 { CODEC_ID_PCM_S16BE, MKTAG('t', 'w', 'o', 's') }, /* 16 bits */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
98 /* { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') },*/ /* 8 bits */ |
118 | 99 { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ |
0 | 100 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ |
101 { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */ | |
102 { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */ | |
103 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */ | |
104 { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */ | |
105 { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */ | |
106 | |
107 { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */ | |
108 { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */ | |
109 { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */ | |
110 /* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ | |
111 /* MP4 tags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
112 { CODEC_ID_AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG 4 AAC or audio ? */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
113 /* The standard for mpeg4 audio is still not normalised AFAIK anyway */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
114 { CODEC_ID_NONE, 0 }, |
0 | 115 }; |
116 | |
117 /* the QuickTime file format is quite convoluted... | |
118 * it has lots of index tables, each indexing something in another one... | |
119 * Here we just use what is needed to read the chunks | |
120 */ | |
121 | |
122 typedef struct MOV_sample_to_chunk_tbl { | |
123 long first; | |
124 long count; | |
125 long id; | |
126 } MOV_sample_to_chunk_tbl; | |
127 | |
118 | 128 typedef struct { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
129 uint32_t type; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
130 int64_t offset; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
131 int64_t size; /* total size (excluding the size and type fields) */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
132 } MOV_atom_t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
133 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
134 typedef struct { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
135 int seed; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
136 int flags; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
137 int size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
138 void* clrs; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
139 } MOV_ctab_t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
140 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
141 typedef struct { |
118 | 142 uint8_t version; |
143 uint32_t flags; // 24bit | |
144 | |
145 /* 0x03 ESDescrTag */ | |
146 uint16_t es_id; | |
147 #define MP4ODescrTag 0x01 | |
148 #define MP4IODescrTag 0x02 | |
149 #define MP4ESDescrTag 0x03 | |
150 #define MP4DecConfigDescrTag 0x04 | |
151 #define MP4DecSpecificDescrTag 0x05 | |
152 #define MP4SLConfigDescrTag 0x06 | |
153 #define MP4ContentIdDescrTag 0x07 | |
154 #define MP4SupplContentIdDescrTag 0x08 | |
155 #define MP4IPIPtrDescrTag 0x09 | |
156 #define MP4IPMPPtrDescrTag 0x0A | |
157 #define MP4IPMPDescrTag 0x0B | |
158 #define MP4RegistrationDescrTag 0x0D | |
159 #define MP4ESIDIncDescrTag 0x0E | |
160 #define MP4ESIDRefDescrTag 0x0F | |
161 #define MP4FileIODescrTag 0x10 | |
162 #define MP4FileODescrTag 0x11 | |
163 #define MP4ExtProfileLevelDescrTag 0x13 | |
164 #define MP4ExtDescrTagsStart 0x80 | |
165 #define MP4ExtDescrTagsEnd 0xFE | |
166 uint8_t stream_priority; | |
167 | |
168 /* 0x04 DecConfigDescrTag */ | |
169 uint8_t object_type_id; | |
170 uint8_t stream_type; | |
171 /* XXX: really streamType is | |
172 * only 6bit, followed by: | |
173 * 1bit upStream | |
174 * 1bit reserved | |
175 */ | |
176 uint32_t buffer_size_db; // 24 | |
177 uint32_t max_bitrate; | |
178 uint32_t avg_bitrate; | |
179 | |
180 /* 0x05 DecSpecificDescrTag */ | |
181 uint8_t decoder_cfg_len; | |
182 uint8_t *decoder_cfg; | |
183 | |
184 /* 0x06 SLConfigDescrTag */ | |
185 uint8_t sl_config_len; | |
186 uint8_t *sl_config; | |
187 } MOV_esds_t; | |
188 | |
121 | 189 struct MOVParseTableEntry; |
190 | |
0 | 191 typedef struct MOVStreamContext { |
192 int ffindex; /* the ffmpeg stream id */ | |
193 int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */ | |
194 long next_chunk; | |
195 long chunk_count; | |
65 | 196 int64_t *chunk_offsets; |
0 | 197 long sample_to_chunk_sz; |
198 MOV_sample_to_chunk_tbl *sample_to_chunk; | |
199 long sample_to_chunk_index; | |
200 long sample_size; | |
201 long sample_count; | |
202 long *sample_sizes; | |
118 | 203 int time_scale; |
0 | 204 long current_sample; |
205 long left_in_chunk; /* how many samples before next chunk */ | |
206 /* specific MPEG4 header which is added at the beginning of the stream */ | |
207 int header_len; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
208 uint8_t *header_data; |
118 | 209 MOV_esds_t esds; |
0 | 210 } MOVStreamContext; |
211 | |
212 typedef struct MOVContext { | |
213 int mp4; /* set to 1 as soon as we are sure that the file is an .mp4 file (even some header parsing depends on this) */ | |
214 AVFormatContext *fc; | |
118 | 215 int time_scale; |
216 int duration; /* duration of the longest track */ | |
0 | 217 int found_moov; /* when both 'moov' and 'mdat' sections has been found */ |
218 int found_mdat; /* we suppose we have enough data to read the file */ | |
65 | 219 int64_t mdat_size; |
220 int64_t mdat_offset; | |
0 | 221 int total_streams; |
222 /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio | |
223 * but we need the info to be able to skip data from those streams in the 'mdat' section | |
224 */ | |
225 MOVStreamContext *streams[MAX_STREAMS]; | |
118 | 226 |
65 | 227 int64_t next_chunk_offset; |
118 | 228 MOVStreamContext *partial; /* != 0 : there is still to read in the current chunk */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
229 int ctab_size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
230 MOV_ctab_t **ctab; /* color tables */ |
121 | 231 const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */ |
232 /* NOTE: for recursion save to/ restore from local variable! */ | |
0 | 233 } MOVContext; |
234 | |
235 | |
236 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ | |
237 | |
238 /* those functions parse an atom */ | |
239 /* return code: | |
240 1: found what I wanted, exit | |
241 0: continue to parse next atom | |
242 -1: error occured, exit | |
243 */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
244 typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom); |
0 | 245 |
246 /* links atom IDs to parse functions */ | |
247 typedef struct MOVParseTableEntry { | |
65 | 248 uint32_t type; |
0 | 249 mov_parse_function func; |
250 } MOVParseTableEntry; | |
251 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
252 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
253 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
254 * XXX: static sux, even more in a multithreaded environment... |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
255 * Avoid them. This is here just to help debugging. |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
256 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
257 static int debug_indent = 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
258 void print_atom(const char *str, MOV_atom_t atom) |
0 | 259 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
260 unsigned int tag, i; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
261 tag = (unsigned int) atom.type; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
262 i=debug_indent; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
263 if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L'); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
264 while(i--) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
265 printf("|"); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
266 printf("parse:"); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
267 printf(" %s: tag=%c%c%c%c offset=0x%x size=0x%x\n", |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
268 str, tag & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
269 (tag >> 8) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
270 (tag >> 16) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
271 (tag >> 24) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
272 (unsigned int)atom.offset, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
273 (unsigned int)atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
274 assert((unsigned int)atom.size < 0x7fffffff);// catching errors |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
275 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
276 #else |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
277 #define print_atom(a,b) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
278 #endif |
121 | 279 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
280 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
281 static int mov_read_leaf(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
282 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
283 print_atom("leaf", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
284 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
285 if (atom.size>1) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
286 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
287 /* url_seek(pb, atom_offset+atom.size, SEEK_SET); */ |
0 | 288 return 0; |
289 } | |
290 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
291 static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 292 { |
121 | 293 int64_t total_size = 0; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
294 MOV_atom_t a; |
0 | 295 int i; |
296 int err = 0; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
297 |
0 | 298 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
299 print_atom("default", atom); |
0 | 300 debug_indent++; |
301 #endif | |
118 | 302 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
303 a.offset = atom.offset; |
0 | 304 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
305 if(atom.size < 0) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
306 atom.size = 0x0FFFFFFFFFFFFFFF; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
307 while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
308 a.size = atom.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
309 a.type=0L; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
310 if(atom.size >= 8) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
311 a.size = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
312 a.type = get_le32(pb); |
0 | 313 } |
118 | 314 total_size += 8; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
315 a.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
316 //printf("type: %08x %.4s sz: %Lx %Lx %Lx\n", type, (char*)&type, size, atom.size, total_size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
317 if (a.size == 1) { /* 64 bit extended size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
318 a.size = get_be64(pb) - 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
319 a.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
320 total_size += 8; |
0 | 321 } |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
322 if (a.size == 0) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
323 a.size = atom.size - total_size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
324 if (a.size <= 8) |
118 | 325 break; |
326 } | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
327 for (i = 0; c->parse_table[i].type != 0L |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
328 && c->parse_table[i].type != a.type; i++) |
118 | 329 /* empty */; |
330 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
331 a.size -= 8; |
0 | 332 // printf(" i=%ld\n", i); |
121 | 333 if (c->parse_table[i].type == 0) { /* skip leaf atoms data */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
334 // url_seek(pb, atom.offset+atom.size, SEEK_SET); |
0 | 335 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
336 print_atom("unknown", a); |
0 | 337 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
338 url_fskip(pb, a.size); |
121 | 339 } else { |
340 #ifdef DEBUG | |
341 //char b[5] = { type & 0xff, (type >> 8) & 0xff, (type >> 16) & 0xff, (type >> 24) & 0xff, 0 }; | |
342 //print_atom(b, type, offset, size); | |
343 #endif | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
344 err = (c->parse_table[i].func)(c, pb, a); |
121 | 345 } |
0 | 346 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
347 a.offset += a.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
348 total_size += a.size; |
0 | 349 } |
350 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
351 if (!err && total_size < atom.size && atom.size < 0x7ffff) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
352 //printf("RESET %Ld %Ld err:%d\n", atom.size, total_size, err); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
353 url_fskip(pb, atom.size - total_size); |
118 | 354 } |
355 | |
0 | 356 #ifdef DEBUG |
357 debug_indent--; | |
358 #endif | |
359 return err; | |
360 } | |
361 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
362 static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 363 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
364 unsigned int len; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
365 MOV_ctab_t *t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
366 //url_fskip(pb, atom.size); // for now |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
367 c->ctab = av_realloc(c->ctab, ++c->ctab_size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
368 t = c->ctab[c->ctab_size]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
369 t->seed = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
370 t->flags = get_be16(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
371 t->size = get_be16(pb) + 1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
372 len = 2 * t->size * 4; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
373 if (len > 0) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
374 t->clrs = av_malloc(len); // 16bit A R G B |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
375 if (t->clrs) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
376 get_buffer(pb, t->clrs, len); |
0 | 377 } |
118 | 378 |
0 | 379 return 0; |
380 } | |
381 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
382 static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 383 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
384 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
0 | 385 int len = 0; |
121 | 386 uint8_t *buf; |
65 | 387 uint32_t type; |
388 uint32_t ctype; | |
121 | 389 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
390 print_atom("hdlr", atom); |
0 | 391 |
392 get_byte(pb); /* version */ | |
393 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
394 | |
395 /* component type */ | |
396 ctype = get_le32(pb); | |
397 type = get_le32(pb); /* component subtype */ | |
398 | |
399 #ifdef DEBUG | |
400 printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype); | |
401 printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | |
402 #endif | |
403 #ifdef DEBUG | |
404 /* XXX: yeah this is ugly... */ | |
405 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
406 if(type == MKTAG('v', 'i', 'd', 'e')) | |
407 puts("hdlr: vide"); | |
408 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
409 puts("hdlr: soun"); | |
410 } else if(ctype == 0) { /* MP4 */ | |
411 if(type == MKTAG('v', 'i', 'd', 'e')) | |
412 puts("hdlr: vide"); | |
413 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
414 puts("hdlr: soun"); | |
415 else if(type == MKTAG('o', 'd', 's', 'm')) | |
416 puts("hdlr: odsm"); | |
417 else if(type == MKTAG('s', 'd', 's', 'm')) | |
418 puts("hdlr: sdsm"); | |
419 } else puts("hdlr: meta"); | |
420 #endif | |
421 | |
422 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
423 /* helps parsing the string hereafter... */ | |
424 c->mp4 = 0; | |
425 if(type == MKTAG('v', 'i', 'd', 'e')) | |
426 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
427 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
428 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
429 } else if(ctype == 0) { /* MP4 */ | |
430 /* helps parsing the string hereafter... */ | |
431 c->mp4 = 1; | |
432 if(type == MKTAG('v', 'i', 'd', 'e')) | |
433 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
434 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
435 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
436 } | |
437 get_be32(pb); /* component manufacture */ | |
438 get_be32(pb); /* component flags */ | |
439 get_be32(pb); /* component flags mask */ | |
440 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
441 if(atom.size <= 24) |
0 | 442 return 0; /* nothing left to read */ |
443 /* XXX: MP4 uses a C string, not a pascal one */ | |
444 /* component name */ | |
445 | |
446 if(c->mp4) { | |
447 /* .mp4: C string */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
448 while(get_byte(pb) && (++len < (atom.size - 24))); |
0 | 449 } else { |
450 /* .mov: PASCAL string */ | |
451 len = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
452 #ifdef DEBUG |
121 | 453 buf = (uint8_t*) av_malloc(len+1); |
454 if (buf) { | |
455 get_buffer(pb, buf, len); | |
456 buf[len] = '\0'; | |
457 printf("**buf='%s'\n", buf); | |
458 av_free(buf); | |
459 } else | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
460 #endif |
121 | 461 url_fskip(pb, len); |
0 | 462 } |
118 | 463 |
0 | 464 return 0; |
465 } | |
466 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
467 static int mov_mp4_read_descr_len(ByteIOContext *pb) |
0 | 468 { |
118 | 469 int len = 0; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
470 int count = 4; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
471 while (count--) { |
118 | 472 int c = get_byte(pb); |
473 len = (len << 7) | (c & 0x7f); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
474 if (!(c & 0x80)) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
475 break; |
0 | 476 } |
477 return len; | |
478 } | |
479 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
480 static int mov_mp4_read_descr(ByteIOContext *pb, int *tag) |
0 | 481 { |
482 int len; | |
483 *tag = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
484 len = mov_mp4_read_descr_len(pb); |
0 | 485 #ifdef DEBUG |
486 printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len); | |
487 #endif | |
488 return len; | |
489 } | |
490 | |
118 | 491 static inline unsigned int get_be24(ByteIOContext *s) |
492 { | |
493 unsigned int val; | |
494 val = get_byte(s) << 16; | |
495 val |= get_byte(s) << 8; | |
496 val |= get_byte(s); | |
497 return val; | |
498 } | |
499 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
500 static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
118 | 501 { |
502 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
503 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
504 int64_t start_pos = url_ftell(pb); |
118 | 505 int tag, len; |
121 | 506 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
507 print_atom("esds", atom); |
118 | 508 |
509 /* Well, broken but suffisant for some MP4 streams */ | |
510 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
511 len = mov_mp4_read_descr(pb, &tag); |
118 | 512 if (tag == MP4ESDescrTag) { |
513 get_be16(pb); /* ID */ | |
514 get_byte(pb); /* priority */ | |
515 } else | |
516 get_be16(pb); /* ID */ | |
517 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
518 len = mov_mp4_read_descr(pb, &tag); |
118 | 519 if (tag == MP4DecConfigDescrTag) { |
520 sc->esds.object_type_id = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
521 sc->esds.stream_type = get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
522 sc->esds.buffer_size_db = get_be24(pb); |
118 | 523 sc->esds.max_bitrate = get_be32(pb); |
524 sc->esds.avg_bitrate = get_be32(pb); | |
525 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
526 len = mov_mp4_read_descr(pb, &tag); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
527 //printf("LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate); |
118 | 528 if (tag == MP4DecSpecificDescrTag) { |
529 #ifdef DEBUG | |
530 printf("Specific MPEG4 header len=%d\n", len); | |
531 #endif | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
532 st->codec.extradata = (uint8_t*) av_mallocz(len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
533 if (st->codec.extradata) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
534 get_buffer(pb, st->codec.extradata, len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
535 st->codec.extradata_size = len; |
118 | 536 } |
537 } | |
538 } | |
539 /* in any case, skip garbage */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
540 url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos))); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
541 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
542 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
543 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
544 /* this atom contains actual media data */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
545 static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
546 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
547 print_atom("mdat", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
548 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
549 if(atom.size == 0) /* wrong one (MP4) */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
550 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
551 c->found_mdat=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
552 c->mdat_offset = atom.offset; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
553 c->mdat_size = atom.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
554 if(c->found_moov) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
555 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
556 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
557 return 0; /* now go for moov */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
558 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
559 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
560 /* this atom should contain all header atoms */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
561 static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
562 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
563 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
564 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
565 print_atom("moov", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
566 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
567 err = mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
568 /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
569 /* so we don't parse the whole file if over a network */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
570 c->found_moov=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
571 if(c->found_mdat) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
572 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
573 return 0; /* now go for mdat */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
574 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
575 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
576 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
577 static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
578 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
579 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
580 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
581 print_atom("mdhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
582 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
583 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
584 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
585 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
586 get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
587 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
588 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
589 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
590 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
591 c->streams[c->total_streams]->time_scale = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
592 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
593 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
594 printf("track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->total_streams]->time_scale); /* time scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
595 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
596 get_be32(pb); /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
597 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
598 get_be16(pb); /* language */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
599 get_be16(pb); /* quality */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
600 |
118 | 601 return 0; |
602 } | |
603 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
604 static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
605 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
606 print_atom("mvhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
607 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
608 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
609 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
610 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
611 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
612 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
613 c->time_scale = get_be32(pb); /* time scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
614 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
615 printf("time scale = %i\n", c->time_scale); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
616 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
617 c->duration = get_be32(pb); /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
618 get_be32(pb); /* preferred scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
619 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
620 get_be16(pb); /* preferred volume */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
621 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
622 url_fskip(pb, 10); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
623 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
624 url_fskip(pb, 36); /* display matrix */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
625 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
626 get_be32(pb); /* preview time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
627 get_be32(pb); /* preview duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
628 get_be32(pb); /* poster time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
629 get_be32(pb); /* selection time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
630 get_be32(pb); /* selection duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
631 get_be32(pb); /* current time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
632 get_be32(pb); /* next track ID */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
633 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
634 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
635 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
636 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
637 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
638 static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 639 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
640 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
641 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
642 int entries, i; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
643 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
644 print_atom("stco", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
645 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
646 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
647 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
648 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
649 entries = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
650 sc->chunk_count = entries; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
651 sc->chunk_offsets = (int64_t*) av_malloc(entries * sizeof(int64_t)); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
652 if (!sc->chunk_offsets) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
653 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
654 if (atom.type == MKTAG('s', 't', 'c', 'o')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
655 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
656 sc->chunk_offsets[i] = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
657 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
658 } else if (atom.type == MKTAG('c', 'o', '6', '4')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
659 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
660 sc->chunk_offsets[i] = get_be64(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
661 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
662 } else |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
663 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
664 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
665 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
666 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
667 printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
668 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
669 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
670 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
671 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
672 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
673 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
674 static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
675 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
676 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
677 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
678 int entries, frames_per_sample; |
65 | 679 uint32_t format; |
121 | 680 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
681 print_atom("stsd", atom); |
0 | 682 |
683 get_byte(pb); /* version */ | |
684 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
685 | |
686 entries = get_be32(pb); | |
687 | |
688 while(entries--) { | |
121 | 689 enum CodecID id; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
690 int size = get_be32(pb); /* size */ |
0 | 691 format = get_le32(pb); /* data format */ |
118 | 692 |
0 | 693 get_be32(pb); /* reserved */ |
694 get_be16(pb); /* reserved */ | |
695 get_be16(pb); /* index */ | |
696 | |
697 /* for MPEG4: set codec type by looking for it */ | |
698 id = codec_get_id(mov_video_tags, format); | |
699 if (id >= 0) { | |
700 AVCodec *codec; | |
121 | 701 codec = avcodec_find_decoder(id); |
0 | 702 if (codec) |
121 | 703 st->codec.codec_type = codec->type; |
0 | 704 } |
705 #ifdef DEBUG | |
118 | 706 printf("size=%d 4CC= %c%c%c%c codec_type=%d\n", |
707 size, | |
0 | 708 (format >> 0) & 0xff, |
709 (format >> 8) & 0xff, | |
710 (format >> 16) & 0xff, | |
711 (format >> 24) & 0xff, | |
712 st->codec.codec_type); | |
713 #endif | |
118 | 714 st->codec.codec_tag = format; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
715 if(st->codec.codec_type==CODEC_TYPE_VIDEO) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
716 MOV_atom_t a = { 0, 0, 0 }; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
717 st->codec.codec_id = id; |
0 | 718 get_be16(pb); /* version */ |
719 get_be16(pb); /* revision level */ | |
720 get_be32(pb); /* vendor */ | |
721 get_be32(pb); /* temporal quality */ | |
722 get_be32(pb); /* spacial quality */ | |
723 st->codec.width = get_be16(pb); /* width */ | |
724 st->codec.height = get_be16(pb); /* height */ | |
725 #if 1 | |
726 if (st->codec.codec_id == CODEC_ID_MPEG4) { | |
727 /* in some MPEG4 the width/height are not correct, so | |
728 we ignore this info */ | |
729 st->codec.width = 0; | |
730 st->codec.height = 0; | |
731 } | |
732 #endif | |
733 get_be32(pb); /* horiz resolution */ | |
734 get_be32(pb); /* vert resolution */ | |
735 get_be32(pb); /* data size, always 0 */ | |
118 | 736 frames_per_sample = get_be16(pb); /* frames per samples */ |
0 | 737 #ifdef DEBUG |
738 printf("frames/samples = %d\n", frames_per_sample); | |
739 #endif | |
121 | 740 get_buffer(pb, (uint8_t *)st->codec.codec_name, 32); /* codec name */ |
0 | 741 |
118 | 742 st->codec.bits_per_sample = get_be16(pb); /* depth */ |
743 st->codec.color_table_id = get_be16(pb); /* colortable id */ | |
744 | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
745 st->codec.frame_rate = 25; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
746 st->codec.frame_rate_base = 1; |
118 | 747 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
748 size -= (16+8*4+2+32+2*2); |
118 | 749 #if 0 |
750 while (size >= 8) { | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
751 MOV_atom_t a; |
65 | 752 int64_t start_pos; |
118 | 753 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
754 a.size = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
755 a.type = get_le32(pb); |
118 | 756 size -= 8; |
0 | 757 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
758 printf("VIDEO: atom_type=%c%c%c%c atom.size=%Ld size_left=%d\n", |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
759 (a.type >> 0) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
760 (a.type >> 8) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
761 (a.type >> 16) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
762 (a.type >> 24) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
763 a.size, size); |
0 | 764 #endif |
765 start_pos = url_ftell(pb); | |
766 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
767 switch(a.type) { |
0 | 768 case MKTAG('e', 's', 'd', 's'): |
769 { | |
770 int tag, len; | |
771 /* Well, broken but suffisant for some MP4 streams */ | |
772 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
773 len = mov_mp4_read_descr(pb, &tag); |
0 | 774 if (tag == 0x03) { |
775 /* MP4ESDescrTag */ | |
776 get_be16(pb); /* ID */ | |
777 get_byte(pb); /* priority */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
778 len = mov_mp4_read_descr(pb, &tag); |
0 | 779 if (tag != 0x04) |
780 goto fail; | |
781 /* MP4DecConfigDescrTag */ | |
782 get_byte(pb); /* objectTypeId */ | |
783 get_be32(pb); /* streamType + buffer size */ | |
118 | 784 get_be32(pb); /* max bit rate */ |
0 | 785 get_be32(pb); /* avg bit rate */ |
786 len = mp4_read_descr(pb, &tag); | |
787 if (tag != 0x05) | |
788 goto fail; | |
789 /* MP4DecSpecificDescrTag */ | |
790 #ifdef DEBUG | |
791 printf("Specific MPEG4 header len=%d\n", len); | |
792 #endif | |
793 sc->header_data = av_mallocz(len); | |
794 if (sc->header_data) { | |
795 get_buffer(pb, sc->header_data, len); | |
118 | 796 sc->header_len = len; |
0 | 797 } |
798 } | |
799 /* in any case, skip garbage */ | |
800 } | |
801 break; | |
802 default: | |
803 break; | |
804 } | |
118 | 805 fail: |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
806 printf("ATOMENEWSIZE %Ld %d\n", atom.size, url_ftell(pb) - start_pos); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
807 if (atom.size > 8) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
808 url_fskip(pb, (atom.size - 8) - |
118 | 809 ((url_ftell(pb) - start_pos))); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
810 size -= atom.size - 8; |
118 | 811 } |
812 } | |
0 | 813 if (size > 0) { |
814 /* unknown extension */ | |
815 url_fskip(pb, size); | |
816 } | |
118 | 817 #else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
818 a.size = size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
819 mov_read_default(c, pb, a); |
118 | 820 #endif |
821 } else { | |
0 | 822 get_be16(pb); /* version */ |
823 get_be16(pb); /* revision level */ | |
824 get_be32(pb); /* vendor */ | |
825 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
826 st->codec.channels = get_be16(pb); /* channel count */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
827 st->codec.bits_per_sample = get_be16(pb); /* sample size */ |
118 | 828 |
829 st->codec.codec_id = codec_get_id(mov_audio_tags, format); | |
0 | 830 /* handle specific s8 codec */ |
831 get_be16(pb); /* compression id = 0*/ | |
832 get_be16(pb); /* packet size = 0 */ | |
118 | 833 |
0 | 834 st->codec.sample_rate = ((get_be32(pb) >> 16)); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
835 //printf("CODECID %d %d %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format); |
118 | 836 |
121 | 837 switch (st->codec.codec_id) { |
838 case CODEC_ID_PCM_S16BE: | |
118 | 839 if (st->codec.bits_per_sample == 8) |
840 st->codec.codec_id = CODEC_ID_PCM_S8; | |
121 | 841 /* fall */ |
842 case CODEC_ID_PCM_U8: | |
843 st->codec.bit_rate = st->codec.sample_rate * 8; | |
844 break; | |
845 default: | |
846 ; | |
118 | 847 } |
848 get_be32(pb); /* samples per packet */ | |
849 get_be32(pb); /* bytes per packet */ | |
850 get_be32(pb); /* bytes per frame */ | |
851 get_be32(pb); /* bytes per sample */ | |
0 | 852 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
853 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
854 MOV_atom_t a = { format, url_ftell(pb), size - (16 + 20 + 16 + 8) }; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
855 mov_read_default(c, pb, a); |
118 | 856 } |
0 | 857 } |
858 } | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
859 |
0 | 860 return 0; |
861 } | |
862 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
863 static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 864 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
865 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
866 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 867 int entries, i; |
868 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
869 print_atom("stsc", atom); |
118 | 870 |
0 | 871 get_byte(pb); /* version */ |
872 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
873 | |
874 entries = get_be32(pb); | |
875 #ifdef DEBUG | |
876 printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); | |
877 #endif | |
878 sc->sample_to_chunk_sz = entries; | |
121 | 879 sc->sample_to_chunk = (MOV_sample_to_chunk_tbl*) av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl)); |
880 if (!sc->sample_to_chunk) | |
881 return -1; | |
0 | 882 for(i=0; i<entries; i++) { |
883 sc->sample_to_chunk[i].first = get_be32(pb); | |
884 sc->sample_to_chunk[i].count = get_be32(pb); | |
885 sc->sample_to_chunk[i].id = get_be32(pb); | |
886 #ifdef DEBUG | |
887 /* printf("sample_to_chunk first=%ld count=%ld, id=%ld\n", sc->sample_to_chunk[i].first, sc->sample_to_chunk[i].count, sc->sample_to_chunk[i].id); */ | |
888 #endif | |
889 } | |
890 return 0; | |
891 } | |
892 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
893 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 894 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
895 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
896 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 897 int entries, i; |
121 | 898 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
899 print_atom("stsz", atom); |
118 | 900 |
0 | 901 get_byte(pb); /* version */ |
902 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
118 | 903 |
0 | 904 sc->sample_size = get_be32(pb); |
905 entries = get_be32(pb); | |
906 sc->sample_count = entries; | |
907 #ifdef DEBUG | |
908 printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count); | |
909 #endif | |
910 if(sc->sample_size) | |
911 return 0; /* there isn't any table following */ | |
121 | 912 sc->sample_sizes = (long*) av_malloc(entries * sizeof(long)); |
913 if (!sc->sample_sizes) | |
914 return -1; | |
0 | 915 for(i=0; i<entries; i++) { |
916 sc->sample_sizes[i] = get_be32(pb); | |
917 #ifdef DEBUG | |
918 /* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */ | |
919 #endif | |
920 } | |
921 return 0; | |
922 } | |
923 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
924 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 925 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
926 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
927 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 928 int entries, i; |
121 | 929 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
930 print_atom("stts", atom); |
0 | 931 |
932 get_byte(pb); /* version */ | |
933 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
934 entries = get_be32(pb); | |
935 #ifdef DEBUG | |
936 printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); | |
937 #endif | |
938 for(i=0; i<entries; i++) { | |
939 int sample_duration; | |
940 | |
941 get_be32(pb); | |
942 sample_duration = get_be32(pb); | |
943 | |
944 if (!i && st->codec.codec_type==CODEC_TYPE_VIDEO) { | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
945 st->codec.frame_rate_base = sample_duration ? sample_duration : 1; |
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
946 st->codec.frame_rate = c->streams[c->total_streams]->time_scale; |
0 | 947 #ifdef DEBUG |
948 printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration); | |
949 #endif | |
950 } | |
951 } | |
952 return 0; | |
953 } | |
954 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
955 static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
956 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
957 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
958 MOVStreamContext *sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
959 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
960 print_atom("trak", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
961 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
962 st = av_new_stream(c->fc, c->fc->nb_streams); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
963 if (!st) return -2; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
964 sc = (MOVStreamContext*) av_mallocz(sizeof(MOVStreamContext)); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
965 if (!sc) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
966 av_free(st); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
967 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
968 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
969 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
970 sc->sample_to_chunk_index = -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
971 st->priv_data = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
972 st->codec.codec_type = CODEC_TYPE_MOV_OTHER; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
973 st->time_length = (c->duration * 1000) / c->time_scale; // time in miliseconds |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
974 c->streams[c->fc->nb_streams-1] = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
975 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
976 return mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
977 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
978 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
979 static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
980 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
981 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
982 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
983 print_atom("tkhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
984 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
985 st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
986 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
987 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
988 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
989 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
990 get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
991 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
992 MOV_TRACK_ENABLED 0x0001 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
993 MOV_TRACK_IN_MOVIE 0x0002 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
994 MOV_TRACK_IN_PREVIEW 0x0004 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
995 MOV_TRACK_IN_POSTER 0x0008 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
996 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
997 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
998 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
999 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1000 st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1001 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1002 st->time_length = get_be32(pb) * 1000 / c->time_scale; /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1003 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1004 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1005 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1006 get_be16(pb); /* layer */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1007 get_be16(pb); /* alternate group */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1008 get_be16(pb); /* volume */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1009 get_be16(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1010 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1011 url_fskip(pb, 36); /* display matrix */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1012 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1013 /* those are fixed-point */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1014 st->codec.width = get_be32(pb) >> 16; /* track width */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1015 st->codec.height = get_be32(pb) >> 16; /* track height */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1016 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1017 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1018 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1019 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1020 /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1021 /* like the files created with Adobe Premiere 5.0, for samples see */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1022 /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1023 static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1024 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1025 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1026 uint32_t type; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1027 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1028 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1029 print_atom("wide", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1030 debug_indent++; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1031 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1032 if (atom.size < 8) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1033 return 0; /* continue */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1034 if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1035 url_fskip(pb, atom.size - 4); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1036 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1037 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1038 atom.type = get_le32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1039 atom.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1040 atom.size -= 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1041 if (type != MKTAG('m', 'd', 'a', 't')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1042 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1043 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1044 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1045 err = mov_read_mdat(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1046 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1047 debug_indent--; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1048 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1049 return err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1050 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1051 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1052 |
0 | 1053 #ifdef CONFIG_ZLIB |
65 | 1054 static int null_read_packet(void *opaque, uint8_t *buf, int buf_size) |
0 | 1055 { |
1056 return -1; | |
1057 } | |
1058 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1059 static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1060 { |
1061 ByteIOContext ctx; | |
121 | 1062 uint8_t *cmov_data; |
1063 uint8_t *moov_data; /* uncompressed data */ | |
0 | 1064 long cmov_len, moov_len; |
1065 int ret; | |
121 | 1066 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1067 print_atom("cmov", atom); |
0 | 1068 |
1069 get_be32(pb); /* dcom atom */ | |
1070 if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' )) | |
1071 return -1; | |
1072 if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) { | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1073 dprintf("unknown compression for cmov atom !"); |
0 | 1074 return -1; |
1075 } | |
1076 get_be32(pb); /* cmvd atom */ | |
1077 if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' )) | |
1078 return -1; | |
1079 moov_len = get_be32(pb); /* uncompressed size */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1080 cmov_len = atom.size - 6 * 4; |
118 | 1081 |
121 | 1082 cmov_data = (uint8_t *) av_malloc(cmov_len); |
0 | 1083 if (!cmov_data) |
1084 return -1; | |
121 | 1085 moov_data = (uint8_t *) av_malloc(moov_len); |
0 | 1086 if (!moov_data) { |
1087 av_free(cmov_data); | |
1088 return -1; | |
1089 } | |
1090 get_buffer(pb, cmov_data, cmov_len); | |
121 | 1091 if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) |
0 | 1092 return -1; |
1093 if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0) | |
1094 return -1; | |
1095 ctx.buf_end = ctx.buffer + moov_len; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1096 atom.type = MKTAG( 'm', 'o', 'o', 'v' ); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1097 atom.offset = 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1098 atom.size = moov_len; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1099 ret = mov_read_default(c, &ctx, atom); |
0 | 1100 av_free(moov_data); |
1101 av_free(cmov_data); | |
1102 return ret; | |
1103 } | |
1104 #endif | |
1105 | |
1106 static const MOVParseTableEntry mov_default_parse_table[] = { | |
1107 /* mp4 atoms */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1108 { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1109 { MKTAG( 'c', 'p', 'r', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1110 { MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1111 { MKTAG( 'c', 't', 't', 's' ), mov_read_leaf }, /* composition time to sample */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1112 { MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1113 { MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1114 { MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1115 { MKTAG( 'e', 'd', 't', 's' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1116 { MKTAG( 'e', 'l', 's', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1117 { MKTAG( 'f', 'r', 'e', 'e' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1118 { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1119 { MKTAG( 'h', 'i', 'n', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1120 { MKTAG( 'h', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1121 { MKTAG( 'i', 'o', 'd', 's' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1122 { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1123 { MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1124 { MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1125 { MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1126 { MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1127 { MKTAG( 'm', 'p', '4', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1128 { MKTAG( 'm', 'p', '4', 's' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1129 { MKTAG( 'm', 'p', '4', 'v' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1130 { MKTAG( 'm', 'p', 'o', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1131 { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1132 { MKTAG( 'n', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1133 { MKTAG( 'o', 'd', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1134 { MKTAG( 's', 'd', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1135 { MKTAG( 's', 'k', 'i', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1136 { MKTAG( 's', 'm', 'h', 'd' ), mov_read_leaf }, /* sound media info header */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1137 { MKTAG( 's', 't', 'b', 'l' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1138 { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1139 { MKTAG( 's', 't', 'd', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1140 { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1141 { MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1142 { MKTAG( 's', 't', 's', 'h' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1143 { MKTAG( 's', 't', 's', 's' ), mov_read_leaf }, /* sync sample */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1144 { MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1145 { MKTAG( 's', 't', 't', 's' ), mov_read_stts }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1146 { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1147 { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1148 { MKTAG( 't', 'r', 'e', 'f' ), mov_read_default }, /* not really */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1149 { MKTAG( 'u', 'd', 't', 'a' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1150 { MKTAG( 'u', 'r', 'l', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1151 { MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1152 { MKTAG( 'u', 'u', 'i', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1153 { MKTAG( 'v', 'm', 'h', 'd' ), mov_read_leaf }, /* video media info header */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1154 { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default }, |
0 | 1155 /* extra mp4 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1156 { MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf }, |
0 | 1157 /* QT atoms */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1158 { MKTAG( 'c', 'h', 'a', 'p' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1159 { MKTAG( 'c', 'l', 'i', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1160 { MKTAG( 'c', 'r', 'g', 'n' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1161 { MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1162 { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1163 { MKTAG( 'k', 'm', 'a', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1164 { MKTAG( 'm', 'a', 't', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1165 { MKTAG( 'r', 'd', 'r', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1166 { MKTAG( 'r', 'm', 'd', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1167 { MKTAG( 'r', 'm', 'd', 'r' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1168 { MKTAG( 'r', 'm', 'r', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1169 { MKTAG( 's', 'c', 'p', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1170 { MKTAG( 's', 's', 'r', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1171 { MKTAG( 's', 'y', 'n', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1172 { MKTAG( 't', 'c', 'm', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1173 { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1174 //{ MKTAG( 'r', 'm', 'q', 'u' ), mov_read_leaf }, |
0 | 1175 #ifdef CONFIG_ZLIB |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1176 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov }, |
0 | 1177 #else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1178 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_leaf }, |
0 | 1179 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1180 { 0L, mov_read_leaf } |
0 | 1181 }; |
1182 | |
1183 static void mov_free_stream_context(MOVStreamContext *sc) | |
1184 { | |
1185 if(sc) { | |
1186 av_free(sc->chunk_offsets); | |
1187 av_free(sc->sample_to_chunk); | |
118 | 1188 av_free(sc->sample_sizes); |
0 | 1189 av_free(sc->header_data); |
1190 av_free(sc); | |
1191 } | |
1192 } | |
1193 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1194 static inline uint32_t mov_to_tag(uint8_t *buf) |
0 | 1195 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1196 return MKTAG(buf[0], buf[1], buf[2], buf[3]); |
0 | 1197 } |
1198 | |
118 | 1199 static inline uint32_t to_be32(uint8_t *buf) |
0 | 1200 { |
1201 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
1202 } | |
1203 | |
121 | 1204 /* XXX: is it sufficient ? */ |
0 | 1205 static int mov_probe(AVProbeData *p) |
1206 { | |
1207 unsigned int offset; | |
1208 uint32_t tag; | |
1209 | |
1210 /* check file header */ | |
1211 if (p->buf_size <= 12) | |
1212 return 0; | |
1213 offset = 0; | |
1214 for(;;) { | |
1215 /* ignore invalid offset */ | |
1216 if ((offset + 8) > (unsigned int)p->buf_size) | |
1217 return 0; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1218 tag = mov_to_tag(p->buf + offset + 4); |
0 | 1219 switch(tag) { |
1220 case MKTAG( 'm', 'o', 'o', 'v' ): | |
1221 case MKTAG( 'w', 'i', 'd', 'e' ): | |
1222 case MKTAG( 'f', 'r', 'e', 'e' ): | |
24 | 1223 case MKTAG( 'm', 'd', 'a', 't' ): |
1224 case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */ | |
0 | 1225 return AVPROBE_SCORE_MAX; |
1226 case MKTAG( 'f', 't', 'y', 'p' ): | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1227 case MKTAG( 's', 'k', 'i', 'p' ): |
0 | 1228 offset = to_be32(p->buf) + offset; |
1229 break; | |
1230 default: | |
1231 /* unrecognized tag */ | |
1232 return 0; | |
1233 } | |
1234 } | |
1235 return 0; | |
1236 } | |
1237 | |
1238 static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
1239 { | |
121 | 1240 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1241 ByteIOContext *pb = &s->pb; |
1242 int i, j, nb, err; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1243 MOV_atom_t atom = { 0, 0, 0 }; |
0 | 1244 |
1245 mov->fc = s; | |
121 | 1246 mov->parse_table = mov_default_parse_table; |
0 | 1247 #if 0 |
1248 /* XXX: I think we should auto detect */ | |
1249 if(s->iformat->name[1] == 'p') | |
1250 mov->mp4 = 1; | |
1251 #endif | |
1252 if(!url_is_streamed(pb)) /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1253 atom.size = url_filesize(url_fileno(pb)); |
0 | 1254 else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1255 atom.size = 0x7FFFFFFFFFFFFFFF; |
0 | 1256 |
1257 #ifdef DEBUG | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1258 printf("filesz=%Ld\n", atom.size); |
0 | 1259 #endif |
1260 | |
1261 /* check MOV header */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1262 err = mov_read_default(mov, pb, atom); |
0 | 1263 if(err<0 || (!mov->found_moov || !mov->found_mdat)) { |
1264 puts("header not found !!!"); | |
1265 exit(1); | |
1266 } | |
1267 #ifdef DEBUG | |
1268 printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb)); | |
1269 #endif | |
1270 /* some cleanup : make sure we are on the mdat atom */ | |
1271 if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset)) | |
1272 url_fseek(pb, mov->mdat_offset, SEEK_SET); | |
1273 | |
1274 mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */ | |
1275 | |
1276 #ifdef DEBUG | |
1277 printf("mdat_reset_offset=%d\n", (int) url_ftell(pb)); | |
1278 #endif | |
1279 | |
1280 #ifdef DEBUG | |
1281 printf("streams= %d\n", s->nb_streams); | |
1282 #endif | |
1283 mov->total_streams = nb = s->nb_streams; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1284 |
0 | 1285 #if 1 |
1286 for(i=0; i<s->nb_streams;) { | |
1287 if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */ | |
1288 av_free(s->streams[i]); | |
1289 for(j=i+1; j<s->nb_streams; j++) | |
1290 s->streams[j-1] = s->streams[j]; | |
1291 s->nb_streams--; | |
1292 } else | |
1293 i++; | |
1294 } | |
1295 for(i=0; i<s->nb_streams;i++) { | |
1296 MOVStreamContext *sc; | |
1297 sc = (MOVStreamContext *)s->streams[i]->priv_data; | |
1298 sc->ffindex = i; | |
1299 sc->is_ff_stream = 1; | |
1300 } | |
1301 #endif | |
1302 #ifdef DEBUG | |
1303 printf("real streams= %d\n", s->nb_streams); | |
1304 #endif | |
1305 return 0; | |
1306 } | |
1307 | |
1308 /* Yes, this is ugly... I didn't write the specs of QT :p */ | |
1309 /* XXX:remove useless commented code sometime */ | |
1310 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1311 { | |
121 | 1312 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1313 MOVStreamContext *sc; |
65 | 1314 int64_t offset = 0x0FFFFFFFFFFFFFFF; |
0 | 1315 int i; |
118 | 1316 int size; |
0 | 1317 size = 0x0FFFFFFF; |
118 | 1318 |
0 | 1319 #ifdef MOV_SPLIT_CHUNKS |
1320 if (mov->partial) { | |
118 | 1321 |
0 | 1322 int idx; |
1323 | |
118 | 1324 sc = mov->partial; |
1325 idx = sc->sample_to_chunk_index; | |
0 | 1326 |
118 | 1327 if (idx < 0) return 0; |
1328 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1329 |
118 | 1330 sc->current_sample++; |
1331 sc->left_in_chunk--; | |
1332 | |
1333 if (sc->left_in_chunk <= 0) | |
0 | 1334 mov->partial = 0; |
1335 offset = mov->next_chunk_offset; | |
1336 /* extract the sample */ | |
1337 | |
1338 goto readchunk; | |
1339 } | |
1340 #endif | |
1341 | |
1342 again: | |
118 | 1343 sc = 0; |
0 | 1344 for(i=0; i<mov->total_streams; i++) { |
118 | 1345 MOVStreamContext *msc = mov->streams[i]; |
1346 //printf("MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb)); | |
1347 if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0 | |
1348 && (msc->chunk_offsets[msc->next_chunk] < offset)) { | |
1349 sc = msc; | |
1350 offset = msc->chunk_offsets[msc->next_chunk]; | |
1351 //printf("SELETED %Ld i:%d\n", offset, i); | |
0 | 1352 } |
1353 } | |
118 | 1354 if (!sc || offset==0x0FFFFFFFFFFFFFFF) |
1355 return -1; | |
1356 | |
1357 sc->next_chunk++; | |
1358 | |
0 | 1359 if(mov->next_chunk_offset < offset) { /* some meta data */ |
1360 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); | |
1361 mov->next_chunk_offset = offset; | |
1362 } | |
1363 | |
1364 //printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset); | |
118 | 1365 if(!sc->is_ff_stream) { |
0 | 1366 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); |
1367 mov->next_chunk_offset = offset; | |
1368 offset = 0x0FFFFFFFFFFFFFFF; | |
1369 goto again; | |
1370 } | |
1371 | |
1372 /* now get the chunk size... */ | |
1373 | |
1374 for(i=0; i<mov->total_streams; i++) { | |
118 | 1375 MOVStreamContext *msc = mov->streams[i]; |
1376 if ((msc->next_chunk < msc->chunk_count) | |
1377 && ((msc->chunk_offsets[msc->next_chunk] - offset) < size)) | |
1378 size = msc->chunk_offsets[msc->next_chunk] - offset; | |
0 | 1379 } |
1380 #ifdef MOV_SPLIT_CHUNKS | |
1381 /* split chunks into samples */ | |
118 | 1382 if (sc->sample_size == 0) { |
1383 int idx = sc->sample_to_chunk_index; | |
1384 if ((idx + 1 < sc->sample_to_chunk_sz) | |
1385 && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first)) | |
1386 idx++; | |
1387 sc->sample_to_chunk_index = idx; | |
1388 if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) { | |
1389 mov->partial = sc; | |
0 | 1390 /* we'll have to get those samples before next chunk */ |
118 | 1391 sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1; |
1392 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1393 } |
1394 | |
118 | 1395 sc->current_sample++; |
0 | 1396 } |
1397 #endif | |
1398 | |
1399 readchunk: | |
1400 //printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size); | |
1401 if(size == 0x0FFFFFFF) | |
1402 size = mov->mdat_size + mov->mdat_offset - offset; | |
1403 if(size < 0) | |
1404 return -1; | |
1405 if(size == 0) | |
1406 return -1; | |
1407 url_fseek(&s->pb, offset, SEEK_SET); | |
118 | 1408 |
1409 //printf("READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb)); | |
0 | 1410 if (sc->header_len > 0) { |
1411 av_new_packet(pkt, size + sc->header_len); | |
1412 memcpy(pkt->data, sc->header_data, sc->header_len); | |
1413 get_buffer(&s->pb, pkt->data + sc->header_len, size); | |
1414 /* free header */ | |
1415 av_freep(&sc->header_data); | |
1416 sc->header_len = 0; | |
1417 } else { | |
1418 av_new_packet(pkt, size); | |
1419 get_buffer(&s->pb, pkt->data, pkt->size); | |
1420 } | |
1421 pkt->stream_index = sc->ffindex; | |
1422 | |
1423 #ifdef DEBUG | |
1424 /* | |
1425 printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size); | |
1426 for(i=0; i<8; i++) | |
1427 printf("%02x ", pkt->data[i]); | |
1428 for(i=0; i<8; i++) | |
1429 printf("%c ", (pkt->data[i]) & 0x7F); | |
1430 puts(""); | |
1431 */ | |
1432 #endif | |
1433 | |
1434 mov->next_chunk_offset = offset + size; | |
1435 | |
1436 return 0; | |
1437 } | |
1438 | |
1439 static int mov_read_close(AVFormatContext *s) | |
1440 { | |
1441 int i; | |
121 | 1442 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1443 for(i=0; i<mov->total_streams; i++) |
1444 mov_free_stream_context(mov->streams[i]); | |
1445 for(i=0; i<s->nb_streams; i++) | |
1446 av_freep(&s->streams[i]); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1447 /* free color tabs */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1448 for(i=0; i<mov->ctab_size; i++) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1449 av_freep(&mov->ctab[i]); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1450 av_freep(&mov->ctab); |
0 | 1451 return 0; |
1452 } | |
1453 | |
1454 static AVInputFormat mov_iformat = { | |
1455 "mov", | |
1456 "QuickTime/MPEG4 format", | |
1457 sizeof(MOVContext), | |
1458 mov_probe, | |
1459 mov_read_header, | |
1460 mov_read_packet, | |
1461 mov_read_close, | |
1462 }; | |
1463 | |
1464 int mov_init(void) | |
1465 { | |
1466 av_register_input_format(&mov_iformat); | |
1467 return 0; | |
1468 } |