Mercurial > libavformat.hg
annotate mov.c @ 4473:9eedb6599102 libavformat
MXF D-10 muxer
author | bcoudurier |
---|---|
date | Fri, 13 Feb 2009 07:28:20 +0000 |
parents | 7d1460900c59 |
children | 9267b8cf7918 |
rev | line source |
---|---|
1845 | 1 /* |
2 * MOV demuxer | |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
4242
diff
changeset
|
3 * Copyright (c) 2001 Fabrice Bellard |
1845 | 4 * |
5 * This file is part of FFmpeg. | |
6 * | |
7 * FFmpeg is free software; you can redistribute it and/or | |
8 * modify it under the terms of the GNU Lesser General Public | |
9 * License as published by the Free Software Foundation; either | |
10 * version 2.1 of the License, or (at your option) any later version. | |
11 * | |
12 * FFmpeg is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * Lesser General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU Lesser General Public | |
18 * License along with FFmpeg; if not, write to the Free Software | |
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 */ | |
21 | |
22 #include <limits.h> | |
23 | |
24 //#define DEBUG | |
25 | |
4201
7d2f3f1b68d8
Fix build: Add intreadwrite.h and bswap.h #includes where necessary.
diego
parents:
4197
diff
changeset
|
26 #include "libavutil/intreadwrite.h" |
1845 | 27 #include "avformat.h" |
28 #include "riff.h" | |
29 #include "isom.h" | |
30 #include "dv.h" | |
3286 | 31 #include "libavcodec/mpeg4audio.h" |
32 #include "libavcodec/mpegaudiodata.h" | |
1845 | 33 |
4206 | 34 #if CONFIG_ZLIB |
1845 | 35 #include <zlib.h> |
36 #endif | |
37 | |
38 /* | |
39 * First version by Francois Revol revol@free.fr | |
40 * Seek function by Gael Chardon gael.dev@4now.net | |
41 * | |
42 * Features and limitations: | |
43 * - reads most of the QT files I have (at least the structure), | |
44 * Sample QuickTime files with mp3 audio can be found at: http://www.3ivx.com/showcase.html | |
45 * - the code is quite ugly... maybe I won't do it recursive next time :-) | |
46 * | |
47 * Funny I didn't know about http://sourceforge.net/projects/qt-ffmpeg/ | |
48 * when coding this :) (it's a writer anyway) | |
49 * | |
50 * Reference documents: | |
51 * http://www.geocities.com/xhelmboyx/quicktime/formats/qtm-layout.txt | |
52 * Apple: | |
53 * http://developer.apple.com/documentation/QuickTime/QTFF/ | |
54 * http://developer.apple.com/documentation/QuickTime/QTFF/qtff.pdf | |
55 * QuickTime is a trademark of Apple (AFAIK :)) | |
56 */ | |
57 | |
58 #include "qtpalette.h" | |
59 | |
60 | |
61 #undef NDEBUG | |
62 #include <assert.h> | |
63 | |
64 /* the QuickTime file format is quite convoluted... | |
65 * it has lots of index tables, each indexing something in another one... | |
66 * Here we just use what is needed to read the chunks | |
67 */ | |
68 | |
2045
aa5e56700fdf
cosmectics, use consistant and homogeneous type names for atoms
bcoudurier
parents:
2044
diff
changeset
|
69 typedef struct { |
2030 | 70 int first; |
71 int count; | |
72 int id; | |
4079 | 73 } MOVStsc; |
1845 | 74 |
75 typedef struct { | |
76 uint32_t type; | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
77 char *path; |
4079 | 78 } MOVDref; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
79 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
80 typedef struct { |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
81 uint32_t type; |
1845 | 82 int64_t offset; |
83 int64_t size; /* total size (excluding the size and type fields) */ | |
4079 | 84 } MOVAtom; |
1845 | 85 |
86 struct MOVParseTableEntry; | |
87 | |
3169 | 88 typedef struct { |
89 unsigned track_id; | |
90 uint64_t base_data_offset; | |
91 uint64_t moof_offset; | |
92 unsigned stsd_id; | |
93 unsigned duration; | |
94 unsigned size; | |
95 unsigned flags; | |
96 } MOVFragment; | |
97 | |
98 typedef struct { | |
99 unsigned track_id; | |
100 unsigned stsd_id; | |
101 unsigned duration; | |
102 unsigned size; | |
103 unsigned flags; | |
104 } MOVTrackExt; | |
105 | |
1845 | 106 typedef struct MOVStreamContext { |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
107 ByteIOContext *pb; |
1845 | 108 int ffindex; /* the ffmpeg stream id */ |
2030 | 109 int next_chunk; |
1845 | 110 unsigned int chunk_count; |
111 int64_t *chunk_offsets; | |
112 unsigned int stts_count; | |
4079 | 113 MOVStts *stts_data; |
1845 | 114 unsigned int ctts_count; |
4079 | 115 MOVStts *ctts_data; |
4412 | 116 unsigned int stsc_count; |
117 MOVStsc *stsc_data; | |
4411 | 118 int ctts_index; |
119 int ctts_sample; | |
1845 | 120 unsigned int sample_size; |
121 unsigned int sample_count; | |
2030 | 122 int *sample_sizes; |
1845 | 123 unsigned int keyframe_count; |
2030 | 124 int *keyframes; |
1845 | 125 int time_scale; |
126 int time_rate; | |
4407 | 127 int time_offset; ///< time offset of the first edit list entry |
2030 | 128 int current_sample; |
1940
1a7f66384792
cosmetics, sample_size_v1 -> bytes_per_frame / samples_per_frame
bcoudurier
parents:
1939
diff
changeset
|
129 unsigned int bytes_per_frame; |
1a7f66384792
cosmetics, sample_size_v1 -> bytes_per_frame / samples_per_frame
bcoudurier
parents:
1939
diff
changeset
|
130 unsigned int samples_per_frame; |
1845 | 131 int dv_audio_container; |
3299
80a497804aa8
demux all stsd ids if codec is the same, fix premature_mov_ending.mov, closes #451
bcoudurier
parents:
3286
diff
changeset
|
132 int pseudo_stream_id; ///< -1 means demux all ids |
3029
10abe8748ec2
use correct demux mechanism when audio compression id is -2, dv audio does not matter, demux partially qt_dv_pal_test.mov which does NOT use cid -2
bcoudurier
parents:
3027
diff
changeset
|
133 int16_t audio_cid; ///< stsd audio compression id |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
134 unsigned drefs_count; |
4079 | 135 MOVDref *drefs; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
136 int dref_id; |
3956
8bdecea89071
support negative ctts in some way, unset wrong dts
bcoudurier
parents:
3935
diff
changeset
|
137 int wrong_dts; ///< dts are wrong due to negative ctts |
4202 | 138 int width; ///< tkhd width |
139 int height; ///< tkhd height | |
1845 | 140 } MOVStreamContext; |
141 | |
142 typedef struct MOVContext { | |
143 AVFormatContext *fc; | |
144 int time_scale; | |
145 int64_t duration; /* duration of the longest track */ | |
146 int found_moov; /* when both 'moov' and 'mdat' sections has been found */ | |
147 int found_mdat; /* we suppose we have enough data to read the file */ | |
148 AVPaletteControl palette_control; | |
149 DVDemuxContext *dv_demux; | |
150 AVFormatContext *dv_fctx; | |
151 int isom; /* 1 if file is ISO Media (mp4/3gp) */ | |
3169 | 152 MOVFragment fragment; ///< current fragment in moof atom |
153 MOVTrackExt *trex_data; | |
154 unsigned trex_count; | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
155 int itunes_metadata; ///< metadata are itunes style |
1845 | 156 } MOVContext; |
157 | |
158 | |
159 /* XXX: it's the first time I make a recursive parser I think... sorry if it's ugly :P */ | |
160 | |
161 /* those functions parse an atom */ | |
162 /* return code: | |
3160 | 163 0: continue to parse next atom |
3175 | 164 <0: error occurred, exit |
3160 | 165 */ |
1845 | 166 /* links atom IDs to parse functions */ |
167 typedef struct MOVParseTableEntry { | |
168 uint32_t type; | |
4079 | 169 int (*parse)(MOVContext *ctx, ByteIOContext *pb, MOVAtom atom); |
1845 | 170 } MOVParseTableEntry; |
171 | |
2820
95ce00ad6f3e
save pointer to parse table, it is unlikely to change
bcoudurier
parents:
2819
diff
changeset
|
172 static const MOVParseTableEntry mov_default_parse_table[]; |
95ce00ad6f3e
save pointer to parse table, it is unlikely to change
bcoudurier
parents:
2819
diff
changeset
|
173 |
4079 | 174 static int mov_read_default(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 175 { |
176 int64_t total_size = 0; | |
4079 | 177 MOVAtom a; |
1845 | 178 int i; |
179 int err = 0; | |
180 | |
181 a.offset = atom.offset; | |
182 | |
183 if (atom.size < 0) | |
2026 | 184 atom.size = INT64_MAX; |
1845 | 185 while(((total_size + 8) < atom.size) && !url_feof(pb) && !err) { |
186 a.size = atom.size; | |
2826 | 187 a.type=0; |
1845 | 188 if(atom.size >= 8) { |
189 a.size = get_be32(pb); | |
190 a.type = get_le32(pb); | |
191 } | |
192 total_size += 8; | |
193 a.offset += 8; | |
2902 | 194 dprintf(c->fc, "type: %08x %.4s sz: %"PRIx64" %"PRIx64" %"PRIx64"\n", |
195 a.type, (char*)&a.type, a.size, atom.size, total_size); | |
1845 | 196 if (a.size == 1) { /* 64 bit extended size */ |
197 a.size = get_be64(pb) - 8; | |
198 a.offset += 8; | |
199 total_size += 8; | |
200 } | |
201 if (a.size == 0) { | |
202 a.size = atom.size - total_size; | |
203 if (a.size <= 8) | |
204 break; | |
205 } | |
1964
4571a481081d
move atom size check before parsing function search
bcoudurier
parents:
1963
diff
changeset
|
206 a.size -= 8; |
2660
022174d849d5
fix issue 225, instead of stoping when wrong atom size is found,
bcoudurier
parents:
2589
diff
changeset
|
207 if(a.size < 0) |
1964
4571a481081d
move atom size check before parsing function search
bcoudurier
parents:
1963
diff
changeset
|
208 break; |
2665 | 209 a.size = FFMIN(a.size, atom.size - total_size); |
1964
4571a481081d
move atom size check before parsing function search
bcoudurier
parents:
1963
diff
changeset
|
210 |
2826 | 211 for (i = 0; mov_default_parse_table[i].type != 0 |
2820
95ce00ad6f3e
save pointer to parse table, it is unlikely to change
bcoudurier
parents:
2819
diff
changeset
|
212 && mov_default_parse_table[i].type != a.type; i++) |
1845 | 213 /* empty */; |
214 | |
2820
95ce00ad6f3e
save pointer to parse table, it is unlikely to change
bcoudurier
parents:
2819
diff
changeset
|
215 if (mov_default_parse_table[i].type == 0) { /* skip leaf atoms data */ |
1845 | 216 url_fskip(pb, a.size); |
217 } else { | |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3967
diff
changeset
|
218 int64_t start_pos = url_ftell(pb); |
1845 | 219 int64_t left; |
2822
bdb887c3e9e9
cosmetics: func -> parse, remove useless parenthesis
bcoudurier
parents:
2821
diff
changeset
|
220 err = mov_default_parse_table[i].parse(c, pb, a); |
3166
c082ee7573b2
simplify, and only stop parsing when non streamable
bcoudurier
parents:
3164
diff
changeset
|
221 if (url_is_streamed(pb) && c->found_moov && c->found_mdat) |
2817 | 222 break; |
1845 | 223 left = a.size - url_ftell(pb) + start_pos; |
224 if (left > 0) /* skip garbage at atom end */ | |
225 url_fskip(pb, left); | |
226 } | |
227 | |
228 a.offset += a.size; | |
229 total_size += a.size; | |
230 } | |
231 | |
3181 | 232 if (!err && total_size < atom.size && atom.size < 0x7ffff) |
1845 | 233 url_fskip(pb, atom.size - total_size); |
234 | |
235 return err; | |
236 } | |
237 | |
4079 | 238 static int mov_read_dref(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
239 { |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
240 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
241 MOVStreamContext *sc = st->priv_data; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
242 int entries, i, j; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
243 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
244 get_be32(pb); // version + flags |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
245 entries = get_be32(pb); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
246 if (entries >= UINT_MAX / sizeof(*sc->drefs)) |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
247 return -1; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
248 sc->drefs_count = entries; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
249 sc->drefs = av_mallocz(entries * sizeof(*sc->drefs)); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
250 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
251 for (i = 0; i < sc->drefs_count; i++) { |
4079 | 252 MOVDref *dref = &sc->drefs[i]; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
253 uint32_t size = get_be32(pb); |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3967
diff
changeset
|
254 int64_t next = url_ftell(pb) + size - 4; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
255 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
256 dref->type = get_le32(pb); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
257 get_be32(pb); // version + flags |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
258 dprintf(c->fc, "type %.4s size %d\n", (char*)&dref->type, size); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
259 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
260 if (dref->type == MKTAG('a','l','i','s') && size > 150) { |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
261 /* macintosh alias record */ |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
262 uint16_t volume_len, len; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
263 char volume[28]; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
264 int16_t type; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
265 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
266 url_fskip(pb, 10); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
267 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
268 volume_len = get_byte(pb); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
269 volume_len = FFMIN(volume_len, 27); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
270 get_buffer(pb, volume, 27); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
271 volume[volume_len] = 0; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
272 av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", volume, volume_len); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
273 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
274 url_fskip(pb, 112); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
275 |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
276 for (type = 0; type != -1 && url_ftell(pb) < next; ) { |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
277 type = get_be16(pb); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
278 len = get_be16(pb); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
279 av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
280 if (len&1) |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
281 len += 1; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
282 if (type == 2) { // absolute path |
3092 | 283 av_free(dref->path); |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
284 dref->path = av_mallocz(len+1); |
3091 | 285 if (!dref->path) |
286 return AVERROR(ENOMEM); | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
287 get_buffer(pb, dref->path, len); |
3090 | 288 if (len > volume_len && !strncmp(dref->path, volume, volume_len)) { |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
289 len -= volume_len; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
290 memmove(dref->path, dref->path+volume_len, len); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
291 dref->path[len] = 0; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
292 } |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
293 for (j = 0; j < len; j++) |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
294 if (dref->path[j] == ':') |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
295 dref->path[j] = '/'; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
296 av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
297 } else |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
298 url_fskip(pb, len); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
299 } |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
300 } |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
301 url_fseek(pb, next, SEEK_SET); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
302 } |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
303 return 0; |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
304 } |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
305 |
4079 | 306 static int mov_read_hdlr(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 307 { |
308 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
309 uint32_t type; | |
310 uint32_t ctype; | |
311 | |
312 get_byte(pb); /* version */ | |
3145 | 313 get_be24(pb); /* flags */ |
1845 | 314 |
315 /* component type */ | |
316 ctype = get_le32(pb); | |
317 type = get_le32(pb); /* component subtype */ | |
318 | |
2902 | 319 dprintf(c->fc, "ctype= %c%c%c%c (0x%08x)\n", *((char *)&ctype), ((char *)&ctype)[1], |
320 ((char *)&ctype)[2], ((char *)&ctype)[3], (int) ctype); | |
321 dprintf(c->fc, "stype= %c%c%c%c\n", | |
322 *((char *)&type), ((char *)&type)[1], ((char *)&type)[2], ((char *)&type)[3]); | |
1845 | 323 if(!ctype) |
324 c->isom = 1; | |
3254 | 325 if (type == MKTAG('v','i','d','e')) |
1845 | 326 st->codec->codec_type = CODEC_TYPE_VIDEO; |
3253 | 327 else if(type == MKTAG('s','o','u','n')) |
1845 | 328 st->codec->codec_type = CODEC_TYPE_AUDIO; |
3253 | 329 else if(type == MKTAG('m','1','a',' ')) |
1845 | 330 st->codec->codec_id = CODEC_ID_MP2; |
3253 | 331 else if(type == MKTAG('s','u','b','p')) { |
1845 | 332 st->codec->codec_type = CODEC_TYPE_SUBTITLE; |
333 } | |
334 get_be32(pb); /* component manufacture */ | |
335 get_be32(pb); /* component flags */ | |
336 get_be32(pb); /* component flags mask */ | |
337 | |
338 if(atom.size <= 24) | |
339 return 0; /* nothing left to read */ | |
340 | |
341 url_fskip(pb, atom.size - (url_ftell(pb) - atom.offset)); | |
342 return 0; | |
343 } | |
344 | |
2029 | 345 static int mp4_read_descr_len(ByteIOContext *pb) |
1845 | 346 { |
347 int len = 0; | |
348 int count = 4; | |
349 while (count--) { | |
350 int c = get_byte(pb); | |
351 len = (len << 7) | (c & 0x7f); | |
352 if (!(c & 0x80)) | |
353 break; | |
354 } | |
355 return len; | |
356 } | |
357 | |
2029 | 358 static int mp4_read_descr(MOVContext *c, ByteIOContext *pb, int *tag) |
1845 | 359 { |
360 int len; | |
361 *tag = get_byte(pb); | |
2029 | 362 len = mp4_read_descr_len(pb); |
1907 | 363 dprintf(c->fc, "MPEG4 description: tag=0x%02x len=%d\n", *tag, len); |
1845 | 364 return len; |
365 } | |
366 | |
2028 | 367 #define MP4ESDescrTag 0x03 |
368 #define MP4DecConfigDescrTag 0x04 | |
369 #define MP4DecSpecificDescrTag 0x05 | |
370 | |
3261
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
371 static const AVCodecTag mp4_audio_types[] = { |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
372 { CODEC_ID_MP3ON4, 29 }, /* old mp3on4 draft */ |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
373 { CODEC_ID_MP3ON4, 32 }, /* layer 1 */ |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
374 { CODEC_ID_MP3ON4, 33 }, /* layer 2 */ |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
375 { CODEC_ID_MP3ON4, 34 }, /* layer 3 */ |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
376 { CODEC_ID_NONE, 0 }, |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
377 }; |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
378 |
4079 | 379 static int mov_read_esds(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 380 { |
381 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
382 int tag, len; | |
383 | |
384 get_be32(pb); /* version + flags */ | |
2029 | 385 len = mp4_read_descr(c, pb, &tag); |
1845 | 386 if (tag == MP4ESDescrTag) { |
387 get_be16(pb); /* ID */ | |
388 get_byte(pb); /* priority */ | |
389 } else | |
390 get_be16(pb); /* ID */ | |
391 | |
2029 | 392 len = mp4_read_descr(c, pb, &tag); |
1845 | 393 if (tag == MP4DecConfigDescrTag) { |
2028 | 394 int object_type_id = get_byte(pb); |
395 get_byte(pb); /* stream type */ | |
396 get_be24(pb); /* buffer size db */ | |
397 get_be32(pb); /* max bitrate */ | |
398 get_be32(pb); /* avg bitrate */ | |
1845 | 399 |
2028 | 400 st->codec->codec_id= codec_get_id(ff_mp4_obj_type, object_type_id); |
401 dprintf(c->fc, "esds object type id %d\n", object_type_id); | |
2029 | 402 len = mp4_read_descr(c, pb, &tag); |
1845 | 403 if (tag == MP4DecSpecificDescrTag) { |
1907 | 404 dprintf(c->fc, "Specific MPEG4 header len=%d\n", len); |
3078 | 405 if((uint64_t)len > (1<<30)) |
406 return -1; | |
1845 | 407 st->codec->extradata = av_mallocz(len + FF_INPUT_BUFFER_PADDING_SIZE); |
3076 | 408 if (!st->codec->extradata) |
409 return AVERROR(ENOMEM); | |
3077 | 410 get_buffer(pb, st->codec->extradata, len); |
411 st->codec->extradata_size = len; | |
3261
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
412 if (st->codec->codec_id == CODEC_ID_AAC) { |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
413 MPEG4AudioConfig cfg; |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
414 ff_mpeg4audio_get_config(&cfg, st->codec->extradata, |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
415 st->codec->extradata_size); |
3362
0dfa207c5d69
aac chan config is 0 if bitstream contains program_config_element
bcoudurier
parents:
3313
diff
changeset
|
416 if (cfg.chan_config > 7) |
3262
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
417 return -1; |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
418 st->codec->channels = ff_mpeg4audio_channels[cfg.chan_config]; |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
419 if (cfg.object_type == 29 && cfg.sampling_index < 3) // old mp3on4 |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
420 st->codec->sample_rate = ff_mpa_freq_tab[cfg.sampling_index]; |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
421 else |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
422 st->codec->sample_rate = cfg.sample_rate; // ext sample rate ? |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
423 dprintf(c->fc, "mp4a config channels %d obj %d ext obj %d " |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
424 "sample rate %d ext sample rate %d\n", st->codec->channels, |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
425 cfg.object_type, cfg.ext_object_type, |
07299732f3b8
set channels and sample rate from mpeg4audio config
bcoudurier
parents:
3261
diff
changeset
|
426 cfg.sample_rate, cfg.ext_sample_rate); |
3261
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
427 if (!(st->codec->codec_id = codec_get_id(mp4_audio_types, |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
428 cfg.object_type))) |
bf5f112efcff
parse mpeg4audio config to correctly detect mp3on4, fix iso mp3on4 reference files
bcoudurier
parents:
3260
diff
changeset
|
429 st->codec->codec_id = CODEC_ID_AAC; |
3077 | 430 } |
1845 | 431 } |
432 } | |
433 return 0; | |
434 } | |
435 | |
4080 | 436 static int mov_read_pasp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
437 { | |
438 const int num = get_be32(pb); | |
439 const int den = get_be32(pb); | |
440 AVStream * const st = c->fc->streams[c->fc->nb_streams-1]; | |
441 if (den != 0) { | |
4264
bf7a9658de71
change sample aspect ratio test to be more clear, print old one
bcoudurier
parents:
4251
diff
changeset
|
442 if ((st->sample_aspect_ratio.den != 1 || st->sample_aspect_ratio.num) && // default |
bf7a9658de71
change sample aspect ratio test to be more clear, print old one
bcoudurier
parents:
4251
diff
changeset
|
443 (den != st->sample_aspect_ratio.den || num != st->sample_aspect_ratio.num)) |
4080 | 444 av_log(c->fc, AV_LOG_WARNING, |
4264
bf7a9658de71
change sample aspect ratio test to be more clear, print old one
bcoudurier
parents:
4251
diff
changeset
|
445 "sample aspect ratio already set to %d:%d, overriding by 'pasp' atom\n", |
bf7a9658de71
change sample aspect ratio test to be more clear, print old one
bcoudurier
parents:
4251
diff
changeset
|
446 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den); |
4080 | 447 st->sample_aspect_ratio.num = num; |
448 st->sample_aspect_ratio.den = den; | |
449 } | |
450 return 0; | |
451 } | |
452 | |
1845 | 453 /* this atom contains actual media data */ |
4079 | 454 static int mov_read_mdat(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 455 { |
456 if(atom.size == 0) /* wrong one (MP4) */ | |
457 return 0; | |
458 c->found_mdat=1; | |
459 return 0; /* now go for moov */ | |
460 } | |
461 | |
4079 | 462 static int mov_read_ftyp(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 463 { |
464 uint32_t type = get_le32(pb); | |
465 | |
466 if (type != MKTAG('q','t',' ',' ')) | |
467 c->isom = 1; | |
468 av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type); | |
469 get_be32(pb); /* minor version */ | |
470 url_fskip(pb, atom.size - 8); | |
471 return 0; | |
472 } | |
473 | |
474 /* this atom should contain all header atoms */ | |
4079 | 475 static int mov_read_moov(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 476 { |
2806
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
477 if (mov_read_default(c, pb, atom) < 0) |
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
478 return -1; |
1845 | 479 /* we parsed the 'moov' atom, we can terminate the parsing as soon as we find the 'mdat' */ |
480 /* so we don't parse the whole file if over a network */ | |
481 c->found_moov=1; | |
482 return 0; /* now go for mdat */ | |
483 } | |
484 | |
4079 | 485 static int mov_read_moof(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
3169 | 486 { |
487 c->fragment.moof_offset = url_ftell(pb) - 8; | |
488 dprintf(c->fc, "moof offset %llx\n", c->fragment.moof_offset); | |
489 return mov_read_default(c, pb, atom); | |
490 } | |
1845 | 491 |
4079 | 492 static int mov_read_mdhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 493 { |
494 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 495 MOVStreamContext *sc = st->priv_data; |
1845 | 496 int version = get_byte(pb); |
4269 | 497 unsigned lang; |
1845 | 498 |
499 if (version > 1) | |
3259 | 500 return -1; /* unsupported */ |
1845 | 501 |
3145 | 502 get_be24(pb); /* flags */ |
1845 | 503 if (version == 1) { |
504 get_be64(pb); | |
505 get_be64(pb); | |
506 } else { | |
507 get_be32(pb); /* creation time */ | |
508 get_be32(pb); /* modification time */ | |
509 } | |
510 | |
511 sc->time_scale = get_be32(pb); | |
512 st->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ | |
513 | |
514 lang = get_be16(pb); /* language */ | |
515 ff_mov_lang_to_iso639(lang, st->language); | |
516 get_be16(pb); /* quality */ | |
517 | |
518 return 0; | |
519 } | |
520 | |
4079 | 521 static int mov_read_mvhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 522 { |
523 int version = get_byte(pb); /* version */ | |
3145 | 524 get_be24(pb); /* flags */ |
1845 | 525 |
526 if (version == 1) { | |
527 get_be64(pb); | |
528 get_be64(pb); | |
529 } else { | |
530 get_be32(pb); /* creation time */ | |
531 get_be32(pb); /* modification time */ | |
532 } | |
533 c->time_scale = get_be32(pb); /* time scale */ | |
2044 | 534 |
535 dprintf(c->fc, "time scale = %i\n", c->time_scale); | |
536 | |
1845 | 537 c->duration = (version == 1) ? get_be64(pb) : get_be32(pb); /* duration */ |
538 get_be32(pb); /* preferred scale */ | |
539 | |
540 get_be16(pb); /* preferred volume */ | |
541 | |
542 url_fskip(pb, 10); /* reserved */ | |
543 | |
544 url_fskip(pb, 36); /* display matrix */ | |
545 | |
546 get_be32(pb); /* preview time */ | |
547 get_be32(pb); /* preview duration */ | |
548 get_be32(pb); /* poster time */ | |
549 get_be32(pb); /* selection time */ | |
550 get_be32(pb); /* selection duration */ | |
551 get_be32(pb); /* current time */ | |
552 get_be32(pb); /* next track ID */ | |
553 | |
554 return 0; | |
555 } | |
556 | |
4079 | 557 static int mov_read_smi(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 558 { |
559 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
560 | |
561 if((uint64_t)atom.size > (1<<30)) | |
562 return -1; | |
563 | |
564 // currently SVQ3 decoder expect full STSD header - so let's fake it | |
565 // this should be fixed and just SMI header should be passed | |
566 av_free(st->codec->extradata); | |
3076 | 567 st->codec->extradata = av_mallocz(atom.size + 0x5a + FF_INPUT_BUFFER_PADDING_SIZE); |
568 if (!st->codec->extradata) | |
569 return AVERROR(ENOMEM); | |
3077 | 570 st->codec->extradata_size = 0x5a + atom.size; |
571 memcpy(st->codec->extradata, "SVQ3", 4); // fake | |
572 get_buffer(pb, st->codec->extradata + 0x5a, atom.size); | |
573 dprintf(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a); | |
1845 | 574 return 0; |
575 } | |
576 | |
4079 | 577 static int mov_read_enda(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 578 { |
579 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
580 int little_endian = get_be16(pb); | |
581 | |
4184
bc40129f13cc
only set le if value is 1, fix boom5.mov, issue #770
bcoudurier
parents:
4123
diff
changeset
|
582 dprintf(c->fc, "enda %d\n", little_endian); |
bc40129f13cc
only set le if value is 1, fix boom5.mov, issue #770
bcoudurier
parents:
4123
diff
changeset
|
583 if (little_endian == 1) { |
1845 | 584 switch (st->codec->codec_id) { |
585 case CODEC_ID_PCM_S24BE: | |
586 st->codec->codec_id = CODEC_ID_PCM_S24LE; | |
587 break; | |
588 case CODEC_ID_PCM_S32BE: | |
589 st->codec->codec_id = CODEC_ID_PCM_S32LE; | |
590 break; | |
3738
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
591 case CODEC_ID_PCM_F32BE: |
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
592 st->codec->codec_id = CODEC_ID_PCM_F32LE; |
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
593 break; |
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
594 case CODEC_ID_PCM_F64BE: |
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
595 st->codec->codec_id = CODEC_ID_PCM_F64LE; |
0c46eb1cd9b3
Make MOV demuxer handle F32BE, F32LE, F64BE and F64LE PCM audio.
pross
parents:
3626
diff
changeset
|
596 break; |
1845 | 597 default: |
598 break; | |
599 } | |
600 } | |
601 return 0; | |
602 } | |
603 | |
604 /* FIXME modify qdm2/svq3/h264 decoders to take full atom as extradata */ | |
4079 | 605 static int mov_read_extradata(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 606 { |
4116
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
607 AVStream *st; |
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
608 uint64_t size; |
2589
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
609 uint8_t *buf; |
4116
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
610 |
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
611 if (c->fc->nb_streams < 1) // will happen with jp2 files |
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
612 return 0; |
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
613 st= c->fc->streams[c->fc->nb_streams-1]; |
f693bc71dc1e
check that nb_streams is valid before setting stream, fix crash with jp2 which do not use same structure
bcoudurier
parents:
4080
diff
changeset
|
614 size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE; |
2589
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
615 if(size > INT_MAX || (uint64_t)atom.size > INT_MAX) |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
616 return -1; |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
617 buf= av_realloc(st->codec->extradata, size); |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
618 if(!buf) |
1845 | 619 return -1; |
2589
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
620 st->codec->extradata= buf; |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
621 buf+= st->codec->extradata_size; |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
622 st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE; |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
623 AV_WB32( buf , atom.size + 8); |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
624 AV_WL32( buf + 4, atom.type); |
960795567b33
append extradata atoms when parsing, fix OLOCOONS_O3.mov
bcoudurier
parents:
2547
diff
changeset
|
625 get_buffer(pb, buf + 8, atom.size); |
1845 | 626 return 0; |
627 } | |
628 | |
4079 | 629 static int mov_read_wave(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 630 { |
631 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
632 | |
633 if((uint64_t)atom.size > (1<<30)) | |
634 return -1; | |
635 | |
636 if (st->codec->codec_id == CODEC_ID_QDM2) { | |
637 // pass all frma atom to codec, needed at least for QDM2 | |
638 av_free(st->codec->extradata); | |
3076 | 639 st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); |
640 if (!st->codec->extradata) | |
641 return AVERROR(ENOMEM); | |
1845 | 642 st->codec->extradata_size = atom.size; |
3076 | 643 get_buffer(pb, st->codec->extradata, atom.size); |
1845 | 644 } else if (atom.size > 8) { /* to read frma, esds atoms */ |
2806
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
645 if (mov_read_default(c, pb, atom) < 0) |
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
646 return -1; |
1845 | 647 } else |
648 url_fskip(pb, atom.size); | |
649 return 0; | |
650 } | |
651 | |
2837
1caef0e2fb46
supports glbl atom containing generic extradata for all codecs
bcoudurier
parents:
2826
diff
changeset
|
652 /** |
1caef0e2fb46
supports glbl atom containing generic extradata for all codecs
bcoudurier
parents:
2826
diff
changeset
|
653 * This function reads atom content and puts data in extradata without tag |
1caef0e2fb46
supports glbl atom containing generic extradata for all codecs
bcoudurier
parents:
2826
diff
changeset
|
654 * nor size unlike mov_read_extradata. |
1caef0e2fb46
supports glbl atom containing generic extradata for all codecs
bcoudurier
parents:
2826
diff
changeset
|
655 */ |
4079 | 656 static int mov_read_glbl(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 657 { |
658 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
659 | |
660 if((uint64_t)atom.size > (1<<30)) | |
661 return -1; | |
662 | |
663 av_free(st->codec->extradata); | |
3076 | 664 st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE); |
665 if (!st->codec->extradata) | |
666 return AVERROR(ENOMEM); | |
1845 | 667 st->codec->extradata_size = atom.size; |
3076 | 668 get_buffer(pb, st->codec->extradata, atom.size); |
1845 | 669 return 0; |
670 } | |
671 | |
4079 | 672 static int mov_read_stco(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 673 { |
674 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 675 MOVStreamContext *sc = st->priv_data; |
1845 | 676 unsigned int i, entries; |
677 | |
678 get_byte(pb); /* version */ | |
3145 | 679 get_be24(pb); /* flags */ |
1845 | 680 |
681 entries = get_be32(pb); | |
682 | |
683 if(entries >= UINT_MAX/sizeof(int64_t)) | |
684 return -1; | |
685 | |
686 sc->chunk_count = entries; | |
687 sc->chunk_offsets = av_malloc(entries * sizeof(int64_t)); | |
688 if (!sc->chunk_offsets) | |
689 return -1; | |
3254 | 690 if (atom.type == MKTAG('s','t','c','o')) |
691 for(i=0; i<entries; i++) | |
1845 | 692 sc->chunk_offsets[i] = get_be32(pb); |
3254 | 693 else if (atom.type == MKTAG('c','o','6','4')) |
694 for(i=0; i<entries; i++) | |
1845 | 695 sc->chunk_offsets[i] = get_be64(pb); |
3254 | 696 else |
1845 | 697 return -1; |
698 | |
699 return 0; | |
700 } | |
701 | |
3625 | 702 /** |
703 * Compute codec id for 'lpcm' tag. | |
704 * See CoreAudioTypes and AudioStreamBasicDescription at Apple. | |
705 */ | |
3967 | 706 static enum CodecID mov_get_lpcm_codec_id(int bps, int flags) |
3625 | 707 { |
708 if (flags & 1) { // floating point | |
709 if (flags & 2) { // big endian | |
710 if (bps == 32) return CODEC_ID_PCM_F32BE; | |
3751 | 711 else if (bps == 64) return CODEC_ID_PCM_F64BE; |
3625 | 712 } else { |
3751 | 713 if (bps == 32) return CODEC_ID_PCM_F32LE; |
714 else if (bps == 64) return CODEC_ID_PCM_F64LE; | |
3625 | 715 } |
716 } else { | |
717 if (flags & 2) { | |
718 if (bps == 8) | |
719 // signed integer | |
720 if (flags & 4) return CODEC_ID_PCM_S8; | |
721 else return CODEC_ID_PCM_U8; | |
722 else if (bps == 16) return CODEC_ID_PCM_S16BE; | |
723 else if (bps == 24) return CODEC_ID_PCM_S24BE; | |
724 else if (bps == 32) return CODEC_ID_PCM_S32BE; | |
725 } else { | |
726 if (bps == 8) | |
727 if (flags & 4) return CODEC_ID_PCM_S8; | |
728 else return CODEC_ID_PCM_U8; | |
3626 | 729 else if (bps == 16) return CODEC_ID_PCM_S16LE; |
3625 | 730 else if (bps == 24) return CODEC_ID_PCM_S24LE; |
731 else if (bps == 32) return CODEC_ID_PCM_S32LE; | |
732 } | |
733 } | |
3967 | 734 return CODEC_ID_NONE; |
3625 | 735 } |
736 | |
4079 | 737 static int mov_read_stsd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 738 { |
739 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 740 MOVStreamContext *sc = st->priv_data; |
3263 | 741 int j, entries, pseudo_stream_id; |
1845 | 742 |
743 get_byte(pb); /* version */ | |
3145 | 744 get_be24(pb); /* flags */ |
1845 | 745 |
746 entries = get_be32(pb); | |
747 | |
3167 | 748 for(pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) { |
749 //Parsing Sample description table | |
1845 | 750 enum CodecID id; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
751 int dref_id; |
4079 | 752 MOVAtom a = { 0, 0, 0 }; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3967
diff
changeset
|
753 int64_t start_pos = url_ftell(pb); |
1845 | 754 int size = get_be32(pb); /* size */ |
3263 | 755 uint32_t format = get_le32(pb); /* data format */ |
1845 | 756 |
757 get_be32(pb); /* reserved */ | |
758 get_be16(pb); /* reserved */ | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
759 dref_id = get_be16(pb); |
1845 | 760 |
3022
800db1ceafc6
Allow the user to select which codec out of several in stsd he wants.
michael
parents:
2974
diff
changeset
|
761 if (st->codec->codec_tag && |
3299
80a497804aa8
demux all stsd ids if codec is the same, fix premature_mov_ending.mov, closes #451
bcoudurier
parents:
3286
diff
changeset
|
762 st->codec->codec_tag != format && |
3022
800db1ceafc6
Allow the user to select which codec out of several in stsd he wants.
michael
parents:
2974
diff
changeset
|
763 (c->fc->video_codec_id ? codec_get_id(codec_movvideo_tags, format) != c->fc->video_codec_id |
3253 | 764 : st->codec->codec_tag != MKTAG('j','p','e','g')) |
3022
800db1ceafc6
Allow the user to select which codec out of several in stsd he wants.
michael
parents:
2974
diff
changeset
|
765 ){ |
3135 | 766 /* Multiple fourcc, we skip JPEG. This is not correct, we should |
767 * export it as a separate AVStream but this needs a few changes | |
768 * in the MOV demuxer, patch welcome. */ | |
3300 | 769 av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n"); |
1845 | 770 url_fskip(pb, size - (url_ftell(pb) - start_pos)); |
771 continue; | |
772 } | |
3299
80a497804aa8
demux all stsd ids if codec is the same, fix premature_mov_ending.mov, closes #451
bcoudurier
parents:
3286
diff
changeset
|
773 sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
774 sc->dref_id= dref_id; |
1845 | 775 |
776 st->codec->codec_tag = format; | |
1847
922180a45610
recommit of the change below after reverting earlier cosmetic-functional mix
michael
parents:
1846
diff
changeset
|
777 id = codec_get_id(codec_movaudio_tags, format); |
3253 | 778 if (id<=0 && (format&0xFFFF) == 'm'+('s'<<8)) |
2298 | 779 id = codec_get_id(codec_wav_tags, bswap_32(format)&0xFFFF); |
780 | |
1845 | 781 if (st->codec->codec_type != CODEC_TYPE_VIDEO && id > 0) { |
782 st->codec->codec_type = CODEC_TYPE_AUDIO; | |
783 } else if (st->codec->codec_type != CODEC_TYPE_AUDIO && /* do not overwrite codec type */ | |
3253 | 784 format && format != MKTAG('m','p','4','s')) { /* skip old asf mpeg4 tag */ |
1847
922180a45610
recommit of the change below after reverting earlier cosmetic-functional mix
michael
parents:
1846
diff
changeset
|
785 id = codec_get_id(codec_movvideo_tags, format); |
1845 | 786 if (id <= 0) |
787 id = codec_get_id(codec_bmp_tags, format); | |
788 if (id > 0) | |
789 st->codec->codec_type = CODEC_TYPE_VIDEO; | |
2969 | 790 else if(st->codec->codec_type == CODEC_TYPE_DATA){ |
791 id = codec_get_id(ff_codec_movsubtitle_tags, format); | |
792 if(id > 0) | |
793 st->codec->codec_type = CODEC_TYPE_SUBTITLE; | |
794 } | |
1845 | 795 } |
796 | |
2902 | 797 dprintf(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size, |
798 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff, | |
799 (format >> 24) & 0xff, st->codec->codec_type); | |
1845 | 800 |
801 if(st->codec->codec_type==CODEC_TYPE_VIDEO) { | |
3263 | 802 uint8_t codec_name[32]; |
803 unsigned int color_depth; | |
804 int color_greyscale; | |
805 | |
1845 | 806 st->codec->codec_id = id; |
807 get_be16(pb); /* version */ | |
808 get_be16(pb); /* revision level */ | |
809 get_be32(pb); /* vendor */ | |
810 get_be32(pb); /* temporal quality */ | |
2730 | 811 get_be32(pb); /* spatial quality */ |
1845 | 812 |
813 st->codec->width = get_be16(pb); /* width */ | |
814 st->codec->height = get_be16(pb); /* height */ | |
815 | |
816 get_be32(pb); /* horiz resolution */ | |
817 get_be32(pb); /* vert resolution */ | |
818 get_be32(pb); /* data size, always 0 */ | |
3264 | 819 get_be16(pb); /* frames per samples */ |
2044 | 820 |
3265 | 821 get_buffer(pb, codec_name, 32); /* codec name, pascal string */ |
1845 | 822 if (codec_name[0] <= 31) { |
823 memcpy(st->codec->codec_name, &codec_name[1],codec_name[0]); | |
824 st->codec->codec_name[codec_name[0]] = 0; | |
825 } | |
826 | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
827 st->codec->bits_per_coded_sample = get_be16(pb); /* depth */ |
1845 | 828 st->codec->color_table_id = get_be16(pb); /* colortable id */ |
3095
da04b574d131
set codec bps to grayscale bits, fix 256grey.mov
bcoudurier
parents:
3093
diff
changeset
|
829 dprintf(c->fc, "depth %d, ctab id %d\n", |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
830 st->codec->bits_per_coded_sample, st->codec->color_table_id); |
1845 | 831 /* figure out the palette situation */ |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
832 color_depth = st->codec->bits_per_coded_sample & 0x1F; |
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
833 color_greyscale = st->codec->bits_per_coded_sample & 0x20; |
1845 | 834 |
835 /* if the depth is 2, 4, or 8 bpp, file is palettized */ | |
836 if ((color_depth == 2) || (color_depth == 4) || | |
837 (color_depth == 8)) { | |
3257 | 838 /* for palette traversal */ |
839 unsigned int color_start, color_count, color_end; | |
840 unsigned char r, g, b; | |
841 | |
1845 | 842 if (color_greyscale) { |
3257 | 843 int color_index, color_dec; |
1845 | 844 /* compute the greyscale palette */ |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
845 st->codec->bits_per_coded_sample = color_depth; |
1845 | 846 color_count = 1 << color_depth; |
847 color_index = 255; | |
848 color_dec = 256 / (color_count - 1); | |
849 for (j = 0; j < color_count; j++) { | |
850 r = g = b = color_index; | |
851 c->palette_control.palette[j] = | |
852 (r << 16) | (g << 8) | (b); | |
853 color_index -= color_dec; | |
854 if (color_index < 0) | |
855 color_index = 0; | |
856 } | |
3179
5f56b694f9bf
according to specs, only color table id set to 0, have it in stsd, fix 4colors.mov
bcoudurier
parents:
3178
diff
changeset
|
857 } else if (st->codec->color_table_id) { |
3257 | 858 const uint8_t *color_table; |
1845 | 859 /* if flag bit 3 is set, use the default palette */ |
860 color_count = 1 << color_depth; | |
861 if (color_depth == 2) | |
862 color_table = ff_qt_default_palette_4; | |
863 else if (color_depth == 4) | |
864 color_table = ff_qt_default_palette_16; | |
865 else | |
866 color_table = ff_qt_default_palette_256; | |
867 | |
868 for (j = 0; j < color_count; j++) { | |
869 r = color_table[j * 4 + 0]; | |
870 g = color_table[j * 4 + 1]; | |
871 b = color_table[j * 4 + 2]; | |
872 c->palette_control.palette[j] = | |
873 (r << 16) | (g << 8) | (b); | |
874 } | |
875 } else { | |
876 /* load the palette from the file */ | |
877 color_start = get_be32(pb); | |
878 color_count = get_be16(pb); | |
879 color_end = get_be16(pb); | |
2809
17086a526938
Check sanity in the palette loading operation. The addresses a potential security risk in
melanson
parents:
2807
diff
changeset
|
880 if ((color_start <= 255) && |
17086a526938
Check sanity in the palette loading operation. The addresses a potential security risk in
melanson
parents:
2807
diff
changeset
|
881 (color_end <= 255)) { |
2810 | 882 for (j = color_start; j <= color_end; j++) { |
883 /* each R, G, or B component is 16 bits; | |
884 * only use the top 8 bits; skip alpha bytes | |
885 * up front */ | |
886 get_byte(pb); | |
887 get_byte(pb); | |
888 r = get_byte(pb); | |
889 get_byte(pb); | |
890 g = get_byte(pb); | |
891 get_byte(pb); | |
892 b = get_byte(pb); | |
893 get_byte(pb); | |
894 c->palette_control.palette[j] = | |
895 (r << 16) | (g << 8) | (b); | |
2809
17086a526938
Check sanity in the palette loading operation. The addresses a potential security risk in
melanson
parents:
2807
diff
changeset
|
896 } |
1845 | 897 } |
898 } | |
899 st->codec->palctrl = &c->palette_control; | |
900 st->codec->palctrl->palette_changed = 1; | |
901 } else | |
902 st->codec->palctrl = NULL; | |
903 } else if(st->codec->codec_type==CODEC_TYPE_AUDIO) { | |
3622 | 904 int bits_per_sample, flags; |
1845 | 905 uint16_t version = get_be16(pb); |
906 | |
907 st->codec->codec_id = id; | |
908 get_be16(pb); /* revision level */ | |
909 get_be32(pb); /* vendor */ | |
910 | |
911 st->codec->channels = get_be16(pb); /* channel count */ | |
1907 | 912 dprintf(c->fc, "audio channels %d\n", st->codec->channels); |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
913 st->codec->bits_per_coded_sample = get_be16(pb); /* sample size */ |
1845 | 914 |
3029
10abe8748ec2
use correct demux mechanism when audio compression id is -2, dv audio does not matter, demux partially qt_dv_pal_test.mov which does NOT use cid -2
bcoudurier
parents:
3027
diff
changeset
|
915 sc->audio_cid = get_be16(pb); |
1845 | 916 get_be16(pb); /* packet size = 0 */ |
917 | |
918 st->codec->sample_rate = ((get_be32(pb) >> 16)); | |
919 | |
3619
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
920 //Read QT version 1 fields. In version 0 these do not exist. |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
921 dprintf(c->fc, "version =%d, isom =%d\n",version,c->isom); |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
922 if(!c->isom) { |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
923 if(version==1) { |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
924 sc->samples_per_frame = get_be32(pb); |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
925 get_be32(pb); /* bytes per packet */ |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
926 sc->bytes_per_frame = get_be32(pb); |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
927 get_be32(pb); /* bytes per sample */ |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
928 } else if(version==2) { |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
929 get_be32(pb); /* sizeof struct only */ |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
930 st->codec->sample_rate = av_int2dbl(get_be64(pb)); /* float 64 */ |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
931 st->codec->channels = get_be32(pb); |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
932 get_be32(pb); /* always 0x7F000000 */ |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
933 st->codec->bits_per_coded_sample = get_be32(pb); /* bits per channel if sound is uncompressed */ |
3622 | 934 flags = get_be32(pb); /* lcpm format specific flag */ |
3620 | 935 sc->bytes_per_frame = get_be32(pb); /* bytes per audio packet if constant */ |
936 sc->samples_per_frame = get_be32(pb); /* lpcm frames per audio packet if constant */ | |
3625 | 937 if (format == MKTAG('l','p','c','m')) |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
938 st->codec->codec_id = mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags); |
3619
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
939 } |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
940 } |
bd4b7c8fec83
move version specific parsing code before codec specific code, will be needed
bcoudurier
parents:
3615
diff
changeset
|
941 |
1845 | 942 switch (st->codec->codec_id) { |
943 case CODEC_ID_PCM_S8: | |
944 case CODEC_ID_PCM_U8: | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
945 if (st->codec->bits_per_coded_sample == 16) |
1845 | 946 st->codec->codec_id = CODEC_ID_PCM_S16BE; |
947 break; | |
948 case CODEC_ID_PCM_S16LE: | |
949 case CODEC_ID_PCM_S16BE: | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
950 if (st->codec->bits_per_coded_sample == 8) |
1845 | 951 st->codec->codec_id = CODEC_ID_PCM_S8; |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
952 else if (st->codec->bits_per_coded_sample == 24) |
3621
0415fc41780a
keep original codec/fourcc endianness, fix XDCAMHD.mov
bcoudurier
parents:
3620
diff
changeset
|
953 st->codec->codec_id = |
0415fc41780a
keep original codec/fourcc endianness, fix XDCAMHD.mov
bcoudurier
parents:
3620
diff
changeset
|
954 st->codec->codec_id == CODEC_ID_PCM_S16BE ? |
0415fc41780a
keep original codec/fourcc endianness, fix XDCAMHD.mov
bcoudurier
parents:
3620
diff
changeset
|
955 CODEC_ID_PCM_S24BE : CODEC_ID_PCM_S24LE; |
1845 | 956 break; |
3036
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
957 /* set values for old format before stsd version 1 appeared */ |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
958 case CODEC_ID_MACE3: |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
959 sc->samples_per_frame = 6; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
960 sc->bytes_per_frame = 2*st->codec->channels; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
961 break; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
962 case CODEC_ID_MACE6: |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
963 sc->samples_per_frame = 6; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
964 sc->bytes_per_frame = 1*st->codec->channels; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
965 break; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
966 case CODEC_ID_ADPCM_IMA_QT: |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
967 sc->samples_per_frame = 64; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
968 sc->bytes_per_frame = 34*st->codec->channels; |
62181fbfc128
remove messy and not always correct chunk size workaround, use correct values instead
bcoudurier
parents:
3034
diff
changeset
|
969 break; |
3252
f4fcd39c5d7f
set gsm default frame size and bytes per frame, needed by old qt format, fix sample-gsm-8000.mov
bcoudurier
parents:
3245
diff
changeset
|
970 case CODEC_ID_GSM: |
f4fcd39c5d7f
set gsm default frame size and bytes per frame, needed by old qt format, fix sample-gsm-8000.mov
bcoudurier
parents:
3245
diff
changeset
|
971 sc->samples_per_frame = 160; |
f4fcd39c5d7f
set gsm default frame size and bytes per frame, needed by old qt format, fix sample-gsm-8000.mov
bcoudurier
parents:
3245
diff
changeset
|
972 sc->bytes_per_frame = 33; |
f4fcd39c5d7f
set gsm default frame size and bytes per frame, needed by old qt format, fix sample-gsm-8000.mov
bcoudurier
parents:
3245
diff
changeset
|
973 break; |
1845 | 974 default: |
975 break; | |
976 } | |
977 | |
978 bits_per_sample = av_get_bits_per_sample(st->codec->codec_id); | |
979 if (bits_per_sample) { | |
3908
1d3d17de20ba
Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents:
3796
diff
changeset
|
980 st->codec->bits_per_coded_sample = bits_per_sample; |
1845 | 981 sc->sample_size = (bits_per_sample >> 3) * st->codec->channels; |
982 } | |
2972
bc330130bdce
Set subtitle codec id correctly, i hope this does not break anything.
michael
parents:
2970
diff
changeset
|
983 } else if(st->codec->codec_type==CODEC_TYPE_SUBTITLE){ |
4192
a48a6a414dfe
Read extradata (justification, colors, fonts, etc) for mov/mp4 timed text
conrad
parents:
4184
diff
changeset
|
984 // ttxt stsd contains display flags, justification, background |
a48a6a414dfe
Read extradata (justification, colors, fonts, etc) for mov/mp4 timed text
conrad
parents:
4184
diff
changeset
|
985 // color, fonts, and default styles, so fake an atom to read it |
a48a6a414dfe
Read extradata (justification, colors, fonts, etc) for mov/mp4 timed text
conrad
parents:
4184
diff
changeset
|
986 MOVAtom fake_atom = { .size = size - (url_ftell(pb) - start_pos) }; |
a48a6a414dfe
Read extradata (justification, colors, fonts, etc) for mov/mp4 timed text
conrad
parents:
4184
diff
changeset
|
987 mov_read_glbl(c, pb, fake_atom); |
2972
bc330130bdce
Set subtitle codec id correctly, i hope this does not break anything.
michael
parents:
2970
diff
changeset
|
988 st->codec->codec_id= id; |
4202 | 989 st->codec->width = sc->width; |
990 st->codec->height = sc->height; | |
1845 | 991 } else { |
992 /* other codec type, just skip (rtp, mp4s, tmcd ...) */ | |
993 url_fskip(pb, size - (url_ftell(pb) - start_pos)); | |
994 } | |
995 /* this will read extra atoms at the end (wave, alac, damr, avcC, SMI ...) */ | |
996 a.size = size - (url_ftell(pb) - start_pos); | |
2806
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
997 if (a.size > 8) { |
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
998 if (mov_read_default(c, pb, a) < 0) |
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
999 return -1; |
1ce39cda4a59
check mov_read_default return value where appropriate, patch by takis, fix issue 285
bcoudurier
parents:
2794
diff
changeset
|
1000 } else if (a.size > 0) |
1845 | 1001 url_fskip(pb, a.size); |
1002 } | |
1003 | |
3084 | 1004 if(st->codec->codec_type==CODEC_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1) |
1845 | 1005 st->codec->sample_rate= sc->time_scale; |
1006 | |
1007 /* special codec parameters handling */ | |
1008 switch (st->codec->codec_id) { | |
4206 | 1009 #if CONFIG_DV_DEMUXER |
1845 | 1010 case CODEC_ID_DVAUDIO: |
4406
146d6083662b
Replace the calls to the deprecated av_alloc_format_context() with
stefano
parents:
4399
diff
changeset
|
1011 c->dv_fctx = avformat_alloc_context(); |
1845 | 1012 c->dv_demux = dv_init_demux(c->dv_fctx); |
1013 if (!c->dv_demux) { | |
1014 av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n"); | |
1015 return -1; | |
1016 } | |
1017 sc->dv_audio_container = 1; | |
1018 st->codec->codec_id = CODEC_ID_PCM_S16LE; | |
1019 break; | |
1020 #endif | |
1021 /* no ifdef since parameters are always those */ | |
3245
9f25267bee44
demux qcelp, so this can work with soc decoder and stream copy
bcoudurier
parents:
3242
diff
changeset
|
1022 case CODEC_ID_QCELP: |
4056
a6a5fe159af7
Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
4054
diff
changeset
|
1023 st->codec->frame_size= 160; |
4054 | 1024 st->codec->channels= 1; /* really needed */ |
4056
a6a5fe159af7
Commit last ok'ed parts of QCELP decoder and enable it.
vitor
parents:
4054
diff
changeset
|
1025 break; |
3256
b09eff5b0e89
parser should not be needed anymore, merge cases and set frame size for amr too
bcoudurier
parents:
3255
diff
changeset
|
1026 case CODEC_ID_AMR_NB: |
3933 | 1027 case CODEC_ID_AMR_WB: |
3258 | 1028 st->codec->frame_size= sc->samples_per_frame; |
1845 | 1029 st->codec->channels= 1; /* really needed */ |
3974
a8383d02c686
set sample rate for amr to allow stream copy since no decoder is present,
bcoudurier
parents:
3973
diff
changeset
|
1030 /* force sample rate for amr, stsd in 3gp does not store sample rate */ |
3989 | 1031 if (st->codec->codec_id == CODEC_ID_AMR_NB) |
3974
a8383d02c686
set sample rate for amr to allow stream copy since no decoder is present,
bcoudurier
parents:
3973
diff
changeset
|
1032 st->codec->sample_rate = 8000; |
3989 | 1033 else if (st->codec->codec_id == CODEC_ID_AMR_WB) |
1034 st->codec->sample_rate = 16000; | |
1845 | 1035 break; |
1036 case CODEC_ID_MP2: | |
1953
edfd6b33d1f6
activate parser on MP3 id, fix [A-Destiny]_Konjiki_no_Gash_Bell_-_65_[71EE362C].mp4
bcoudurier
parents:
1950
diff
changeset
|
1037 case CODEC_ID_MP3: |
1845 | 1038 st->codec->codec_type = CODEC_TYPE_AUDIO; /* force type after stsd for m1a hdlr */ |
2023 | 1039 st->need_parsing = AVSTREAM_PARSE_FULL; |
1845 | 1040 break; |
3187 | 1041 case CODEC_ID_GSM: |
2299
fe59c768ecf7
set block align to stsd audio v2 bytes per frame for adpcm ms and ima wav, fix surge-2-16-L-ms11.mov and surge-2-16-L-ms02.mov
bcoudurier
parents:
2298
diff
changeset
|
1042 case CODEC_ID_ADPCM_MS: |
fe59c768ecf7
set block align to stsd audio v2 bytes per frame for adpcm ms and ima wav, fix surge-2-16-L-ms11.mov and surge-2-16-L-ms02.mov
bcoudurier
parents:
2298
diff
changeset
|
1043 case CODEC_ID_ADPCM_IMA_WAV: |
fe59c768ecf7
set block align to stsd audio v2 bytes per frame for adpcm ms and ima wav, fix surge-2-16-L-ms11.mov and surge-2-16-L-ms02.mov
bcoudurier
parents:
2298
diff
changeset
|
1044 st->codec->block_align = sc->bytes_per_frame; |
fe59c768ecf7
set block align to stsd audio v2 bytes per frame for adpcm ms and ima wav, fix surge-2-16-L-ms11.mov and surge-2-16-L-ms02.mov
bcoudurier
parents:
2298
diff
changeset
|
1045 break; |
3242 | 1046 case CODEC_ID_ALAC: |
4122
30262468fff4
set alac channels from extradata, fix alac mono in m4a
bcoudurier
parents:
4116
diff
changeset
|
1047 if (st->codec->extradata_size == 36) { |
4123
e536841c1aeb
cosmetics, remove useless parenthesis and whitespaces
bcoudurier
parents:
4122
diff
changeset
|
1048 st->codec->frame_size = AV_RB32(st->codec->extradata+12); |
e536841c1aeb
cosmetics, remove useless parenthesis and whitespaces
bcoudurier
parents:
4122
diff
changeset
|
1049 st->codec->channels = AV_RB8 (st->codec->extradata+21); |
4122
30262468fff4
set alac channels from extradata, fix alac mono in m4a
bcoudurier
parents:
4116
diff
changeset
|
1050 } |
3242 | 1051 break; |
1845 | 1052 default: |
1053 break; | |
1054 } | |
1055 | |
1056 return 0; | |
1057 } | |
1058 | |
4079 | 1059 static int mov_read_stsc(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1060 { |
1061 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 1062 MOVStreamContext *sc = st->priv_data; |
1845 | 1063 unsigned int i, entries; |
1064 | |
1065 get_byte(pb); /* version */ | |
3145 | 1066 get_be24(pb); /* flags */ |
1845 | 1067 |
1068 entries = get_be32(pb); | |
1069 | |
4412 | 1070 if(entries >= UINT_MAX / sizeof(*sc->stsc_data)) |
1845 | 1071 return -1; |
1072 | |
2044 | 1073 dprintf(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries); |
1074 | |
4412 | 1075 sc->stsc_count = entries; |
1076 sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data)); | |
1077 if (!sc->stsc_data) | |
1845 | 1078 return -1; |
1079 for(i=0; i<entries; i++) { | |
4412 | 1080 sc->stsc_data[i].first = get_be32(pb); |
1081 sc->stsc_data[i].count = get_be32(pb); | |
1082 sc->stsc_data[i].id = get_be32(pb); | |
1845 | 1083 } |
1084 return 0; | |
1085 } | |
1086 | |
4079 | 1087 static int mov_read_stss(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1088 { |
1089 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 1090 MOVStreamContext *sc = st->priv_data; |
1845 | 1091 unsigned int i, entries; |
1092 | |
1093 get_byte(pb); /* version */ | |
3145 | 1094 get_be24(pb); /* flags */ |
1845 | 1095 |
1096 entries = get_be32(pb); | |
1097 | |
2030 | 1098 if(entries >= UINT_MAX / sizeof(int)) |
1845 | 1099 return -1; |
1100 | |
1101 sc->keyframe_count = entries; | |
2044 | 1102 |
1103 dprintf(c->fc, "keyframe_count = %d\n", sc->keyframe_count); | |
1104 | |
2030 | 1105 sc->keyframes = av_malloc(entries * sizeof(int)); |
1845 | 1106 if (!sc->keyframes) |
1107 return -1; | |
1108 for(i=0; i<entries; i++) { | |
1109 sc->keyframes[i] = get_be32(pb); | |
2044 | 1110 //dprintf(c->fc, "keyframes[]=%d\n", sc->keyframes[i]); |
1845 | 1111 } |
1112 return 0; | |
1113 } | |
1114 | |
4079 | 1115 static int mov_read_stsz(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1116 { |
1117 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 1118 MOVStreamContext *sc = st->priv_data; |
1845 | 1119 unsigned int i, entries, sample_size; |
1120 | |
1121 get_byte(pb); /* version */ | |
3145 | 1122 get_be24(pb); /* flags */ |
1845 | 1123 |
1124 sample_size = get_be32(pb); | |
1125 if (!sc->sample_size) /* do not overwrite value computed in stsd */ | |
1126 sc->sample_size = sample_size; | |
1127 entries = get_be32(pb); | |
2030 | 1128 if(entries >= UINT_MAX / sizeof(int)) |
1845 | 1129 return -1; |
1130 | |
1131 sc->sample_count = entries; | |
1132 if (sample_size) | |
1133 return 0; | |
1134 | |
2044 | 1135 dprintf(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, sc->sample_count); |
1136 | |
2030 | 1137 sc->sample_sizes = av_malloc(entries * sizeof(int)); |
1845 | 1138 if (!sc->sample_sizes) |
1139 return -1; | |
3156
487b1979f195
remove useless debug print since now mov_build_index will do
bcoudurier
parents:
3155
diff
changeset
|
1140 for(i=0; i<entries; i++) |
1845 | 1141 sc->sample_sizes[i] = get_be32(pb); |
1142 return 0; | |
1143 } | |
1144 | |
4079 | 1145 static int mov_read_stts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1146 { |
1147 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 1148 MOVStreamContext *sc = st->priv_data; |
1845 | 1149 unsigned int i, entries; |
1150 int64_t duration=0; | |
1151 int64_t total_sample_count=0; | |
1152 | |
1153 get_byte(pb); /* version */ | |
3145 | 1154 get_be24(pb); /* flags */ |
1845 | 1155 entries = get_be32(pb); |
4079 | 1156 if(entries >= UINT_MAX / sizeof(*sc->stts_data)) |
1845 | 1157 return -1; |
1158 | |
1159 sc->stts_count = entries; | |
4079 | 1160 sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data)); |
2807
5bf4b9df2794
return error if malloc failed, found by takis, fix issue 286
bcoudurier
parents:
2806
diff
changeset
|
1161 if (!sc->stts_data) |
5bf4b9df2794
return error if malloc failed, found by takis, fix issue 286
bcoudurier
parents:
2806
diff
changeset
|
1162 return -1; |
2044 | 1163 dprintf(c->fc, "track[%i].stts.entries = %i\n", c->fc->nb_streams-1, entries); |
1845 | 1164 |
1165 for(i=0; i<entries; i++) { | |
1166 int sample_duration; | |
1167 int sample_count; | |
1168 | |
1169 sample_count=get_be32(pb); | |
1170 sample_duration = get_be32(pb); | |
1171 sc->stts_data[i].count= sample_count; | |
1172 sc->stts_data[i].duration= sample_duration; | |
1173 | |
4242 | 1174 sc->time_rate= av_gcd(sc->time_rate, sample_duration); |
1845 | 1175 |
1907 | 1176 dprintf(c->fc, "sample_count=%d, sample_duration=%d\n",sample_count,sample_duration); |
1845 | 1177 |
1178 duration+=(int64_t)sample_duration*sample_count; | |
1179 total_sample_count+=sample_count; | |
1180 } | |
1181 | |
1182 st->nb_frames= total_sample_count; | |
1183 if(duration) | |
1184 st->duration= duration; | |
1185 return 0; | |
1186 } | |
1187 | |
4079 | 1188 static int mov_read_ctts(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1189 { |
1190 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; | |
2006 | 1191 MOVStreamContext *sc = st->priv_data; |
1845 | 1192 unsigned int i, entries; |
1193 | |
1194 get_byte(pb); /* version */ | |
3145 | 1195 get_be24(pb); /* flags */ |
1845 | 1196 entries = get_be32(pb); |
4079 | 1197 if(entries >= UINT_MAX / sizeof(*sc->ctts_data)) |
1845 | 1198 return -1; |
1199 | |
1200 sc->ctts_count = entries; | |
4079 | 1201 sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data)); |
2807
5bf4b9df2794
return error if malloc failed, found by takis, fix issue 286
bcoudurier
parents:
2806
diff
changeset
|
1202 if (!sc->ctts_data) |
5bf4b9df2794
return error if malloc failed, found by takis, fix issue 286
bcoudurier
parents:
2806
diff
changeset
|
1203 return -1; |
1907 | 1204 dprintf(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries); |
1845 | 1205 |
1206 for(i=0; i<entries; i++) { | |
1207 int count =get_be32(pb); | |
1208 int duration =get_be32(pb); | |
1209 | |
1210 if (duration < 0) { | |
3956
8bdecea89071
support negative ctts in some way, unset wrong dts
bcoudurier
parents:
3935
diff
changeset
|
1211 sc->wrong_dts = 1; |
8bdecea89071
support negative ctts in some way, unset wrong dts
bcoudurier
parents:
3935
diff
changeset
|
1212 st->codec->has_b_frames = 1; |
1845 | 1213 } |
1214 sc->ctts_data[i].count = count; | |
1215 sc->ctts_data[i].duration= duration; | |
1216 | |
4242 | 1217 sc->time_rate= av_gcd(sc->time_rate, FFABS(duration)); |
1845 | 1218 } |
1219 return 0; | |
1220 } | |
1221 | |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1222 static void mov_build_index(MOVContext *mov, AVStream *st) |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1223 { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1224 MOVStreamContext *sc = st->priv_data; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3967
diff
changeset
|
1225 int64_t current_offset; |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1226 int64_t current_dts = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1227 unsigned int stts_index = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1228 unsigned int stsc_index = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1229 unsigned int stss_index = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1230 unsigned int i, j; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1231 |
4399
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1232 /* adjust first dts according to edit list */ |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1233 if (sc->time_offset) { |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1234 assert(sc->time_offset % sc->time_rate == 0); |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1235 current_dts = - (sc->time_offset / sc->time_rate); |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1236 } |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1237 |
3178
73b7ef886091
Only use chunk demuxing for old uncompressed audio mechanism specified by stts.
bcoudurier
parents:
3175
diff
changeset
|
1238 /* only use old uncompressed audio chunk demuxing when stts specifies it */ |
73b7ef886091
Only use chunk demuxing for old uncompressed audio mechanism specified by stts.
bcoudurier
parents:
3175
diff
changeset
|
1239 if (!(st->codec->codec_type == CODEC_TYPE_AUDIO && |
73b7ef886091
Only use chunk demuxing for old uncompressed audio mechanism specified by stts.
bcoudurier
parents:
3175
diff
changeset
|
1240 sc->stts_count == 1 && sc->stts_data[0].duration == 1)) { |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1241 unsigned int current_sample = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1242 unsigned int stts_sample = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1243 unsigned int keyframe, sample_size; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1244 unsigned int distance = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1245 int key_off = sc->keyframes && sc->keyframes[0] == 1; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1246 |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1247 st->nb_frames = sc->sample_count; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1248 for (i = 0; i < sc->chunk_count; i++) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1249 current_offset = sc->chunk_offsets[i]; |
4412 | 1250 if (stsc_index + 1 < sc->stsc_count && |
1251 i + 1 == sc->stsc_data[stsc_index + 1].first) | |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1252 stsc_index++; |
4412 | 1253 for (j = 0; j < sc->stsc_data[stsc_index].count; j++) { |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1254 if (current_sample >= sc->sample_count) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1255 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n"); |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1256 goto out; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1257 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1258 keyframe = !sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index]; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1259 if (keyframe) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1260 distance = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1261 if (stss_index + 1 < sc->keyframe_count) |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1262 stss_index++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1263 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1264 sample_size = sc->sample_size > 0 ? sc->sample_size : sc->sample_sizes[current_sample]; |
3299
80a497804aa8
demux all stsd ids if codec is the same, fix premature_mov_ending.mov, closes #451
bcoudurier
parents:
3286
diff
changeset
|
1265 if(sc->pseudo_stream_id == -1 || |
4412 | 1266 sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) { |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1267 av_add_index_entry(st, current_offset, current_dts, sample_size, distance, |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1268 keyframe ? AVINDEX_KEYFRAME : 0); |
3301
11b6da5ffe78
only print debug info when sample is actually added
bcoudurier
parents:
3300
diff
changeset
|
1269 dprintf(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " |
11b6da5ffe78
only print debug info when sample is actually added
bcoudurier
parents:
3300
diff
changeset
|
1270 "size %d, distance %d, keyframe %d\n", st->index, current_sample, |
11b6da5ffe78
only print debug info when sample is actually added
bcoudurier
parents:
3300
diff
changeset
|
1271 current_offset, current_dts, sample_size, distance, keyframe); |
11b6da5ffe78
only print debug info when sample is actually added
bcoudurier
parents:
3300
diff
changeset
|
1272 } |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1273 current_offset += sample_size; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1274 assert(sc->stts_data[stts_index].duration % sc->time_rate == 0); |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1275 current_dts += sc->stts_data[stts_index].duration / sc->time_rate; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1276 distance++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1277 stts_sample++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1278 current_sample++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1279 if (stts_index + 1 < sc->stts_count && stts_sample == sc->stts_data[stts_index].count) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1280 stts_sample = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1281 stts_index++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1282 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1283 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1284 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1285 } else { /* read whole chunk */ |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1286 unsigned int chunk_samples, chunk_size, chunk_duration; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1287 unsigned int frames = 1; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1288 for (i = 0; i < sc->chunk_count; i++) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1289 current_offset = sc->chunk_offsets[i]; |
4412 | 1290 if (stsc_index + 1 < sc->stsc_count && |
1291 i + 1 == sc->stsc_data[stsc_index + 1].first) | |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1292 stsc_index++; |
4412 | 1293 chunk_samples = sc->stsc_data[stsc_index].count; |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1294 /* get chunk size, beware of alaw/ulaw/mace */ |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1295 if (sc->samples_per_frame > 0 && |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1296 (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) { |
3255 | 1297 if (sc->samples_per_frame < 160) |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1298 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1299 else { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1300 chunk_size = sc->bytes_per_frame; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1301 frames = chunk_samples / sc->samples_per_frame; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1302 chunk_samples = sc->samples_per_frame; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1303 } |
3173
cb3eb255f80d
sample size to 1 might happen for data, fix GMCMidiaASX.mov, fallback is better than failing
bcoudurier
parents:
3170
diff
changeset
|
1304 } else |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1305 chunk_size = chunk_samples * sc->sample_size; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1306 for (j = 0; j < frames; j++) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1307 av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1308 /* get chunk duration */ |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1309 chunk_duration = 0; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1310 while (chunk_samples > 0) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1311 if (chunk_samples < sc->stts_data[stts_index].count) { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1312 chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1313 sc->stts_data[stts_index].count -= chunk_samples; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1314 break; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1315 } else { |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1316 chunk_duration += sc->stts_data[stts_index].duration * chunk_samples; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1317 chunk_samples -= sc->stts_data[stts_index].count; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1318 if (stts_index + 1 < sc->stts_count) |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1319 stts_index++; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1320 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1321 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1322 current_offset += sc->bytes_per_frame; |
3167 | 1323 dprintf(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", " |
1324 "size %d, duration %d\n", st->index, i, current_offset, current_dts, | |
1325 chunk_size, chunk_duration); | |
3154
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1326 assert(chunk_duration % sc->time_rate == 0); |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1327 current_dts += chunk_duration / sc->time_rate; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1328 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1329 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1330 } |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1331 out: |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1332 /* adjust sample count to avindex entries */ |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1333 sc->sample_count = st->nb_index_entries; |
01f6f3c905db
move mov_build_index before mov_read_trak to avoid useless declaration
bcoudurier
parents:
3153
diff
changeset
|
1334 } |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1335 |
4079 | 1336 static int mov_read_trak(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1337 { |
1338 AVStream *st; | |
1339 MOVStreamContext *sc; | |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1340 int ret; |
1845 | 1341 |
1342 st = av_new_stream(c->fc, c->fc->nb_streams); | |
3162 | 1343 if (!st) return AVERROR(ENOMEM); |
1845 | 1344 sc = av_mallocz(sizeof(MOVStreamContext)); |
3161
60be75aa8c47
cannot free AVStream like this, and return ENOMEM
bcoudurier
parents:
3160
diff
changeset
|
1345 if (!sc) return AVERROR(ENOMEM); |
1845 | 1346 |
1347 st->priv_data = sc; | |
1348 st->codec->codec_type = CODEC_TYPE_DATA; | |
4197
84251a788a67
move ffindex set before mov_read_default so it can be used in functions
bcoudurier
parents:
4192
diff
changeset
|
1349 sc->ffindex = st->index; |
1845 | 1350 |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1351 if ((ret = mov_read_default(c, pb, atom)) < 0) |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1352 return ret; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1353 |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1354 /* sanity checks */ |
4412 | 1355 if(sc->chunk_count && (!sc->stts_count || !sc->stsc_count || |
3191
68c7fd8c44ca
support mp4 fragmented files without any samples in the moov atom
bcoudurier
parents:
3190
diff
changeset
|
1356 (!sc->sample_size && !sc->sample_count))){ |
3180 | 1357 av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n", |
1358 st->index); | |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1359 sc->sample_count = 0; //ignore track |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1360 return 0; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1361 } |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1362 if(!sc->time_rate) |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1363 sc->time_rate=1; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1364 if(!sc->time_scale) |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1365 sc->time_scale= c->time_scale; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1366 av_set_pts_info(st, 64, sc->time_rate, sc->time_scale); |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1367 |
3245
9f25267bee44
demux qcelp, so this can work with soc decoder and stream copy
bcoudurier
parents:
3242
diff
changeset
|
1368 if (st->codec->codec_type == CODEC_TYPE_AUDIO && |
4454
7d1460900c59
fix frame size, time rate is not stts duration anymore with time offset
bcoudurier
parents:
4453
diff
changeset
|
1369 !st->codec->frame_size && sc->stts_count == 1) { |
7d1460900c59
fix frame size, time rate is not stts duration anymore with time offset
bcoudurier
parents:
4453
diff
changeset
|
1370 st->codec->frame_size = av_rescale(sc->stts_data[0].duration, |
7d1460900c59
fix frame size, time rate is not stts duration anymore with time offset
bcoudurier
parents:
4453
diff
changeset
|
1371 st->codec->sample_rate, sc->time_scale); |
7d1460900c59
fix frame size, time rate is not stts duration anymore with time offset
bcoudurier
parents:
4453
diff
changeset
|
1372 dprintf(c->fc, "frame size %d\n", st->codec->frame_size); |
7d1460900c59
fix frame size, time rate is not stts duration anymore with time offset
bcoudurier
parents:
4453
diff
changeset
|
1373 } |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1374 |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1375 if(st->duration != AV_NOPTS_VALUE){ |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1376 assert(st->duration % sc->time_rate == 0); |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1377 st->duration /= sc->time_rate; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1378 } |
4197
84251a788a67
move ffindex set before mov_read_default so it can be used in functions
bcoudurier
parents:
4192
diff
changeset
|
1379 |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1380 mov_build_index(c, st); |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1381 |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1382 if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) { |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1383 if (url_fopen(&sc->pb, sc->drefs[sc->dref_id-1].path, URL_RDONLY) < 0) |
3182 | 1384 av_log(c->fc, AV_LOG_ERROR, "stream %d, error opening file %s: %s\n", |
1385 st->index, sc->drefs[sc->dref_id-1].path, strerror(errno)); | |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1386 } else |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1387 sc->pb = c->fc->pb; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1388 |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1389 switch (st->codec->codec_id) { |
4206 | 1390 #if CONFIG_H261_DECODER |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1391 case CODEC_ID_H261: |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1392 #endif |
4206 | 1393 #if CONFIG_H263_DECODER |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1394 case CODEC_ID_H263: |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1395 #endif |
4206 | 1396 #if CONFIG_MPEG4_DECODER |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1397 case CODEC_ID_MPEG4: |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1398 #endif |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1399 st->codec->width= 0; /* let decoder init width/height */ |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1400 st->codec->height= 0; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1401 break; |
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1402 } |
3155 | 1403 |
1404 /* Do not need those anymore. */ | |
1405 av_freep(&sc->chunk_offsets); | |
4412 | 1406 av_freep(&sc->stsc_data); |
3155 | 1407 av_freep(&sc->sample_sizes); |
1408 av_freep(&sc->keyframes); | |
1409 av_freep(&sc->stts_data); | |
1410 | |
3153
4ded3fdf5c7c
move specific end treatment when trak is detected, will be needed for fragments
bcoudurier
parents:
3145
diff
changeset
|
1411 return 0; |
1845 | 1412 } |
1413 | |
4079 | 1414 static int mov_read_ilst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1415 { |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1416 int ret; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1417 c->itunes_metadata = 1; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1418 ret = mov_read_default(c, pb, atom); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1419 c->itunes_metadata = 0; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1420 return ret; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1421 } |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1422 |
4079 | 1423 static int mov_read_meta(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1424 { |
4044
5d5238798d59
decrease atom size, fix broken files missing version/flags
bcoudurier
parents:
4033
diff
changeset
|
1425 url_fskip(pb, 4); // version + flags |
5d5238798d59
decrease atom size, fix broken files missing version/flags
bcoudurier
parents:
4033
diff
changeset
|
1426 atom.size -= 4; |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1427 return mov_read_default(c, pb, atom); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1428 } |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1429 |
4079 | 1430 static int mov_read_trkn(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1431 { |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1432 get_be32(pb); // type |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1433 get_be32(pb); // unknown |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1434 c->fc->track = get_be32(pb); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1435 dprintf(c->fc, "%.4s %d\n", (char*)&atom.type, c->fc->track); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1436 return 0; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1437 } |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1438 |
4079 | 1439 static int mov_read_udta_string(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
2296
0cfc556604e3
fill title, author, copyright and comment fields by parsing udta atom
benoit
parents:
2164
diff
changeset
|
1440 { |
4028 | 1441 char *str = NULL; |
1442 int size; | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1443 uint16_t str_size; |
2296
0cfc556604e3
fill title, author, copyright and comment fields by parsing udta atom
benoit
parents:
2164
diff
changeset
|
1444 |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1445 if (c->itunes_metadata) { |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1446 int data_size = get_be32(pb); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1447 int tag = get_le32(pb); |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1448 if (tag == MKTAG('d','a','t','a')) { |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1449 get_be32(pb); // type |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1450 get_be32(pb); // unknown |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1451 str_size = data_size - 16; |
4369
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1452 atom.size -= 16; |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1453 } else return 0; |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1454 } else { |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1455 str_size = get_be16(pb); // string length |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1456 get_be16(pb); // language |
4369
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1457 atom.size -= 4; |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1458 } |
4028 | 1459 switch (atom.type) { |
1460 case MKTAG(0xa9,'n','a','m'): | |
1461 str = c->fc->title; size = sizeof(c->fc->title); break; | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1462 case MKTAG(0xa9,'A','R','T'): |
4028 | 1463 case MKTAG(0xa9,'w','r','t'): |
1464 str = c->fc->author; size = sizeof(c->fc->author); break; | |
1465 case MKTAG(0xa9,'c','p','y'): | |
1466 str = c->fc->copyright; size = sizeof(c->fc->copyright); break; | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1467 case MKTAG(0xa9,'c','m','t'): |
4028 | 1468 case MKTAG(0xa9,'i','n','f'): |
1469 str = c->fc->comment; size = sizeof(c->fc->comment); break; | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1470 case MKTAG(0xa9,'a','l','b'): |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1471 str = c->fc->album; size = sizeof(c->fc->album); break; |
4028 | 1472 } |
1473 if (!str) | |
1474 return 0; | |
4369
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1475 if (atom.size < 0) |
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1476 return -1; |
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1477 |
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1478 get_buffer(pb, str, FFMIN3(size, str_size, atom.size)); |
329080adea79
prevent reading more than container atom size, fix broken file broken_by_rev15830.MOV, fix #818
bcoudurier
parents:
4290
diff
changeset
|
1479 dprintf(c->fc, "%.4s %s %d %lld\n", (char*)&atom.type, str, str_size, atom.size); |
2296
0cfc556604e3
fill title, author, copyright and comment fields by parsing udta atom
benoit
parents:
2164
diff
changeset
|
1480 return 0; |
0cfc556604e3
fill title, author, copyright and comment fields by parsing udta atom
benoit
parents:
2164
diff
changeset
|
1481 } |
0cfc556604e3
fill title, author, copyright and comment fields by parsing udta atom
benoit
parents:
2164
diff
changeset
|
1482 |
4079 | 1483 static int mov_read_tkhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1484 { |
3595 | 1485 int i; |
1486 int width; | |
1487 int height; | |
1488 int64_t disp_transform[2]; | |
1489 int display_matrix[3][2]; | |
1845 | 1490 AVStream *st = c->fc->streams[c->fc->nb_streams-1]; |
4202 | 1491 MOVStreamContext *sc = st->priv_data; |
1845 | 1492 int version = get_byte(pb); |
1493 | |
3145 | 1494 get_be24(pb); /* flags */ |
1845 | 1495 /* |
1496 MOV_TRACK_ENABLED 0x0001 | |
1497 MOV_TRACK_IN_MOVIE 0x0002 | |
1498 MOV_TRACK_IN_PREVIEW 0x0004 | |
1499 MOV_TRACK_IN_POSTER 0x0008 | |
1500 */ | |
1501 | |
1502 if (version == 1) { | |
1503 get_be64(pb); | |
1504 get_be64(pb); | |
1505 } else { | |
1506 get_be32(pb); /* creation time */ | |
1507 get_be32(pb); /* modification time */ | |
1508 } | |
1509 st->id = (int)get_be32(pb); /* track id (NOT 0 !)*/ | |
1510 get_be32(pb); /* reserved */ | |
4453
f9ab71b3ace7
do not set start time to 0, it is not the case with elst time offset
bcoudurier
parents:
4447
diff
changeset
|
1511 |
3167 | 1512 /* highlevel (considering edits) duration in movie timebase */ |
1513 (version == 1) ? get_be64(pb) : get_be32(pb); | |
1845 | 1514 get_be32(pb); /* reserved */ |
1515 get_be32(pb); /* reserved */ | |
1516 | |
1517 get_be16(pb); /* layer */ | |
1518 get_be16(pb); /* alternate group */ | |
1519 get_be16(pb); /* volume */ | |
1520 get_be16(pb); /* reserved */ | |
1521 | |
3595 | 1522 //read in the display matrix (outlined in ISO 14496-12, Section 6.2.2) |
1523 // they're kept in fixed point format through all calculations | |
1524 // ignore u,v,z b/c we don't need the scale factor to calc aspect ratio | |
1525 for (i = 0; i < 3; i++) { | |
1526 display_matrix[i][0] = get_be32(pb); // 16.16 fixed point | |
1527 display_matrix[i][1] = get_be32(pb); // 16.16 fixed point | |
1528 get_be32(pb); // 2.30 fixed point (not used) | |
1529 } | |
1530 | |
1531 width = get_be32(pb); // 16.16 fixed point track width | |
1532 height = get_be32(pb); // 16.16 fixed point track height | |
4202 | 1533 sc->width = width >> 16; |
1534 sc->height = height >> 16; | |
1845 | 1535 |
3595 | 1536 //transform the display width/height according to the matrix |
1537 // skip this if the display matrix is the default identity matrix | |
1538 // to keep the same scale, use [width height 1<<16] | |
1539 if (width && height && | |
1540 (display_matrix[0][0] != 65536 || display_matrix[0][1] || | |
1541 display_matrix[1][0] || display_matrix[1][1] != 65536 || | |
1542 display_matrix[2][0] || display_matrix[2][1])) { | |
1543 for (i = 0; i < 2; i++) | |
1544 disp_transform[i] = | |
1545 (int64_t) width * display_matrix[0][i] + | |
1546 (int64_t) height * display_matrix[1][i] + | |
1547 ((int64_t) display_matrix[2][i] << 16); | |
1845 | 1548 |
3595 | 1549 //sample aspect ratio is new width/height divided by old width/height |
3759
27537074f2a9
convert every muxer/demuxer to write/read sample_aspect_ratio from/to
aurel
parents:
3751
diff
changeset
|
1550 st->sample_aspect_ratio = av_d2q( |
3595 | 1551 ((double) disp_transform[0] * height) / |
1552 ((double) disp_transform[1] * width), INT_MAX); | |
1553 } | |
1845 | 1554 return 0; |
1555 } | |
1556 | |
4079 | 1557 static int mov_read_tfhd(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
3169 | 1558 { |
1559 MOVFragment *frag = &c->fragment; | |
1560 MOVTrackExt *trex = NULL; | |
1561 int flags, track_id, i; | |
1562 | |
1563 get_byte(pb); /* version */ | |
1564 flags = get_be24(pb); | |
1565 | |
1566 track_id = get_be32(pb); | |
1567 if (!track_id || track_id > c->fc->nb_streams) | |
1568 return -1; | |
1569 frag->track_id = track_id; | |
1570 for (i = 0; i < c->trex_count; i++) | |
1571 if (c->trex_data[i].track_id == frag->track_id) { | |
1572 trex = &c->trex_data[i]; | |
1573 break; | |
1574 } | |
1575 if (!trex) { | |
1576 av_log(c->fc, AV_LOG_ERROR, "could not find corresponding trex\n"); | |
1577 return -1; | |
1578 } | |
1579 | |
1580 if (flags & 0x01) frag->base_data_offset = get_be64(pb); | |
1581 else frag->base_data_offset = frag->moof_offset; | |
1582 if (flags & 0x02) frag->stsd_id = get_be32(pb); | |
1583 else frag->stsd_id = trex->stsd_id; | |
1584 | |
1585 frag->duration = flags & 0x08 ? get_be32(pb) : trex->duration; | |
1586 frag->size = flags & 0x10 ? get_be32(pb) : trex->size; | |
1587 frag->flags = flags & 0x20 ? get_be32(pb) : trex->flags; | |
1588 dprintf(c->fc, "frag flags 0x%x\n", frag->flags); | |
1589 return 0; | |
1590 } | |
1591 | |
4079 | 1592 static int mov_read_trex(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
3169 | 1593 { |
1594 MOVTrackExt *trex; | |
1595 | |
1596 if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data)) | |
1597 return -1; | |
1598 c->trex_data = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data)); | |
1599 if (!c->trex_data) | |
1600 return AVERROR(ENOMEM); | |
1601 trex = &c->trex_data[c->trex_count++]; | |
1602 get_byte(pb); /* version */ | |
1603 get_be24(pb); /* flags */ | |
1604 trex->track_id = get_be32(pb); | |
1605 trex->stsd_id = get_be32(pb); | |
1606 trex->duration = get_be32(pb); | |
1607 trex->size = get_be32(pb); | |
1608 trex->flags = get_be32(pb); | |
1609 return 0; | |
1610 } | |
1611 | |
4079 | 1612 static int mov_read_trun(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
3169 | 1613 { |
1614 MOVFragment *frag = &c->fragment; | |
3190 | 1615 AVStream *st; |
1616 MOVStreamContext *sc; | |
3169 | 1617 uint64_t offset; |
1618 int64_t dts; | |
1619 int data_offset = 0; | |
1620 unsigned entries, first_sample_flags = frag->flags; | |
1621 int flags, distance, i; | |
1622 | |
3190 | 1623 if (!frag->track_id || frag->track_id > c->fc->nb_streams) |
1624 return -1; | |
1625 st = c->fc->streams[frag->track_id-1]; | |
1626 sc = st->priv_data; | |
3169 | 1627 if (sc->pseudo_stream_id+1 != frag->stsd_id) |
1628 return 0; | |
1629 get_byte(pb); /* version */ | |
1630 flags = get_be24(pb); | |
1631 entries = get_be32(pb); | |
1632 dprintf(c->fc, "flags 0x%x entries %d\n", flags, entries); | |
1633 if (flags & 0x001) data_offset = get_be32(pb); | |
1634 if (flags & 0x004) first_sample_flags = get_be32(pb); | |
1635 if (flags & 0x800) { | |
1636 if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data)) | |
1637 return -1; | |
1638 sc->ctts_data = av_realloc(sc->ctts_data, | |
1639 (entries+sc->ctts_count)*sizeof(*sc->ctts_data)); | |
1640 if (!sc->ctts_data) | |
1641 return AVERROR(ENOMEM); | |
1642 } | |
1643 dts = st->duration; | |
1644 offset = frag->base_data_offset + data_offset; | |
1645 distance = 0; | |
1646 dprintf(c->fc, "first sample flags 0x%x\n", first_sample_flags); | |
1647 for (i = 0; i < entries; i++) { | |
1648 unsigned sample_size = frag->size; | |
1649 int sample_flags = i ? frag->flags : first_sample_flags; | |
1650 unsigned sample_duration = frag->duration; | |
1651 int keyframe; | |
1652 | |
1653 if (flags & 0x100) sample_duration = get_be32(pb); | |
1654 if (flags & 0x200) sample_size = get_be32(pb); | |
1655 if (flags & 0x400) sample_flags = get_be32(pb); | |
1656 if (flags & 0x800) { | |
1657 sc->ctts_data[sc->ctts_count].count = 1; | |
1658 sc->ctts_data[sc->ctts_count].duration = get_be32(pb); | |
1659 sc->ctts_count++; | |
1660 } | |
1661 if ((keyframe = st->codec->codec_type == CODEC_TYPE_AUDIO || | |
1662 (flags & 0x004 && !i && !sample_flags) || sample_flags & 0x2000000)) | |
1663 distance = 0; | |
1664 av_add_index_entry(st, offset, dts, sample_size, distance, | |
1665 keyframe ? AVINDEX_KEYFRAME : 0); | |
1666 dprintf(c->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", " | |
1667 "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i, | |
1668 offset, dts, sample_size, distance, keyframe); | |
1669 distance++; | |
1670 assert(sample_duration % sc->time_rate == 0); | |
1671 dts += sample_duration / sc->time_rate; | |
1672 offset += sample_size; | |
1673 } | |
1674 frag->moof_offset = offset; | |
1675 sc->sample_count = st->nb_index_entries; | |
1676 st->duration = dts; | |
1677 return 0; | |
1678 } | |
1679 | |
1845 | 1680 /* this atom should be null (from specs), but some buggy files put the 'moov' atom inside it... */ |
1681 /* like the files created with Adobe Premiere 5.0, for samples see */ | |
1682 /* http://graphics.tudelft.nl/~wouter/publications/soundtests/ */ | |
4079 | 1683 static int mov_read_wide(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1684 { |
1685 int err; | |
1686 | |
1687 if (atom.size < 8) | |
1688 return 0; /* continue */ | |
1689 if (get_be32(pb) != 0) { /* 0 sized mdat atom... use the 'wide' atom size */ | |
1690 url_fskip(pb, atom.size - 4); | |
1691 return 0; | |
1692 } | |
1693 atom.type = get_le32(pb); | |
1694 atom.offset += 8; | |
1695 atom.size -= 8; | |
3253 | 1696 if (atom.type != MKTAG('m','d','a','t')) { |
1845 | 1697 url_fskip(pb, atom.size); |
1698 return 0; | |
1699 } | |
1700 err = mov_read_mdat(c, pb, atom); | |
1701 return err; | |
1702 } | |
1703 | |
4079 | 1704 static int mov_read_cmov(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1705 { |
4206 | 1706 #if CONFIG_ZLIB |
1845 | 1707 ByteIOContext ctx; |
1708 uint8_t *cmov_data; | |
1709 uint8_t *moov_data; /* uncompressed data */ | |
1710 long cmov_len, moov_len; | |
3313
8e83e0b76105
free moov and cmov when error occurs, fix memleak, patch by Albert Astals Cid, aastals at tv-wan dot es
bcoudurier
parents:
3301
diff
changeset
|
1711 int ret = -1; |
1845 | 1712 |
1713 get_be32(pb); /* dcom atom */ | |
3253 | 1714 if (get_le32(pb) != MKTAG('d','c','o','m')) |
1845 | 1715 return -1; |
3253 | 1716 if (get_le32(pb) != MKTAG('z','l','i','b')) { |
1845 | 1717 av_log(NULL, AV_LOG_ERROR, "unknown compression for cmov atom !"); |
1718 return -1; | |
1719 } | |
1720 get_be32(pb); /* cmvd atom */ | |
3253 | 1721 if (get_le32(pb) != MKTAG('c','m','v','d')) |
1845 | 1722 return -1; |
1723 moov_len = get_be32(pb); /* uncompressed size */ | |
1724 cmov_len = atom.size - 6 * 4; | |
1725 | |
1726 cmov_data = av_malloc(cmov_len); | |
1727 if (!cmov_data) | |
1728 return -1; | |
1729 moov_data = av_malloc(moov_len); | |
1730 if (!moov_data) { | |
1731 av_free(cmov_data); | |
1732 return -1; | |
1733 } | |
1734 get_buffer(pb, cmov_data, cmov_len); | |
1735 if(uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK) | |
3313
8e83e0b76105
free moov and cmov when error occurs, fix memleak, patch by Albert Astals Cid, aastals at tv-wan dot es
bcoudurier
parents:
3301
diff
changeset
|
1736 goto free_and_return; |
1845 | 1737 if(init_put_byte(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0) |
3313
8e83e0b76105
free moov and cmov when error occurs, fix memleak, patch by Albert Astals Cid, aastals at tv-wan dot es
bcoudurier
parents:
3301
diff
changeset
|
1738 goto free_and_return; |
3253 | 1739 atom.type = MKTAG('m','o','o','v'); |
1845 | 1740 atom.offset = 0; |
1741 atom.size = moov_len; | |
1742 #ifdef DEBUG | |
1743 // { int fd = open("/tmp/uncompheader.mov", O_WRONLY | O_CREAT); write(fd, moov_data, moov_len); close(fd); } | |
1744 #endif | |
1745 ret = mov_read_default(c, &ctx, atom); | |
3313
8e83e0b76105
free moov and cmov when error occurs, fix memleak, patch by Albert Astals Cid, aastals at tv-wan dot es
bcoudurier
parents:
3301
diff
changeset
|
1746 free_and_return: |
1845 | 1747 av_free(moov_data); |
1748 av_free(cmov_data); | |
1749 return ret; | |
1750 #else | |
1751 av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n"); | |
1752 return -1; | |
1753 #endif | |
1754 } | |
1755 | |
1756 /* edit list atom */ | |
4079 | 1757 static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOVAtom atom) |
1845 | 1758 { |
2824
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
1759 MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data; |
1845 | 1760 int i, edit_count; |
1761 | |
1762 get_byte(pb); /* version */ | |
3145 | 1763 get_be24(pb); /* flags */ |
4410 | 1764 edit_count = get_be32(pb); /* entries */ |
1845 | 1765 |
1766 for(i=0; i<edit_count; i++){ | |
3038
db12cabbe337
warn use if edit list is not starting at 0, a/v desync might occur
bcoudurier
parents:
3037
diff
changeset
|
1767 int time; |
1845 | 1768 get_be32(pb); /* Track duration */ |
3038
db12cabbe337
warn use if edit list is not starting at 0, a/v desync might occur
bcoudurier
parents:
3037
diff
changeset
|
1769 time = get_be32(pb); /* Media time */ |
1845 | 1770 get_be32(pb); /* Media rate */ |
4447 | 1771 if (i == 0 && time != -1) { |
4399
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1772 sc->time_offset = time; |
4447 | 1773 sc->time_rate = av_gcd(sc->time_rate, time); |
1774 } | |
1845 | 1775 } |
4399
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1776 |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1777 if(edit_count > 1) |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1778 av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, " |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1779 "a/v desync might occur, patch welcome\n"); |
530e55405feb
offset dts according to edit list, hackish but works, based on patch by Reimar
bcoudurier
parents:
4369
diff
changeset
|
1780 |
4429
7ed870203bfe
fix compilation with DEBUG defined, field does not exist anymore
bcoudurier
parents:
4412
diff
changeset
|
1781 dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, edit_count); |
1845 | 1782 return 0; |
1783 } | |
1784 | |
1785 static const MOVParseTableEntry mov_default_parse_table[] = { | |
3496
cdbf302a3c00
chinese avs demuxing support, demux AVSFileFormat.mp4
bcoudurier
parents:
3487
diff
changeset
|
1786 { MKTAG('a','v','s','s'), mov_read_extradata }, |
3253 | 1787 { MKTAG('c','o','6','4'), mov_read_stco }, |
1788 { MKTAG('c','t','t','s'), mov_read_ctts }, /* composition time to sample */ | |
1789 { MKTAG('d','i','n','f'), mov_read_default }, | |
1790 { MKTAG('d','r','e','f'), mov_read_dref }, | |
1791 { MKTAG('e','d','t','s'), mov_read_default }, | |
1792 { MKTAG('e','l','s','t'), mov_read_elst }, | |
1793 { MKTAG('e','n','d','a'), mov_read_enda }, | |
1794 { MKTAG('f','i','e','l'), mov_read_extradata }, | |
1795 { MKTAG('f','t','y','p'), mov_read_ftyp }, | |
1796 { MKTAG('g','l','b','l'), mov_read_glbl }, | |
1797 { MKTAG('h','d','l','r'), mov_read_hdlr }, | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1798 { MKTAG('i','l','s','t'), mov_read_ilst }, |
3253 | 1799 { MKTAG('j','p','2','h'), mov_read_extradata }, |
1800 { MKTAG('m','d','a','t'), mov_read_mdat }, | |
1801 { MKTAG('m','d','h','d'), mov_read_mdhd }, | |
1802 { MKTAG('m','d','i','a'), mov_read_default }, | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1803 { MKTAG('m','e','t','a'), mov_read_meta }, |
3253 | 1804 { MKTAG('m','i','n','f'), mov_read_default }, |
1805 { MKTAG('m','o','o','f'), mov_read_moof }, | |
1806 { MKTAG('m','o','o','v'), mov_read_moov }, | |
1807 { MKTAG('m','v','e','x'), mov_read_default }, | |
1808 { MKTAG('m','v','h','d'), mov_read_mvhd }, | |
1809 { MKTAG('S','M','I',' '), mov_read_smi }, /* Sorenson extension ??? */ | |
1810 { MKTAG('a','l','a','c'), mov_read_extradata }, /* alac specific atom */ | |
1811 { MKTAG('a','v','c','C'), mov_read_glbl }, | |
4080 | 1812 { MKTAG('p','a','s','p'), mov_read_pasp }, |
3253 | 1813 { MKTAG('s','t','b','l'), mov_read_default }, |
1814 { MKTAG('s','t','c','o'), mov_read_stco }, | |
1815 { MKTAG('s','t','s','c'), mov_read_stsc }, | |
1816 { MKTAG('s','t','s','d'), mov_read_stsd }, /* sample description */ | |
1817 { MKTAG('s','t','s','s'), mov_read_stss }, /* sync sample */ | |
1818 { MKTAG('s','t','s','z'), mov_read_stsz }, /* sample size */ | |
1819 { MKTAG('s','t','t','s'), mov_read_stts }, | |
1820 { MKTAG('t','k','h','d'), mov_read_tkhd }, /* track header */ | |
1821 { MKTAG('t','f','h','d'), mov_read_tfhd }, /* track fragment header */ | |
1822 { MKTAG('t','r','a','k'), mov_read_trak }, | |
1823 { MKTAG('t','r','a','f'), mov_read_default }, | |
1824 { MKTAG('t','r','e','x'), mov_read_trex }, | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1825 { MKTAG('t','r','k','n'), mov_read_trkn }, |
3253 | 1826 { MKTAG('t','r','u','n'), mov_read_trun }, |
4028 | 1827 { MKTAG('u','d','t','a'), mov_read_default }, |
3253 | 1828 { MKTAG('w','a','v','e'), mov_read_wave }, |
1829 { MKTAG('e','s','d','s'), mov_read_esds }, | |
1830 { MKTAG('w','i','d','e'), mov_read_wide }, /* place holder */ | |
1831 { MKTAG('c','m','o','v'), mov_read_cmov }, | |
4028 | 1832 { MKTAG(0xa9,'n','a','m'), mov_read_udta_string }, |
1833 { MKTAG(0xa9,'w','r','t'), mov_read_udta_string }, | |
1834 { MKTAG(0xa9,'c','p','y'), mov_read_udta_string }, | |
1835 { MKTAG(0xa9,'i','n','f'), mov_read_udta_string }, | |
4033
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1836 { MKTAG(0xa9,'i','n','f'), mov_read_udta_string }, |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1837 { MKTAG(0xa9,'A','R','T'), mov_read_udta_string }, |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1838 { MKTAG(0xa9,'a','l','b'), mov_read_udta_string }, |
836e25632f0b
read itunes metadata, code based on Reimar's patch
bcoudurier
parents:
4028
diff
changeset
|
1839 { MKTAG(0xa9,'c','m','t'), mov_read_udta_string }, |
2826 | 1840 { 0, NULL } |
1845 | 1841 }; |
1842 | |
1843 static int mov_probe(AVProbeData *p) | |
1844 { | |
1845 unsigned int offset; | |
1846 uint32_t tag; | |
1847 int score = 0; | |
1848 | |
1849 /* check file header */ | |
1850 offset = 0; | |
1851 for(;;) { | |
1852 /* ignore invalid offset */ | |
1853 if ((offset + 8) > (unsigned int)p->buf_size) | |
1854 return score; | |
1855 tag = AV_RL32(p->buf + offset + 4); | |
1856 switch(tag) { | |
1857 /* check for obvious tags */ | |
3253 | 1858 case MKTAG('j','P',' ',' '): /* jpeg 2000 signature */ |
1859 case MKTAG('m','o','o','v'): | |
1860 case MKTAG('m','d','a','t'): | |
1861 case MKTAG('p','n','o','t'): /* detect movs with preview pics like ew.mov and april.mov */ | |
1862 case MKTAG('u','d','t','a'): /* Packet Video PVAuthor adds this and a lot of more junk */ | |
3587
7d5480d3989d
Return max score when ftyp atom is encountered.
bcoudurier
parents:
3496
diff
changeset
|
1863 case MKTAG('f','t','y','p'): |
1845 | 1864 return AVPROBE_SCORE_MAX; |
1865 /* those are more common words, so rate then a bit less */ | |
3253 | 1866 case MKTAG('e','d','i','w'): /* xdcam files have reverted first tags */ |
1867 case MKTAG('w','i','d','e'): | |
1868 case MKTAG('f','r','e','e'): | |
1869 case MKTAG('j','u','n','k'): | |
1870 case MKTAG('p','i','c','t'): | |
1845 | 1871 return AVPROBE_SCORE_MAX - 5; |
3588 | 1872 case MKTAG(0x82,0x82,0x7f,0x7d): |
3253 | 1873 case MKTAG('s','k','i','p'): |
1874 case MKTAG('u','u','i','d'): | |
1875 case MKTAG('p','r','f','l'): | |
1845 | 1876 offset = AV_RB32(p->buf+offset) + offset; |
1877 /* if we only find those cause probedata is too small at least rate them */ | |
1878 score = AVPROBE_SCORE_MAX - 50; | |
1879 break; | |
1880 default: | |
1881 /* unrecognized tag */ | |
1882 return score; | |
1883 } | |
1884 } | |
1885 return score; | |
1886 } | |
1887 | |
1888 static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) | |
1889 { | |
2006 | 1890 MOVContext *mov = s->priv_data; |
2771
d52c718e83f9
Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents:
2730
diff
changeset
|
1891 ByteIOContext *pb = s->pb; |
3155 | 1892 int err; |
4079 | 1893 MOVAtom atom = { 0, 0, 0 }; |
1845 | 1894 |
1895 mov->fc = s; | |
3167 | 1896 /* .mov and .mp4 aren't streamable anyway (only progressive download if moov is before mdat) */ |
1897 if(!url_is_streamed(pb)) | |
1845 | 1898 atom.size = url_fsize(pb); |
1899 else | |
2026 | 1900 atom.size = INT64_MAX; |
1845 | 1901 |
1902 /* check MOV header */ | |
3204 | 1903 if ((err = mov_read_default(mov, pb, atom)) < 0) { |
1904 av_log(s, AV_LOG_ERROR, "error reading header: %d\n", err); | |
1905 return err; | |
1906 } | |
1907 if (!mov->found_moov) { | |
1908 av_log(s, AV_LOG_ERROR, "moov atom not found\n"); | |
1845 | 1909 return -1; |
1910 } | |
3205 | 1911 dprintf(mov->fc, "on_parse_exit_offset=%lld\n", url_ftell(pb)); |
1845 | 1912 |
1913 return 0; | |
1914 } | |
1915 | |
1916 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt) | |
1917 { | |
1918 MOVContext *mov = s->priv_data; | |
1919 MOVStreamContext *sc = 0; | |
1920 AVIndexEntry *sample = 0; | |
1921 int64_t best_dts = INT64_MAX; | |
1922 int i; | |
3170 | 1923 retry: |
2823 | 1924 for (i = 0; i < s->nb_streams; i++) { |
2824
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
1925 AVStream *st = s->streams[i]; |
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
1926 MOVStreamContext *msc = st->priv_data; |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
1927 if (st->discard != AVDISCARD_ALL && msc->pb && msc->current_sample < msc->sample_count) { |
2824
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
1928 AVIndexEntry *current_sample = &st->index_entries[msc->current_sample]; |
2902 | 1929 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, |
1930 AV_TIME_BASE, msc->time_scale); | |
2030 | 1931 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); |
2817 | 1932 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || |
1933 (!url_is_streamed(s->pb) && | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
1934 ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb && |
2817 | 1935 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
1936 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) { |
1845 | 1937 sample = current_sample; |
1938 best_dts = dts; | |
1939 sc = msc; | |
1940 } | |
1941 } | |
1942 } | |
3170 | 1943 if (!sample) { |
1944 mov->found_mdat = 0; | |
1945 if (!url_is_streamed(s->pb) || | |
4079 | 1946 mov_read_default(mov, s->pb, (MOVAtom){ 0, 0, INT64_MAX }) < 0 || |
3170 | 1947 url_feof(s->pb)) |
1948 return -1; | |
1949 dprintf(s, "read fragments, offset 0x%llx\n", url_ftell(s->pb)); | |
1950 goto retry; | |
1951 } | |
1845 | 1952 /* must be done just before reading, to avoid infinite loop on sample */ |
1953 sc->current_sample++; | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
1954 if (url_fseek(sc->pb, sample->pos, SEEK_SET) != sample->pos) { |
2902 | 1955 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", |
1956 sc->ffindex, sample->pos); | |
1845 | 1957 return -1; |
1958 } | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
1959 av_get_packet(sc->pb, pkt, sample->size); |
4206 | 1960 #if CONFIG_DV_DEMUXER |
3027 | 1961 if (mov->dv_demux && sc->dv_audio_container) { |
1962 dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); | |
1963 av_free(pkt->data); | |
3034 | 1964 pkt->size = 0; |
1965 if (dv_get_packet(mov->dv_demux, pkt) < 0) | |
1966 return -1; | |
3027 | 1967 } |
1845 | 1968 #endif |
1969 pkt->stream_index = sc->ffindex; | |
1970 pkt->dts = sample->timestamp; | |
1971 if (sc->ctts_data) { | |
4411 | 1972 assert(sc->ctts_data[sc->ctts_index].duration % sc->time_rate == 0); |
1973 pkt->pts = pkt->dts + sc->ctts_data[sc->ctts_index].duration / sc->time_rate; | |
1845 | 1974 /* update ctts context */ |
4411 | 1975 sc->ctts_sample++; |
1976 if (sc->ctts_index < sc->ctts_count && | |
1977 sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) { | |
1978 sc->ctts_index++; | |
1979 sc->ctts_sample = 0; | |
1845 | 1980 } |
3956
8bdecea89071
support negative ctts in some way, unset wrong dts
bcoudurier
parents:
3935
diff
changeset
|
1981 if (sc->wrong_dts) |
8bdecea89071
support negative ctts in some way, unset wrong dts
bcoudurier
parents:
3935
diff
changeset
|
1982 pkt->dts = AV_NOPTS_VALUE; |
1845 | 1983 } else { |
3267 | 1984 AVStream *st = s->streams[sc->ffindex]; |
1985 int64_t next_dts = (sc->current_sample < sc->sample_count) ? | |
1986 st->index_entries[sc->current_sample].timestamp : st->duration; | |
1987 pkt->duration = next_dts - pkt->dts; | |
1845 | 1988 pkt->pts = pkt->dts; |
1989 } | |
1990 pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? PKT_FLAG_KEY : 0; | |
1991 pkt->pos = sample->pos; | |
2902 | 1992 dprintf(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n", |
1993 pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration); | |
1845 | 1994 return 0; |
1995 } | |
1996 | |
1997 static int mov_seek_stream(AVStream *st, int64_t timestamp, int flags) | |
1998 { | |
1999 MOVStreamContext *sc = st->priv_data; | |
2000 int sample, time_sample; | |
2001 int i; | |
2002 | |
2003 sample = av_index_search_timestamp(st, timestamp, flags); | |
1907 | 2004 dprintf(st->codec, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample); |
1845 | 2005 if (sample < 0) /* not sure what to do */ |
2006 return -1; | |
2007 sc->current_sample = sample; | |
2030 | 2008 dprintf(st->codec, "stream %d, found sample %d\n", st->index, sc->current_sample); |
1845 | 2009 /* adjust ctts index */ |
2010 if (sc->ctts_data) { | |
2011 time_sample = 0; | |
2012 for (i = 0; i < sc->ctts_count; i++) { | |
2083
2c3887f02739
fix ctts index computation when seeking, check must be done against next ctts sample, thanks to Uoti
bcoudurier
parents:
2046
diff
changeset
|
2013 int next = time_sample + sc->ctts_data[i].count; |
2c3887f02739
fix ctts index computation when seeking, check must be done against next ctts sample, thanks to Uoti
bcoudurier
parents:
2046
diff
changeset
|
2014 if (next > sc->current_sample) { |
4411 | 2015 sc->ctts_index = i; |
2016 sc->ctts_sample = sc->current_sample - time_sample; | |
1845 | 2017 break; |
2018 } | |
2083
2c3887f02739
fix ctts index computation when seeking, check must be done against next ctts sample, thanks to Uoti
bcoudurier
parents:
2046
diff
changeset
|
2019 time_sample = next; |
1845 | 2020 } |
2021 } | |
2022 return sample; | |
2023 } | |
2024 | |
2025 static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags) | |
2026 { | |
2027 AVStream *st; | |
2028 int64_t seek_timestamp, timestamp; | |
2029 int sample; | |
2030 int i; | |
2031 | |
2032 if (stream_index >= s->nb_streams) | |
2033 return -1; | |
4290 | 2034 if (sample_time < 0) |
2035 sample_time = 0; | |
1845 | 2036 |
2037 st = s->streams[stream_index]; | |
2038 sample = mov_seek_stream(st, sample_time, flags); | |
2039 if (sample < 0) | |
2040 return -1; | |
2041 | |
2042 /* adjust seek timestamp to found sample timestamp */ | |
2043 seek_timestamp = st->index_entries[sample].timestamp; | |
2044 | |
2045 for (i = 0; i < s->nb_streams; i++) { | |
2046 st = s->streams[i]; | |
2047 if (stream_index == i || st->discard == AVDISCARD_ALL) | |
2048 continue; | |
2049 | |
2050 timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base); | |
2051 mov_seek_stream(st, timestamp, flags); | |
2052 } | |
2053 return 0; | |
2054 } | |
2055 | |
2056 static int mov_read_close(AVFormatContext *s) | |
2057 { | |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2058 int i, j; |
2006 | 2059 MOVContext *mov = s->priv_data; |
2823 | 2060 for(i=0; i<s->nb_streams; i++) { |
2824
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
2061 MOVStreamContext *sc = s->streams[i]->priv_data; |
ecbfaa8712a1
do not retain useless pointers to avstream priv_data, use it directly
bcoudurier
parents:
2823
diff
changeset
|
2062 av_freep(&sc->ctts_data); |
3085
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2063 for (j=0; j<sc->drefs_count; j++) |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2064 av_freep(&sc->drefs[j].path); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2065 av_freep(&sc->drefs); |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2066 if (sc->pb && sc->pb != s->pb) |
bae59276377f
support mov reference files, ref.mov/ref.m2v/ref.wav and detect BrianCox.mov
bcoudurier
parents:
3084
diff
changeset
|
2067 url_fclose(sc->pb); |
2084 | 2068 } |
1845 | 2069 if(mov->dv_demux){ |
2070 for(i=0; i<mov->dv_fctx->nb_streams; i++){ | |
2071 av_freep(&mov->dv_fctx->streams[i]->codec); | |
2072 av_freep(&mov->dv_fctx->streams[i]); | |
2073 } | |
2074 av_freep(&mov->dv_fctx); | |
2075 av_freep(&mov->dv_demux); | |
2076 } | |
3169 | 2077 av_freep(&mov->trex_data); |
1845 | 2078 return 0; |
2079 } | |
2080 | |
2081 AVInputFormat mov_demuxer = { | |
2082 "mov,mp4,m4a,3gp,3g2,mj2", | |
3424
7a0230981402
Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents:
3362
diff
changeset
|
2083 NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"), |
1845 | 2084 sizeof(MOVContext), |
2085 mov_probe, | |
2086 mov_read_header, | |
2087 mov_read_packet, | |
2088 mov_read_close, | |
2089 mov_read_seek, | |
2090 }; |