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