Mercurial > libavformat.hg
annotate mov.c @ 131:5bb5f3d201d6 libavformat
* uninitialized/unused vars cleanup
author | kabi |
---|---|
date | Mon, 12 May 2003 11:07:46 +0000 |
parents | f607ed6aa365 |
children | 9ca36221ae23 |
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; |
65 | 386 uint32_t type; |
387 uint32_t ctype; | |
121 | 388 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
389 print_atom("hdlr", atom); |
0 | 390 |
391 get_byte(pb); /* version */ | |
392 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
393 | |
394 /* component type */ | |
395 ctype = get_le32(pb); | |
396 type = get_le32(pb); /* component subtype */ | |
397 | |
398 #ifdef DEBUG | |
399 printf("ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype); | |
400 printf("stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | |
401 #endif | |
402 #ifdef DEBUG | |
403 /* XXX: yeah this is ugly... */ | |
404 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
405 if(type == MKTAG('v', 'i', 'd', 'e')) | |
406 puts("hdlr: vide"); | |
407 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
408 puts("hdlr: soun"); | |
409 } else if(ctype == 0) { /* MP4 */ | |
410 if(type == MKTAG('v', 'i', 'd', 'e')) | |
411 puts("hdlr: vide"); | |
412 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
413 puts("hdlr: soun"); | |
414 else if(type == MKTAG('o', 'd', 's', 'm')) | |
415 puts("hdlr: odsm"); | |
416 else if(type == MKTAG('s', 'd', 's', 'm')) | |
417 puts("hdlr: sdsm"); | |
418 } else puts("hdlr: meta"); | |
419 #endif | |
420 | |
421 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
422 /* helps parsing the string hereafter... */ | |
423 c->mp4 = 0; | |
424 if(type == MKTAG('v', 'i', 'd', 'e')) | |
425 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
426 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
427 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
428 } else if(ctype == 0) { /* MP4 */ | |
429 /* helps parsing the string hereafter... */ | |
430 c->mp4 = 1; | |
431 if(type == MKTAG('v', 'i', 'd', 'e')) | |
432 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
433 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
434 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
435 } | |
436 get_be32(pb); /* component manufacture */ | |
437 get_be32(pb); /* component flags */ | |
438 get_be32(pb); /* component flags mask */ | |
439 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
440 if(atom.size <= 24) |
0 | 441 return 0; /* nothing left to read */ |
442 /* XXX: MP4 uses a C string, not a pascal one */ | |
443 /* component name */ | |
444 | |
445 if(c->mp4) { | |
446 /* .mp4: C string */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
447 while(get_byte(pb) && (++len < (atom.size - 24))); |
0 | 448 } else { |
449 /* .mov: PASCAL string */ | |
450 len = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
451 #ifdef DEBUG |
121 | 452 buf = (uint8_t*) av_malloc(len+1); |
453 if (buf) { | |
454 get_buffer(pb, buf, len); | |
455 buf[len] = '\0'; | |
456 printf("**buf='%s'\n", buf); | |
457 av_free(buf); | |
458 } else | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
459 #endif |
121 | 460 url_fskip(pb, len); |
0 | 461 } |
118 | 462 |
0 | 463 return 0; |
464 } | |
465 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
466 static int mov_mp4_read_descr_len(ByteIOContext *pb) |
0 | 467 { |
118 | 468 int len = 0; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
469 int count = 4; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
470 while (count--) { |
118 | 471 int c = get_byte(pb); |
472 len = (len << 7) | (c & 0x7f); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
473 if (!(c & 0x80)) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
474 break; |
0 | 475 } |
476 return len; | |
477 } | |
478 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
479 static int mov_mp4_read_descr(ByteIOContext *pb, int *tag) |
0 | 480 { |
481 int len; | |
482 *tag = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
483 len = mov_mp4_read_descr_len(pb); |
0 | 484 #ifdef DEBUG |
485 printf("MPEG4 description: tag=0x%02x len=%d\n", *tag, len); | |
486 #endif | |
487 return len; | |
488 } | |
489 | |
118 | 490 static inline unsigned int get_be24(ByteIOContext *s) |
491 { | |
492 unsigned int val; | |
493 val = get_byte(s) << 16; | |
494 val |= get_byte(s) << 8; | |
495 val |= get_byte(s); | |
496 return val; | |
497 } | |
498 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
499 static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
118 | 500 { |
501 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
502 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
503 int64_t start_pos = url_ftell(pb); |
118 | 504 int tag, len; |
121 | 505 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
506 print_atom("esds", atom); |
118 | 507 |
508 /* Well, broken but suffisant for some MP4 streams */ | |
509 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
510 len = mov_mp4_read_descr(pb, &tag); |
118 | 511 if (tag == MP4ESDescrTag) { |
512 get_be16(pb); /* ID */ | |
513 get_byte(pb); /* priority */ | |
514 } else | |
515 get_be16(pb); /* ID */ | |
516 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
517 len = mov_mp4_read_descr(pb, &tag); |
118 | 518 if (tag == MP4DecConfigDescrTag) { |
519 sc->esds.object_type_id = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
520 sc->esds.stream_type = get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
521 sc->esds.buffer_size_db = get_be24(pb); |
118 | 522 sc->esds.max_bitrate = get_be32(pb); |
523 sc->esds.avg_bitrate = get_be32(pb); | |
524 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
525 len = mov_mp4_read_descr(pb, &tag); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
526 //printf("LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate); |
118 | 527 if (tag == MP4DecSpecificDescrTag) { |
528 #ifdef DEBUG | |
529 printf("Specific MPEG4 header len=%d\n", len); | |
530 #endif | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
531 st->codec.extradata = (uint8_t*) av_mallocz(len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
532 if (st->codec.extradata) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
533 get_buffer(pb, st->codec.extradata, len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
534 st->codec.extradata_size = len; |
118 | 535 } |
536 } | |
537 } | |
538 /* in any case, skip garbage */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
539 url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos))); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
540 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
541 } |
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 /* this atom contains actual media data */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
544 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
|
545 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
546 print_atom("mdat", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
547 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
548 if(atom.size == 0) /* wrong one (MP4) */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
549 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
550 c->found_mdat=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
551 c->mdat_offset = atom.offset; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
552 c->mdat_size = atom.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
553 if(c->found_moov) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
554 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
555 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
556 return 0; /* now go for moov */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
557 } |
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 /* this atom should contain all header atoms */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
560 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
|
561 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
562 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
563 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
564 print_atom("moov", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
565 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
566 err = mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
567 /* 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
|
568 /* 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
|
569 c->found_moov=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
570 if(c->found_mdat) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
571 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
572 return 0; /* now go for mdat */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
573 } |
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 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
|
577 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
578 print_atom("mdhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
579 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
580 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
581 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
582 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
583 get_byte(pb); /* flags */ |
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_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
586 get_be32(pb); /* modification time */ |
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 c->streams[c->total_streams]->time_scale = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
589 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
590 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
591 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
|
592 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
593 get_be32(pb); /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
594 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
595 get_be16(pb); /* language */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
596 get_be16(pb); /* quality */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
597 |
118 | 598 return 0; |
599 } | |
600 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
601 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
|
602 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
603 print_atom("mvhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
604 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
605 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
606 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
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_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
609 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
610 c->time_scale = get_be32(pb); /* time scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
611 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
612 printf("time scale = %i\n", c->time_scale); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
613 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
614 c->duration = get_be32(pb); /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
615 get_be32(pb); /* preferred scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
616 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
617 get_be16(pb); /* preferred volume */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
618 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
619 url_fskip(pb, 10); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
620 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
621 url_fskip(pb, 36); /* display matrix */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
622 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
623 get_be32(pb); /* preview time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
624 get_be32(pb); /* preview duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
625 get_be32(pb); /* poster time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
626 get_be32(pb); /* selection time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
627 get_be32(pb); /* selection duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
628 get_be32(pb); /* current time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
629 get_be32(pb); /* next track ID */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
630 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
631 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
632 } |
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 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
635 static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 636 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
637 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
638 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
639 int entries, i; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
640 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
641 print_atom("stco", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
642 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
643 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
644 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
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 entries = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
647 sc->chunk_count = entries; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
648 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
|
649 if (!sc->chunk_offsets) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
650 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
651 if (atom.type == MKTAG('s', 't', 'c', 'o')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
652 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
653 sc->chunk_offsets[i] = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
654 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
655 } else if (atom.type == MKTAG('c', 'o', '6', '4')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
656 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
657 sc->chunk_offsets[i] = get_be64(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
658 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
659 } else |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
660 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
661 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
662 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
663 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
664 printf("chunk offset=0x%Lx\n", sc->chunk_offsets[i]); |
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 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
667 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
668 return 0; |
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 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
671 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
|
672 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
673 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
131 | 674 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
675 int entries, frames_per_sample; |
65 | 676 uint32_t format; |
121 | 677 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
678 print_atom("stsd", atom); |
0 | 679 |
680 get_byte(pb); /* version */ | |
681 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
682 | |
683 entries = get_be32(pb); | |
684 | |
685 while(entries--) { | |
121 | 686 enum CodecID id; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
687 int size = get_be32(pb); /* size */ |
0 | 688 format = get_le32(pb); /* data format */ |
118 | 689 |
0 | 690 get_be32(pb); /* reserved */ |
691 get_be16(pb); /* reserved */ | |
692 get_be16(pb); /* index */ | |
693 | |
694 /* for MPEG4: set codec type by looking for it */ | |
695 id = codec_get_id(mov_video_tags, format); | |
696 if (id >= 0) { | |
697 AVCodec *codec; | |
121 | 698 codec = avcodec_find_decoder(id); |
0 | 699 if (codec) |
121 | 700 st->codec.codec_type = codec->type; |
0 | 701 } |
702 #ifdef DEBUG | |
118 | 703 printf("size=%d 4CC= %c%c%c%c codec_type=%d\n", |
704 size, | |
0 | 705 (format >> 0) & 0xff, |
706 (format >> 8) & 0xff, | |
707 (format >> 16) & 0xff, | |
708 (format >> 24) & 0xff, | |
709 st->codec.codec_type); | |
710 #endif | |
118 | 711 st->codec.codec_tag = format; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
712 if(st->codec.codec_type==CODEC_TYPE_VIDEO) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
713 MOV_atom_t a = { 0, 0, 0 }; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
714 st->codec.codec_id = id; |
0 | 715 get_be16(pb); /* version */ |
716 get_be16(pb); /* revision level */ | |
717 get_be32(pb); /* vendor */ | |
718 get_be32(pb); /* temporal quality */ | |
719 get_be32(pb); /* spacial quality */ | |
720 st->codec.width = get_be16(pb); /* width */ | |
721 st->codec.height = get_be16(pb); /* height */ | |
722 #if 1 | |
723 if (st->codec.codec_id == CODEC_ID_MPEG4) { | |
724 /* in some MPEG4 the width/height are not correct, so | |
725 we ignore this info */ | |
726 st->codec.width = 0; | |
727 st->codec.height = 0; | |
728 } | |
729 #endif | |
730 get_be32(pb); /* horiz resolution */ | |
731 get_be32(pb); /* vert resolution */ | |
732 get_be32(pb); /* data size, always 0 */ | |
118 | 733 frames_per_sample = get_be16(pb); /* frames per samples */ |
0 | 734 #ifdef DEBUG |
735 printf("frames/samples = %d\n", frames_per_sample); | |
736 #endif | |
121 | 737 get_buffer(pb, (uint8_t *)st->codec.codec_name, 32); /* codec name */ |
0 | 738 |
118 | 739 st->codec.bits_per_sample = get_be16(pb); /* depth */ |
740 st->codec.color_table_id = get_be16(pb); /* colortable id */ | |
741 | |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
742 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
|
743 st->codec.frame_rate_base = 1; |
118 | 744 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
745 size -= (16+8*4+2+32+2*2); |
118 | 746 #if 0 |
747 while (size >= 8) { | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
748 MOV_atom_t a; |
65 | 749 int64_t start_pos; |
118 | 750 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
751 a.size = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
752 a.type = get_le32(pb); |
118 | 753 size -= 8; |
0 | 754 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
755 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
|
756 (a.type >> 0) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
757 (a.type >> 8) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
758 (a.type >> 16) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
759 (a.type >> 24) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
760 a.size, size); |
0 | 761 #endif |
762 start_pos = url_ftell(pb); | |
763 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
764 switch(a.type) { |
0 | 765 case MKTAG('e', 's', 'd', 's'): |
766 { | |
767 int tag, len; | |
768 /* Well, broken but suffisant for some MP4 streams */ | |
769 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
770 len = mov_mp4_read_descr(pb, &tag); |
0 | 771 if (tag == 0x03) { |
772 /* MP4ESDescrTag */ | |
773 get_be16(pb); /* ID */ | |
774 get_byte(pb); /* priority */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
775 len = mov_mp4_read_descr(pb, &tag); |
0 | 776 if (tag != 0x04) |
777 goto fail; | |
778 /* MP4DecConfigDescrTag */ | |
779 get_byte(pb); /* objectTypeId */ | |
780 get_be32(pb); /* streamType + buffer size */ | |
118 | 781 get_be32(pb); /* max bit rate */ |
0 | 782 get_be32(pb); /* avg bit rate */ |
783 len = mp4_read_descr(pb, &tag); | |
784 if (tag != 0x05) | |
785 goto fail; | |
786 /* MP4DecSpecificDescrTag */ | |
787 #ifdef DEBUG | |
788 printf("Specific MPEG4 header len=%d\n", len); | |
789 #endif | |
790 sc->header_data = av_mallocz(len); | |
791 if (sc->header_data) { | |
792 get_buffer(pb, sc->header_data, len); | |
118 | 793 sc->header_len = len; |
0 | 794 } |
795 } | |
796 /* in any case, skip garbage */ | |
797 } | |
798 break; | |
799 default: | |
800 break; | |
801 } | |
118 | 802 fail: |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
803 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
|
804 if (atom.size > 8) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
805 url_fskip(pb, (atom.size - 8) - |
118 | 806 ((url_ftell(pb) - start_pos))); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
807 size -= atom.size - 8; |
118 | 808 } |
809 } | |
0 | 810 if (size > 0) { |
811 /* unknown extension */ | |
812 url_fskip(pb, size); | |
813 } | |
118 | 814 #else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
815 a.size = size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
816 mov_read_default(c, pb, a); |
118 | 817 #endif |
818 } else { | |
0 | 819 get_be16(pb); /* version */ |
820 get_be16(pb); /* revision level */ | |
821 get_be32(pb); /* vendor */ | |
822 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
823 st->codec.channels = get_be16(pb); /* channel count */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
824 st->codec.bits_per_sample = get_be16(pb); /* sample size */ |
118 | 825 |
826 st->codec.codec_id = codec_get_id(mov_audio_tags, format); | |
0 | 827 /* handle specific s8 codec */ |
828 get_be16(pb); /* compression id = 0*/ | |
829 get_be16(pb); /* packet size = 0 */ | |
118 | 830 |
0 | 831 st->codec.sample_rate = ((get_be32(pb) >> 16)); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
832 //printf("CODECID %d %d %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format); |
118 | 833 |
121 | 834 switch (st->codec.codec_id) { |
835 case CODEC_ID_PCM_S16BE: | |
118 | 836 if (st->codec.bits_per_sample == 8) |
837 st->codec.codec_id = CODEC_ID_PCM_S8; | |
121 | 838 /* fall */ |
839 case CODEC_ID_PCM_U8: | |
840 st->codec.bit_rate = st->codec.sample_rate * 8; | |
841 break; | |
842 default: | |
843 ; | |
118 | 844 } |
845 get_be32(pb); /* samples per packet */ | |
846 get_be32(pb); /* bytes per packet */ | |
847 get_be32(pb); /* bytes per frame */ | |
848 get_be32(pb); /* bytes per sample */ | |
0 | 849 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
850 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
851 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
|
852 mov_read_default(c, pb, a); |
118 | 853 } |
0 | 854 } |
855 } | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
856 |
0 | 857 return 0; |
858 } | |
859 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
860 static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 861 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
862 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
863 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 864 int entries, i; |
865 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
866 print_atom("stsc", atom); |
118 | 867 |
0 | 868 get_byte(pb); /* version */ |
869 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
870 | |
871 entries = get_be32(pb); | |
872 #ifdef DEBUG | |
873 printf("track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); | |
874 #endif | |
875 sc->sample_to_chunk_sz = entries; | |
121 | 876 sc->sample_to_chunk = (MOV_sample_to_chunk_tbl*) av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl)); |
877 if (!sc->sample_to_chunk) | |
878 return -1; | |
0 | 879 for(i=0; i<entries; i++) { |
880 sc->sample_to_chunk[i].first = get_be32(pb); | |
881 sc->sample_to_chunk[i].count = get_be32(pb); | |
882 sc->sample_to_chunk[i].id = get_be32(pb); | |
883 #ifdef DEBUG | |
884 /* 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); */ | |
885 #endif | |
886 } | |
887 return 0; | |
888 } | |
889 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
890 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 891 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
892 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
893 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 894 int entries, i; |
121 | 895 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
896 print_atom("stsz", atom); |
118 | 897 |
0 | 898 get_byte(pb); /* version */ |
899 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
118 | 900 |
0 | 901 sc->sample_size = get_be32(pb); |
902 entries = get_be32(pb); | |
903 sc->sample_count = entries; | |
904 #ifdef DEBUG | |
905 printf("sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count); | |
906 #endif | |
907 if(sc->sample_size) | |
908 return 0; /* there isn't any table following */ | |
121 | 909 sc->sample_sizes = (long*) av_malloc(entries * sizeof(long)); |
910 if (!sc->sample_sizes) | |
911 return -1; | |
0 | 912 for(i=0; i<entries; i++) { |
913 sc->sample_sizes[i] = get_be32(pb); | |
914 #ifdef DEBUG | |
915 /* printf("sample_sizes[]=%ld\n", sc->sample_sizes[i]); */ | |
916 #endif | |
917 } | |
918 return 0; | |
919 } | |
920 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
921 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 922 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
923 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
131 | 924 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 925 int entries, i; |
121 | 926 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
927 print_atom("stts", atom); |
0 | 928 |
929 get_byte(pb); /* version */ | |
930 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
931 entries = get_be32(pb); | |
932 #ifdef DEBUG | |
933 printf("track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); | |
934 #endif | |
935 for(i=0; i<entries; i++) { | |
936 int sample_duration; | |
937 | |
938 get_be32(pb); | |
939 sample_duration = get_be32(pb); | |
940 | |
941 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
|
942 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
|
943 st->codec.frame_rate = c->streams[c->total_streams]->time_scale; |
0 | 944 #ifdef DEBUG |
945 printf("VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration); | |
946 #endif | |
947 } | |
948 } | |
949 return 0; | |
950 } | |
951 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
952 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
|
953 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
954 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
955 MOVStreamContext *sc; |
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 print_atom("trak", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
958 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
959 st = av_new_stream(c->fc, c->fc->nb_streams); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
960 if (!st) return -2; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
961 sc = (MOVStreamContext*) av_mallocz(sizeof(MOVStreamContext)); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
962 if (!sc) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
963 av_free(st); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
964 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
965 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
966 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
967 sc->sample_to_chunk_index = -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
968 st->priv_data = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
969 st->codec.codec_type = CODEC_TYPE_MOV_OTHER; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
970 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
|
971 c->streams[c->fc->nb_streams-1] = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
972 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
973 return mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
974 } |
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 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
|
977 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
978 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
979 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
980 print_atom("tkhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
981 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
982 st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
983 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
984 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
985 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
986 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
987 get_byte(pb); /* flags */ |
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 MOV_TRACK_ENABLED 0x0001 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
990 MOV_TRACK_IN_MOVIE 0x0002 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
991 MOV_TRACK_IN_PREVIEW 0x0004 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
992 MOV_TRACK_IN_POSTER 0x0008 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
993 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
994 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
995 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
996 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
997 st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
998 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
999 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
|
1000 get_be32(pb); /* reserved */ |
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 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1003 get_be16(pb); /* layer */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1004 get_be16(pb); /* alternate group */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1005 get_be16(pb); /* volume */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1006 get_be16(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1007 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1008 url_fskip(pb, 36); /* display matrix */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1009 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1010 /* those are fixed-point */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1011 st->codec.width = get_be32(pb) >> 16; /* track width */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1012 st->codec.height = get_be32(pb) >> 16; /* track height */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1013 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1014 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1015 } |
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 /* 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
|
1018 /* 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
|
1019 /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1020 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
|
1021 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1022 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1023 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1024 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1025 print_atom("wide", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1026 debug_indent++; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1027 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1028 if (atom.size < 8) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1029 return 0; /* continue */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1030 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
|
1031 url_fskip(pb, atom.size - 4); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1032 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1033 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1034 atom.type = get_le32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1035 atom.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1036 atom.size -= 8; |
131 | 1037 if (atom.type != MKTAG('m', 'd', 'a', 't')) { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1038 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1039 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1040 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1041 err = mov_read_mdat(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1042 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1043 debug_indent--; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1044 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1045 return err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1046 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1047 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1048 |
0 | 1049 #ifdef CONFIG_ZLIB |
65 | 1050 static int null_read_packet(void *opaque, uint8_t *buf, int buf_size) |
0 | 1051 { |
1052 return -1; | |
1053 } | |
1054 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1055 static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1056 { |
1057 ByteIOContext ctx; | |
121 | 1058 uint8_t *cmov_data; |
1059 uint8_t *moov_data; /* uncompressed data */ | |
0 | 1060 long cmov_len, moov_len; |
1061 int ret; | |
121 | 1062 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1063 print_atom("cmov", atom); |
0 | 1064 |
1065 get_be32(pb); /* dcom atom */ | |
1066 if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' )) | |
1067 return -1; | |
1068 if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) { | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1069 dprintf("unknown compression for cmov atom !"); |
0 | 1070 return -1; |
1071 } | |
1072 get_be32(pb); /* cmvd atom */ | |
1073 if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' )) | |
1074 return -1; | |
1075 moov_len = get_be32(pb); /* uncompressed size */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1076 cmov_len = atom.size - 6 * 4; |
118 | 1077 |
121 | 1078 cmov_data = (uint8_t *) av_malloc(cmov_len); |
0 | 1079 if (!cmov_data) |
1080 return -1; | |
121 | 1081 moov_data = (uint8_t *) av_malloc(moov_len); |
0 | 1082 if (!moov_data) { |
1083 av_free(cmov_data); | |
1084 return -1; | |
1085 } | |
1086 get_buffer(pb, cmov_data, cmov_len); | |
121 | 1087 if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) |
0 | 1088 return -1; |
1089 if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0) | |
1090 return -1; | |
1091 ctx.buf_end = ctx.buffer + moov_len; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1092 atom.type = MKTAG( 'm', 'o', 'o', 'v' ); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1093 atom.offset = 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1094 atom.size = moov_len; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1095 ret = mov_read_default(c, &ctx, atom); |
0 | 1096 av_free(moov_data); |
1097 av_free(cmov_data); | |
1098 return ret; | |
1099 } | |
1100 #endif | |
1101 | |
1102 static const MOVParseTableEntry mov_default_parse_table[] = { | |
1103 /* mp4 atoms */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1104 { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1105 { MKTAG( 'c', 'p', 'r', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1106 { MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1107 { 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
|
1108 { MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1109 { MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1110 { MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1111 { MKTAG( 'e', 'd', 't', 's' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1112 { MKTAG( 'e', 'l', 's', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1113 { MKTAG( 'f', 'r', 'e', 'e' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1114 { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1115 { MKTAG( 'h', 'i', 'n', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1116 { MKTAG( 'h', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1117 { MKTAG( 'i', 'o', 'd', 's' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1118 { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1119 { MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1120 { MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1121 { MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1122 { MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1123 { MKTAG( 'm', 'p', '4', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1124 { MKTAG( 'm', 'p', '4', 's' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1125 { MKTAG( 'm', 'p', '4', 'v' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1126 { MKTAG( 'm', 'p', 'o', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1127 { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1128 { MKTAG( 'n', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1129 { MKTAG( 'o', 'd', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1130 { MKTAG( 's', 'd', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1131 { MKTAG( 's', 'k', 'i', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1132 { 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
|
1133 { MKTAG( 's', 't', 'b', 'l' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1134 { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1135 { MKTAG( 's', 't', 'd', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1136 { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1137 { MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1138 { MKTAG( 's', 't', 's', 'h' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1139 { MKTAG( 's', 't', 's', 's' ), mov_read_leaf }, /* sync sample */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1140 { MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1141 { MKTAG( 's', 't', 't', 's' ), mov_read_stts }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1142 { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1143 { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1144 { MKTAG( 't', 'r', 'e', 'f' ), mov_read_default }, /* not really */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1145 { MKTAG( 'u', 'd', 't', 'a' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1146 { MKTAG( 'u', 'r', 'l', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1147 { MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1148 { MKTAG( 'u', 'u', 'i', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1149 { 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
|
1150 { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default }, |
0 | 1151 /* extra mp4 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1152 { MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf }, |
0 | 1153 /* QT atoms */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1154 { MKTAG( 'c', 'h', 'a', 'p' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1155 { MKTAG( 'c', 'l', 'i', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1156 { MKTAG( 'c', 'r', 'g', 'n' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1157 { MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1158 { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1159 { MKTAG( 'k', 'm', 'a', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1160 { MKTAG( 'm', 'a', 't', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1161 { MKTAG( 'r', 'd', 'r', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1162 { MKTAG( 'r', 'm', 'd', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1163 { MKTAG( 'r', 'm', 'd', 'r' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1164 { MKTAG( 'r', 'm', 'r', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1165 { MKTAG( 's', 'c', 'p', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1166 { MKTAG( 's', 's', 'r', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1167 { MKTAG( 's', 'y', 'n', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1168 { MKTAG( 't', 'c', 'm', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1169 { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1170 //{ MKTAG( 'r', 'm', 'q', 'u' ), mov_read_leaf }, |
0 | 1171 #ifdef CONFIG_ZLIB |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1172 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov }, |
0 | 1173 #else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1174 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_leaf }, |
0 | 1175 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1176 { 0L, mov_read_leaf } |
0 | 1177 }; |
1178 | |
1179 static void mov_free_stream_context(MOVStreamContext *sc) | |
1180 { | |
1181 if(sc) { | |
1182 av_free(sc->chunk_offsets); | |
1183 av_free(sc->sample_to_chunk); | |
118 | 1184 av_free(sc->sample_sizes); |
0 | 1185 av_free(sc->header_data); |
1186 av_free(sc); | |
1187 } | |
1188 } | |
1189 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1190 static inline uint32_t mov_to_tag(uint8_t *buf) |
0 | 1191 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1192 return MKTAG(buf[0], buf[1], buf[2], buf[3]); |
0 | 1193 } |
1194 | |
118 | 1195 static inline uint32_t to_be32(uint8_t *buf) |
0 | 1196 { |
1197 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
1198 } | |
1199 | |
121 | 1200 /* XXX: is it sufficient ? */ |
0 | 1201 static int mov_probe(AVProbeData *p) |
1202 { | |
1203 unsigned int offset; | |
1204 uint32_t tag; | |
1205 | |
1206 /* check file header */ | |
1207 if (p->buf_size <= 12) | |
1208 return 0; | |
1209 offset = 0; | |
1210 for(;;) { | |
1211 /* ignore invalid offset */ | |
1212 if ((offset + 8) > (unsigned int)p->buf_size) | |
1213 return 0; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1214 tag = mov_to_tag(p->buf + offset + 4); |
0 | 1215 switch(tag) { |
1216 case MKTAG( 'm', 'o', 'o', 'v' ): | |
1217 case MKTAG( 'w', 'i', 'd', 'e' ): | |
1218 case MKTAG( 'f', 'r', 'e', 'e' ): | |
24 | 1219 case MKTAG( 'm', 'd', 'a', 't' ): |
1220 case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */ | |
0 | 1221 return AVPROBE_SCORE_MAX; |
1222 case MKTAG( 'f', 't', 'y', 'p' ): | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1223 case MKTAG( 's', 'k', 'i', 'p' ): |
0 | 1224 offset = to_be32(p->buf) + offset; |
1225 break; | |
1226 default: | |
1227 /* unrecognized tag */ | |
1228 return 0; | |
1229 } | |
1230 } | |
1231 return 0; | |
1232 } | |
1233 | |
1234 static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
1235 { | |
121 | 1236 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1237 ByteIOContext *pb = &s->pb; |
1238 int i, j, nb, err; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1239 MOV_atom_t atom = { 0, 0, 0 }; |
0 | 1240 |
1241 mov->fc = s; | |
121 | 1242 mov->parse_table = mov_default_parse_table; |
0 | 1243 #if 0 |
1244 /* XXX: I think we should auto detect */ | |
1245 if(s->iformat->name[1] == 'p') | |
1246 mov->mp4 = 1; | |
1247 #endif | |
1248 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
|
1249 atom.size = url_filesize(url_fileno(pb)); |
0 | 1250 else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1251 atom.size = 0x7FFFFFFFFFFFFFFF; |
0 | 1252 |
1253 #ifdef DEBUG | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1254 printf("filesz=%Ld\n", atom.size); |
0 | 1255 #endif |
1256 | |
1257 /* check MOV header */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1258 err = mov_read_default(mov, pb, atom); |
0 | 1259 if(err<0 || (!mov->found_moov || !mov->found_mdat)) { |
1260 puts("header not found !!!"); | |
1261 exit(1); | |
1262 } | |
1263 #ifdef DEBUG | |
1264 printf("on_parse_exit_offset=%d\n", (int) url_ftell(pb)); | |
1265 #endif | |
1266 /* some cleanup : make sure we are on the mdat atom */ | |
1267 if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset)) | |
1268 url_fseek(pb, mov->mdat_offset, SEEK_SET); | |
1269 | |
1270 mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */ | |
1271 | |
1272 #ifdef DEBUG | |
1273 printf("mdat_reset_offset=%d\n", (int) url_ftell(pb)); | |
1274 #endif | |
1275 | |
1276 #ifdef DEBUG | |
1277 printf("streams= %d\n", s->nb_streams); | |
1278 #endif | |
1279 mov->total_streams = nb = s->nb_streams; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1280 |
0 | 1281 #if 1 |
1282 for(i=0; i<s->nb_streams;) { | |
1283 if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */ | |
1284 av_free(s->streams[i]); | |
1285 for(j=i+1; j<s->nb_streams; j++) | |
1286 s->streams[j-1] = s->streams[j]; | |
1287 s->nb_streams--; | |
1288 } else | |
1289 i++; | |
1290 } | |
1291 for(i=0; i<s->nb_streams;i++) { | |
1292 MOVStreamContext *sc; | |
1293 sc = (MOVStreamContext *)s->streams[i]->priv_data; | |
1294 sc->ffindex = i; | |
1295 sc->is_ff_stream = 1; | |
1296 } | |
1297 #endif | |
1298 #ifdef DEBUG | |
1299 printf("real streams= %d\n", s->nb_streams); | |
1300 #endif | |
1301 return 0; | |
1302 } | |
1303 | |
1304 /* Yes, this is ugly... I didn't write the specs of QT :p */ | |
1305 /* XXX:remove useless commented code sometime */ | |
1306 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1307 { | |
121 | 1308 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1309 MOVStreamContext *sc; |
65 | 1310 int64_t offset = 0x0FFFFFFFFFFFFFFF; |
0 | 1311 int i; |
118 | 1312 int size; |
0 | 1313 size = 0x0FFFFFFF; |
118 | 1314 |
0 | 1315 #ifdef MOV_SPLIT_CHUNKS |
1316 if (mov->partial) { | |
118 | 1317 |
0 | 1318 int idx; |
1319 | |
118 | 1320 sc = mov->partial; |
1321 idx = sc->sample_to_chunk_index; | |
0 | 1322 |
118 | 1323 if (idx < 0) return 0; |
1324 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1325 |
118 | 1326 sc->current_sample++; |
1327 sc->left_in_chunk--; | |
1328 | |
1329 if (sc->left_in_chunk <= 0) | |
0 | 1330 mov->partial = 0; |
1331 offset = mov->next_chunk_offset; | |
1332 /* extract the sample */ | |
1333 | |
1334 goto readchunk; | |
1335 } | |
1336 #endif | |
1337 | |
1338 again: | |
118 | 1339 sc = 0; |
0 | 1340 for(i=0; i<mov->total_streams; i++) { |
118 | 1341 MOVStreamContext *msc = mov->streams[i]; |
1342 //printf("MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb)); | |
1343 if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0 | |
1344 && (msc->chunk_offsets[msc->next_chunk] < offset)) { | |
1345 sc = msc; | |
1346 offset = msc->chunk_offsets[msc->next_chunk]; | |
1347 //printf("SELETED %Ld i:%d\n", offset, i); | |
0 | 1348 } |
1349 } | |
118 | 1350 if (!sc || offset==0x0FFFFFFFFFFFFFFF) |
1351 return -1; | |
1352 | |
1353 sc->next_chunk++; | |
1354 | |
0 | 1355 if(mov->next_chunk_offset < offset) { /* some meta data */ |
1356 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); | |
1357 mov->next_chunk_offset = offset; | |
1358 } | |
1359 | |
1360 //printf("chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset); | |
118 | 1361 if(!sc->is_ff_stream) { |
0 | 1362 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); |
1363 mov->next_chunk_offset = offset; | |
1364 offset = 0x0FFFFFFFFFFFFFFF; | |
1365 goto again; | |
1366 } | |
1367 | |
1368 /* now get the chunk size... */ | |
1369 | |
1370 for(i=0; i<mov->total_streams; i++) { | |
118 | 1371 MOVStreamContext *msc = mov->streams[i]; |
1372 if ((msc->next_chunk < msc->chunk_count) | |
1373 && ((msc->chunk_offsets[msc->next_chunk] - offset) < size)) | |
1374 size = msc->chunk_offsets[msc->next_chunk] - offset; | |
0 | 1375 } |
1376 #ifdef MOV_SPLIT_CHUNKS | |
1377 /* split chunks into samples */ | |
118 | 1378 if (sc->sample_size == 0) { |
1379 int idx = sc->sample_to_chunk_index; | |
1380 if ((idx + 1 < sc->sample_to_chunk_sz) | |
1381 && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first)) | |
1382 idx++; | |
1383 sc->sample_to_chunk_index = idx; | |
1384 if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) { | |
1385 mov->partial = sc; | |
0 | 1386 /* we'll have to get those samples before next chunk */ |
118 | 1387 sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1; |
1388 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1389 } |
1390 | |
118 | 1391 sc->current_sample++; |
0 | 1392 } |
1393 #endif | |
1394 | |
1395 readchunk: | |
1396 //printf("chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size); | |
1397 if(size == 0x0FFFFFFF) | |
1398 size = mov->mdat_size + mov->mdat_offset - offset; | |
1399 if(size < 0) | |
1400 return -1; | |
1401 if(size == 0) | |
1402 return -1; | |
1403 url_fseek(&s->pb, offset, SEEK_SET); | |
118 | 1404 |
1405 //printf("READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb)); | |
0 | 1406 if (sc->header_len > 0) { |
1407 av_new_packet(pkt, size + sc->header_len); | |
1408 memcpy(pkt->data, sc->header_data, sc->header_len); | |
1409 get_buffer(&s->pb, pkt->data + sc->header_len, size); | |
1410 /* free header */ | |
1411 av_freep(&sc->header_data); | |
1412 sc->header_len = 0; | |
1413 } else { | |
1414 av_new_packet(pkt, size); | |
1415 get_buffer(&s->pb, pkt->data, pkt->size); | |
1416 } | |
1417 pkt->stream_index = sc->ffindex; | |
1418 | |
1419 #ifdef DEBUG | |
1420 /* | |
1421 printf("Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size); | |
1422 for(i=0; i<8; i++) | |
1423 printf("%02x ", pkt->data[i]); | |
1424 for(i=0; i<8; i++) | |
1425 printf("%c ", (pkt->data[i]) & 0x7F); | |
1426 puts(""); | |
1427 */ | |
1428 #endif | |
1429 | |
1430 mov->next_chunk_offset = offset + size; | |
1431 | |
1432 return 0; | |
1433 } | |
1434 | |
1435 static int mov_read_close(AVFormatContext *s) | |
1436 { | |
1437 int i; | |
121 | 1438 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1439 for(i=0; i<mov->total_streams; i++) |
1440 mov_free_stream_context(mov->streams[i]); | |
1441 for(i=0; i<s->nb_streams; i++) | |
1442 av_freep(&s->streams[i]); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1443 /* free color tabs */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1444 for(i=0; i<mov->ctab_size; i++) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1445 av_freep(&mov->ctab[i]); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1446 av_freep(&mov->ctab); |
0 | 1447 return 0; |
1448 } | |
1449 | |
1450 static AVInputFormat mov_iformat = { | |
1451 "mov", | |
1452 "QuickTime/MPEG4 format", | |
1453 sizeof(MOVContext), | |
1454 mov_probe, | |
1455 mov_read_header, | |
1456 mov_read_packet, | |
1457 mov_read_close, | |
1458 }; | |
1459 | |
1460 int mov_init(void) | |
1461 { | |
1462 av_register_input_format(&mov_iformat); | |
1463 return 0; | |
1464 } |