Mercurial > libavformat.hg
annotate mov.c @ 508:4655d19a3d94 libavformat
* fixing a bug in DV timestamp generation. Now libavtest doesn't
depend on a local TZ anymore.
author | romansh |
---|---|
date | Mon, 02 Aug 2004 05:42:49 +0000 |
parents | 74ad3aa6749c |
children | 59da52e5f5a5 |
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 */ | |
395
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
19 |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
20 #include <limits.h> |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
21 |
0 | 22 #include "avformat.h" |
23 #include "avi.h" | |
24 | |
25 #ifdef CONFIG_ZLIB | |
26 #include <zlib.h> | |
27 #endif | |
28 | |
29 /* | |
30 * First version by Francois Revol revol@free.fr | |
491 | 31 * Seek function by Gael Chardon gael.dev@4now.net |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
32 * |
0 | 33 * Features and limitations: |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
34 * - reads most of the QT files I have (at least the structure), |
0 | 35 * the exceptions are .mov with zlib compressed headers ('cmov' section). It shouldn't be hard to implement. |
36 * FIXED, Francois Revol, 07/17/2002 | |
37 * - ffmpeg has nearly none of the usual QuickTime codecs, | |
38 * although I succesfully dumped raw and mp3 audio tracks off .mov files. | |
39 * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html | |
40 * - .mp4 parsing is still hazardous, although the format really is QuickTime with some minor changes | |
41 * (to make .mov parser crash maybe ?), despite what they say in the MPEG FAQ at | |
42 * http://mpeg.telecomitalialab.com/faq.htm | |
43 * - the code is quite ugly... maybe I won't do it recursive next time :-) | |
491 | 44 * - seek is not supported with files that contain edit list |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
45 * |
0 | 46 * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/ |
47 * when coding this :) (it's a writer anyway) | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
48 * |
0 | 49 * Reference documents: |
50 * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt | |
51 * Apple: | |
491 | 52 * http://developer.apple.com/documentation/QuickTime/QTFF/ |
506
74ad3aa6749c
2000/00/00 to 2001/03/01 QT fileformat documentation patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
500
diff
changeset
|
53 * http://developer.apple.com/documentation/QuickTime/QTFF/qtff.pdf |
0 | 54 * QuickTime is a trademark of Apple (AFAIK :)) |
55 */ | |
56 | |
57 //#define DEBUG | |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
58 #ifdef DEBUG |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
59 #include <stdio.h> |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
60 #include <fcntl.h> |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
61 #endif |
0 | 62 |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
63 #include "qtpalette.h" |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
64 |
491 | 65 |
66 /* Allows seeking (MOV_SPLIT_CHUNKS should also be defined) */ | |
67 #define MOV_SEEK | |
68 | |
0 | 69 /* allows chunk splitting - should work now... */ |
70 /* in case you can't read a file, try commenting */ | |
71 #define MOV_SPLIT_CHUNKS | |
72 | |
147 | 73 /* Special handling for movies created with Minolta Dimaxe Xi*/ |
74 /* this fix should not interfere with other .mov files, but just in case*/ | |
75 #define MOV_MINOLTA_FIX | |
76 | |
0 | 77 /* some streams in QT (and in MP4 mostly) aren't either video nor audio */ |
78 /* so we first list them as this, then clean up the list of streams we give back, */ | |
79 /* getting rid of these */ | |
121 | 80 #define CODEC_TYPE_MOV_OTHER (enum CodecType) 2 |
0 | 81 |
82 static const CodecTag mov_video_tags[] = { | |
83 /* { CODEC_ID_, MKTAG('c', 'v', 'i', 'd') }, *//* Cinepak */ | |
84 /* { CODEC_ID_H263, MKTAG('r', 'a', 'w', ' ') }, *//* Uncompressed RGB */ | |
85 /* { 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
|
86 /* { CODEC_ID_RAWVIDEO, MKTAG('A', 'V', 'U', 'I') }, *//* YUV with alpha-channel (AVID Uncompressed) */ |
0 | 87 /* Graphics */ |
88 /* Animation */ | |
89 /* Apple video */ | |
90 /* Kodak Photo CD */ | |
91 { CODEC_ID_MJPEG, MKTAG('j', 'p', 'e', 'g') }, /* PhotoJPEG */ | |
92 { CODEC_ID_MPEG1VIDEO, MKTAG('m', 'p', 'e', 'g') }, /* MPEG */ | |
93 { CODEC_ID_MJPEG, MKTAG('m', 'j', 'p', 'a') }, /* Motion-JPEG (format A) */ | |
94 { 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
|
95 { 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
|
96 /* { CODEC_ID_MJPEG, MKTAG('A', 'V', 'R', 'n') }, *//* MJPEG with alpha-channel (AVID ABVB/Truevision NuVista) */ |
0 | 97 /* { CODEC_ID_GIF, MKTAG('g', 'i', 'f', ' ') }, *//* embedded gif files as frames (usually one "click to play movie" frame) */ |
98 /* Sorenson video */ | |
99 { CODEC_ID_SVQ1, MKTAG('S', 'V', 'Q', '1') }, /* Sorenson Video v1 */ | |
100 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', '1') }, /* Sorenson Video v1 */ | |
101 { CODEC_ID_SVQ1, MKTAG('s', 'v', 'q', 'i') }, /* Sorenson Video v1 (from QT specs)*/ | |
129 | 102 { CODEC_ID_SVQ3, MKTAG('S', 'V', 'Q', '3') }, /* Sorenson Video v3 */ |
0 | 103 { CODEC_ID_MPEG4, MKTAG('m', 'p', '4', 'v') }, |
104 { CODEC_ID_MPEG4, MKTAG('D', 'I', 'V', 'X') }, /* OpenDiVX *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ | |
289 | 105 { CODEC_ID_MPEG4, MKTAG('X', 'V', 'I', 'D') }, |
0 | 106 /* { CODEC_ID_, MKTAG('I', 'V', '5', '0') }, *//* Indeo 5.0 */ |
107 { CODEC_ID_H263, MKTAG('h', '2', '6', '3') }, /* H263 */ | |
133 | 108 { CODEC_ID_H263, MKTAG('s', '2', '6', '3') }, /* H263 ?? works */ |
0 | 109 { CODEC_ID_DVVIDEO, MKTAG('d', 'v', 'c', ' ') }, /* DV NTSC */ |
110 { 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
|
111 /* { CODEC_ID_DVVIDEO, MKTAG('A', 'V', 'd', 'v') }, *//* AVID dv */ |
124 | 112 { CODEC_ID_VP3, MKTAG('V', 'P', '3', '1') }, /* On2 VP3 */ |
266
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
258
diff
changeset
|
113 { CODEC_ID_RPZA, MKTAG('r', 'p', 'z', 'a') }, /* Apple Video (RPZA) */ |
8bb470d85249
New demuxers: Sega FILM/CPK, Westwood VQA & AUD; new decoders: MS RLE &
tmmm
parents:
258
diff
changeset
|
114 { CODEC_ID_CINEPAK, MKTAG('c', 'v', 'i', 'd') }, /* Cinepak */ |
301 | 115 { CODEC_ID_8BPS, MKTAG('8', 'B', 'P', 'S') }, /* Planar RGB (8BPS) */ |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
116 { CODEC_ID_SMC, MKTAG('s', 'm', 'c', ' ') }, /* Apple Graphics (SMC) */ |
358
d18a2b1fc182
initial commit for Quicktime Animation (RLE) video decoder; bit depths
melanson
parents:
308
diff
changeset
|
117 { CODEC_ID_QTRLE, MKTAG('r', 'l', 'e', ' ') }, /* Apple Animation (RLE) */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
118 { CODEC_ID_NONE, 0 }, |
0 | 119 }; |
120 | |
121 static const CodecTag mov_audio_tags[] = { | |
122 /* { CODEC_ID_PCM_S16BE, MKTAG('N', 'O', 'N', 'E') }, *//* uncompressed */ | |
123 { 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
|
124 /* { CODEC_ID_PCM_S8, MKTAG('t', 'w', 'o', 's') },*/ /* 8 bits */ |
118 | 125 { CODEC_ID_PCM_U8, MKTAG('r', 'a', 'w', ' ') }, /* 8 bits unsigned */ |
0 | 126 { CODEC_ID_PCM_S16LE, MKTAG('s', 'o', 'w', 't') }, /* */ |
127 { CODEC_ID_PCM_MULAW, MKTAG('u', 'l', 'a', 'w') }, /* */ | |
128 { CODEC_ID_PCM_ALAW, MKTAG('a', 'l', 'a', 'w') }, /* */ | |
129 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i', 'm', 'a', '4') }, /* IMA-4 ADPCM */ | |
130 { CODEC_ID_MACE3, MKTAG('M', 'A', 'C', '3') }, /* Macintosh Audio Compression and Expansion 3:1 */ | |
131 { CODEC_ID_MACE6, MKTAG('M', 'A', 'C', '6') }, /* Macintosh Audio Compression and Expansion 6:1 */ | |
132 | |
133 { CODEC_ID_MP2, MKTAG('.', 'm', 'p', '3') }, /* MPEG layer 3 */ /* sample files at http://www.3ivx.com/showcase.html use this tag */ | |
134 { CODEC_ID_MP2, 0x6D730055 }, /* MPEG layer 3 */ | |
135 { CODEC_ID_MP2, 0x5500736D }, /* MPEG layer 3 *//* XXX: check endianness */ | |
136 /* { CODEC_ID_OGG_VORBIS, MKTAG('O', 'g', 'g', 'S') }, *//* sample files at http://heroinewarrior.com/xmovie.php3 use this tag */ | |
137 /* MP4 tags */ | |
286
eccf0c3e3289
Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents:
266
diff
changeset
|
138 { CODEC_ID_MPEG4AAC, MKTAG('m', 'p', '4', 'a') }, /* MPEG-4 AAC */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
139 /* The standard for mpeg4 audio is still not normalised AFAIK anyway */ |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
140 { CODEC_ID_AMR_NB, MKTAG('s', 'a', 'm', 'r') }, /* AMR-NB 3gp */ |
258
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
141 { CODEC_ID_AMR_WB, MKTAG('s', 'a', 'w', 'b') }, /* AMR-WB 3gp */ |
289 | 142 { CODEC_ID_AC3, MKTAG('m', 's', 0x20, 0x00) }, /* Dolby AC-3 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
143 { CODEC_ID_NONE, 0 }, |
0 | 144 }; |
145 | |
146 /* the QuickTime file format is quite convoluted... | |
147 * it has lots of index tables, each indexing something in another one... | |
148 * Here we just use what is needed to read the chunks | |
149 */ | |
150 | |
151 typedef struct MOV_sample_to_chunk_tbl { | |
152 long first; | |
153 long count; | |
154 long id; | |
155 } MOV_sample_to_chunk_tbl; | |
156 | |
118 | 157 typedef struct { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
158 uint32_t type; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
159 int64_t offset; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
160 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
|
161 } MOV_atom_t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
162 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
163 typedef struct { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
164 int seed; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
165 int flags; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
166 int size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
167 void* clrs; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
168 } MOV_ctab_t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
169 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
170 typedef struct { |
118 | 171 uint8_t version; |
172 uint32_t flags; // 24bit | |
173 | |
174 /* 0x03 ESDescrTag */ | |
175 uint16_t es_id; | |
176 #define MP4ODescrTag 0x01 | |
177 #define MP4IODescrTag 0x02 | |
178 #define MP4ESDescrTag 0x03 | |
179 #define MP4DecConfigDescrTag 0x04 | |
180 #define MP4DecSpecificDescrTag 0x05 | |
181 #define MP4SLConfigDescrTag 0x06 | |
182 #define MP4ContentIdDescrTag 0x07 | |
183 #define MP4SupplContentIdDescrTag 0x08 | |
184 #define MP4IPIPtrDescrTag 0x09 | |
185 #define MP4IPMPPtrDescrTag 0x0A | |
186 #define MP4IPMPDescrTag 0x0B | |
187 #define MP4RegistrationDescrTag 0x0D | |
188 #define MP4ESIDIncDescrTag 0x0E | |
189 #define MP4ESIDRefDescrTag 0x0F | |
190 #define MP4FileIODescrTag 0x10 | |
191 #define MP4FileODescrTag 0x11 | |
192 #define MP4ExtProfileLevelDescrTag 0x13 | |
193 #define MP4ExtDescrTagsStart 0x80 | |
194 #define MP4ExtDescrTagsEnd 0xFE | |
195 uint8_t stream_priority; | |
196 | |
197 /* 0x04 DecConfigDescrTag */ | |
198 uint8_t object_type_id; | |
199 uint8_t stream_type; | |
200 /* XXX: really streamType is | |
201 * only 6bit, followed by: | |
202 * 1bit upStream | |
203 * 1bit reserved | |
204 */ | |
205 uint32_t buffer_size_db; // 24 | |
206 uint32_t max_bitrate; | |
207 uint32_t avg_bitrate; | |
208 | |
209 /* 0x05 DecSpecificDescrTag */ | |
210 uint8_t decoder_cfg_len; | |
211 uint8_t *decoder_cfg; | |
212 | |
213 /* 0x06 SLConfigDescrTag */ | |
214 uint8_t sl_config_len; | |
215 uint8_t *sl_config; | |
216 } MOV_esds_t; | |
217 | |
121 | 218 struct MOVParseTableEntry; |
219 | |
0 | 220 typedef struct MOVStreamContext { |
221 int ffindex; /* the ffmpeg stream id */ | |
222 int is_ff_stream; /* Is this stream presented to ffmpeg ? i.e. is this an audio or video stream ? */ | |
223 long next_chunk; | |
224 long chunk_count; | |
65 | 225 int64_t *chunk_offsets; |
491 | 226 int32_t stts_count; |
227 uint64_t *stts_data; /* concatenated data from the time-to-sample atom (count|duration) */ | |
228 int32_t edit_count; /* number of 'edit' (elst atom) */ | |
0 | 229 long sample_to_chunk_sz; |
230 MOV_sample_to_chunk_tbl *sample_to_chunk; | |
231 long sample_to_chunk_index; | |
232 long sample_size; | |
233 long sample_count; | |
234 long *sample_sizes; | |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
235 long keyframe_count; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
236 long *keyframes; |
118 | 237 int time_scale; |
0 | 238 long current_sample; |
239 long left_in_chunk; /* how many samples before next chunk */ | |
240 /* specific MPEG4 header which is added at the beginning of the stream */ | |
241 int header_len; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
242 uint8_t *header_data; |
118 | 243 MOV_esds_t esds; |
0 | 244 } MOVStreamContext; |
245 | |
246 typedef struct MOVContext { | |
247 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) */ | |
248 AVFormatContext *fc; | |
118 | 249 int time_scale; |
250 int duration; /* duration of the longest track */ | |
0 | 251 int found_moov; /* when both 'moov' and 'mdat' sections has been found */ |
252 int found_mdat; /* we suppose we have enough data to read the file */ | |
65 | 253 int64_t mdat_size; |
254 int64_t mdat_offset; | |
0 | 255 int total_streams; |
256 /* some streams listed here aren't presented to the ffmpeg API, since they aren't either video nor audio | |
257 * but we need the info to be able to skip data from those streams in the 'mdat' section | |
258 */ | |
259 MOVStreamContext *streams[MAX_STREAMS]; | |
118 | 260 |
65 | 261 int64_t next_chunk_offset; |
118 | 262 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
|
263 int ctab_size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
264 MOV_ctab_t **ctab; /* color tables */ |
121 | 265 const struct MOVParseTableEntry *parse_table; /* could be eventually used to change the table */ |
266 /* NOTE: for recursion save to/ restore from local variable! */ | |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
267 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
268 AVPaletteControl palette_control; |
0 | 269 } MOVContext; |
270 | |
271 | |
272 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ | |
273 | |
274 /* those functions parse an atom */ | |
275 /* return code: | |
276 1: found what I wanted, exit | |
277 0: continue to parse next atom | |
278 -1: error occured, exit | |
279 */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
280 typedef int (*mov_parse_function)(MOVContext *ctx, ByteIOContext *pb, MOV_atom_t atom); |
0 | 281 |
282 /* links atom IDs to parse functions */ | |
283 typedef struct MOVParseTableEntry { | |
65 | 284 uint32_t type; |
0 | 285 mov_parse_function func; |
286 } MOVParseTableEntry; | |
287 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
288 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
289 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
290 * XXX: static sux, even more in a multithreaded environment... |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
291 * Avoid them. This is here just to help debugging. |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
292 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
293 static int debug_indent = 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
294 void print_atom(const char *str, MOV_atom_t atom) |
0 | 295 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
296 unsigned int tag, i; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
297 tag = (unsigned int) atom.type; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
298 i=debug_indent; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
299 if(tag == 0) tag = MKTAG('N', 'U', 'L', 'L'); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
300 while(i--) |
491 | 301 av_log(NULL, AV_LOG_DEBUG, "|"); |
302 av_log(NULL, AV_LOG_DEBUG, "parse:"); | |
303 av_log(NULL, AV_LOG_DEBUG, " %s: tag=%c%c%c%c offset=0x%x size=0x%x\n", | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
304 str, tag & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
305 (tag >> 8) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
306 (tag >> 16) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
307 (tag >> 24) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
308 (unsigned int)atom.offset, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
309 (unsigned int)atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
310 assert((unsigned int)atom.size < 0x7fffffff);// catching errors |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
311 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
312 #else |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
313 #define print_atom(a,b) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
314 #endif |
121 | 315 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
316 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
317 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
|
318 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
319 print_atom("leaf", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
320 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
321 if (atom.size>1) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
322 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
323 /* url_seek(pb, atom_offset+atom.size, SEEK_SET); */ |
0 | 324 return 0; |
325 } | |
326 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
327 static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 328 { |
121 | 329 int64_t total_size = 0; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
330 MOV_atom_t a; |
0 | 331 int i; |
332 int err = 0; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
333 |
0 | 334 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
335 print_atom("default", atom); |
0 | 336 debug_indent++; |
337 #endif | |
118 | 338 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
339 a.offset = atom.offset; |
0 | 340 |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
341 if (atom.size < 0) |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
342 atom.size = 0x7fffffffffffffffLL; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
343 while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
344 a.size = atom.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
345 a.type=0L; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
346 if(atom.size >= 8) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
347 a.size = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
348 a.type = get_le32(pb); |
0 | 349 } |
118 | 350 total_size += 8; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
351 a.offset += 8; |
491 | 352 //av_log(NULL, AV_LOG_DEBUG, "type: %08x %.4s sz: %Lx %Lx %Lx\n", type, (char*)&type, size, atom.size, total_size); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
353 if (a.size == 1) { /* 64 bit extended size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
354 a.size = get_be64(pb) - 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
355 a.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
356 total_size += 8; |
0 | 357 } |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
358 if (a.size == 0) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
359 a.size = atom.size - total_size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
360 if (a.size <= 8) |
118 | 361 break; |
362 } | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
363 for (i = 0; c->parse_table[i].type != 0L |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
364 && c->parse_table[i].type != a.type; i++) |
118 | 365 /* empty */; |
366 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
367 a.size -= 8; |
491 | 368 // av_log(NULL, AV_LOG_DEBUG, " i=%ld\n", i); |
121 | 369 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
|
370 // url_seek(pb, atom.offset+atom.size, SEEK_SET); |
0 | 371 #ifdef DEBUG |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
372 print_atom("unknown", a); |
0 | 373 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
374 url_fskip(pb, a.size); |
121 | 375 } else { |
376 #ifdef DEBUG | |
377 //char b[5] = { type & 0xff, (type >> 8) & 0xff, (type >> 16) & 0xff, (type >> 24) & 0xff, 0 }; | |
378 //print_atom(b, type, offset, size); | |
379 #endif | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
380 err = (c->parse_table[i].func)(c, pb, a); |
121 | 381 } |
0 | 382 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
383 a.offset += a.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
384 total_size += a.size; |
0 | 385 } |
386 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
387 if (!err && total_size < atom.size && atom.size < 0x7ffff) { |
491 | 388 //av_log(NULL, AV_LOG_DEBUG, "RESET %Ld %Ld err:%d\n", atom.size, total_size, err); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
389 url_fskip(pb, atom.size - total_size); |
118 | 390 } |
391 | |
0 | 392 #ifdef DEBUG |
393 debug_indent--; | |
394 #endif | |
395 return err; | |
396 } | |
397 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
398 static int mov_read_ctab(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 399 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
400 unsigned int len; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
401 MOV_ctab_t *t; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
402 //url_fskip(pb, atom.size); // for now |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
403 c->ctab = av_realloc(c->ctab, ++c->ctab_size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
404 t = c->ctab[c->ctab_size]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
405 t->seed = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
406 t->flags = get_be16(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
407 t->size = get_be16(pb) + 1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
408 len = 2 * t->size * 4; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
409 if (len > 0) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
410 t->clrs = av_malloc(len); // 16bit A R G B |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
411 if (t->clrs) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
412 get_buffer(pb, t->clrs, len); |
0 | 413 } |
118 | 414 |
0 | 415 return 0; |
416 } | |
417 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
418 static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 419 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
420 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
0 | 421 int len = 0; |
65 | 422 uint32_t type; |
423 uint32_t ctype; | |
121 | 424 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
425 print_atom("hdlr", atom); |
0 | 426 |
427 get_byte(pb); /* version */ | |
428 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
429 | |
430 /* component type */ | |
431 ctype = get_le32(pb); | |
432 type = get_le32(pb); /* component subtype */ | |
433 | |
434 #ifdef DEBUG | |
491 | 435 av_log(NULL, AV_LOG_DEBUG, "ctype= %c%c%c%c (0x%08lx)\n", *((char *)&ctype), ((char *)&ctype)[1], ((char *)&ctype)[2], ((char *)&ctype)[3], (long) ctype); |
436 av_log(NULL, AV_LOG_DEBUG, "stype= %c%c%c%c\n", *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | |
0 | 437 #endif |
438 #ifdef DEBUG | |
439 /* XXX: yeah this is ugly... */ | |
440 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
441 if(type == MKTAG('v', 'i', 'd', 'e')) | |
442 puts("hdlr: vide"); | |
443 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
444 puts("hdlr: soun"); | |
445 } else if(ctype == 0) { /* MP4 */ | |
446 if(type == MKTAG('v', 'i', 'd', 'e')) | |
447 puts("hdlr: vide"); | |
448 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
449 puts("hdlr: soun"); | |
450 else if(type == MKTAG('o', 'd', 's', 'm')) | |
451 puts("hdlr: odsm"); | |
452 else if(type == MKTAG('s', 'd', 's', 'm')) | |
453 puts("hdlr: sdsm"); | |
454 } else puts("hdlr: meta"); | |
455 #endif | |
456 | |
457 if(ctype == MKTAG('m', 'h', 'l', 'r')) { /* MOV */ | |
458 /* helps parsing the string hereafter... */ | |
459 c->mp4 = 0; | |
460 if(type == MKTAG('v', 'i', 'd', 'e')) | |
461 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
462 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
463 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
464 } else if(ctype == 0) { /* MP4 */ | |
465 /* helps parsing the string hereafter... */ | |
466 c->mp4 = 1; | |
467 if(type == MKTAG('v', 'i', 'd', 'e')) | |
468 st->codec.codec_type = CODEC_TYPE_VIDEO; | |
469 else if(type == MKTAG('s', 'o', 'u', 'n')) | |
470 st->codec.codec_type = CODEC_TYPE_AUDIO; | |
471 } | |
472 get_be32(pb); /* component manufacture */ | |
473 get_be32(pb); /* component flags */ | |
474 get_be32(pb); /* component flags mask */ | |
475 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
476 if(atom.size <= 24) |
0 | 477 return 0; /* nothing left to read */ |
478 /* XXX: MP4 uses a C string, not a pascal one */ | |
479 /* component name */ | |
480 | |
481 if(c->mp4) { | |
482 /* .mp4: C string */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
483 while(get_byte(pb) && (++len < (atom.size - 24))); |
0 | 484 } else { |
485 /* .mov: PASCAL string */ | |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
486 #ifdef DEBUG |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
487 char* buf; |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
488 #endif |
0 | 489 len = get_byte(pb); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
490 #ifdef DEBUG |
121 | 491 buf = (uint8_t*) av_malloc(len+1); |
492 if (buf) { | |
493 get_buffer(pb, buf, len); | |
494 buf[len] = '\0'; | |
491 | 495 av_log(NULL, AV_LOG_DEBUG, "**buf='%s'\n", buf); |
121 | 496 av_free(buf); |
497 } else | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
498 #endif |
121 | 499 url_fskip(pb, len); |
0 | 500 } |
118 | 501 |
489
aeb69a5f3756
The atom 'skip' should be handled by 'mov_read_leaf()', not by
michael
parents:
438
diff
changeset
|
502 url_fskip(pb, atom.size - (url_ftell(pb) - atom.offset)); |
0 | 503 return 0; |
504 } | |
505 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
506 static int mov_mp4_read_descr_len(ByteIOContext *pb) |
0 | 507 { |
118 | 508 int len = 0; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
509 int count = 4; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
510 while (count--) { |
118 | 511 int c = get_byte(pb); |
512 len = (len << 7) | (c & 0x7f); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
513 if (!(c & 0x80)) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
514 break; |
0 | 515 } |
516 return len; | |
517 } | |
518 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
519 static int mov_mp4_read_descr(ByteIOContext *pb, int *tag) |
0 | 520 { |
521 int len; | |
522 *tag = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
523 len = mov_mp4_read_descr_len(pb); |
0 | 524 #ifdef DEBUG |
491 | 525 av_log(NULL, AV_LOG_DEBUG, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); |
0 | 526 #endif |
527 return len; | |
528 } | |
529 | |
118 | 530 static inline unsigned int get_be24(ByteIOContext *s) |
531 { | |
532 unsigned int val; | |
533 val = get_byte(s) << 16; | |
534 val |= get_byte(s) << 8; | |
535 val |= get_byte(s); | |
536 return val; | |
537 } | |
538 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
539 static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
118 | 540 { |
541 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
542 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
543 int64_t start_pos = url_ftell(pb); |
118 | 544 int tag, len; |
121 | 545 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
546 print_atom("esds", atom); |
118 | 547 |
548 /* Well, broken but suffisant for some MP4 streams */ | |
549 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
550 len = mov_mp4_read_descr(pb, &tag); |
118 | 551 if (tag == MP4ESDescrTag) { |
552 get_be16(pb); /* ID */ | |
553 get_byte(pb); /* priority */ | |
554 } else | |
555 get_be16(pb); /* ID */ | |
556 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
557 len = mov_mp4_read_descr(pb, &tag); |
118 | 558 if (tag == MP4DecConfigDescrTag) { |
559 sc->esds.object_type_id = get_byte(pb); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
560 sc->esds.stream_type = get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
561 sc->esds.buffer_size_db = get_be24(pb); |
118 | 562 sc->esds.max_bitrate = get_be32(pb); |
563 sc->esds.avg_bitrate = get_be32(pb); | |
564 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
565 len = mov_mp4_read_descr(pb, &tag); |
491 | 566 //av_log(NULL, AV_LOG_DEBUG, "LEN %d TAG %d m:%d a:%d\n", len, tag, sc->esds.max_bitrate, sc->esds.avg_bitrate); |
118 | 567 if (tag == MP4DecSpecificDescrTag) { |
568 #ifdef DEBUG | |
491 | 569 av_log(NULL, AV_LOG_DEBUG, "Specific MPEG4 header len=%d\n", len); |
118 | 570 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
571 st->codec.extradata = (uint8_t*) av_mallocz(len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
572 if (st->codec.extradata) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
573 get_buffer(pb, st->codec.extradata, len); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
574 st->codec.extradata_size = len; |
118 | 575 } |
576 } | |
577 } | |
578 /* in any case, skip garbage */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
579 url_fskip(pb, atom.size - ((url_ftell(pb) - start_pos))); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
580 return 0; |
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 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
583 /* this atom contains actual media data */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
584 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
|
585 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
586 print_atom("mdat", atom); |
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 if(atom.size == 0) /* wrong one (MP4) */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
589 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
590 c->found_mdat=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
591 c->mdat_offset = atom.offset; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
592 c->mdat_size = atom.size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
593 if(c->found_moov) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
594 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
595 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
596 return 0; /* now go for moov */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
597 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
598 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
599 /* this atom should contain all header atoms */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
600 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
|
601 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
602 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
603 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
604 print_atom("moov", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
605 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
606 err = mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
607 /* 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
|
608 /* 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
|
609 c->found_moov=1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
610 if(c->found_mdat) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
611 return 1; /* found both, just go */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
612 return 0; /* now go for mdat */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
613 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
614 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
615 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
616 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
|
617 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
618 print_atom("mdhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
619 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
620 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
621 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
622 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
623 get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
624 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
625 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
626 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
627 |
491 | 628 c->streams[c->fc->nb_streams-1]->time_scale = get_be32(pb); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
629 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
630 #ifdef DEBUG |
491 | 631 av_log(NULL, AV_LOG_DEBUG, "track[%i].time_scale = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->time_scale); /* time scale */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
632 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
633 get_be32(pb); /* duration */ |
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 get_be16(pb); /* language */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
636 get_be16(pb); /* quality */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
637 |
118 | 638 return 0; |
639 } | |
640 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
641 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
|
642 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
643 print_atom("mvhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
644 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
645 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
646 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
647 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
648 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
649 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
650 c->time_scale = get_be32(pb); /* time scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
651 #ifdef DEBUG |
491 | 652 av_log(NULL, AV_LOG_DEBUG, "time scale = %i\n", c->time_scale); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
653 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
654 c->duration = get_be32(pb); /* duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
655 get_be32(pb); /* preferred scale */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
656 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
657 get_be16(pb); /* preferred volume */ |
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 url_fskip(pb, 10); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
660 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
661 url_fskip(pb, 36); /* display matrix */ |
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 get_be32(pb); /* preview time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
664 get_be32(pb); /* preview duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
665 get_be32(pb); /* poster time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
666 get_be32(pb); /* selection time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
667 get_be32(pb); /* selection duration */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
668 get_be32(pb); /* current time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
669 get_be32(pb); /* next track ID */ |
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 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
672 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
673 |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
674 static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
675 { |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
676 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
677 |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
678 // currently SVQ3 decoder expect full STSD header - so let's fake it |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
679 // this should be fixed and just SMI header should be passed |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
680 av_free(st->codec.extradata); |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
681 st->codec.extradata_size = 0x5a + atom.size; |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
682 st->codec.extradata = (uint8_t*) av_mallocz(st->codec.extradata_size); |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
683 |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
684 if (st->codec.extradata) { |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
685 strcpy(st->codec.extradata, "SVQ3"); // fake |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
686 get_buffer(pb, st->codec.extradata + 0x5a, atom.size); |
491 | 687 //av_log(NULL, AV_LOG_DEBUG, "Reading SMI %Ld %s\n", atom.size, (char*)st->codec.extradata + 0x5a); |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
688 } else |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
689 url_fskip(pb, atom.size); |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
690 |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
691 return 0; |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
692 } |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
693 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
694 static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 695 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
696 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
697 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
698 int entries, i; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
699 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
700 print_atom("stco", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
701 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
702 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
703 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
704 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
705 entries = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
706 sc->chunk_count = entries; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
707 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
|
708 if (!sc->chunk_offsets) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
709 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
710 if (atom.type == MKTAG('s', 't', 'c', 'o')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
711 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
712 sc->chunk_offsets[i] = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
713 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
714 } else if (atom.type == MKTAG('c', 'o', '6', '4')) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
715 for(i=0; i<entries; i++) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
716 sc->chunk_offsets[i] = get_be64(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
717 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
718 } else |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
719 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
720 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
721 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
722 for(i=0; i<entries; i++) { |
491 | 723 av_log(NULL, AV_LOG_DEBUG, "chunk offset=0x%Lx\n", sc->chunk_offsets[i]); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
724 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
725 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
726 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
727 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
728 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
729 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
730 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
|
731 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
732 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
131 | 733 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
734 int entries, frames_per_sample; |
65 | 735 uint32_t format; |
121 | 736 |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
737 /* for palette traversal */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
738 int color_depth; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
739 int color_start; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
740 int color_count; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
741 int color_end; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
742 int color_index; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
743 int color_dec; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
744 int color_greyscale; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
745 unsigned char *color_table; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
746 int j; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
747 unsigned char r, g, b; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
748 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
749 print_atom("stsd", atom); |
0 | 750 |
751 get_byte(pb); /* version */ | |
752 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
753 | |
754 entries = get_be32(pb); | |
755 | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
756 while(entries--) { //Parsing Sample description table |
121 | 757 enum CodecID id; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
758 int size = get_be32(pb); /* size */ |
0 | 759 format = get_le32(pb); /* data format */ |
118 | 760 |
0 | 761 get_be32(pb); /* reserved */ |
762 get_be16(pb); /* reserved */ | |
763 get_be16(pb); /* index */ | |
764 | |
765 /* for MPEG4: set codec type by looking for it */ | |
766 id = codec_get_id(mov_video_tags, format); | |
767 if (id >= 0) { | |
768 AVCodec *codec; | |
121 | 769 codec = avcodec_find_decoder(id); |
0 | 770 if (codec) |
121 | 771 st->codec.codec_type = codec->type; |
0 | 772 } |
773 #ifdef DEBUG | |
491 | 774 av_log(NULL, AV_LOG_DEBUG, "size=%d 4CC= %c%c%c%c codec_type=%d\n", |
118 | 775 size, |
0 | 776 (format >> 0) & 0xff, |
777 (format >> 8) & 0xff, | |
778 (format >> 16) & 0xff, | |
779 (format >> 24) & 0xff, | |
780 st->codec.codec_type); | |
781 #endif | |
118 | 782 st->codec.codec_tag = format; |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
783 if(st->codec.codec_type==CODEC_TYPE_VIDEO) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
784 MOV_atom_t a = { 0, 0, 0 }; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
785 st->codec.codec_id = id; |
0 | 786 get_be16(pb); /* version */ |
787 get_be16(pb); /* revision level */ | |
788 get_be32(pb); /* vendor */ | |
789 get_be32(pb); /* temporal quality */ | |
790 get_be32(pb); /* spacial quality */ | |
791 st->codec.width = get_be16(pb); /* width */ | |
792 st->codec.height = get_be16(pb); /* height */ | |
793 #if 1 | |
794 if (st->codec.codec_id == CODEC_ID_MPEG4) { | |
795 /* in some MPEG4 the width/height are not correct, so | |
796 we ignore this info */ | |
797 st->codec.width = 0; | |
798 st->codec.height = 0; | |
799 } | |
800 #endif | |
801 get_be32(pb); /* horiz resolution */ | |
802 get_be32(pb); /* vert resolution */ | |
803 get_be32(pb); /* data size, always 0 */ | |
118 | 804 frames_per_sample = get_be16(pb); /* frames per samples */ |
0 | 805 #ifdef DEBUG |
491 | 806 av_log(NULL, AV_LOG_DEBUG, "frames/samples = %d\n", frames_per_sample); |
0 | 807 #endif |
121 | 808 get_buffer(pb, (uint8_t *)st->codec.codec_name, 32); /* codec name */ |
0 | 809 |
118 | 810 st->codec.bits_per_sample = get_be16(pb); /* depth */ |
811 st->codec.color_table_id = get_be16(pb); /* colortable id */ | |
812 | |
147 | 813 /* These are set in mov_read_stts and might already be set! |
85
25062c9b1f86
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
65
diff
changeset
|
814 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
|
815 st->codec.frame_rate_base = 1; |
147 | 816 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
817 size -= (16+8*4+2+32+2*2); |
118 | 818 #if 0 |
819 while (size >= 8) { | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
820 MOV_atom_t a; |
65 | 821 int64_t start_pos; |
118 | 822 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
823 a.size = get_be32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
824 a.type = get_le32(pb); |
118 | 825 size -= 8; |
0 | 826 #ifdef DEBUG |
491 | 827 av_log(NULL, AV_LOG_DEBUG, "VIDEO: atom_type=%c%c%c%c atom.size=%Ld size_left=%d\n", |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
828 (a.type >> 0) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
829 (a.type >> 8) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
830 (a.type >> 16) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
831 (a.type >> 24) & 0xff, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
832 a.size, size); |
0 | 833 #endif |
834 start_pos = url_ftell(pb); | |
835 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
836 switch(a.type) { |
0 | 837 case MKTAG('e', 's', 'd', 's'): |
838 { | |
839 int tag, len; | |
840 /* Well, broken but suffisant for some MP4 streams */ | |
841 get_be32(pb); /* version + flags */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
842 len = mov_mp4_read_descr(pb, &tag); |
0 | 843 if (tag == 0x03) { |
844 /* MP4ESDescrTag */ | |
845 get_be16(pb); /* ID */ | |
846 get_byte(pb); /* priority */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
847 len = mov_mp4_read_descr(pb, &tag); |
0 | 848 if (tag != 0x04) |
849 goto fail; | |
850 /* MP4DecConfigDescrTag */ | |
851 get_byte(pb); /* objectTypeId */ | |
852 get_be32(pb); /* streamType + buffer size */ | |
118 | 853 get_be32(pb); /* max bit rate */ |
0 | 854 get_be32(pb); /* avg bit rate */ |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
855 len = mov_mp4_read_descr(pb, &tag); |
0 | 856 if (tag != 0x05) |
857 goto fail; | |
858 /* MP4DecSpecificDescrTag */ | |
859 #ifdef DEBUG | |
491 | 860 av_log(NULL, AV_LOG_DEBUG, "Specific MPEG4 header len=%d\n", len); |
0 | 861 #endif |
862 sc->header_data = av_mallocz(len); | |
863 if (sc->header_data) { | |
864 get_buffer(pb, sc->header_data, len); | |
118 | 865 sc->header_len = len; |
0 | 866 } |
867 } | |
868 /* in any case, skip garbage */ | |
869 } | |
870 break; | |
871 default: | |
872 break; | |
873 } | |
118 | 874 fail: |
491 | 875 av_log(NULL, AV_LOG_DEBUG, "ATOMENEWSIZE %Ld %d\n", atom.size, url_ftell(pb) - start_pos); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
876 if (atom.size > 8) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
877 url_fskip(pb, (atom.size - 8) - |
118 | 878 ((url_ftell(pb) - start_pos))); |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
879 size -= atom.size - 8; |
118 | 880 } |
881 } | |
0 | 882 if (size > 0) { |
883 /* unknown extension */ | |
884 url_fskip(pb, size); | |
885 } | |
118 | 886 #else |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
887 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
888 /* figure out the palette situation */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
889 color_depth = st->codec.bits_per_sample & 0x1F; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
890 color_greyscale = st->codec.bits_per_sample & 0x20; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
891 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
892 /* if the depth is 2, 4, or 8 bpp, file is palettized */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
893 if ((color_depth == 2) || (color_depth == 4) || |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
894 (color_depth == 8)) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
895 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
896 if (color_greyscale) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
897 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
898 /* compute the greyscale palette */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
899 color_count = 1 << color_depth; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
900 color_index = 255; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
901 color_dec = 256 / (color_count - 1); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
902 for (j = 0; j < color_count; j++) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
903 r = g = b = color_index; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
904 c->palette_control.palette[j] = |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
905 (r << 16) | (g << 8) | (b); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
906 color_index -= color_dec; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
907 if (color_index < 0) |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
908 color_index = 0; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
909 } |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
910 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
911 } else if (st->codec.color_table_id & 0x08) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
912 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
913 /* if flag bit 3 is set, use the default palette */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
914 color_count = 1 << color_depth; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
915 if (color_depth == 2) |
431 | 916 color_table = ff_qt_default_palette_4; |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
917 else if (color_depth == 4) |
431 | 918 color_table = ff_qt_default_palette_16; |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
919 else |
431 | 920 color_table = ff_qt_default_palette_256; |
302
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
921 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
922 for (j = 0; j < color_count; j++) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
923 r = color_table[j * 4 + 0]; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
924 g = color_table[j * 4 + 1]; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
925 b = color_table[j * 4 + 2]; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
926 c->palette_control.palette[j] = |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
927 (r << 16) | (g << 8) | (b); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
928 } |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
929 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
930 } else { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
931 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
932 /* load the palette from the file */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
933 color_start = get_be32(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
934 color_count = get_be16(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
935 color_end = get_be16(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
936 for (j = color_start; j <= color_end; j++) { |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
937 /* each R, G, or B component is 16 bits; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
938 * only use the top 8 bits; skip alpha bytes |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
939 * up front */ |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
940 get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
941 get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
942 r = get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
943 get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
944 g = get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
945 get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
946 b = get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
947 get_byte(pb); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
948 c->palette_control.palette[j] = |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
949 (r << 16) | (g << 8) | (b); |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
950 } |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
951 } |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
952 |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
953 st->codec.palctrl = &c->palette_control; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
954 st->codec.palctrl->palette_changed = 1; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
955 } else |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
956 st->codec.palctrl = NULL; |
6949df67922d
added palette support to the QT demuxer; registered SMC video decoder
melanson
parents:
301
diff
changeset
|
957 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
958 a.size = size; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
959 mov_read_default(c, pb, a); |
118 | 960 #endif |
961 } else { | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
962 st->codec.codec_id = codec_get_id(mov_audio_tags, format); |
258
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
963 if(st->codec.codec_id==CODEC_ID_AMR_NB || st->codec.codec_id==CODEC_ID_AMR_WB) //from TS26.244 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
964 { |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
965 #ifdef DEBUG |
491 | 966 av_log(NULL, AV_LOG_DEBUG, "AMR-NB or AMR-WB audio identified!!\n"); |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
967 #endif |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
968 get_be32(pb);get_be32(pb); //Reserved_8 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
969 get_be16(pb);//Reserved_2 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
970 get_be16(pb);//Reserved_2 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
971 get_be32(pb);//Reserved_4 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
972 get_be16(pb);//TimeScale |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
973 get_be16(pb);//Reserved_2 |
118 | 974 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
975 //AMRSpecificBox.(10 bytes) |
258
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
976 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
977 get_be32(pb); //size |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
978 get_be32(pb); //type=='damr' |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
979 get_be32(pb); //vendor |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
980 get_byte(pb); //decoder version |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
981 get_be16(pb); //mode_set |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
982 get_byte(pb); //mode_change_period |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
983 get_byte(pb); //frames_per_sample |
118 | 984 |
191 | 985 st->duration = AV_NOPTS_VALUE;//Not possible to get from this info, must count number of AMR frames |
258
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
986 if(st->codec.codec_id==CODEC_ID_AMR_NB) |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
987 { |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
988 st->codec.sample_rate=8000; |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
989 st->codec.channels=1; |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
990 } |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
991 else //AMR-WB |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
992 { |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
993 st->codec.sample_rate=16000; |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
994 st->codec.channels=1; |
59c2e84817a1
AMR-WB support by (Johannes Carlsson <joca at rixmail dot se>)
michaelni
parents:
191
diff
changeset
|
995 } |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
996 st->codec.bits_per_sample=16; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
997 st->codec.bit_rate=0; /*It is not possible to tell this before we have |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
998 an audio frame and even then every frame can be different*/ |
118 | 999 } |
147 | 1000 else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 's' )) |
1001 { | |
1002 //This is some stuff for the hint track, lets ignore it! | |
1003 //Do some mp4 auto detect. | |
1004 c->mp4=1; | |
1005 size-=(16); | |
1006 url_fskip(pb, size); /* The mp4s atom also contians a esds atom that we can skip*/ | |
1007 } | |
428
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1008 else if( st->codec.codec_tag == MKTAG( 'm', 'p', '4', 'a' )) |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1009 { |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1010 /* Handle mp4 audio tag */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1011 get_be32(pb); /* version */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1012 get_be32(pb); |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1013 st->codec.channels = get_be16(pb); /* channels */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1014 st->codec.bits_per_sample = get_be16(pb); /* bits per sample */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1015 get_be32(pb); |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1016 st->codec.sample_rate = get_be16(pb); /* sample rate, not always correct */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1017 get_be16(pb); |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1018 c->mp4=1; |
438
b3fdae08c556
libavformat/mov.c fails with gcc 2.95.3 patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
431
diff
changeset
|
1019 { |
428
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1020 MOV_atom_t a = { format, url_ftell(pb), size - (20 + 20 + 8) }; |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1021 mov_read_default(c, pb, a); |
438
b3fdae08c556
libavformat/mov.c fails with gcc 2.95.3 patch by ("Steven M. Schultz" <sms at 2BSD dot COM>)
michael
parents:
431
diff
changeset
|
1022 } |
428
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1023 /* Get correct sample rate from extradata */ |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1024 if(st->codec.extradata_size) { |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1025 const int samplerate_table[] = { |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1026 96000, 88200, 64000, 48000, 44100, 32000, |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1027 24000, 22050, 16000, 12000, 11025, 8000, |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1028 7350, 0, 0, 0 |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1029 }; |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1030 unsigned char *px = st->codec.extradata; |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1031 // 5 bits objectTypeIndex, 4 bits sampleRateIndex, 4 bits channels |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1032 int samplerate_index = ((px[0] & 7) << 1) + ((px[1] >> 7) & 1); |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1033 st->codec.sample_rate = samplerate_table[samplerate_index]; |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1034 } |
5ac07c7b4874
correctly identify AAC audio in mov/mp4/etc. files. patch by ("Thomas Raivio" <tjraivio at cc dot hut dot fi>)
michael
parents:
401
diff
changeset
|
1035 } |
147 | 1036 else if(size>=(16+20)) |
1037 {//16 bytes read, reading atleast 20 more | |
1038 #ifdef DEBUG | |
491 | 1039 av_log(NULL, AV_LOG_DEBUG, "audio size=0x%X\n",size); |
147 | 1040 #endif |
1041 uint16_t version = get_be16(pb); /* version */ | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1042 get_be16(pb); /* revision level */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1043 get_be32(pb); /* vendor */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1044 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1045 st->codec.channels = get_be16(pb); /* channel count */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1046 st->codec.bits_per_sample = get_be16(pb); /* sample size */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1047 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1048 /* handle specific s8 codec */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1049 get_be16(pb); /* compression id = 0*/ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1050 get_be16(pb); /* packet size = 0 */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1051 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1052 st->codec.sample_rate = ((get_be32(pb) >> 16)); |
491 | 1053 //av_log(NULL, AV_LOG_DEBUG, "CODECID %d %d %.4s\n", st->codec.codec_id, CODEC_ID_PCM_S16BE, (char*)&format); |
0 | 1054 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1055 switch (st->codec.codec_id) { |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1056 case CODEC_ID_PCM_S16BE: |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1057 if (st->codec.bits_per_sample == 8) |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1058 st->codec.codec_id = CODEC_ID_PCM_S8; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1059 /* fall */ |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1060 case CODEC_ID_PCM_U8: |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1061 st->codec.bit_rate = st->codec.sample_rate * 8; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1062 break; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1063 default: |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1064 ; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1065 } |
147 | 1066 |
1067 //Read QT version 1 fields. In version 0 theese dont exist | |
1068 #ifdef DEBUG | |
491 | 1069 av_log(NULL, AV_LOG_DEBUG, "version =%d mp4=%d\n",version,c->mp4); |
1070 av_log(NULL, AV_LOG_DEBUG, "size-(16+20+16)=%d\n",size-(16+20+16)); | |
147 | 1071 #endif |
1072 if((version==1) && size>=(16+20+16)) | |
1073 { | |
1074 get_be32(pb); /* samples per packet */ | |
1075 get_be32(pb); /* bytes per packet */ | |
1076 get_be32(pb); /* bytes per frame */ | |
1077 get_be32(pb); /* bytes per sample */ | |
1078 if(size>(16+20+16)) | |
1079 { | |
1080 //Optional, additional atom-based fields | |
1081 #ifdef DEBUG | |
491 | 1082 av_log(NULL, AV_LOG_DEBUG, "offest=0x%X, sizeleft=%d=0x%x,format=%c%c%c%c\n",(int)url_ftell(pb),size - (16 + 20 + 16 ),size - (16 + 20 + 16 ), |
147 | 1083 (format >> 0) & 0xff, |
1084 (format >> 8) & 0xff, | |
1085 (format >> 16) & 0xff, | |
1086 (format >> 24) & 0xff); | |
1087 #endif | |
1088 MOV_atom_t a = { format, url_ftell(pb), size - (16 + 20 + 16 + 8) }; | |
1089 mov_read_default(c, pb, a); | |
1090 } | |
1091 } | |
1092 else | |
1093 { | |
1094 //We should be down to 0 bytes here, but lets make sure. | |
1095 size-=(16+20); | |
1096 #ifdef DEBUG | |
1097 if(size>0) | |
491 | 1098 av_log(NULL, AV_LOG_DEBUG, "skipping 0x%X bytes\n",size-(16+20)); |
147 | 1099 #endif |
1100 url_fskip(pb, size); | |
1101 } | |
1102 } | |
1103 else | |
1104 { | |
1105 size-=16; | |
1106 //Unknown size, but lets do our best and skip the rest. | |
1107 #ifdef DEBUG | |
491 | 1108 av_log(NULL, AV_LOG_DEBUG, "Strange size, skipping 0x%X bytes\n",size); |
147 | 1109 #endif |
1110 url_fskip(pb, size); | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1111 } |
0 | 1112 } |
1113 } | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1114 |
0 | 1115 return 0; |
1116 } | |
1117 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1118 static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1119 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1120 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1121 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 1122 int entries, i; |
1123 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1124 print_atom("stsc", atom); |
118 | 1125 |
0 | 1126 get_byte(pb); /* version */ |
1127 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
1128 | |
1129 entries = get_be32(pb); | |
1130 #ifdef DEBUG | |
491 | 1131 av_log(NULL, AV_LOG_DEBUG, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); |
0 | 1132 #endif |
1133 sc->sample_to_chunk_sz = entries; | |
121 | 1134 sc->sample_to_chunk = (MOV_sample_to_chunk_tbl*) av_malloc(entries * sizeof(MOV_sample_to_chunk_tbl)); |
1135 if (!sc->sample_to_chunk) | |
1136 return -1; | |
0 | 1137 for(i=0; i<entries; i++) { |
1138 sc->sample_to_chunk[i].first = get_be32(pb); | |
1139 sc->sample_to_chunk[i].count = get_be32(pb); | |
1140 sc->sample_to_chunk[i].id = get_be32(pb); | |
1141 #ifdef DEBUG | |
491 | 1142 /* av_log(NULL, AV_LOG_DEBUG, "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); */ |
0 | 1143 #endif |
1144 } | |
1145 return 0; | |
1146 } | |
1147 | |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1148 static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1149 { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1150 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1151 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1152 int entries, i; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1153 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1154 print_atom("stss", atom); |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1155 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1156 get_byte(pb); /* version */ |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1157 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1158 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1159 entries = get_be32(pb); |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1160 sc->keyframe_count = entries; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1161 #ifdef DEBUG |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1162 av_log(NULL, AV_LOG_DEBUG, "keyframe_count = %ld\n", sc->keyframe_count); |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1163 #endif |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1164 sc->keyframes = (long*) av_malloc(entries * sizeof(long)); |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1165 if (!sc->keyframes) |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1166 return -1; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1167 for(i=0; i<entries; i++) { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1168 sc->keyframes[i] = get_be32(pb); |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1169 #ifdef DEBUG |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1170 /* av_log(NULL, AV_LOG_DEBUG, "keyframes[]=%ld\n", sc->keyframes[i]); */ |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1171 #endif |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1172 } |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1173 return 0; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1174 } |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1175 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1176 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1177 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1178 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1179 MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 1180 int entries, i; |
121 | 1181 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1182 print_atom("stsz", atom); |
118 | 1183 |
0 | 1184 get_byte(pb); /* version */ |
1185 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
118 | 1186 |
0 | 1187 sc->sample_size = get_be32(pb); |
1188 entries = get_be32(pb); | |
1189 sc->sample_count = entries; | |
1190 #ifdef DEBUG | |
491 | 1191 av_log(NULL, AV_LOG_DEBUG, "sample_size = %ld sample_count = %ld\n", sc->sample_size, sc->sample_count); |
0 | 1192 #endif |
1193 if(sc->sample_size) | |
1194 return 0; /* there isn't any table following */ | |
121 | 1195 sc->sample_sizes = (long*) av_malloc(entries * sizeof(long)); |
1196 if (!sc->sample_sizes) | |
1197 return -1; | |
0 | 1198 for(i=0; i<entries; i++) { |
1199 sc->sample_sizes[i] = get_be32(pb); | |
1200 #ifdef DEBUG | |
491 | 1201 /* av_log(NULL, AV_LOG_DEBUG, "sample_sizes[]=%ld\n", sc->sample_sizes[i]); */ |
0 | 1202 #endif |
1203 } | |
1204 return 0; | |
1205 } | |
1206 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1207 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1208 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1209 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
131 | 1210 //MOVStreamContext *sc = (MOVStreamContext *)st->priv_data; |
0 | 1211 int entries, i; |
395
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1212 int64_t duration=0; |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1213 int64_t total_sample_count=0; |
121 | 1214 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1215 print_atom("stts", atom); |
0 | 1216 |
1217 get_byte(pb); /* version */ | |
1218 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
1219 entries = get_be32(pb); | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1220 |
491 | 1221 c->streams[c->fc->nb_streams-1]->stts_count = entries; |
1222 c->streams[c->fc->nb_streams-1]->stts_data = (uint64_t*) av_malloc(entries * sizeof(uint64_t)); | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1223 |
0 | 1224 #ifdef DEBUG |
491 | 1225 av_log(NULL, AV_LOG_DEBUG, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); |
0 | 1226 #endif |
1227 for(i=0; i<entries; i++) { | |
491 | 1228 int32_t sample_duration; |
1229 int32_t sample_count; | |
0 | 1230 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1231 sample_count=get_be32(pb); |
0 | 1232 sample_duration = get_be32(pb); |
491 | 1233 c->streams[c->fc->nb_streams - 1]->stts_data[i] = (uint64_t)sample_count<<32 | (uint64_t)sample_duration; |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1234 #ifdef DEBUG |
491 | 1235 av_log(NULL, AV_LOG_DEBUG, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1236 #endif |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1237 duration+=sample_duration*sample_count; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1238 total_sample_count+=sample_count; |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1239 |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1240 #if 0 //We calculate an average instead, needed by .mp4-files created with nec e606 3g phone |
0 | 1241 |
1242 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
|
1243 st->codec.frame_rate_base = sample_duration ? sample_duration : 1; |
491 | 1244 st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale; |
0 | 1245 #ifdef DEBUG |
491 | 1246 av_log(NULL, AV_LOG_DEBUG, "VIDEO FRAME RATE= %i (sd= %i)\n", st->codec.frame_rate, sample_duration); |
0 | 1247 #endif |
1248 } | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1249 #endif |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1250 } |
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1251 |
147 | 1252 /*The stsd atom which contain codec type sometimes comes after the stts so we cannot check for codec_type*/ |
1253 if(duration>0) | |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1254 { |
395
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1255 av_reduce( |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1256 &st->codec.frame_rate, |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1257 &st->codec.frame_rate_base, |
491 | 1258 c->streams[c->fc->nb_streams-1]->time_scale * total_sample_count, |
395
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1259 duration, |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1260 INT_MAX |
c1ed10f3b052
cleanup frame_rate code, this may also fix some large file bugs
michael
parents:
383
diff
changeset
|
1261 ); |
147 | 1262 |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1263 #ifdef DEBUG |
491 | 1264 av_log(NULL, AV_LOG_DEBUG, "FRAME RATE average (video or audio)= %f (tot sample count= %i ,tot dur= %i timescale=%d)\n", (float)st->codec.frame_rate/st->codec.frame_rate_base,total_sample_count,duration,c->streams[c->fc->nb_streams-1]->time_scale); |
134
5cda954c6e9a
AMR-NB audio support patch by (<joca at rixmail dot se>)
michaelni
parents:
133
diff
changeset
|
1265 #endif |
0 | 1266 } |
147 | 1267 else |
1268 { | |
1269 st->codec.frame_rate_base = 1; | |
491 | 1270 st->codec.frame_rate = c->streams[c->fc->nb_streams-1]->time_scale; |
147 | 1271 } |
0 | 1272 return 0; |
1273 } | |
1274 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1275 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
|
1276 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1277 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1278 MOVStreamContext *sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1279 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1280 print_atom("trak", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1281 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1282 st = av_new_stream(c->fc, c->fc->nb_streams); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1283 if (!st) return -2; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1284 sc = (MOVStreamContext*) av_mallocz(sizeof(MOVStreamContext)); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1285 if (!sc) { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1286 av_free(st); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1287 return -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1288 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1289 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1290 sc->sample_to_chunk_index = -1; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1291 st->priv_data = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1292 st->codec.codec_type = CODEC_TYPE_MOV_OTHER; |
191 | 1293 st->start_time = 0; /* XXX: check */ |
1294 st->duration = (c->duration * (int64_t)AV_TIME_BASE) / c->time_scale; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1295 c->streams[c->fc->nb_streams-1] = sc; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1296 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1297 return mov_read_default(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1298 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1299 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1300 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
|
1301 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1302 AVStream *st; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1303 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1304 print_atom("tkhd", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1305 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1306 st = c->fc->streams[c->fc->nb_streams-1]; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1307 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1308 get_byte(pb); /* version */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1309 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1310 get_byte(pb); get_byte(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1311 get_byte(pb); /* flags */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1312 /* |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1313 MOV_TRACK_ENABLED 0x0001 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1314 MOV_TRACK_IN_MOVIE 0x0002 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1315 MOV_TRACK_IN_PREVIEW 0x0004 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1316 MOV_TRACK_IN_POSTER 0x0008 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1317 */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1318 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1319 get_be32(pb); /* creation time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1320 get_be32(pb); /* modification time */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1321 st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1322 get_be32(pb); /* reserved */ |
191 | 1323 st->start_time = 0; /* check */ |
1324 st->duration = (get_be32(pb) * (int64_t)AV_TIME_BASE) / c->time_scale; /* duration */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1325 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1326 get_be32(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1327 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1328 get_be16(pb); /* layer */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1329 get_be16(pb); /* alternate group */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1330 get_be16(pb); /* volume */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1331 get_be16(pb); /* reserved */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1332 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1333 url_fskip(pb, 36); /* display matrix */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1334 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1335 /* those are fixed-point */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1336 st->codec.width = get_be32(pb) >> 16; /* track width */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1337 st->codec.height = get_be32(pb) >> 16; /* track height */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1338 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1339 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1340 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1341 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1342 /* 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
|
1343 /* 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
|
1344 /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1345 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
|
1346 { |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1347 int err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1348 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1349 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1350 print_atom("wide", atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1351 debug_indent++; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1352 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1353 if (atom.size < 8) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1354 return 0; /* continue */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1355 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
|
1356 url_fskip(pb, atom.size - 4); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1357 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1358 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1359 atom.type = get_le32(pb); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1360 atom.offset += 8; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1361 atom.size -= 8; |
131 | 1362 if (atom.type != MKTAG('m', 'd', 'a', 't')) { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1363 url_fskip(pb, atom.size); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1364 return 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1365 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1366 err = mov_read_mdat(c, pb, atom); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1367 #ifdef DEBUG |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1368 debug_indent--; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1369 #endif |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1370 return err; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1371 } |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1372 |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1373 |
0 | 1374 #ifdef CONFIG_ZLIB |
65 | 1375 static int null_read_packet(void *opaque, uint8_t *buf, int buf_size) |
0 | 1376 { |
1377 return -1; | |
1378 } | |
1379 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1380 static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) |
0 | 1381 { |
1382 ByteIOContext ctx; | |
121 | 1383 uint8_t *cmov_data; |
1384 uint8_t *moov_data; /* uncompressed data */ | |
0 | 1385 long cmov_len, moov_len; |
1386 int ret; | |
121 | 1387 |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1388 print_atom("cmov", atom); |
0 | 1389 |
1390 get_be32(pb); /* dcom atom */ | |
1391 if (get_le32(pb) != MKTAG( 'd', 'c', 'o', 'm' )) | |
1392 return -1; | |
1393 if (get_le32(pb) != MKTAG( 'z', 'l', 'i', 'b' )) { | |
491 | 1394 av_log(NULL, AV_LOG_DEBUG, "unknown compression for cmov atom !"); |
0 | 1395 return -1; |
1396 } | |
1397 get_be32(pb); /* cmvd atom */ | |
1398 if (get_le32(pb) != MKTAG( 'c', 'm', 'v', 'd' )) | |
1399 return -1; | |
1400 moov_len = get_be32(pb); /* uncompressed size */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1401 cmov_len = atom.size - 6 * 4; |
118 | 1402 |
121 | 1403 cmov_data = (uint8_t *) av_malloc(cmov_len); |
0 | 1404 if (!cmov_data) |
1405 return -1; | |
121 | 1406 moov_data = (uint8_t *) av_malloc(moov_len); |
0 | 1407 if (!moov_data) { |
1408 av_free(cmov_data); | |
1409 return -1; | |
1410 } | |
1411 get_buffer(pb, cmov_data, cmov_len); | |
121 | 1412 if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) |
0 | 1413 return -1; |
1414 if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, null_read_packet, NULL, NULL) != 0) | |
1415 return -1; | |
1416 ctx.buf_end = ctx.buffer + moov_len; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1417 atom.type = MKTAG( 'm', 'o', 'o', 'v' ); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1418 atom.offset = 0; |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1419 atom.size = moov_len; |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1420 #ifdef DEBUG |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1421 { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); } |
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1422 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1423 ret = mov_read_default(c, &ctx, atom); |
0 | 1424 av_free(moov_data); |
1425 av_free(cmov_data); | |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1426 |
0 | 1427 return ret; |
1428 } | |
1429 #endif | |
1430 | |
491 | 1431 /* edit list atom */ |
1432 static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) | |
1433 { | |
500
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1434 int i, edit_count; |
491 | 1435 print_atom("elst", atom); |
1436 | |
1437 get_byte(pb); /* version */ | |
1438 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ | |
500
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1439 edit_count= c->streams[c->fc->nb_streams-1]->edit_count = get_be32(pb); /* entries */ |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1440 |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1441 for(i=0; i<edit_count; i++){ |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1442 get_be32(pb); /* Track duration */ |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1443 get_be32(pb); /* Media time */ |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1444 get_be32(pb); /* Media rate */ |
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1445 } |
491 | 1446 #ifdef DEBUG |
1447 av_log(NULL, AV_LOG_DEBUG, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->edit_count); | |
1448 #endif | |
1449 return 0; | |
1450 } | |
1451 | |
0 | 1452 static const MOVParseTableEntry mov_default_parse_table[] = { |
1453 /* mp4 atoms */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1454 { MKTAG( 'c', 'o', '6', '4' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1455 { MKTAG( 'c', 'p', 'r', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1456 { MKTAG( 'c', 'r', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1457 { 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
|
1458 { MKTAG( 'd', 'i', 'n', 'f' ), mov_read_default }, /* data information */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1459 { MKTAG( 'd', 'p', 'n', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1460 { MKTAG( 'd', 'r', 'e', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1461 { MKTAG( 'e', 'd', 't', 's' ), mov_read_default }, |
500
4070a7d58d2c
mov_read_elst fix, based upon a patch by (Sebastien Bechet <s.bechet at av7 dot net>)
michael
parents:
499
diff
changeset
|
1462 { MKTAG( 'e', 'l', 's', 't' ), mov_read_elst }, |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1463 { MKTAG( 'f', 'r', 'e', 'e' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1464 { MKTAG( 'h', 'd', 'l', 'r' ), mov_read_hdlr }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1465 { MKTAG( 'h', 'i', 'n', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1466 { MKTAG( 'h', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1467 { MKTAG( 'i', 'o', 'd', 's' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1468 { MKTAG( 'm', 'd', 'a', 't' ), mov_read_mdat }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1469 { MKTAG( 'm', 'd', 'h', 'd' ), mov_read_mdhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1470 { MKTAG( 'm', 'd', 'i', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1471 { MKTAG( 'm', 'i', 'n', 'f' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1472 { MKTAG( 'm', 'o', 'o', 'v' ), mov_read_moov }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1473 { MKTAG( 'm', 'p', '4', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1474 { MKTAG( 'm', 'p', '4', 's' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1475 { MKTAG( 'm', 'p', '4', 'v' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1476 { MKTAG( 'm', 'p', 'o', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1477 { MKTAG( 'm', 'v', 'h', 'd' ), mov_read_mvhd }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1478 { MKTAG( 'n', 'm', 'h', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1479 { MKTAG( 'o', 'd', 'h', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1480 { MKTAG( 's', 'd', 'h', 'd' ), mov_read_default }, |
489
aeb69a5f3756
The atom 'skip' should be handled by 'mov_read_leaf()', not by
michael
parents:
438
diff
changeset
|
1481 { MKTAG( 's', 'k', 'i', 'p' ), mov_read_leaf }, |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1482 { MKTAG( 's', 'm', 'h', 'd' ), mov_read_leaf }, /* sound media info header */ |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1483 { MKTAG( 'S', 'M', 'I', ' ' ), mov_read_smi }, /* Sorrenson extension ??? */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1484 { MKTAG( 's', 't', 'b', 'l' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1485 { MKTAG( 's', 't', 'c', 'o' ), mov_read_stco }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1486 { MKTAG( 's', 't', 'd', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1487 { MKTAG( 's', 't', 's', 'c' ), mov_read_stsc }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1488 { MKTAG( 's', 't', 's', 'd' ), mov_read_stsd }, /* sample description */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1489 { MKTAG( 's', 't', 's', 'h' ), mov_read_default }, |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1490 { MKTAG( 's', 't', 's', 's' ), mov_read_stss }, /* sync sample */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1491 { MKTAG( 's', 't', 's', 'z' ), mov_read_stsz }, /* sample size */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1492 { MKTAG( 's', 't', 't', 's' ), mov_read_stts }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1493 { MKTAG( 't', 'k', 'h', 'd' ), mov_read_tkhd }, /* track header */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1494 { MKTAG( 't', 'r', 'a', 'k' ), mov_read_trak }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1495 { MKTAG( 't', 'r', 'e', 'f' ), mov_read_default }, /* not really */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1496 { MKTAG( 'u', 'd', 't', 'a' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1497 { MKTAG( 'u', 'r', 'l', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1498 { MKTAG( 'u', 'r', 'n', ' ' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1499 { MKTAG( 'u', 'u', 'i', 'd' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1500 { 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
|
1501 { MKTAG( 'w', 'a', 'v', 'e' ), mov_read_default }, |
0 | 1502 /* extra mp4 */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1503 { MKTAG( 'M', 'D', 'E', 'S' ), mov_read_leaf }, |
0 | 1504 /* QT atoms */ |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1505 { MKTAG( 'c', 'h', 'a', 'p' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1506 { MKTAG( 'c', 'l', 'i', 'p' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1507 { MKTAG( 'c', 'r', 'g', 'n' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1508 { MKTAG( 'c', 't', 'a', 'b' ), mov_read_ctab }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1509 { MKTAG( 'e', 's', 'd', 's' ), mov_read_esds }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1510 { MKTAG( 'k', 'm', 'a', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1511 { MKTAG( 'm', 'a', 't', 't' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1512 { MKTAG( 'r', 'd', 'r', 'f' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1513 { MKTAG( 'r', 'm', 'd', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1514 { MKTAG( 'r', 'm', 'd', 'r' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1515 { MKTAG( 'r', 'm', 'r', 'a' ), mov_read_default }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1516 { MKTAG( 's', 'c', 'p', 't' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1517 { MKTAG( 's', 's', 'r', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1518 { MKTAG( 's', 'y', 'n', 'c' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1519 { MKTAG( 't', 'c', 'm', 'd' ), mov_read_leaf }, |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1520 { MKTAG( 'w', 'i', 'd', 'e' ), mov_read_wide }, /* place holder */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1521 //{ MKTAG( 'r', 'm', 'q', 'u' ), mov_read_leaf }, |
0 | 1522 #ifdef CONFIG_ZLIB |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1523 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_cmov }, |
0 | 1524 #else |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1525 { MKTAG( 'c', 'm', 'o', 'v' ), mov_read_leaf }, |
0 | 1526 #endif |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1527 { 0L, mov_read_leaf } |
0 | 1528 }; |
1529 | |
1530 static void mov_free_stream_context(MOVStreamContext *sc) | |
1531 { | |
1532 if(sc) { | |
1533 av_free(sc->chunk_offsets); | |
1534 av_free(sc->sample_to_chunk); | |
118 | 1535 av_free(sc->sample_sizes); |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1536 av_free(sc->keyframes); |
0 | 1537 av_free(sc->header_data); |
491 | 1538 av_free(sc->stts_data); |
0 | 1539 av_free(sc); |
1540 } | |
1541 } | |
1542 | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1543 static inline uint32_t mov_to_tag(uint8_t *buf) |
0 | 1544 { |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1545 return MKTAG(buf[0], buf[1], buf[2], buf[3]); |
0 | 1546 } |
1547 | |
118 | 1548 static inline uint32_t to_be32(uint8_t *buf) |
0 | 1549 { |
1550 return (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3]; | |
1551 } | |
1552 | |
121 | 1553 /* XXX: is it sufficient ? */ |
0 | 1554 static int mov_probe(AVProbeData *p) |
1555 { | |
1556 unsigned int offset; | |
1557 uint32_t tag; | |
1558 | |
1559 /* check file header */ | |
1560 if (p->buf_size <= 12) | |
1561 return 0; | |
1562 offset = 0; | |
1563 for(;;) { | |
1564 /* ignore invalid offset */ | |
1565 if ((offset + 8) > (unsigned int)p->buf_size) | |
1566 return 0; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1567 tag = mov_to_tag(p->buf + offset + 4); |
0 | 1568 switch(tag) { |
1569 case MKTAG( 'm', 'o', 'o', 'v' ): | |
1570 case MKTAG( 'w', 'i', 'd', 'e' ): | |
1571 case MKTAG( 'f', 'r', 'e', 'e' ): | |
24 | 1572 case MKTAG( 'm', 'd', 'a', 't' ): |
1573 case MKTAG( 'p', 'n', 'o', 't' ): /* detect movs with preview pics like ew.mov and april.mov */ | |
146 | 1574 case MKTAG( 'u', 'd', 't', 'a' ): /* Packet Video PVAuthor adds this and a lot of more junk */ |
0 | 1575 return AVPROBE_SCORE_MAX; |
1576 case MKTAG( 'f', 't', 'y', 'p' ): | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1577 case MKTAG( 's', 'k', 'i', 'p' ): |
147 | 1578 offset = to_be32(p->buf+offset) + offset; |
0 | 1579 break; |
1580 default: | |
1581 /* unrecognized tag */ | |
1582 return 0; | |
1583 } | |
1584 } | |
1585 return 0; | |
1586 } | |
1587 | |
1588 static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
1589 { | |
121 | 1590 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1591 ByteIOContext *pb = &s->pb; |
1592 int i, j, nb, err; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1593 MOV_atom_t atom = { 0, 0, 0 }; |
0 | 1594 |
1595 mov->fc = s; | |
121 | 1596 mov->parse_table = mov_default_parse_table; |
0 | 1597 #if 0 |
1598 /* XXX: I think we should auto detect */ | |
1599 if(s->iformat->name[1] == 'p') | |
1600 mov->mp4 = 1; | |
1601 #endif | |
1602 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
|
1603 atom.size = url_filesize(url_fileno(pb)); |
0 | 1604 else |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1605 atom.size = 0x7FFFFFFFFFFFFFFFLL; |
0 | 1606 |
1607 #ifdef DEBUG | |
491 | 1608 av_log(NULL, AV_LOG_DEBUG, "filesz=%Ld\n", atom.size); |
0 | 1609 #endif |
1610 | |
1611 /* check MOV header */ | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1612 err = mov_read_default(mov, pb, atom); |
133 | 1613 if (err<0 || (!mov->found_moov && !mov->found_mdat)) { |
370
845f9de2c883
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
358
diff
changeset
|
1614 av_log(s, AV_LOG_ERROR, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%lld\n", |
133 | 1615 err, mov->found_moov, mov->found_mdat, url_ftell(pb)); |
1616 return -1; | |
0 | 1617 } |
1618 #ifdef DEBUG | |
491 | 1619 av_log(NULL, AV_LOG_DEBUG, "on_parse_exit_offset=%d\n", (int) url_ftell(pb)); |
0 | 1620 #endif |
1621 /* some cleanup : make sure we are on the mdat atom */ | |
1622 if(!url_is_streamed(pb) && (url_ftell(pb) != mov->mdat_offset)) | |
1623 url_fseek(pb, mov->mdat_offset, SEEK_SET); | |
1624 | |
1625 mov->next_chunk_offset = mov->mdat_offset; /* initialise reading */ | |
1626 | |
1627 #ifdef DEBUG | |
491 | 1628 av_log(NULL, AV_LOG_DEBUG, "mdat_reset_offset=%d\n", (int) url_ftell(pb)); |
0 | 1629 #endif |
1630 | |
1631 #ifdef DEBUG | |
491 | 1632 av_log(NULL, AV_LOG_DEBUG, "streams= %d\n", s->nb_streams); |
0 | 1633 #endif |
1634 mov->total_streams = nb = s->nb_streams; | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
1635 |
0 | 1636 #if 1 |
1637 for(i=0; i<s->nb_streams;) { | |
1638 if(s->streams[i]->codec.codec_type == CODEC_TYPE_MOV_OTHER) {/* not audio, not video, delete */ | |
1639 av_free(s->streams[i]); | |
1640 for(j=i+1; j<s->nb_streams; j++) | |
1641 s->streams[j-1] = s->streams[j]; | |
1642 s->nb_streams--; | |
1643 } else | |
1644 i++; | |
1645 } | |
1646 for(i=0; i<s->nb_streams;i++) { | |
1647 MOVStreamContext *sc; | |
1648 sc = (MOVStreamContext *)s->streams[i]->priv_data; | |
1649 sc->ffindex = i; | |
1650 sc->is_ff_stream = 1; | |
1651 } | |
1652 #endif | |
1653 #ifdef DEBUG | |
491 | 1654 av_log(NULL, AV_LOG_DEBUG, "real streams= %d\n", s->nb_streams); |
0 | 1655 #endif |
1656 return 0; | |
1657 } | |
1658 | |
1659 /* Yes, this is ugly... I didn't write the specs of QT :p */ | |
1660 /* XXX:remove useless commented code sometime */ | |
1661 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1662 { | |
121 | 1663 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 1664 MOVStreamContext *sc; |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1665 int64_t offset = 0x0FFFFFFFFFFFFFFFLL; |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1666 int i, a, b, m; |
118 | 1667 int size; |
0 | 1668 size = 0x0FFFFFFF; |
118 | 1669 |
0 | 1670 #ifdef MOV_SPLIT_CHUNKS |
1671 if (mov->partial) { | |
118 | 1672 |
0 | 1673 int idx; |
1674 | |
118 | 1675 sc = mov->partial; |
1676 idx = sc->sample_to_chunk_index; | |
0 | 1677 |
118 | 1678 if (idx < 0) return 0; |
1679 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1680 |
118 | 1681 sc->current_sample++; |
1682 sc->left_in_chunk--; | |
1683 | |
1684 if (sc->left_in_chunk <= 0) | |
0 | 1685 mov->partial = 0; |
1686 offset = mov->next_chunk_offset; | |
1687 /* extract the sample */ | |
1688 | |
1689 goto readchunk; | |
1690 } | |
1691 #endif | |
1692 | |
1693 again: | |
118 | 1694 sc = 0; |
0 | 1695 for(i=0; i<mov->total_streams; i++) { |
118 | 1696 MOVStreamContext *msc = mov->streams[i]; |
491 | 1697 //av_log(NULL, AV_LOG_DEBUG, "MOCHUNK %ld %d %p pos:%Ld\n", mov->streams[i]->next_chunk, mov->total_streams, mov->streams[i], url_ftell(&s->pb)); |
118 | 1698 if ((msc->next_chunk < msc->chunk_count) && msc->next_chunk >= 0 |
1699 && (msc->chunk_offsets[msc->next_chunk] < offset)) { | |
1700 sc = msc; | |
1701 offset = msc->chunk_offsets[msc->next_chunk]; | |
491 | 1702 //av_log(NULL, AV_LOG_DEBUG, "SELETED %Ld i:%d\n", offset, i); |
0 | 1703 } |
1704 } | |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1705 if (!sc || offset==0x0FFFFFFFFFFFFFFFLL) |
118 | 1706 return -1; |
1707 | |
1708 sc->next_chunk++; | |
1709 | |
0 | 1710 if(mov->next_chunk_offset < offset) { /* some meta data */ |
1711 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); | |
1712 mov->next_chunk_offset = offset; | |
1713 } | |
1714 | |
491 | 1715 //av_log(NULL, AV_LOG_DEBUG, "chunk: [%i] %lli -> %lli\n", st_id, mov->next_chunk_offset, offset); |
118 | 1716 if(!sc->is_ff_stream) { |
0 | 1717 url_fskip(&s->pb, (offset - mov->next_chunk_offset)); |
1718 mov->next_chunk_offset = offset; | |
132
9ca36221ae23
* passing ImageDescriptions for SVQ3 (Vertical300K.sorenson works)
kabi
parents:
131
diff
changeset
|
1719 offset = 0x0FFFFFFFFFFFFFFFLL; |
0 | 1720 goto again; |
1721 } | |
1722 | |
1723 /* now get the chunk size... */ | |
1724 | |
1725 for(i=0; i<mov->total_streams; i++) { | |
118 | 1726 MOVStreamContext *msc = mov->streams[i]; |
1727 if ((msc->next_chunk < msc->chunk_count) | |
1728 && ((msc->chunk_offsets[msc->next_chunk] - offset) < size)) | |
1729 size = msc->chunk_offsets[msc->next_chunk] - offset; | |
0 | 1730 } |
146 | 1731 |
1732 #ifdef MOV_MINOLTA_FIX | |
1733 //Make sure that size is according to sample_size (Needed by .mov files | |
1734 //created on a Minolta Dimage Xi where audio chunks contains waste data in the end) | |
1735 //Maybe we should really not only check sc->sample_size, but also sc->sample_sizes | |
1736 //but I have no such movies | |
1737 if (sc->sample_size > 0) { | |
1738 int foundsize=0; | |
1739 for(i=0; i<(sc->sample_to_chunk_sz); i++) { | |
1740 if( (sc->sample_to_chunk[i].first)<=(sc->next_chunk) && (sc->sample_size>0) ) | |
1741 { | |
401
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1742 // I can't figure out why for PCM audio sample_size is always 1 |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1743 // (it should actually be channels*bits_per_second/8) but it is. |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1744 AVCodecContext* cod = &s->streams[sc->ffindex]->codec; |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1745 if (sc->sample_size == 1 && (cod->codec_id == CODEC_ID_PCM_S16BE || cod->codec_id == CODEC_ID_PCM_S16LE)) |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1746 foundsize=(sc->sample_to_chunk[i].count*cod->channels*cod->bits_per_sample)/8; |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1747 else |
42cc78ece67f
* .mov files with uncompressed audio can't be correctly processed
romansh
parents:
395
diff
changeset
|
1748 foundsize=sc->sample_to_chunk[i].count*sc->sample_size; |
146 | 1749 } |
1750 #ifdef DEBUG | |
491 | 1751 /*av_log(NULL, AV_LOG_DEBUG, "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);*/ |
146 | 1752 #endif |
1753 } | |
1754 if( (foundsize>0) && (foundsize<size) ) | |
1755 { | |
1756 #ifdef DEBUG | |
491 | 1757 /*av_log(NULL, AV_LOG_DEBUG, "this size should actually be %d\n",foundsize);*/ |
146 | 1758 #endif |
1759 size=foundsize; | |
1760 } | |
1761 } | |
1762 #endif //MOV_MINOLTA_FIX | |
1763 | |
0 | 1764 #ifdef MOV_SPLIT_CHUNKS |
1765 /* split chunks into samples */ | |
118 | 1766 if (sc->sample_size == 0) { |
1767 int idx = sc->sample_to_chunk_index; | |
1768 if ((idx + 1 < sc->sample_to_chunk_sz) | |
1769 && (sc->next_chunk >= sc->sample_to_chunk[idx + 1].first)) | |
1770 idx++; | |
1771 sc->sample_to_chunk_index = idx; | |
1772 if (idx >= 0 && sc->sample_to_chunk[idx].count != 1) { | |
1773 mov->partial = sc; | |
0 | 1774 /* we'll have to get those samples before next chunk */ |
118 | 1775 sc->left_in_chunk = sc->sample_to_chunk[idx].count - 1; |
1776 size = sc->sample_sizes[sc->current_sample]; | |
0 | 1777 } |
1778 | |
118 | 1779 sc->current_sample++; |
0 | 1780 } |
1781 #endif | |
1782 | |
1783 readchunk: | |
491 | 1784 //av_log(NULL, AV_LOG_DEBUG, "chunk: [%i] %lli -> %lli (%i)\n", st_id, offset, offset + size, size); |
0 | 1785 if(size == 0x0FFFFFFF) |
1786 size = mov->mdat_size + mov->mdat_offset - offset; | |
1787 if(size < 0) | |
1788 return -1; | |
1789 if(size == 0) | |
1790 return -1; | |
1791 url_fseek(&s->pb, offset, SEEK_SET); | |
118 | 1792 |
491 | 1793 //av_log(NULL, AV_LOG_DEBUG, "READCHUNK hlen: %d %d off: %Ld pos:%Ld\n", size, sc->header_len, offset, url_ftell(&s->pb)); |
0 | 1794 if (sc->header_len > 0) { |
1795 av_new_packet(pkt, size + sc->header_len); | |
1796 memcpy(pkt->data, sc->header_data, sc->header_len); | |
1797 get_buffer(&s->pb, pkt->data + sc->header_len, size); | |
1798 /* free header */ | |
1799 av_freep(&sc->header_data); | |
1800 sc->header_len = 0; | |
1801 } else { | |
1802 av_new_packet(pkt, size); | |
1803 get_buffer(&s->pb, pkt->data, pkt->size); | |
1804 } | |
1805 pkt->stream_index = sc->ffindex; | |
383
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1806 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1807 // If the keyframes table exists, mark any samples that are in the table as key frames. |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1808 // If no table exists, treat very sample as a key frame. |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1809 if (sc->keyframes) { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1810 a = 0; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1811 b = sc->keyframe_count - 1; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1812 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1813 while (a < b) { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1814 m = (a + b + 1) >> 1; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1815 if (sc->keyframes[m] > sc->current_sample) { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1816 b = m - 1; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1817 } else { |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1818 a = m; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1819 } |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1820 } |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1821 |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1822 if (sc->keyframes[a] == sc->current_sample) |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1823 pkt->flags |= PKT_FLAG_KEY; |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1824 } |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1825 else |
1674ed5ca2f0
Parse stss info in MOV files to get key frames patch by ("Brian Becker" <Brian dot Becker at palmone dot com>)
michael
parents:
370
diff
changeset
|
1826 pkt->flags |= PKT_FLAG_KEY; |
0 | 1827 |
1828 #ifdef DEBUG | |
1829 /* | |
491 | 1830 av_log(NULL, AV_LOG_DEBUG, "Packet (%d, %d, %ld) ", pkt->stream_index, st_id, pkt->size); |
0 | 1831 for(i=0; i<8; i++) |
491 | 1832 av_log(NULL, AV_LOG_DEBUG, "%02x ", pkt->data[i]); |
0 | 1833 for(i=0; i<8; i++) |
491 | 1834 av_log(NULL, AV_LOG_DEBUG, "%c ", (pkt->data[i]) & 0x7F); |
0 | 1835 puts(""); |
1836 */ | |
1837 #endif | |
1838 | |
1839 mov->next_chunk_offset = offset + size; | |
1840 | |
1841 return 0; | |
1842 } | |
1843 | |
491 | 1844 #if defined(MOV_SPLIT_CHUNKS) && defined(MOV_SEEK) |
1845 /** | |
1846 * Seek method based on the one described in the Appendix C of QTFileFormat.pdf | |
1847 */ | |
1848 static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp) | |
1849 { | |
1850 MOVContext* mov = (MOVContext *) s->priv_data; | |
1851 MOVStreamContext* sc; | |
1852 int32_t i, a, b, m; | |
1853 int64_t sample_time; | |
1854 int64_t start_time; | |
1855 int32_t seek_sample, sample; | |
1856 int32_t duration; | |
1857 int32_t count; | |
1858 int32_t chunk; | |
1859 int32_t left_in_chunk; | |
1860 int64_t chunk_file_offset; | |
1861 int64_t sample_file_offset; | |
1862 int32_t first_chunk_sample; | |
1863 int32_t sample_to_chunk_idx; | |
1864 int mov_idx; | |
1865 | |
1866 // Find the corresponding mov stream | |
1867 for (mov_idx = 0; mov_idx < mov->total_streams; mov_idx++) | |
1868 if (mov->streams[mov_idx]->ffindex == stream_index) | |
1869 break; | |
1870 if (mov_idx == mov->total_streams) { | |
1871 av_log(s, AV_LOG_ERROR, "mov: requested stream was not found in mov streams (idx=%i)\n", stream_index); | |
1872 return -1; | |
1873 } | |
1874 sc = mov->streams[mov_idx]; | |
1875 | |
1876 // Step 1. Find the edit that contains the requested time (elst) | |
1877 if (sc->edit_count) { | |
1878 // FIXME should handle edit list | |
1879 av_log(s, AV_LOG_ERROR, "mov: does not handle seeking in files that contain edit list (c:%d)\n", sc->edit_count); | |
1880 return -1; | |
1881 } | |
1882 | |
1883 // Step 2. Find the corresponding sample using the Time-to-sample atom (stts) */ | |
1884 #ifdef DEBUG | |
1885 av_log(s, AV_LOG_DEBUG, "Searching for time %li in stream #%i (time_scale=%i)\n", (long)timestamp, mov_idx, sc->time_scale); | |
1886 #endif | |
1887 // convert timestamp from time_base unit to timescale unit | |
1888 sample_time = av_rescale( timestamp, | |
1889 (int64_t)sc->time_scale * s->streams[stream_index]->time_base.num, | |
1890 (int64_t)s->streams[stream_index]->time_base.den); | |
1891 start_time = 0; // FIXME use elst atom | |
1892 sample = 1; // sample are 0 based in table | |
1893 #ifdef DEBUG | |
1894 av_log(s, AV_LOG_DEBUG, "Searching for sample_time %li \n", (long)sample_time); | |
1895 #endif | |
1896 for (i = 0; i < sc->stts_count; i++) { | |
1897 count = (uint32_t)(sc->stts_data[i]>>32); | |
1898 duration = (uint32_t)(sc->stts_data[i]&0xffff); | |
1899 //av_log(s, AV_LOG_DEBUG, "> sample_time %lli \n", (long)sample_time); | |
1900 //av_log(s, AV_LOG_DEBUG, "> count=%i duration=%i\n", count, duration); | |
1901 if ((start_time + count*duration) > sample_time) { | |
1902 sample += (sample_time - start_time) / duration; | |
1903 break; | |
1904 } | |
1905 sample += count; | |
1906 start_time += count * duration; | |
1907 } | |
1908 /* NOTE: despite what qt doc say, the dt value (Display Time in qt vocabulary) computed with the stts atom | |
1909 is a decoding time stamp (dts) not a presentation time stamp. And as usual dts != pts for stream with b frames */ | |
1910 | |
1911 #ifdef DEBUG | |
1912 av_log(s, AV_LOG_DEBUG, "Found time %li at sample #%u\n", (long)sample_time, sample); | |
1913 #endif | |
1914 if (sample > sc->sample_count) { | |
1915 av_log(s, AV_LOG_ERROR, "mov: sample pos is too high, unable to seek (req. sample=%i, sample count=%ld)\n", sample, sc->sample_count); | |
1916 return -1; | |
1917 } | |
1918 | |
1919 // Step 3. Find the prior sync. sample using the Sync sample atom (stss) | |
1920 if (sc->keyframes) { | |
1921 a = 0; | |
1922 b = sc->keyframe_count - 1; | |
1923 while (a < b) { | |
1924 m = (a + b + 1) >> 1; | |
1925 if (sc->keyframes[m] > sample) { | |
1926 b = m - 1; | |
1927 } else { | |
1928 a = m; | |
1929 } | |
1930 #ifdef DEBUG | |
1931 // av_log(s, AV_LOG_DEBUG, "a=%i (%i) b=%i (%i) m=%i (%i) stream #%i\n", a, sc->keyframes[a], b, sc->keyframes[b], m, sc->keyframes[m], mov_idx); | |
1932 #endif | |
1933 } | |
1934 seek_sample = sc->keyframes[a]; | |
1935 } | |
1936 else | |
1937 seek_sample = sample; // else all samples are key frames | |
1938 #ifdef DEBUG | |
1939 av_log(s, AV_LOG_DEBUG, "Found nearest keyframe at sample #%i \n", seek_sample); | |
1940 #endif | |
1941 | |
1942 // Step 4. Find the chunk of the sample using the Sample-to-chunk-atom (stsc) | |
1943 for (first_chunk_sample = 1, i = 0; i < (sc->sample_to_chunk_sz - 1); i++) { | |
1944 b = (sc->sample_to_chunk[i + 1].first - sc->sample_to_chunk[i].first) * sc->sample_to_chunk[i].count; | |
1945 if (seek_sample >= first_chunk_sample && seek_sample < (first_chunk_sample + b)) | |
1946 break; | |
1947 first_chunk_sample += b; | |
1948 } | |
1949 chunk = sc->sample_to_chunk[i].first + (seek_sample - first_chunk_sample) / sc->sample_to_chunk[i].count; | |
1950 left_in_chunk = sc->sample_to_chunk[i].count - (seek_sample - first_chunk_sample) % sc->sample_to_chunk[i].count; | |
1951 first_chunk_sample += ((seek_sample - first_chunk_sample) / sc->sample_to_chunk[i].count) * sc->sample_to_chunk[i].count; | |
1952 sample_to_chunk_idx = i; | |
1953 #ifdef DEBUG | |
1954 av_log(s, AV_LOG_DEBUG, "Sample was found in chunk #%i at sample offset %i (idx %i)\n", chunk, seek_sample - first_chunk_sample, sample_to_chunk_idx); | |
1955 #endif | |
1956 | |
1957 // Step 5. Find the offset of the chunk using the chunk offset atom | |
1958 if (!sc->chunk_offsets) { | |
1959 av_log(s, AV_LOG_ERROR, "mov: no chunk offset atom, unable to seek\n"); | |
1960 return -1; | |
1961 } | |
1962 if (chunk > sc->chunk_count) { | |
1963 av_log(s, AV_LOG_ERROR, "mov: chunk offset atom too short, unable to seek (req. chunk=%i, chunk count=%li)\n", chunk, sc->chunk_count); | |
1964 return -1; | |
1965 } | |
1966 chunk_file_offset = sc->chunk_offsets[chunk - 1]; | |
1967 #ifdef DEBUG | |
1968 av_log(s, AV_LOG_DEBUG, "Chunk file offset is #%llu \n", chunk_file_offset); | |
1969 #endif | |
1970 | |
1971 // Step 6. Find the byte offset within the chunk using the sample size atom | |
1972 sample_file_offset = chunk_file_offset; | |
1973 if (sc->sample_size) | |
1974 sample_file_offset += (seek_sample - first_chunk_sample) * sc->sample_size; | |
1975 else { | |
1976 for (i = 0; i < (seek_sample - first_chunk_sample); i++) { | |
1977 sample_file_offset += sc->sample_sizes[first_chunk_sample + i - 1]; | |
1978 } | |
1979 } | |
1980 #ifdef DEBUG | |
1981 av_log(s, AV_LOG_DEBUG, "Sample file offset is #%llu \n", sample_file_offset); | |
1982 #endif | |
1983 | |
1984 // Step 6. Update the parser | |
1985 mov->partial = sc; | |
1986 mov->next_chunk_offset = sample_file_offset; | |
1987 // Update current stream state | |
1988 sc->current_sample = seek_sample - 1; // zero based | |
1989 sc->left_in_chunk = left_in_chunk; | |
1990 sc->next_chunk = chunk; // +1 -1 (zero based) | |
1991 sc->sample_to_chunk_index = sample_to_chunk_idx; | |
1992 | |
1993 // Update other streams | |
1994 for (i = 0; i<mov->total_streams; i++) { | |
492
0ed5d359f63a
compilation of mov.c broken patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
491
diff
changeset
|
1995 MOVStreamContext *msc; |
491 | 1996 if (i == mov_idx) continue; |
1997 // Find the nearest 'next' chunk | |
492
0ed5d359f63a
compilation of mov.c broken patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
491
diff
changeset
|
1998 msc = mov->streams[i]; |
491 | 1999 a = 0; |
2000 b = msc->chunk_count - 1; | |
2001 while (a < b) { | |
2002 m = (a + b + 1) >> 1; | |
2003 if (msc->chunk_offsets[m] > chunk_file_offset) { | |
2004 b = m - 1; | |
2005 } else { | |
2006 a = m; | |
2007 } | |
2008 #ifdef DEBUG | |
2009 /* av_log(s, AV_LOG_DEBUG, "a=%i (%li) b=%i (%li) m=%i (%li) stream #%i\n" | |
2010 , a, (long)msc->chunk_offsets[a], b, (long)msc->chunk_offsets[b], m, (long)msc->chunk_offsets[m], i); */ | |
2011 #endif | |
2012 } | |
2013 msc->next_chunk = a; | |
2014 if (msc->chunk_offsets[a] < chunk_file_offset && a < (msc->chunk_count-1)) | |
2015 msc->next_chunk ++; | |
2016 #ifdef DEBUG | |
2017 av_log(s, AV_LOG_DEBUG, "Nearest next chunk for stream #%i is #%i @%lli\n", i, msc->next_chunk+1, msc->chunk_offsets[msc->next_chunk]); | |
2018 #endif | |
2019 // Compute sample count and index in the sample_to_chunk table (what a pity) | |
2020 msc->sample_to_chunk_index = 0; | |
2021 msc->current_sample = 0; | |
2022 for(; msc->sample_to_chunk_index < (msc->sample_to_chunk_sz - 1) | |
2023 && msc->sample_to_chunk[msc->sample_to_chunk_index + 1].first <= (1 + msc->next_chunk); msc->sample_to_chunk_index++) { | |
2024 msc->current_sample += (msc->sample_to_chunk[msc->sample_to_chunk_index + 1].first - msc->sample_to_chunk[msc->sample_to_chunk_index].first) \ | |
2025 * msc->sample_to_chunk[msc->sample_to_chunk_index].count; | |
2026 } | |
2027 msc->current_sample += (msc->next_chunk - (msc->sample_to_chunk[msc->sample_to_chunk_index].first - 1)) * sc->sample_to_chunk[msc->sample_to_chunk_index].count; | |
2028 msc->left_in_chunk = msc->sample_to_chunk[msc->sample_to_chunk_index].count - 1; | |
2029 #ifdef DEBUG | |
2030 av_log(s, AV_LOG_DEBUG, "Next Sample for stream #%i is #%i @%i\n", i, msc->current_sample + 1, msc->sample_to_chunk_index + 1); | |
2031 #endif | |
2032 } | |
2033 return 0; | |
2034 } | |
2035 #endif | |
2036 | |
0 | 2037 static int mov_read_close(AVFormatContext *s) |
2038 { | |
2039 int i; | |
121 | 2040 MOVContext *mov = (MOVContext *) s->priv_data; |
0 | 2041 for(i=0; i<mov->total_streams; i++) |
2042 mov_free_stream_context(mov->streams[i]); | |
130
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
2043 /* free color tabs */ |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
2044 for(i=0; i<mov->ctab_size; i++) |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
2045 av_freep(&mov->ctab[i]); |
f607ed6aa365
* support for AAC audio (esds decoding - using extradata)
kabi
parents:
129
diff
changeset
|
2046 av_freep(&mov->ctab); |
0 | 2047 return 0; |
2048 } | |
2049 | |
2050 static AVInputFormat mov_iformat = { | |
286
eccf0c3e3289
Using the extension m4a for audio only MPEG-4 files is increasingly
michael
parents:
266
diff
changeset
|
2051 "mov,mp4,m4a,3gp", |
0 | 2052 "QuickTime/MPEG4 format", |
2053 sizeof(MOVContext), | |
2054 mov_probe, | |
2055 mov_read_header, | |
2056 mov_read_packet, | |
2057 mov_read_close, | |
491 | 2058 #if defined(MOV_SPLIT_CHUNKS) && defined(MOV_SEEK) |
2059 mov_read_seek, | |
2060 #endif | |
0 | 2061 }; |
2062 | |
2063 int mov_init(void) | |
2064 { | |
2065 av_register_input_format(&mov_iformat); | |
2066 return 0; | |
2067 } |