00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <limits.h>
00024
00025
00026
00027
00028 #include "libavutil/attributes.h"
00029 #include "libavutil/audioconvert.h"
00030 #include "libavutil/intreadwrite.h"
00031 #include "libavutil/intfloat.h"
00032 #include "libavutil/mathematics.h"
00033 #include "libavutil/avstring.h"
00034 #include "libavutil/dict.h"
00035 #include "libavutil/opt.h"
00036 #include "libavutil/timecode.h"
00037 #include "libavcodec/ac3tab.h"
00038 #include "avformat.h"
00039 #include "internal.h"
00040 #include "avio_internal.h"
00041 #include "riff.h"
00042 #include "isom.h"
00043 #include "libavcodec/get_bits.h"
00044 #include "id3v1.h"
00045 #include "mov_chan.h"
00046
00047 #if CONFIG_ZLIB
00048 #include <zlib.h>
00049 #endif
00050
00051
00052
00053
00054
00055
00056 #include "qtpalette.h"
00057
00058
00059 #undef NDEBUG
00060 #include <assert.h>
00061
00062
00063
00064 typedef struct MOVParseTableEntry {
00065 uint32_t type;
00066 int (*parse)(MOVContext *ctx, AVIOContext *pb, MOVAtom atom);
00067 } MOVParseTableEntry;
00068
00069 static const MOVParseTableEntry mov_default_parse_table[];
00070
00071 static int mov_metadata_track_or_disc_number(MOVContext *c, AVIOContext *pb,
00072 unsigned len, const char *key)
00073 {
00074 char buf[16];
00075
00076 short current, total = 0;
00077 avio_rb16(pb);
00078 current = avio_rb16(pb);
00079 if (len >= 6)
00080 total = avio_rb16(pb);
00081 if (!total)
00082 snprintf(buf, sizeof(buf), "%d", current);
00083 else
00084 snprintf(buf, sizeof(buf), "%d/%d", current, total);
00085 av_dict_set(&c->fc->metadata, key, buf, 0);
00086
00087 return 0;
00088 }
00089
00090 static int mov_metadata_int8_bypass_padding(MOVContext *c, AVIOContext *pb,
00091 unsigned len, const char *key)
00092 {
00093 char buf[16];
00094
00095
00096 avio_r8(pb);
00097 avio_r8(pb);
00098 avio_r8(pb);
00099
00100 snprintf(buf, sizeof(buf), "%d", avio_r8(pb));
00101 av_dict_set(&c->fc->metadata, key, buf, 0);
00102
00103 return 0;
00104 }
00105
00106 static int mov_metadata_int8_no_padding(MOVContext *c, AVIOContext *pb,
00107 unsigned len, const char *key)
00108 {
00109 char buf[16];
00110
00111 snprintf(buf, sizeof(buf), "%d", avio_r8(pb));
00112 av_dict_set(&c->fc->metadata, key, buf, 0);
00113
00114 return 0;
00115 }
00116
00117 static int mov_metadata_gnre(MOVContext *c, AVIOContext *pb,
00118 unsigned len, const char *key)
00119 {
00120 short genre;
00121 char buf[20];
00122
00123 avio_r8(pb);
00124
00125 genre = avio_r8(pb);
00126 if (genre < 1 || genre > ID3v1_GENRE_MAX)
00127 return 0;
00128 snprintf(buf, sizeof(buf), "%s", ff_id3v1_genre_str[genre-1]);
00129 av_dict_set(&c->fc->metadata, key, buf, 0);
00130
00131 return 0;
00132 }
00133
00134 static const uint32_t mac_to_unicode[128] = {
00135 0x00C4,0x00C5,0x00C7,0x00C9,0x00D1,0x00D6,0x00DC,0x00E1,
00136 0x00E0,0x00E2,0x00E4,0x00E3,0x00E5,0x00E7,0x00E9,0x00E8,
00137 0x00EA,0x00EB,0x00ED,0x00EC,0x00EE,0x00EF,0x00F1,0x00F3,
00138 0x00F2,0x00F4,0x00F6,0x00F5,0x00FA,0x00F9,0x00FB,0x00FC,
00139 0x2020,0x00B0,0x00A2,0x00A3,0x00A7,0x2022,0x00B6,0x00DF,
00140 0x00AE,0x00A9,0x2122,0x00B4,0x00A8,0x2260,0x00C6,0x00D8,
00141 0x221E,0x00B1,0x2264,0x2265,0x00A5,0x00B5,0x2202,0x2211,
00142 0x220F,0x03C0,0x222B,0x00AA,0x00BA,0x03A9,0x00E6,0x00F8,
00143 0x00BF,0x00A1,0x00AC,0x221A,0x0192,0x2248,0x2206,0x00AB,
00144 0x00BB,0x2026,0x00A0,0x00C0,0x00C3,0x00D5,0x0152,0x0153,
00145 0x2013,0x2014,0x201C,0x201D,0x2018,0x2019,0x00F7,0x25CA,
00146 0x00FF,0x0178,0x2044,0x20AC,0x2039,0x203A,0xFB01,0xFB02,
00147 0x2021,0x00B7,0x201A,0x201E,0x2030,0x00C2,0x00CA,0x00C1,
00148 0x00CB,0x00C8,0x00CD,0x00CE,0x00CF,0x00CC,0x00D3,0x00D4,
00149 0xF8FF,0x00D2,0x00DA,0x00DB,0x00D9,0x0131,0x02C6,0x02DC,
00150 0x00AF,0x02D8,0x02D9,0x02DA,0x00B8,0x02DD,0x02DB,0x02C7,
00151 };
00152
00153 static int mov_read_mac_string(MOVContext *c, AVIOContext *pb, int len,
00154 char *dst, int dstlen)
00155 {
00156 char *p = dst;
00157 char *end = dst+dstlen-1;
00158 int i;
00159
00160 for (i = 0; i < len; i++) {
00161 uint8_t t, c = avio_r8(pb);
00162 if (c < 0x80 && p < end)
00163 *p++ = c;
00164 else if (p < end)
00165 PUT_UTF8(mac_to_unicode[c-0x80], t, if (p < end) *p++ = t;);
00166 }
00167 *p = 0;
00168 return p - dst;
00169 }
00170
00171 static int mov_read_udta_string(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00172 {
00173 #ifdef MOV_EXPORT_ALL_METADATA
00174 char tmp_key[5];
00175 #endif
00176 char str[1024], key2[16], language[4] = {0};
00177 const char *key = NULL;
00178 uint16_t str_size, langcode = 0;
00179 uint32_t data_type = 0;
00180 int (*parse)(MOVContext*, AVIOContext*, unsigned, const char*) = NULL;
00181
00182 switch (atom.type) {
00183 case MKTAG(0xa9,'n','a','m'): key = "title"; break;
00184 case MKTAG(0xa9,'a','u','t'):
00185 case MKTAG(0xa9,'A','R','T'): key = "artist"; break;
00186 case MKTAG( 'a','A','R','T'): key = "album_artist"; break;
00187 case MKTAG(0xa9,'w','r','t'): key = "composer"; break;
00188 case MKTAG( 'c','p','r','t'):
00189 case MKTAG(0xa9,'c','p','y'): key = "copyright"; break;
00190 case MKTAG(0xa9,'g','r','p'): key = "grouping"; break;
00191 case MKTAG(0xa9,'l','y','r'): key = "lyrics"; break;
00192 case MKTAG(0xa9,'c','m','t'):
00193 case MKTAG(0xa9,'i','n','f'): key = "comment"; break;
00194 case MKTAG(0xa9,'a','l','b'): key = "album"; break;
00195 case MKTAG(0xa9,'d','a','y'): key = "date"; break;
00196 case MKTAG(0xa9,'g','e','n'): key = "genre"; break;
00197 case MKTAG( 'g','n','r','e'): key = "genre";
00198 parse = mov_metadata_gnre; break;
00199 case MKTAG(0xa9,'t','o','o'):
00200 case MKTAG(0xa9,'s','w','r'): key = "encoder"; break;
00201 case MKTAG(0xa9,'e','n','c'): key = "encoder"; break;
00202 case MKTAG( 'd','e','s','c'): key = "description";break;
00203 case MKTAG( 'l','d','e','s'): key = "synopsis"; break;
00204 case MKTAG( 't','v','s','h'): key = "show"; break;
00205 case MKTAG( 't','v','e','n'): key = "episode_id";break;
00206 case MKTAG( 't','v','n','n'): key = "network"; break;
00207 case MKTAG( 't','r','k','n'): key = "track";
00208 parse = mov_metadata_track_or_disc_number; break;
00209 case MKTAG( 'd','i','s','k'): key = "disc";
00210 parse = mov_metadata_track_or_disc_number; break;
00211 case MKTAG( 't','v','e','s'): key = "episode_sort";
00212 parse = mov_metadata_int8_bypass_padding; break;
00213 case MKTAG( 't','v','s','n'): key = "season_number";
00214 parse = mov_metadata_int8_bypass_padding; break;
00215 case MKTAG( 's','t','i','k'): key = "media_type";
00216 parse = mov_metadata_int8_no_padding; break;
00217 case MKTAG( 'h','d','v','d'): key = "hd_video";
00218 parse = mov_metadata_int8_no_padding; break;
00219 case MKTAG( 'p','g','a','p'): key = "gapless_playback";
00220 parse = mov_metadata_int8_no_padding; break;
00221 }
00222
00223 if (c->itunes_metadata && atom.size > 8) {
00224 int data_size = avio_rb32(pb);
00225 int tag = avio_rl32(pb);
00226 if (tag == MKTAG('d','a','t','a')) {
00227 data_type = avio_rb32(pb);
00228 avio_rb32(pb);
00229 str_size = data_size - 16;
00230 atom.size -= 16;
00231 } else return 0;
00232 } else if (atom.size > 4 && key && !c->itunes_metadata) {
00233 str_size = avio_rb16(pb);
00234 langcode = avio_rb16(pb);
00235 ff_mov_lang_to_iso639(langcode, language);
00236 atom.size -= 4;
00237 } else
00238 str_size = atom.size;
00239
00240 #ifdef MOV_EXPORT_ALL_METADATA
00241 if (!key) {
00242 snprintf(tmp_key, 5, "%.4s", (char*)&atom.type);
00243 key = tmp_key;
00244 }
00245 #endif
00246
00247 if (!key)
00248 return 0;
00249 if (atom.size < 0)
00250 return AVERROR_INVALIDDATA;
00251
00252 str_size = FFMIN3(sizeof(str)-1, str_size, atom.size);
00253
00254 if (parse)
00255 parse(c, pb, str_size, key);
00256 else {
00257 if (data_type == 3 || (data_type == 0 && (langcode < 0x400 || langcode == 0x7fff))) {
00258 mov_read_mac_string(c, pb, str_size, str, sizeof(str));
00259 } else {
00260 avio_read(pb, str, str_size);
00261 str[str_size] = 0;
00262 }
00263 av_dict_set(&c->fc->metadata, key, str, 0);
00264 if (*language && strcmp(language, "und")) {
00265 snprintf(key2, sizeof(key2), "%s-%s", key, language);
00266 av_dict_set(&c->fc->metadata, key2, str, 0);
00267 }
00268 }
00269 av_dlog(c->fc, "lang \"%3s\" ", language);
00270 av_dlog(c->fc, "tag \"%s\" value \"%s\" atom \"%.4s\" %d %"PRId64"\n",
00271 key, str, (char*)&atom.type, str_size, atom.size);
00272
00273 return 0;
00274 }
00275
00276 static int mov_read_chpl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00277 {
00278 int64_t start;
00279 int i, nb_chapters, str_len, version;
00280 char str[256+1];
00281
00282 if ((atom.size -= 5) < 0)
00283 return 0;
00284
00285 version = avio_r8(pb);
00286 avio_rb24(pb);
00287 if (version)
00288 avio_rb32(pb);
00289 nb_chapters = avio_r8(pb);
00290
00291 for (i = 0; i < nb_chapters; i++) {
00292 if (atom.size < 9)
00293 return 0;
00294
00295 start = avio_rb64(pb);
00296 str_len = avio_r8(pb);
00297
00298 if ((atom.size -= 9+str_len) < 0)
00299 return 0;
00300
00301 avio_read(pb, str, str_len);
00302 str[str_len] = 0;
00303 avpriv_new_chapter(c->fc, i, (AVRational){1,10000000}, start, AV_NOPTS_VALUE, str);
00304 }
00305 return 0;
00306 }
00307
00308 static int mov_read_default(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00309 {
00310 int64_t total_size = 0;
00311 MOVAtom a;
00312 int i;
00313
00314 if (atom.size < 0)
00315 atom.size = INT64_MAX;
00316 while (total_size + 8 <= atom.size && !url_feof(pb)) {
00317 int (*parse)(MOVContext*, AVIOContext*, MOVAtom) = NULL;
00318 a.size = atom.size;
00319 a.type=0;
00320 if (atom.size >= 8) {
00321 a.size = avio_rb32(pb);
00322 a.type = avio_rl32(pb);
00323 if (atom.type != MKTAG('r','o','o','t') &&
00324 atom.type != MKTAG('m','o','o','v'))
00325 {
00326 if (a.type == MKTAG('t','r','a','k') || a.type == MKTAG('m','d','a','t'))
00327 {
00328 av_log(c->fc, AV_LOG_ERROR, "Broken file, trak/mdat not at top-level\n");
00329 avio_skip(pb, -8);
00330 return 0;
00331 }
00332 }
00333 total_size += 8;
00334 if (a.size == 1) {
00335 a.size = avio_rb64(pb) - 8;
00336 total_size += 8;
00337 }
00338 }
00339 av_dlog(c->fc, "type: %08x '%.4s' parent:'%.4s' sz: %"PRId64" %"PRId64" %"PRId64"\n",
00340 a.type, (char*)&a.type, (char*)&atom.type, a.size, total_size, atom.size);
00341 if (a.size == 0) {
00342 a.size = atom.size - total_size + 8;
00343 }
00344 a.size -= 8;
00345 if (a.size < 0)
00346 break;
00347 a.size = FFMIN(a.size, atom.size - total_size);
00348
00349 for (i = 0; mov_default_parse_table[i].type; i++)
00350 if (mov_default_parse_table[i].type == a.type) {
00351 parse = mov_default_parse_table[i].parse;
00352 break;
00353 }
00354
00355
00356 if (!parse && (atom.type == MKTAG('u','d','t','a') ||
00357 atom.type == MKTAG('i','l','s','t')))
00358 parse = mov_read_udta_string;
00359
00360 if (!parse) {
00361 avio_skip(pb, a.size);
00362 } else {
00363 int64_t start_pos = avio_tell(pb);
00364 int64_t left;
00365 int err = parse(c, pb, a);
00366 if (err < 0)
00367 return err;
00368 if (c->found_moov && c->found_mdat &&
00369 ((!pb->seekable || c->fc->flags & AVFMT_FLAG_IGNIDX) ||
00370 start_pos + a.size == avio_size(pb))) {
00371 if (!pb->seekable || c->fc->flags & AVFMT_FLAG_IGNIDX)
00372 c->next_root_atom = start_pos + a.size;
00373 return 0;
00374 }
00375 left = a.size - avio_tell(pb) + start_pos;
00376 if (left > 0)
00377 avio_skip(pb, left);
00378 }
00379
00380 total_size += a.size;
00381 }
00382
00383 if (total_size < atom.size && atom.size < 0x7ffff)
00384 avio_skip(pb, atom.size - total_size);
00385
00386 return 0;
00387 }
00388
00389 static int mov_read_dref(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00390 {
00391 AVStream *st;
00392 MOVStreamContext *sc;
00393 int entries, i, j;
00394
00395 if (c->fc->nb_streams < 1)
00396 return 0;
00397 st = c->fc->streams[c->fc->nb_streams-1];
00398 sc = st->priv_data;
00399
00400 avio_rb32(pb);
00401 entries = avio_rb32(pb);
00402 if (entries >= UINT_MAX / sizeof(*sc->drefs))
00403 return AVERROR_INVALIDDATA;
00404 av_free(sc->drefs);
00405 sc->drefs_count = 0;
00406 sc->drefs = av_mallocz(entries * sizeof(*sc->drefs));
00407 if (!sc->drefs)
00408 return AVERROR(ENOMEM);
00409 sc->drefs_count = entries;
00410
00411 for (i = 0; i < sc->drefs_count; i++) {
00412 MOVDref *dref = &sc->drefs[i];
00413 uint32_t size = avio_rb32(pb);
00414 int64_t next = avio_tell(pb) + size - 4;
00415
00416 if (size < 12)
00417 return AVERROR_INVALIDDATA;
00418
00419 dref->type = avio_rl32(pb);
00420 avio_rb32(pb);
00421 av_dlog(c->fc, "type %.4s size %d\n", (char*)&dref->type, size);
00422
00423 if (dref->type == MKTAG('a','l','i','s') && size > 150) {
00424
00425 uint16_t volume_len, len;
00426 int16_t type;
00427
00428 avio_skip(pb, 10);
00429
00430 volume_len = avio_r8(pb);
00431 volume_len = FFMIN(volume_len, 27);
00432 avio_read(pb, dref->volume, 27);
00433 dref->volume[volume_len] = 0;
00434 av_log(c->fc, AV_LOG_DEBUG, "volume %s, len %d\n", dref->volume, volume_len);
00435
00436 avio_skip(pb, 12);
00437
00438 len = avio_r8(pb);
00439 len = FFMIN(len, 63);
00440 avio_read(pb, dref->filename, 63);
00441 dref->filename[len] = 0;
00442 av_log(c->fc, AV_LOG_DEBUG, "filename %s, len %d\n", dref->filename, len);
00443
00444 avio_skip(pb, 16);
00445
00446
00447 dref->nlvl_from = avio_rb16(pb);
00448 dref->nlvl_to = avio_rb16(pb);
00449 av_log(c->fc, AV_LOG_DEBUG, "nlvl from %d, nlvl to %d\n",
00450 dref->nlvl_from, dref->nlvl_to);
00451
00452 avio_skip(pb, 16);
00453
00454 for (type = 0; type != -1 && avio_tell(pb) < next; ) {
00455 if(url_feof(pb))
00456 return AVERROR_EOF;
00457 type = avio_rb16(pb);
00458 len = avio_rb16(pb);
00459 av_log(c->fc, AV_LOG_DEBUG, "type %d, len %d\n", type, len);
00460 if (len&1)
00461 len += 1;
00462 if (type == 2) {
00463 av_free(dref->path);
00464 dref->path = av_mallocz(len+1);
00465 if (!dref->path)
00466 return AVERROR(ENOMEM);
00467 avio_read(pb, dref->path, len);
00468 if (len > volume_len && !strncmp(dref->path, dref->volume, volume_len)) {
00469 len -= volume_len;
00470 memmove(dref->path, dref->path+volume_len, len);
00471 dref->path[len] = 0;
00472 }
00473 for (j = 0; j < len; j++)
00474 if (dref->path[j] == ':')
00475 dref->path[j] = '/';
00476 av_log(c->fc, AV_LOG_DEBUG, "path %s\n", dref->path);
00477 } else if (type == 0) {
00478 av_free(dref->dir);
00479 dref->dir = av_malloc(len+1);
00480 if (!dref->dir)
00481 return AVERROR(ENOMEM);
00482 avio_read(pb, dref->dir, len);
00483 dref->dir[len] = 0;
00484 for (j = 0; j < len; j++)
00485 if (dref->dir[j] == ':')
00486 dref->dir[j] = '/';
00487 av_log(c->fc, AV_LOG_DEBUG, "dir %s\n", dref->dir);
00488 } else
00489 avio_skip(pb, len);
00490 }
00491 }
00492 avio_seek(pb, next, SEEK_SET);
00493 }
00494 return 0;
00495 }
00496
00497 static int mov_read_hdlr(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00498 {
00499 AVStream *st;
00500 uint32_t type;
00501 uint32_t av_unused ctype;
00502 int title_size;
00503 char *title_str;
00504
00505 if (c->fc->nb_streams < 1)
00506 return 0;
00507
00508 st = c->fc->streams[c->fc->nb_streams-1];
00509
00510 avio_r8(pb);
00511 avio_rb24(pb);
00512
00513
00514 ctype = avio_rl32(pb);
00515 type = avio_rl32(pb);
00516
00517 av_dlog(c->fc, "ctype= %.4s (0x%08x)\n", (char*)&ctype, ctype);
00518 av_dlog(c->fc, "stype= %.4s\n", (char*)&type);
00519
00520 if (type == MKTAG('v','i','d','e'))
00521 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
00522 else if (type == MKTAG('s','o','u','n'))
00523 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
00524 else if (type == MKTAG('m','1','a',' '))
00525 st->codec->codec_id = CODEC_ID_MP2;
00526 else if ((type == MKTAG('s','u','b','p')) || (type == MKTAG('c','l','c','p')))
00527 st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
00528
00529 avio_rb32(pb);
00530 avio_rb32(pb);
00531 avio_rb32(pb);
00532
00533 title_size = atom.size - 24;
00534 if (title_size > 0) {
00535 title_str = av_malloc(title_size + 1);
00536 if (!title_str)
00537 return AVERROR(ENOMEM);
00538 avio_read(pb, title_str, title_size);
00539 title_str[title_size] = 0;
00540 if (title_str[0])
00541 av_dict_set(&st->metadata, "handler_name", title_str +
00542 (!c->isom && title_str[0] == title_size - 1), 0);
00543 av_freep(&title_str);
00544 }
00545
00546 return 0;
00547 }
00548
00549 int ff_mov_read_esds(AVFormatContext *fc, AVIOContext *pb, MOVAtom atom)
00550 {
00551 AVStream *st;
00552 int tag;
00553
00554 if (fc->nb_streams < 1)
00555 return 0;
00556 st = fc->streams[fc->nb_streams-1];
00557
00558 avio_rb32(pb);
00559 ff_mp4_read_descr(fc, pb, &tag);
00560 if (tag == MP4ESDescrTag) {
00561 ff_mp4_parse_es_descr(pb, NULL);
00562 } else
00563 avio_rb16(pb);
00564
00565 ff_mp4_read_descr(fc, pb, &tag);
00566 if (tag == MP4DecConfigDescrTag)
00567 ff_mp4_read_dec_config_descr(fc, st, pb);
00568 return 0;
00569 }
00570
00571 static int mov_read_esds(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00572 {
00573 return ff_mov_read_esds(c->fc, pb, atom);
00574 }
00575
00576 static int mov_read_dac3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00577 {
00578 AVStream *st;
00579 int ac3info, acmod, lfeon, bsmod;
00580
00581 if (c->fc->nb_streams < 1)
00582 return 0;
00583 st = c->fc->streams[c->fc->nb_streams-1];
00584
00585 ac3info = avio_rb24(pb);
00586 bsmod = (ac3info >> 14) & 0x7;
00587 acmod = (ac3info >> 11) & 0x7;
00588 lfeon = (ac3info >> 10) & 0x1;
00589 st->codec->channels = ((int[]){2,1,2,3,3,4,4,5})[acmod] + lfeon;
00590 st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod];
00591 if (lfeon)
00592 st->codec->channel_layout |= AV_CH_LOW_FREQUENCY;
00593 st->codec->audio_service_type = bsmod;
00594 if (st->codec->channels > 1 && bsmod == 0x7)
00595 st->codec->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
00596
00597 return 0;
00598 }
00599
00600 static int mov_read_dec3(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00601 {
00602 AVStream *st;
00603 int eac3info, acmod, lfeon, bsmod;
00604
00605 if (c->fc->nb_streams < 1)
00606 return 0;
00607 st = c->fc->streams[c->fc->nb_streams-1];
00608
00609
00610
00611
00612 avio_rb16(pb);
00613 eac3info = avio_rb24(pb);
00614 bsmod = (eac3info >> 12) & 0x1f;
00615 acmod = (eac3info >> 9) & 0x7;
00616 lfeon = (eac3info >> 8) & 0x1;
00617 st->codec->channel_layout = avpriv_ac3_channel_layout_tab[acmod];
00618 if (lfeon)
00619 st->codec->channel_layout |= AV_CH_LOW_FREQUENCY;
00620 st->codec->channels = av_get_channel_layout_nb_channels(st->codec->channel_layout);
00621 st->codec->audio_service_type = bsmod;
00622 if (st->codec->channels > 1 && bsmod == 0x7)
00623 st->codec->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
00624
00625 return 0;
00626 }
00627
00628 static int mov_read_chan(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00629 {
00630 AVStream *st;
00631 uint8_t av_unused version;
00632 uint32_t av_unused flags;
00633 uint32_t layout_tag, bitmap, num_descr, label_mask;
00634 int i;
00635
00636 if (c->fc->nb_streams < 1)
00637 return 0;
00638 st = c->fc->streams[c->fc->nb_streams-1];
00639
00640 if (atom.size < 16)
00641 return 0;
00642
00643 version = avio_r8(pb);
00644 flags = avio_rb24(pb);
00645
00646 layout_tag = avio_rb32(pb);
00647 bitmap = avio_rb32(pb);
00648 num_descr = avio_rb32(pb);
00649
00650 if (atom.size < 16ULL + num_descr * 20ULL)
00651 return 0;
00652
00653 av_dlog(c->fc, "chan: size=%" PRId64 " version=%u flags=%u layout=%u bitmap=%u num_descr=%u\n",
00654 atom.size, version, flags, layout_tag, bitmap, num_descr);
00655
00656 label_mask = 0;
00657 for (i = 0; i < num_descr; i++) {
00658 uint32_t label;
00659 label = avio_rb32(pb);
00660 avio_rb32(pb);
00661 avio_rl32(pb);
00662 avio_rl32(pb);
00663 avio_rl32(pb);
00664 if (layout_tag == 0) {
00665 uint32_t mask_incr = ff_mov_get_channel_label(label);
00666 if (mask_incr == 0) {
00667 label_mask = 0;
00668 break;
00669 }
00670 label_mask |= mask_incr;
00671 }
00672 }
00673 if (layout_tag == 0)
00674 st->codec->channel_layout = label_mask;
00675 else
00676 st->codec->channel_layout = ff_mov_get_channel_layout(layout_tag, bitmap);
00677
00678 return 0;
00679 }
00680
00681 static int mov_read_wfex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00682 {
00683 AVStream *st;
00684
00685 if (c->fc->nb_streams < 1)
00686 return 0;
00687 st = c->fc->streams[c->fc->nb_streams-1];
00688
00689 ff_get_wav_header(pb, st->codec, atom.size);
00690
00691 return 0;
00692 }
00693
00694 static int mov_read_pasp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00695 {
00696 const int num = avio_rb32(pb);
00697 const int den = avio_rb32(pb);
00698 AVStream *st;
00699
00700 if (c->fc->nb_streams < 1)
00701 return 0;
00702 st = c->fc->streams[c->fc->nb_streams-1];
00703
00704 if ((st->sample_aspect_ratio.den != 1 || st->sample_aspect_ratio.num) &&
00705 (den != st->sample_aspect_ratio.den || num != st->sample_aspect_ratio.num)) {
00706 av_log(c->fc, AV_LOG_WARNING,
00707 "sample aspect ratio already set to %d:%d, ignoring 'pasp' atom (%d:%d)\n",
00708 st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
00709 num, den);
00710 } else if (den != 0) {
00711 st->sample_aspect_ratio.num = num;
00712 st->sample_aspect_ratio.den = den;
00713 }
00714 return 0;
00715 }
00716
00717
00718 static int mov_read_mdat(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00719 {
00720 if (atom.size == 0)
00721 return 0;
00722 c->found_mdat=1;
00723 return 0;
00724 }
00725
00726
00727 static int mov_read_ftyp(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00728 {
00729 uint32_t minor_ver;
00730 int comp_brand_size;
00731 char minor_ver_str[11];
00732 char* comp_brands_str;
00733 uint8_t type[5] = {0};
00734
00735 avio_read(pb, type, 4);
00736 if (strcmp(type, "qt "))
00737 c->isom = 1;
00738 av_log(c->fc, AV_LOG_DEBUG, "ISO: File Type Major Brand: %.4s\n",(char *)&type);
00739 av_dict_set(&c->fc->metadata, "major_brand", type, 0);
00740 minor_ver = avio_rb32(pb);
00741 snprintf(minor_ver_str, sizeof(minor_ver_str), "%d", minor_ver);
00742 av_dict_set(&c->fc->metadata, "minor_version", minor_ver_str, 0);
00743
00744 comp_brand_size = atom.size - 8;
00745 if (comp_brand_size < 0)
00746 return AVERROR_INVALIDDATA;
00747 comp_brands_str = av_malloc(comp_brand_size + 1);
00748 if (!comp_brands_str)
00749 return AVERROR(ENOMEM);
00750 avio_read(pb, comp_brands_str, comp_brand_size);
00751 comp_brands_str[comp_brand_size] = 0;
00752 av_dict_set(&c->fc->metadata, "compatible_brands", comp_brands_str, 0);
00753 av_freep(&comp_brands_str);
00754
00755 return 0;
00756 }
00757
00758
00759 static int mov_read_moov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00760 {
00761 int ret;
00762
00763 if ((ret = mov_read_default(c, pb, atom)) < 0)
00764 return ret;
00765
00766
00767 c->found_moov=1;
00768 return 0;
00769 }
00770
00771 static int mov_read_moof(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00772 {
00773 c->fragment.moof_offset = avio_tell(pb) - 8;
00774 av_dlog(c->fc, "moof offset %"PRIx64"\n", c->fragment.moof_offset);
00775 return mov_read_default(c, pb, atom);
00776 }
00777
00778 static void mov_metadata_creation_time(AVDictionary **metadata, time_t time)
00779 {
00780 char buffer[32];
00781 if (time) {
00782 struct tm *ptm;
00783 time -= 2082844800;
00784 ptm = gmtime(&time);
00785 if (!ptm) return;
00786 strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", ptm);
00787 av_dict_set(metadata, "creation_time", buffer, 0);
00788 }
00789 }
00790
00791 static int mov_read_mdhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00792 {
00793 AVStream *st;
00794 MOVStreamContext *sc;
00795 int version;
00796 char language[4] = {0};
00797 unsigned lang;
00798 time_t creation_time;
00799
00800 if (c->fc->nb_streams < 1)
00801 return 0;
00802 st = c->fc->streams[c->fc->nb_streams-1];
00803 sc = st->priv_data;
00804
00805 version = avio_r8(pb);
00806 if (version > 1) {
00807 av_log_ask_for_sample(c, "unsupported version %d\n", version);
00808 return AVERROR_PATCHWELCOME;
00809 }
00810 avio_rb24(pb);
00811 if (version == 1) {
00812 creation_time = avio_rb64(pb);
00813 avio_rb64(pb);
00814 } else {
00815 creation_time = avio_rb32(pb);
00816 avio_rb32(pb);
00817 }
00818 mov_metadata_creation_time(&st->metadata, creation_time);
00819
00820 sc->time_scale = avio_rb32(pb);
00821 st->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb);
00822
00823 lang = avio_rb16(pb);
00824 if (ff_mov_lang_to_iso639(lang, language))
00825 av_dict_set(&st->metadata, "language", language, 0);
00826 avio_rb16(pb);
00827
00828 return 0;
00829 }
00830
00831 static int mov_read_mvhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00832 {
00833 time_t creation_time;
00834 int version = avio_r8(pb);
00835 avio_rb24(pb);
00836
00837 if (version == 1) {
00838 creation_time = avio_rb64(pb);
00839 avio_rb64(pb);
00840 } else {
00841 creation_time = avio_rb32(pb);
00842 avio_rb32(pb);
00843 }
00844 mov_metadata_creation_time(&c->fc->metadata, creation_time);
00845 c->time_scale = avio_rb32(pb);
00846
00847 av_dlog(c->fc, "time scale = %i\n", c->time_scale);
00848
00849 c->duration = (version == 1) ? avio_rb64(pb) : avio_rb32(pb);
00850
00851
00852 if (c->time_scale > 0)
00853 c->fc->duration = av_rescale(c->duration, AV_TIME_BASE, c->time_scale);
00854 avio_rb32(pb);
00855
00856 avio_rb16(pb);
00857
00858 avio_skip(pb, 10);
00859
00860 avio_skip(pb, 36);
00861
00862 avio_rb32(pb);
00863 avio_rb32(pb);
00864 avio_rb32(pb);
00865 avio_rb32(pb);
00866 avio_rb32(pb);
00867 avio_rb32(pb);
00868 avio_rb32(pb);
00869 return 0;
00870 }
00871
00872 static int mov_read_smi(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00873 {
00874 AVStream *st;
00875
00876 if (c->fc->nb_streams < 1)
00877 return 0;
00878 st = c->fc->streams[c->fc->nb_streams-1];
00879
00880 if ((uint64_t)atom.size > (1<<30))
00881 return AVERROR_INVALIDDATA;
00882
00883
00884
00885 av_free(st->codec->extradata);
00886 st->codec->extradata_size = 0;
00887 st->codec->extradata = av_mallocz(atom.size + 0x5a + FF_INPUT_BUFFER_PADDING_SIZE);
00888 if (!st->codec->extradata)
00889 return AVERROR(ENOMEM);
00890 st->codec->extradata_size = 0x5a + atom.size;
00891 memcpy(st->codec->extradata, "SVQ3", 4);
00892 avio_read(pb, st->codec->extradata + 0x5a, atom.size);
00893 av_dlog(c->fc, "Reading SMI %"PRId64" %s\n", atom.size, st->codec->extradata + 0x5a);
00894 return 0;
00895 }
00896
00897 static int mov_read_enda(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00898 {
00899 AVStream *st;
00900 int little_endian;
00901
00902 if (c->fc->nb_streams < 1)
00903 return 0;
00904 st = c->fc->streams[c->fc->nb_streams-1];
00905
00906 little_endian = avio_rb16(pb) & 0xFF;
00907 av_dlog(c->fc, "enda %d\n", little_endian);
00908 if (little_endian == 1) {
00909 switch (st->codec->codec_id) {
00910 case CODEC_ID_PCM_S24BE:
00911 st->codec->codec_id = CODEC_ID_PCM_S24LE;
00912 break;
00913 case CODEC_ID_PCM_S32BE:
00914 st->codec->codec_id = CODEC_ID_PCM_S32LE;
00915 break;
00916 case CODEC_ID_PCM_F32BE:
00917 st->codec->codec_id = CODEC_ID_PCM_F32LE;
00918 break;
00919 case CODEC_ID_PCM_F64BE:
00920 st->codec->codec_id = CODEC_ID_PCM_F64LE;
00921 break;
00922 default:
00923 break;
00924 }
00925 }
00926 return 0;
00927 }
00928
00929 static int mov_read_fiel(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00930 {
00931 AVStream *st;
00932 unsigned mov_field_order;
00933 enum AVFieldOrder decoded_field_order = AV_FIELD_UNKNOWN;
00934
00935 if (c->fc->nb_streams < 1)
00936 return 0;
00937 st = c->fc->streams[c->fc->nb_streams-1];
00938 if (atom.size < 2)
00939 return AVERROR_INVALIDDATA;
00940 mov_field_order = avio_rb16(pb);
00941 if ((mov_field_order & 0xFF00) == 0x0100)
00942 decoded_field_order = AV_FIELD_PROGRESSIVE;
00943 else if ((mov_field_order & 0xFF00) == 0x0200) {
00944 switch (mov_field_order & 0xFF) {
00945 case 0x01: decoded_field_order = AV_FIELD_TT;
00946 break;
00947 case 0x06: decoded_field_order = AV_FIELD_BB;
00948 break;
00949 case 0x09: decoded_field_order = AV_FIELD_TB;
00950 break;
00951 case 0x0E: decoded_field_order = AV_FIELD_BT;
00952 break;
00953 }
00954 }
00955 if (decoded_field_order == AV_FIELD_UNKNOWN && mov_field_order) {
00956 av_log(NULL, AV_LOG_ERROR, "Unknown MOV field order 0x%04x\n", mov_field_order);
00957 }
00958 st->codec->field_order = decoded_field_order;
00959
00960 return 0;
00961 }
00962
00963
00964 static int mov_read_extradata(MOVContext *c, AVIOContext *pb, MOVAtom atom,
00965 enum CodecID codec_id)
00966 {
00967 AVStream *st;
00968 uint64_t size;
00969 uint8_t *buf;
00970
00971 if (c->fc->nb_streams < 1)
00972 return 0;
00973 st= c->fc->streams[c->fc->nb_streams-1];
00974
00975 if (st->codec->codec_id != codec_id)
00976 return 0;
00977
00978 size= (uint64_t)st->codec->extradata_size + atom.size + 8 + FF_INPUT_BUFFER_PADDING_SIZE;
00979 if (size > INT_MAX || (uint64_t)atom.size > INT_MAX)
00980 return AVERROR_INVALIDDATA;
00981 buf= av_realloc(st->codec->extradata, size);
00982 if (!buf)
00983 return AVERROR(ENOMEM);
00984 st->codec->extradata= buf;
00985 buf+= st->codec->extradata_size;
00986 st->codec->extradata_size= size - FF_INPUT_BUFFER_PADDING_SIZE;
00987 AV_WB32( buf , atom.size + 8);
00988 AV_WL32( buf + 4, atom.type);
00989 avio_read(pb, buf + 8, atom.size);
00990 return 0;
00991 }
00992
00993
00994 static int mov_read_alac(MOVContext *c, AVIOContext *pb, MOVAtom atom)
00995 {
00996 return mov_read_extradata(c, pb, atom, CODEC_ID_ALAC);
00997 }
00998
00999 static int mov_read_avss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01000 {
01001 return mov_read_extradata(c, pb, atom, CODEC_ID_AVS);
01002 }
01003
01004 static int mov_read_jp2h(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01005 {
01006 return mov_read_extradata(c, pb, atom, CODEC_ID_JPEG2000);
01007 }
01008
01009 static int mov_read_aprg(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01010 {
01011 return mov_read_extradata(c, pb, atom, CODEC_ID_AVUI);
01012 }
01013
01014 static int mov_read_wave(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01015 {
01016 AVStream *st;
01017
01018 if (c->fc->nb_streams < 1)
01019 return 0;
01020 st = c->fc->streams[c->fc->nb_streams-1];
01021
01022 if ((uint64_t)atom.size > (1<<30))
01023 return AVERROR_INVALIDDATA;
01024
01025 if (st->codec->codec_id == CODEC_ID_QDM2 || st->codec->codec_id == CODEC_ID_QDMC) {
01026
01027 av_free(st->codec->extradata);
01028 st->codec->extradata_size = 0;
01029 st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE);
01030 if (!st->codec->extradata)
01031 return AVERROR(ENOMEM);
01032 st->codec->extradata_size = atom.size;
01033 avio_read(pb, st->codec->extradata, atom.size);
01034 } else if (atom.size > 8) {
01035 int ret;
01036 if ((ret = mov_read_default(c, pb, atom)) < 0)
01037 return ret;
01038 } else
01039 avio_skip(pb, atom.size);
01040 return 0;
01041 }
01042
01047 static int mov_read_glbl(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01048 {
01049 AVStream *st;
01050
01051 if (c->fc->nb_streams < 1)
01052 return 0;
01053 st = c->fc->streams[c->fc->nb_streams-1];
01054
01055 if ((uint64_t)atom.size > (1<<30))
01056 return AVERROR_INVALIDDATA;
01057
01058 if (atom.size >= 10) {
01059
01060
01061 unsigned size = avio_rb32(pb);
01062 unsigned type = avio_rl32(pb);
01063 avio_seek(pb, -8, SEEK_CUR);
01064 if (type == MKTAG('f','i','e','l') && size == atom.size)
01065 return mov_read_default(c, pb, atom);
01066 }
01067 av_free(st->codec->extradata);
01068 st->codec->extradata_size = 0;
01069 st->codec->extradata = av_mallocz(atom.size + FF_INPUT_BUFFER_PADDING_SIZE);
01070 if (!st->codec->extradata)
01071 return AVERROR(ENOMEM);
01072 st->codec->extradata_size = atom.size;
01073 avio_read(pb, st->codec->extradata, atom.size);
01074 return 0;
01075 }
01076
01077 static int mov_read_dvc1(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01078 {
01079 AVStream *st;
01080 uint8_t profile_level;
01081
01082 if (c->fc->nb_streams < 1)
01083 return 0;
01084 st = c->fc->streams[c->fc->nb_streams-1];
01085
01086 if (atom.size >= (1<<28) || atom.size < 7)
01087 return AVERROR_INVALIDDATA;
01088
01089 profile_level = avio_r8(pb);
01090 if (profile_level & 0xf0 != 0xc0)
01091 return 0;
01092
01093 av_free(st->codec->extradata);
01094 st->codec->extradata_size = 0;
01095 st->codec->extradata = av_mallocz(atom.size - 7 + FF_INPUT_BUFFER_PADDING_SIZE);
01096 if (!st->codec->extradata)
01097 return AVERROR(ENOMEM);
01098 st->codec->extradata_size = atom.size - 7;
01099 avio_seek(pb, 6, SEEK_CUR);
01100 avio_read(pb, st->codec->extradata, st->codec->extradata_size);
01101 return 0;
01102 }
01103
01109 static int mov_read_strf(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01110 {
01111 AVStream *st;
01112
01113 if (c->fc->nb_streams < 1)
01114 return 0;
01115 if (atom.size <= 40)
01116 return 0;
01117 st = c->fc->streams[c->fc->nb_streams-1];
01118
01119 if ((uint64_t)atom.size > (1<<30))
01120 return AVERROR_INVALIDDATA;
01121
01122 av_free(st->codec->extradata);
01123 st->codec->extradata_size = 0;
01124 st->codec->extradata = av_mallocz(atom.size - 40 + FF_INPUT_BUFFER_PADDING_SIZE);
01125 if (!st->codec->extradata)
01126 return AVERROR(ENOMEM);
01127 st->codec->extradata_size = atom.size - 40;
01128 avio_skip(pb, 40);
01129 avio_read(pb, st->codec->extradata, atom.size - 40);
01130 return 0;
01131 }
01132
01133 static int mov_read_stco(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01134 {
01135 AVStream *st;
01136 MOVStreamContext *sc;
01137 unsigned int i, entries;
01138
01139 if (c->fc->nb_streams < 1)
01140 return 0;
01141 st = c->fc->streams[c->fc->nb_streams-1];
01142 sc = st->priv_data;
01143
01144 avio_r8(pb);
01145 avio_rb24(pb);
01146
01147 entries = avio_rb32(pb);
01148
01149 if (!entries)
01150 return 0;
01151 if (entries >= UINT_MAX/sizeof(int64_t))
01152 return AVERROR_INVALIDDATA;
01153
01154 sc->chunk_offsets = av_malloc(entries * sizeof(int64_t));
01155 if (!sc->chunk_offsets)
01156 return AVERROR(ENOMEM);
01157 sc->chunk_count = entries;
01158
01159 if (atom.type == MKTAG('s','t','c','o'))
01160 for (i=0; i<entries; i++)
01161 sc->chunk_offsets[i] = avio_rb32(pb);
01162 else if (atom.type == MKTAG('c','o','6','4'))
01163 for (i=0; i<entries; i++)
01164 sc->chunk_offsets[i] = avio_rb64(pb);
01165 else
01166 return AVERROR_INVALIDDATA;
01167
01168 return 0;
01169 }
01170
01175 enum CodecID ff_mov_get_lpcm_codec_id(int bps, int flags)
01176 {
01177 if (flags & 1) {
01178 if (flags & 2) {
01179 if (bps == 32) return CODEC_ID_PCM_F32BE;
01180 else if (bps == 64) return CODEC_ID_PCM_F64BE;
01181 } else {
01182 if (bps == 32) return CODEC_ID_PCM_F32LE;
01183 else if (bps == 64) return CODEC_ID_PCM_F64LE;
01184 }
01185 } else {
01186 if (flags & 2) {
01187 if (bps == 8)
01188
01189 if (flags & 4) return CODEC_ID_PCM_S8;
01190 else return CODEC_ID_PCM_U8;
01191 else if (bps == 16) return CODEC_ID_PCM_S16BE;
01192 else if (bps == 24) return CODEC_ID_PCM_S24BE;
01193 else if (bps == 32) return CODEC_ID_PCM_S32BE;
01194 } else {
01195 if (bps == 8)
01196 if (flags & 4) return CODEC_ID_PCM_S8;
01197 else return CODEC_ID_PCM_U8;
01198 else if (bps == 16) return CODEC_ID_PCM_S16LE;
01199 else if (bps == 24) return CODEC_ID_PCM_S24LE;
01200 else if (bps == 32) return CODEC_ID_PCM_S32LE;
01201 }
01202 }
01203 return CODEC_ID_NONE;
01204 }
01205
01206 int ff_mov_read_stsd_entries(MOVContext *c, AVIOContext *pb, int entries)
01207 {
01208 AVStream *st;
01209 MOVStreamContext *sc;
01210 int j, pseudo_stream_id;
01211
01212 if (c->fc->nb_streams < 1)
01213 return 0;
01214 st = c->fc->streams[c->fc->nb_streams-1];
01215 sc = st->priv_data;
01216
01217 for (pseudo_stream_id=0; pseudo_stream_id<entries; pseudo_stream_id++) {
01218
01219 enum CodecID id;
01220 int dref_id = 1;
01221 MOVAtom a = { AV_RL32("stsd") };
01222 int64_t start_pos = avio_tell(pb);
01223 int size = avio_rb32(pb);
01224 uint32_t format = avio_rl32(pb);
01225
01226 if (size >= 16) {
01227 avio_rb32(pb);
01228 avio_rb16(pb);
01229 dref_id = avio_rb16(pb);
01230 }else if (size <= 0){
01231 av_log(c->fc, AV_LOG_ERROR, "invalid size %d in stsd\n", size);
01232 return -1;
01233 }
01234
01235 if (st->codec->codec_tag &&
01236 st->codec->codec_tag != format &&
01237 (c->fc->video_codec_id ? ff_codec_get_id(ff_codec_movvideo_tags, format) != c->fc->video_codec_id
01238 : st->codec->codec_tag != MKTAG('j','p','e','g'))
01239 ){
01240
01241
01242
01243 av_log(c->fc, AV_LOG_WARNING, "multiple fourcc not supported\n");
01244 avio_skip(pb, size - (avio_tell(pb) - start_pos));
01245 continue;
01246 }
01247
01248 if (st->codec->codec_tag && st->codec->codec_tag == AV_RL32("avc1"))
01249 av_log(c->fc, AV_LOG_WARNING, "Concatenated H.264 might not play corrently.\n");
01250 sc->pseudo_stream_id = st->codec->codec_tag ? -1 : pseudo_stream_id;
01251 sc->dref_id= dref_id;
01252
01253 st->codec->codec_tag = format;
01254 id = ff_codec_get_id(ff_codec_movaudio_tags, format);
01255 if (id<=0 && ((format&0xFFFF) == 'm'+('s'<<8) || (format&0xFFFF) == 'T'+('S'<<8)))
01256 id = ff_codec_get_id(ff_codec_wav_tags, av_bswap32(format)&0xFFFF);
01257
01258 if (st->codec->codec_type != AVMEDIA_TYPE_VIDEO && id > 0) {
01259 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
01260 } else if (st->codec->codec_type != AVMEDIA_TYPE_AUDIO &&
01261 format && format != MKTAG('m','p','4','s')) {
01262 id = ff_codec_get_id(ff_codec_movvideo_tags, format);
01263 if (id <= 0)
01264 id = ff_codec_get_id(ff_codec_bmp_tags, format);
01265 if (id > 0)
01266 st->codec->codec_type = AVMEDIA_TYPE_VIDEO;
01267 else if (st->codec->codec_type == AVMEDIA_TYPE_DATA ||
01268 (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE &&
01269 st->codec->codec_id == CODEC_ID_NONE)){
01270 id = ff_codec_get_id(ff_codec_movsubtitle_tags, format);
01271 if (id > 0)
01272 st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
01273 }
01274 }
01275
01276 av_dlog(c->fc, "size=%d 4CC= %c%c%c%c codec_type=%d\n", size,
01277 (format >> 0) & 0xff, (format >> 8) & 0xff, (format >> 16) & 0xff,
01278 (format >> 24) & 0xff, st->codec->codec_type);
01279
01280 if (st->codec->codec_type==AVMEDIA_TYPE_VIDEO) {
01281 unsigned int color_depth, len;
01282 int color_greyscale;
01283 int color_table_id;
01284
01285 st->codec->codec_id = id;
01286 avio_rb16(pb);
01287 avio_rb16(pb);
01288 avio_rb32(pb);
01289 avio_rb32(pb);
01290 avio_rb32(pb);
01291
01292 st->codec->width = avio_rb16(pb);
01293 st->codec->height = avio_rb16(pb);
01294
01295 avio_rb32(pb);
01296 avio_rb32(pb);
01297 avio_rb32(pb);
01298 avio_rb16(pb);
01299
01300 len = avio_r8(pb);
01301 if (len > 31)
01302 len = 31;
01303 mov_read_mac_string(c, pb, len, st->codec->codec_name, 32);
01304 if (len < 31)
01305 avio_skip(pb, 31 - len);
01306
01307 if (!memcmp(st->codec->codec_name, "Planar Y'CbCr 8-bit 4:2:0", 25))
01308 st->codec->codec_tag=MKTAG('I', '4', '2', '0');
01309
01310 st->codec->bits_per_coded_sample = avio_rb16(pb);
01311 color_table_id = avio_rb16(pb);
01312 av_dlog(c->fc, "depth %d, ctab id %d\n",
01313 st->codec->bits_per_coded_sample, color_table_id);
01314
01315 color_depth = st->codec->bits_per_coded_sample & 0x1F;
01316 color_greyscale = st->codec->bits_per_coded_sample & 0x20;
01317
01318
01319 if ((color_depth == 2) || (color_depth == 4) ||
01320 (color_depth == 8)) {
01321
01322 unsigned int color_start, color_count, color_end;
01323 unsigned char a, r, g, b;
01324
01325 if (color_greyscale) {
01326 int color_index, color_dec;
01327
01328 st->codec->bits_per_coded_sample = color_depth;
01329 color_count = 1 << color_depth;
01330 color_index = 255;
01331 color_dec = 256 / (color_count - 1);
01332 for (j = 0; j < color_count; j++) {
01333 if (id == CODEC_ID_CINEPAK){
01334 r = g = b = color_count - 1 - color_index;
01335 }else
01336 r = g = b = color_index;
01337 sc->palette[j] =
01338 (0xFFU << 24) | (r << 16) | (g << 8) | (b);
01339 color_index -= color_dec;
01340 if (color_index < 0)
01341 color_index = 0;
01342 }
01343 } else if (color_table_id) {
01344 const uint8_t *color_table;
01345
01346 color_count = 1 << color_depth;
01347 if (color_depth == 2)
01348 color_table = ff_qt_default_palette_4;
01349 else if (color_depth == 4)
01350 color_table = ff_qt_default_palette_16;
01351 else
01352 color_table = ff_qt_default_palette_256;
01353
01354 for (j = 0; j < color_count; j++) {
01355 r = color_table[j * 3 + 0];
01356 g = color_table[j * 3 + 1];
01357 b = color_table[j * 3 + 2];
01358 sc->palette[j] =
01359 (0xFFU << 24) | (r << 16) | (g << 8) | (b);
01360 }
01361 } else {
01362
01363 color_start = avio_rb32(pb);
01364 color_count = avio_rb16(pb);
01365 color_end = avio_rb16(pb);
01366 if ((color_start <= 255) &&
01367 (color_end <= 255)) {
01368 for (j = color_start; j <= color_end; j++) {
01369
01370
01371 a = avio_r8(pb);
01372 avio_r8(pb);
01373 r = avio_r8(pb);
01374 avio_r8(pb);
01375 g = avio_r8(pb);
01376 avio_r8(pb);
01377 b = avio_r8(pb);
01378 avio_r8(pb);
01379 sc->palette[j] =
01380 (a << 24 ) | (r << 16) | (g << 8) | (b);
01381 }
01382 }
01383 }
01384 sc->has_palette = 1;
01385 }
01386 } else if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO) {
01387 int bits_per_sample, flags;
01388 uint16_t version = avio_rb16(pb);
01389
01390 st->codec->codec_id = id;
01391 avio_rb16(pb);
01392 avio_rb32(pb);
01393
01394 st->codec->channels = avio_rb16(pb);
01395 av_dlog(c->fc, "audio channels %d\n", st->codec->channels);
01396 st->codec->bits_per_coded_sample = avio_rb16(pb);
01397
01398 sc->audio_cid = avio_rb16(pb);
01399 avio_rb16(pb);
01400
01401 st->codec->sample_rate = ((avio_rb32(pb) >> 16));
01402
01403
01404 av_dlog(c->fc, "version =%d, isom =%d\n",version,c->isom);
01405 if (!c->isom) {
01406 if (version==1) {
01407 sc->samples_per_frame = avio_rb32(pb);
01408 avio_rb32(pb);
01409 sc->bytes_per_frame = avio_rb32(pb);
01410 avio_rb32(pb);
01411 } else if (version==2) {
01412 avio_rb32(pb);
01413 st->codec->sample_rate = av_int2double(avio_rb64(pb));
01414 st->codec->channels = avio_rb32(pb);
01415 avio_rb32(pb);
01416 st->codec->bits_per_coded_sample = avio_rb32(pb);
01417 flags = avio_rb32(pb);
01418 sc->bytes_per_frame = avio_rb32(pb);
01419 sc->samples_per_frame = avio_rb32(pb);
01420 if (format == MKTAG('l','p','c','m'))
01421 st->codec->codec_id = ff_mov_get_lpcm_codec_id(st->codec->bits_per_coded_sample, flags);
01422 }
01423 }
01424
01425 switch (st->codec->codec_id) {
01426 case CODEC_ID_PCM_S8:
01427 case CODEC_ID_PCM_U8:
01428 if (st->codec->bits_per_coded_sample == 16)
01429 st->codec->codec_id = CODEC_ID_PCM_S16BE;
01430 break;
01431 case CODEC_ID_PCM_S16LE:
01432 case CODEC_ID_PCM_S16BE:
01433 if (st->codec->bits_per_coded_sample == 8)
01434 st->codec->codec_id = CODEC_ID_PCM_S8;
01435 else if (st->codec->bits_per_coded_sample == 24)
01436 st->codec->codec_id =
01437 st->codec->codec_id == CODEC_ID_PCM_S16BE ?
01438 CODEC_ID_PCM_S24BE : CODEC_ID_PCM_S24LE;
01439 break;
01440
01441 case CODEC_ID_MACE3:
01442 sc->samples_per_frame = 6;
01443 sc->bytes_per_frame = 2*st->codec->channels;
01444 break;
01445 case CODEC_ID_MACE6:
01446 sc->samples_per_frame = 6;
01447 sc->bytes_per_frame = 1*st->codec->channels;
01448 break;
01449 case CODEC_ID_ADPCM_IMA_QT:
01450 sc->samples_per_frame = 64;
01451 sc->bytes_per_frame = 34*st->codec->channels;
01452 break;
01453 case CODEC_ID_GSM:
01454 sc->samples_per_frame = 160;
01455 sc->bytes_per_frame = 33;
01456 break;
01457 default:
01458 break;
01459 }
01460
01461 bits_per_sample = av_get_bits_per_sample(st->codec->codec_id);
01462 if (bits_per_sample) {
01463 st->codec->bits_per_coded_sample = bits_per_sample;
01464 sc->sample_size = (bits_per_sample >> 3) * st->codec->channels;
01465 }
01466 } else if (st->codec->codec_type==AVMEDIA_TYPE_SUBTITLE){
01467
01468
01469 MOVAtom fake_atom = { .size = size - (avio_tell(pb) - start_pos) };
01470 if (format != AV_RL32("mp4s"))
01471 mov_read_glbl(c, pb, fake_atom);
01472 st->codec->codec_id= id;
01473 st->codec->width = sc->width;
01474 st->codec->height = sc->height;
01475 } else {
01476 if (st->codec->codec_tag == MKTAG('t','m','c','d')) {
01477 MOVStreamContext *tmcd_ctx = st->priv_data;
01478 int val;
01479 avio_rb32(pb);
01480 val = avio_rb32(pb);
01481 tmcd_ctx->tmcd_flags = val;
01482 if (val & 1)
01483 st->codec->flags2 |= CODEC_FLAG2_DROP_FRAME_TIMECODE;
01484 avio_rb32(pb);
01485 avio_rb32(pb);
01486 st->codec->time_base.den = avio_r8(pb);
01487 st->codec->time_base.num = 1;
01488 }
01489
01490 avio_skip(pb, size - (avio_tell(pb) - start_pos));
01491 }
01492
01493 a.size = size - (avio_tell(pb) - start_pos);
01494 if (a.size > 8) {
01495 int ret;
01496 if ((ret = mov_read_default(c, pb, a)) < 0)
01497 return ret;
01498 } else if (a.size > 0)
01499 avio_skip(pb, a.size);
01500 }
01501
01502 if (st->codec->codec_type==AVMEDIA_TYPE_AUDIO && st->codec->sample_rate==0 && sc->time_scale>1)
01503 st->codec->sample_rate= sc->time_scale;
01504
01505
01506 switch (st->codec->codec_id) {
01507 #if CONFIG_DV_DEMUXER
01508 case CODEC_ID_DVAUDIO:
01509 c->dv_fctx = avformat_alloc_context();
01510 c->dv_demux = avpriv_dv_init_demux(c->dv_fctx);
01511 if (!c->dv_demux) {
01512 av_log(c->fc, AV_LOG_ERROR, "dv demux context init error\n");
01513 return AVERROR(ENOMEM);
01514 }
01515 sc->dv_audio_container = 1;
01516 st->codec->codec_id = CODEC_ID_PCM_S16LE;
01517 break;
01518 #endif
01519
01520 case CODEC_ID_QCELP:
01521
01522 if (st->codec->codec_tag != MKTAG('Q','c','l','p'))
01523 st->codec->sample_rate = 8000;
01524 st->codec->channels= 1;
01525 break;
01526 case CODEC_ID_AMR_NB:
01527 st->codec->channels= 1;
01528
01529 st->codec->sample_rate = 8000;
01530 break;
01531 case CODEC_ID_AMR_WB:
01532 st->codec->channels = 1;
01533 st->codec->sample_rate = 16000;
01534 break;
01535 case CODEC_ID_MP2:
01536 case CODEC_ID_MP3:
01537 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
01538 st->need_parsing = AVSTREAM_PARSE_FULL;
01539 break;
01540 case CODEC_ID_GSM:
01541 case CODEC_ID_ADPCM_MS:
01542 case CODEC_ID_ADPCM_IMA_WAV:
01543 st->codec->block_align = sc->bytes_per_frame;
01544 break;
01545 case CODEC_ID_ALAC:
01546 if (st->codec->extradata_size == 36) {
01547 st->codec->channels = AV_RB8 (st->codec->extradata+21);
01548 st->codec->sample_rate = AV_RB32(st->codec->extradata+32);
01549 }
01550 break;
01551 case CODEC_ID_AC3:
01552 st->need_parsing = AVSTREAM_PARSE_FULL;
01553 break;
01554 case CODEC_ID_MPEG1VIDEO:
01555 st->need_parsing = AVSTREAM_PARSE_FULL;
01556 break;
01557 case CODEC_ID_VC1:
01558 st->need_parsing = AVSTREAM_PARSE_FULL;
01559 break;
01560 default:
01561 break;
01562 }
01563
01564 return 0;
01565 }
01566
01567 static int mov_read_stsd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01568 {
01569 int entries;
01570
01571 avio_r8(pb);
01572 avio_rb24(pb);
01573 entries = avio_rb32(pb);
01574
01575 return ff_mov_read_stsd_entries(c, pb, entries);
01576 }
01577
01578 static int mov_read_stsc(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01579 {
01580 AVStream *st;
01581 MOVStreamContext *sc;
01582 unsigned int i, entries;
01583
01584 if (c->fc->nb_streams < 1)
01585 return 0;
01586 st = c->fc->streams[c->fc->nb_streams-1];
01587 sc = st->priv_data;
01588
01589 avio_r8(pb);
01590 avio_rb24(pb);
01591
01592 entries = avio_rb32(pb);
01593
01594 av_dlog(c->fc, "track[%i].stsc.entries = %i\n", c->fc->nb_streams-1, entries);
01595
01596 if (!entries)
01597 return 0;
01598 if (entries >= UINT_MAX / sizeof(*sc->stsc_data))
01599 return AVERROR_INVALIDDATA;
01600 sc->stsc_data = av_malloc(entries * sizeof(*sc->stsc_data));
01601 if (!sc->stsc_data)
01602 return AVERROR(ENOMEM);
01603 sc->stsc_count = entries;
01604
01605 for (i=0; i<entries; i++) {
01606 sc->stsc_data[i].first = avio_rb32(pb);
01607 sc->stsc_data[i].count = avio_rb32(pb);
01608 sc->stsc_data[i].id = avio_rb32(pb);
01609 }
01610 return 0;
01611 }
01612
01613 static int mov_read_stps(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01614 {
01615 AVStream *st;
01616 MOVStreamContext *sc;
01617 unsigned i, entries;
01618
01619 if (c->fc->nb_streams < 1)
01620 return 0;
01621 st = c->fc->streams[c->fc->nb_streams-1];
01622 sc = st->priv_data;
01623
01624 avio_rb32(pb);
01625
01626 entries = avio_rb32(pb);
01627 if (entries >= UINT_MAX / sizeof(*sc->stps_data))
01628 return AVERROR_INVALIDDATA;
01629 sc->stps_data = av_malloc(entries * sizeof(*sc->stps_data));
01630 if (!sc->stps_data)
01631 return AVERROR(ENOMEM);
01632 sc->stps_count = entries;
01633
01634 for (i = 0; i < entries; i++) {
01635 sc->stps_data[i] = avio_rb32(pb);
01636
01637 }
01638
01639 return 0;
01640 }
01641
01642 static int mov_read_stss(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01643 {
01644 AVStream *st;
01645 MOVStreamContext *sc;
01646 unsigned int i, entries;
01647
01648 if (c->fc->nb_streams < 1)
01649 return 0;
01650 st = c->fc->streams[c->fc->nb_streams-1];
01651 sc = st->priv_data;
01652
01653 avio_r8(pb);
01654 avio_rb24(pb);
01655
01656 entries = avio_rb32(pb);
01657
01658 av_dlog(c->fc, "keyframe_count = %d\n", entries);
01659
01660 if (!entries)
01661 {
01662 sc->keyframe_absent = 1;
01663 return 0;
01664 }
01665 if (entries >= UINT_MAX / sizeof(int))
01666 return AVERROR_INVALIDDATA;
01667 sc->keyframes = av_malloc(entries * sizeof(int));
01668 if (!sc->keyframes)
01669 return AVERROR(ENOMEM);
01670 sc->keyframe_count = entries;
01671
01672 for (i=0; i<entries; i++) {
01673 sc->keyframes[i] = avio_rb32(pb);
01674
01675 }
01676 return 0;
01677 }
01678
01679 static int mov_read_stsz(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01680 {
01681 AVStream *st;
01682 MOVStreamContext *sc;
01683 unsigned int i, entries, sample_size, field_size, num_bytes;
01684 GetBitContext gb;
01685 unsigned char* buf;
01686
01687 if (c->fc->nb_streams < 1)
01688 return 0;
01689 st = c->fc->streams[c->fc->nb_streams-1];
01690 sc = st->priv_data;
01691
01692 avio_r8(pb);
01693 avio_rb24(pb);
01694
01695 if (atom.type == MKTAG('s','t','s','z')) {
01696 sample_size = avio_rb32(pb);
01697 if (!sc->sample_size)
01698 sc->sample_size = sample_size;
01699 sc->alt_sample_size = sample_size;
01700 field_size = 32;
01701 } else {
01702 sample_size = 0;
01703 avio_rb24(pb);
01704 field_size = avio_r8(pb);
01705 }
01706 entries = avio_rb32(pb);
01707
01708 av_dlog(c->fc, "sample_size = %d sample_count = %d\n", sc->sample_size, entries);
01709
01710 sc->sample_count = entries;
01711 if (sample_size)
01712 return 0;
01713
01714 if (field_size != 4 && field_size != 8 && field_size != 16 && field_size != 32) {
01715 av_log(c->fc, AV_LOG_ERROR, "Invalid sample field size %d\n", field_size);
01716 return AVERROR_INVALIDDATA;
01717 }
01718
01719 if (!entries)
01720 return 0;
01721 if (entries >= UINT_MAX / sizeof(int) || entries >= (UINT_MAX - 4) / field_size)
01722 return AVERROR_INVALIDDATA;
01723 sc->sample_sizes = av_malloc(entries * sizeof(int));
01724 if (!sc->sample_sizes)
01725 return AVERROR(ENOMEM);
01726
01727 num_bytes = (entries*field_size+4)>>3;
01728
01729 buf = av_malloc(num_bytes+FF_INPUT_BUFFER_PADDING_SIZE);
01730 if (!buf) {
01731 av_freep(&sc->sample_sizes);
01732 return AVERROR(ENOMEM);
01733 }
01734
01735 if (avio_read(pb, buf, num_bytes) < num_bytes) {
01736 av_freep(&sc->sample_sizes);
01737 av_free(buf);
01738 return AVERROR_INVALIDDATA;
01739 }
01740
01741 init_get_bits(&gb, buf, 8*num_bytes);
01742
01743 for (i = 0; i < entries; i++) {
01744 sc->sample_sizes[i] = get_bits_long(&gb, field_size);
01745 sc->data_size += sc->sample_sizes[i];
01746 }
01747
01748 av_free(buf);
01749 return 0;
01750 }
01751
01752 static int mov_read_stts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01753 {
01754 AVStream *st;
01755 MOVStreamContext *sc;
01756 unsigned int i, entries;
01757 int64_t duration=0;
01758 int64_t total_sample_count=0;
01759
01760 if (c->fc->nb_streams < 1)
01761 return 0;
01762 st = c->fc->streams[c->fc->nb_streams-1];
01763 sc = st->priv_data;
01764
01765 avio_r8(pb);
01766 avio_rb24(pb);
01767 entries = avio_rb32(pb);
01768
01769 av_dlog(c->fc, "track[%i].stts.entries = %i\n",
01770 c->fc->nb_streams-1, entries);
01771
01772 if (entries >= UINT_MAX / sizeof(*sc->stts_data))
01773 return -1;
01774
01775 sc->stts_data = av_malloc(entries * sizeof(*sc->stts_data));
01776 if (!sc->stts_data)
01777 return AVERROR(ENOMEM);
01778
01779 sc->stts_count = entries;
01780
01781 for (i=0; i<entries; i++) {
01782 int sample_duration;
01783 int sample_count;
01784
01785 sample_count=avio_rb32(pb);
01786 sample_duration = avio_rb32(pb);
01787
01788 if (sample_duration < 0) {
01789 av_log(c->fc, AV_LOG_ERROR, "Invalid SampleDelta in STTS %d\n", sample_duration);
01790 sample_duration = 1;
01791 }
01792 sc->stts_data[i].count= sample_count;
01793 sc->stts_data[i].duration= sample_duration;
01794
01795 av_dlog(c->fc, "sample_count=%d, sample_duration=%d\n",
01796 sample_count, sample_duration);
01797
01798 duration+=(int64_t)sample_duration*sample_count;
01799 total_sample_count+=sample_count;
01800 }
01801
01802 st->nb_frames= total_sample_count;
01803 if (duration)
01804 st->duration= duration;
01805 sc->track_end = duration;
01806 return 0;
01807 }
01808
01809 static int mov_read_ctts(MOVContext *c, AVIOContext *pb, MOVAtom atom)
01810 {
01811 AVStream *st;
01812 MOVStreamContext *sc;
01813 unsigned int i, entries;
01814
01815 if (c->fc->nb_streams < 1)
01816 return 0;
01817 st = c->fc->streams[c->fc->nb_streams-1];
01818 sc = st->priv_data;
01819
01820 avio_r8(pb);
01821 avio_rb24(pb);
01822 entries = avio_rb32(pb);
01823
01824 av_dlog(c->fc, "track[%i].ctts.entries = %i\n", c->fc->nb_streams-1, entries);
01825
01826 if (!entries)
01827 return 0;
01828 if (entries >= UINT_MAX / sizeof(*sc->ctts_data))
01829 return AVERROR_INVALIDDATA;
01830 sc->ctts_data = av_malloc(entries * sizeof(*sc->ctts_data));
01831 if (!sc->ctts_data)
01832 return AVERROR(ENOMEM);
01833 sc->ctts_count = entries;
01834
01835 for (i=0; i<entries; i++) {
01836 int count =avio_rb32(pb);
01837 int duration =avio_rb32(pb);
01838
01839 sc->ctts_data[i].count = count;
01840 sc->ctts_data[i].duration= duration;
01841
01842 if (FFABS(duration) > (1<<28) && i+2<entries) {
01843 av_log(c->fc, AV_LOG_WARNING, "CTTS invalid\n");
01844 av_freep(&sc->ctts_data);
01845 sc->ctts_count = 0;
01846 return 0;
01847 }
01848
01849 if (duration < 0 && i+2<entries)
01850 sc->dts_shift = FFMAX(sc->dts_shift, -duration);
01851 }
01852
01853 av_dlog(c->fc, "dts shift %d\n", sc->dts_shift);
01854
01855 return 0;
01856 }
01857
01858 static void mov_build_index(MOVContext *mov, AVStream *st)
01859 {
01860 MOVStreamContext *sc = st->priv_data;
01861 int64_t current_offset;
01862 int64_t current_dts = 0;
01863 unsigned int stts_index = 0;
01864 unsigned int stsc_index = 0;
01865 unsigned int stss_index = 0;
01866 unsigned int stps_index = 0;
01867 unsigned int i, j;
01868 uint64_t stream_size = 0;
01869 AVIndexEntry *mem;
01870
01871
01872 if ((sc->empty_duration || sc->start_time) && mov->time_scale > 0) {
01873 if (sc->empty_duration)
01874 sc->empty_duration = av_rescale(sc->empty_duration, sc->time_scale, mov->time_scale);
01875 sc->time_offset = sc->start_time - sc->empty_duration;
01876 current_dts = -sc->time_offset;
01877 if (sc->ctts_count>0 && sc->stts_count>0 &&
01878 sc->ctts_data[0].duration / FFMAX(sc->stts_data[0].duration, 1) > 16) {
01879
01880
01881 sc->wrong_dts = 1;
01882 st->codec->has_b_frames = 1;
01883 }
01884 }
01885
01886
01887 if (!(st->codec->codec_type == AVMEDIA_TYPE_AUDIO &&
01888 sc->stts_count == 1 && sc->stts_data[0].duration == 1)) {
01889 unsigned int current_sample = 0;
01890 unsigned int stts_sample = 0;
01891 unsigned int sample_size;
01892 unsigned int distance = 0;
01893 int key_off = (sc->keyframe_count && sc->keyframes[0] > 0) || (sc->stps_data && sc->stps_data[0] > 0);
01894
01895 current_dts -= sc->dts_shift;
01896
01897 if (!sc->sample_count || st->nb_index_entries)
01898 return;
01899 if (sc->sample_count >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
01900 return;
01901 mem = av_realloc(st->index_entries, (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries));
01902 if (!mem)
01903 return;
01904 st->index_entries = mem;
01905 st->index_entries_allocated_size = (st->nb_index_entries + sc->sample_count) * sizeof(*st->index_entries);
01906
01907 for (i = 0; i < sc->chunk_count; i++) {
01908 current_offset = sc->chunk_offsets[i];
01909 while (stsc_index + 1 < sc->stsc_count &&
01910 i + 1 == sc->stsc_data[stsc_index + 1].first)
01911 stsc_index++;
01912 for (j = 0; j < sc->stsc_data[stsc_index].count; j++) {
01913 int keyframe = 0;
01914 if (current_sample >= sc->sample_count) {
01915 av_log(mov->fc, AV_LOG_ERROR, "wrong sample count\n");
01916 return;
01917 }
01918
01919 if (!sc->keyframe_absent && (!sc->keyframe_count || current_sample+key_off == sc->keyframes[stss_index])) {
01920 keyframe = 1;
01921 if (stss_index + 1 < sc->keyframe_count)
01922 stss_index++;
01923 } else if (sc->stps_count && current_sample+key_off == sc->stps_data[stps_index]) {
01924 keyframe = 1;
01925 if (stps_index + 1 < sc->stps_count)
01926 stps_index++;
01927 }
01928 if (keyframe)
01929 distance = 0;
01930 sample_size = sc->alt_sample_size > 0 ? sc->alt_sample_size : sc->sample_sizes[current_sample];
01931 if (sc->pseudo_stream_id == -1 ||
01932 sc->stsc_data[stsc_index].id - 1 == sc->pseudo_stream_id) {
01933 AVIndexEntry *e = &st->index_entries[st->nb_index_entries++];
01934 e->pos = current_offset;
01935 e->timestamp = current_dts;
01936 e->size = sample_size;
01937 e->min_distance = distance;
01938 e->flags = keyframe ? AVINDEX_KEYFRAME : 0;
01939 av_dlog(mov->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
01940 "size %d, distance %d, keyframe %d\n", st->index, current_sample,
01941 current_offset, current_dts, sample_size, distance, keyframe);
01942 }
01943
01944 current_offset += sample_size;
01945 stream_size += sample_size;
01946 current_dts += sc->stts_data[stts_index].duration;
01947 distance++;
01948 stts_sample++;
01949 current_sample++;
01950 if (stts_index + 1 < sc->stts_count && stts_sample == sc->stts_data[stts_index].count) {
01951 stts_sample = 0;
01952 stts_index++;
01953 }
01954 }
01955 }
01956 if (st->duration > 0)
01957 st->codec->bit_rate = stream_size*8*sc->time_scale/st->duration;
01958 } else {
01959 unsigned chunk_samples, total = 0;
01960
01961
01962 for (i = 0; i < sc->stsc_count; i++) {
01963 unsigned count, chunk_count;
01964
01965 chunk_samples = sc->stsc_data[i].count;
01966 if (i != sc->stsc_count - 1 &&
01967 sc->samples_per_frame && chunk_samples % sc->samples_per_frame) {
01968 av_log(mov->fc, AV_LOG_ERROR, "error unaligned chunk\n");
01969 return;
01970 }
01971
01972 if (sc->samples_per_frame >= 160) {
01973 count = chunk_samples / sc->samples_per_frame;
01974 } else if (sc->samples_per_frame > 1) {
01975 unsigned samples = (1024/sc->samples_per_frame)*sc->samples_per_frame;
01976 count = (chunk_samples+samples-1) / samples;
01977 } else {
01978 count = (chunk_samples+1023) / 1024;
01979 }
01980
01981 if (i < sc->stsc_count - 1)
01982 chunk_count = sc->stsc_data[i+1].first - sc->stsc_data[i].first;
01983 else
01984 chunk_count = sc->chunk_count - (sc->stsc_data[i].first - 1);
01985 total += chunk_count * count;
01986 }
01987
01988 av_dlog(mov->fc, "chunk count %d\n", total);
01989 if (total >= UINT_MAX / sizeof(*st->index_entries) - st->nb_index_entries)
01990 return;
01991 mem = av_realloc(st->index_entries, (st->nb_index_entries + total) * sizeof(*st->index_entries));
01992 if (!mem)
01993 return;
01994 st->index_entries = mem;
01995 st->index_entries_allocated_size = (st->nb_index_entries + total) * sizeof(*st->index_entries);
01996
01997
01998 for (i = 0; i < sc->chunk_count; i++) {
01999 current_offset = sc->chunk_offsets[i];
02000 if (stsc_index + 1 < sc->stsc_count &&
02001 i + 1 == sc->stsc_data[stsc_index + 1].first)
02002 stsc_index++;
02003 chunk_samples = sc->stsc_data[stsc_index].count;
02004
02005 while (chunk_samples > 0) {
02006 AVIndexEntry *e;
02007 unsigned size, samples;
02008
02009 if (sc->samples_per_frame >= 160) {
02010 samples = sc->samples_per_frame;
02011 size = sc->bytes_per_frame;
02012 } else {
02013 if (sc->samples_per_frame > 1) {
02014 samples = FFMIN((1024 / sc->samples_per_frame)*
02015 sc->samples_per_frame, chunk_samples);
02016 size = (samples / sc->samples_per_frame) * sc->bytes_per_frame;
02017 } else {
02018 samples = FFMIN(1024, chunk_samples);
02019 size = samples * sc->sample_size;
02020 }
02021 }
02022
02023 if (st->nb_index_entries >= total) {
02024 av_log(mov->fc, AV_LOG_ERROR, "wrong chunk count %d\n", total);
02025 return;
02026 }
02027 e = &st->index_entries[st->nb_index_entries++];
02028 e->pos = current_offset;
02029 e->timestamp = current_dts;
02030 e->size = size;
02031 e->min_distance = 0;
02032 e->flags = AVINDEX_KEYFRAME;
02033 av_dlog(mov->fc, "AVIndex stream %d, chunk %d, offset %"PRIx64", dts %"PRId64", "
02034 "size %d, duration %d\n", st->index, i, current_offset, current_dts,
02035 size, samples);
02036
02037 current_offset += size;
02038 current_dts += samples;
02039 chunk_samples -= samples;
02040 }
02041 }
02042 }
02043 }
02044
02045 static int mov_open_dref(AVIOContext **pb, const char *src, MOVDref *ref,
02046 AVIOInterruptCB *int_cb, int use_absolute_path, AVFormatContext *fc)
02047 {
02048
02049
02050 if (ref->nlvl_to > 0 && ref->nlvl_from > 0) {
02051 char filename[1024];
02052 const char *src_path;
02053 int i, l;
02054
02055
02056 src_path = strrchr(src, '/');
02057 if (src_path)
02058 src_path++;
02059 else
02060 src_path = src;
02061
02062
02063 for (i = 0, l = strlen(ref->path) - 1; l >= 0; l--)
02064 if (ref->path[l] == '/') {
02065 if (i == ref->nlvl_to - 1)
02066 break;
02067 else
02068 i++;
02069 }
02070
02071
02072 if (i == ref->nlvl_to - 1 && src_path - src < sizeof(filename)) {
02073 memcpy(filename, src, src_path - src);
02074 filename[src_path - src] = 0;
02075
02076 for (i = 1; i < ref->nlvl_from; i++)
02077 av_strlcat(filename, "../", 1024);
02078
02079 av_strlcat(filename, ref->path + l + 1, 1024);
02080
02081 if (!avio_open2(pb, filename, AVIO_FLAG_READ, int_cb, NULL))
02082 return 0;
02083 }
02084 } else if (use_absolute_path) {
02085 av_log(fc, AV_LOG_WARNING, "Using absolute path on user request, "
02086 "this is a possible security issue\n");
02087 if (!avio_open2(pb, ref->path, AVIO_FLAG_READ, int_cb, NULL))
02088 return 0;
02089 }
02090
02091 return AVERROR(ENOENT);
02092 }
02093
02094 static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02095 {
02096 AVStream *st;
02097 MOVStreamContext *sc;
02098 int ret;
02099
02100 st = avformat_new_stream(c->fc, NULL);
02101 if (!st) return AVERROR(ENOMEM);
02102 st->id = c->fc->nb_streams;
02103 sc = av_mallocz(sizeof(MOVStreamContext));
02104 if (!sc) return AVERROR(ENOMEM);
02105
02106 st->priv_data = sc;
02107 st->codec->codec_type = AVMEDIA_TYPE_DATA;
02108 sc->ffindex = st->index;
02109
02110 if ((ret = mov_read_default(c, pb, atom)) < 0)
02111 return ret;
02112
02113
02114 if (sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||
02115 (!sc->sample_size && !sc->sample_count))) {
02116 av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",
02117 st->index);
02118 return 0;
02119 }
02120
02121 if (sc->time_scale <= 0) {
02122 av_log(c->fc, AV_LOG_WARNING, "stream %d, timescale not set\n", st->index);
02123 sc->time_scale = c->time_scale;
02124 if (sc->time_scale <= 0)
02125 sc->time_scale = 1;
02126 }
02127
02128 avpriv_set_pts_info(st, 64, 1, sc->time_scale);
02129
02130 mov_build_index(c, st);
02131
02132 if (sc->dref_id-1 < sc->drefs_count && sc->drefs[sc->dref_id-1].path) {
02133 MOVDref *dref = &sc->drefs[sc->dref_id - 1];
02134 if (mov_open_dref(&sc->pb, c->fc->filename, dref, &c->fc->interrupt_callback,
02135 c->use_absolute_path, c->fc) < 0)
02136 av_log(c->fc, AV_LOG_ERROR,
02137 "stream %d, error opening alias: path='%s', dir='%s', "
02138 "filename='%s', volume='%s', nlvl_from=%d, nlvl_to=%d\n",
02139 st->index, dref->path, dref->dir, dref->filename,
02140 dref->volume, dref->nlvl_from, dref->nlvl_to);
02141 } else
02142 sc->pb = c->fc->pb;
02143
02144 if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
02145 if (!st->sample_aspect_ratio.num &&
02146 (st->codec->width != sc->width || st->codec->height != sc->height)) {
02147 st->sample_aspect_ratio = av_d2q(((double)st->codec->height * sc->width) /
02148 ((double)st->codec->width * sc->height), INT_MAX);
02149 }
02150
02151 av_reduce(&st->avg_frame_rate.num, &st->avg_frame_rate.den,
02152 sc->time_scale*st->nb_frames, st->duration, INT_MAX);
02153
02154 if (sc->stts_count == 1 || (sc->stts_count == 2 && sc->stts_data[1].count == 1))
02155 av_reduce(&st->r_frame_rate.num, &st->r_frame_rate.den,
02156 sc->time_scale, sc->stts_data[0].duration, INT_MAX);
02157 }
02158
02159 switch (st->codec->codec_id) {
02160 #if CONFIG_H261_DECODER
02161 case CODEC_ID_H261:
02162 #endif
02163 #if CONFIG_H263_DECODER
02164 case CODEC_ID_H263:
02165 #endif
02166 #if CONFIG_H264_DECODER
02167 case CODEC_ID_H264:
02168 #endif
02169 #if CONFIG_MPEG4_DECODER
02170 case CODEC_ID_MPEG4:
02171 #endif
02172 st->codec->width = 0;
02173 st->codec->height= 0;
02174 break;
02175 }
02176
02177
02178 av_freep(&sc->chunk_offsets);
02179 av_freep(&sc->stsc_data);
02180 av_freep(&sc->sample_sizes);
02181 av_freep(&sc->keyframes);
02182 av_freep(&sc->stts_data);
02183 av_freep(&sc->stps_data);
02184
02185 return 0;
02186 }
02187
02188 static int mov_read_ilst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02189 {
02190 int ret;
02191 c->itunes_metadata = 1;
02192 ret = mov_read_default(c, pb, atom);
02193 c->itunes_metadata = 0;
02194 return ret;
02195 }
02196
02197 static int mov_read_meta(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02198 {
02199 while (atom.size > 8) {
02200 uint32_t tag = avio_rl32(pb);
02201 atom.size -= 4;
02202 if (tag == MKTAG('h','d','l','r')) {
02203 avio_seek(pb, -8, SEEK_CUR);
02204 atom.size += 8;
02205 return mov_read_default(c, pb, atom);
02206 }
02207 }
02208 return 0;
02209 }
02210
02211 static int mov_read_tkhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02212 {
02213 int i;
02214 int width;
02215 int height;
02216 int64_t disp_transform[2];
02217 int display_matrix[3][2];
02218 AVStream *st;
02219 MOVStreamContext *sc;
02220 int version;
02221
02222 if (c->fc->nb_streams < 1)
02223 return 0;
02224 st = c->fc->streams[c->fc->nb_streams-1];
02225 sc = st->priv_data;
02226
02227 version = avio_r8(pb);
02228 avio_rb24(pb);
02229
02230
02231
02232
02233
02234
02235
02236 if (version == 1) {
02237 avio_rb64(pb);
02238 avio_rb64(pb);
02239 } else {
02240 avio_rb32(pb);
02241 avio_rb32(pb);
02242 }
02243 st->id = (int)avio_rb32(pb);
02244 avio_rb32(pb);
02245
02246
02247 (version == 1) ? avio_rb64(pb) : avio_rb32(pb);
02248 avio_rb32(pb);
02249 avio_rb32(pb);
02250
02251 avio_rb16(pb);
02252 avio_rb16(pb);
02253 avio_rb16(pb);
02254 avio_rb16(pb);
02255
02256
02257
02258
02259 for (i = 0; i < 3; i++) {
02260 display_matrix[i][0] = avio_rb32(pb);
02261 display_matrix[i][1] = avio_rb32(pb);
02262 avio_rb32(pb);
02263 }
02264
02265 width = avio_rb32(pb);
02266 height = avio_rb32(pb);
02267 sc->width = width >> 16;
02268 sc->height = height >> 16;
02269
02270
02271
02272
02273 if (display_matrix[1][0] == -65536 && display_matrix[0][1] == 65536) {
02274 av_dict_set(&st->metadata, "rotate", "90", 0);
02275 }
02276
02277 if (display_matrix[0][0] == -65536 && display_matrix[1][1] == -65536) {
02278 av_dict_set(&st->metadata, "rotate", "180", 0);
02279 }
02280
02281 if (display_matrix[1][0] == 65536 && display_matrix[0][1] == -65536) {
02282 av_dict_set(&st->metadata, "rotate", "270", 0);
02283 }
02284
02285
02286
02287
02288
02289 if (width && height &&
02290 ((display_matrix[0][0] != 65536 ||
02291 display_matrix[1][1] != 65536) &&
02292 !display_matrix[0][1] &&
02293 !display_matrix[1][0] &&
02294 !display_matrix[2][0] && !display_matrix[2][1])) {
02295 for (i = 0; i < 2; i++)
02296 disp_transform[i] =
02297 (int64_t) width * display_matrix[0][i] +
02298 (int64_t) height * display_matrix[1][i] +
02299 ((int64_t) display_matrix[2][i] << 16);
02300
02301
02302 st->sample_aspect_ratio = av_d2q(
02303 ((double) disp_transform[0] * height) /
02304 ((double) disp_transform[1] * width), INT_MAX);
02305 }
02306 return 0;
02307 }
02308
02309 static int mov_read_tfhd(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02310 {
02311 MOVFragment *frag = &c->fragment;
02312 MOVTrackExt *trex = NULL;
02313 int flags, track_id, i;
02314
02315 avio_r8(pb);
02316 flags = avio_rb24(pb);
02317
02318 track_id = avio_rb32(pb);
02319 if (!track_id)
02320 return AVERROR_INVALIDDATA;
02321 frag->track_id = track_id;
02322 for (i = 0; i < c->trex_count; i++)
02323 if (c->trex_data[i].track_id == frag->track_id) {
02324 trex = &c->trex_data[i];
02325 break;
02326 }
02327 if (!trex) {
02328 av_log(c->fc, AV_LOG_ERROR, "could not find corresponding trex\n");
02329 return AVERROR_INVALIDDATA;
02330 }
02331
02332 frag->base_data_offset = flags & MOV_TFHD_BASE_DATA_OFFSET ?
02333 avio_rb64(pb) : frag->moof_offset;
02334 frag->stsd_id = flags & MOV_TFHD_STSD_ID ? avio_rb32(pb) : trex->stsd_id;
02335
02336 frag->duration = flags & MOV_TFHD_DEFAULT_DURATION ?
02337 avio_rb32(pb) : trex->duration;
02338 frag->size = flags & MOV_TFHD_DEFAULT_SIZE ?
02339 avio_rb32(pb) : trex->size;
02340 frag->flags = flags & MOV_TFHD_DEFAULT_FLAGS ?
02341 avio_rb32(pb) : trex->flags;
02342 av_dlog(c->fc, "frag flags 0x%x\n", frag->flags);
02343 return 0;
02344 }
02345
02346 static int mov_read_chap(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02347 {
02348 c->chapter_track = avio_rb32(pb);
02349 return 0;
02350 }
02351
02352 static int mov_read_trex(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02353 {
02354 MOVTrackExt *trex;
02355
02356 if ((uint64_t)c->trex_count+1 >= UINT_MAX / sizeof(*c->trex_data))
02357 return AVERROR_INVALIDDATA;
02358 trex = av_realloc(c->trex_data, (c->trex_count+1)*sizeof(*c->trex_data));
02359 if (!trex)
02360 return AVERROR(ENOMEM);
02361
02362 c->fc->duration = AV_NOPTS_VALUE;
02363
02364 c->trex_data = trex;
02365 trex = &c->trex_data[c->trex_count++];
02366 avio_r8(pb);
02367 avio_rb24(pb);
02368 trex->track_id = avio_rb32(pb);
02369 trex->stsd_id = avio_rb32(pb);
02370 trex->duration = avio_rb32(pb);
02371 trex->size = avio_rb32(pb);
02372 trex->flags = avio_rb32(pb);
02373 return 0;
02374 }
02375
02376 static int mov_read_trun(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02377 {
02378 MOVFragment *frag = &c->fragment;
02379 AVStream *st = NULL;
02380 MOVStreamContext *sc;
02381 MOVStts *ctts_data;
02382 uint64_t offset;
02383 int64_t dts;
02384 int data_offset = 0;
02385 unsigned entries, first_sample_flags = frag->flags;
02386 int flags, distance, i, found_keyframe = 0;
02387
02388 for (i = 0; i < c->fc->nb_streams; i++) {
02389 if (c->fc->streams[i]->id == frag->track_id) {
02390 st = c->fc->streams[i];
02391 break;
02392 }
02393 }
02394 if (!st) {
02395 av_log(c->fc, AV_LOG_ERROR, "could not find corresponding track id %d\n", frag->track_id);
02396 return AVERROR_INVALIDDATA;
02397 }
02398 sc = st->priv_data;
02399 if (sc->pseudo_stream_id+1 != frag->stsd_id)
02400 return 0;
02401 avio_r8(pb);
02402 flags = avio_rb24(pb);
02403 entries = avio_rb32(pb);
02404 av_dlog(c->fc, "flags 0x%x entries %d\n", flags, entries);
02405
02406
02407
02408
02409
02410
02411 if (!sc->ctts_count && sc->sample_count)
02412 {
02413
02414 ctts_data = av_malloc(sizeof(*sc->ctts_data));
02415 if (!ctts_data)
02416 return AVERROR(ENOMEM);
02417 sc->ctts_data = ctts_data;
02418 sc->ctts_data[sc->ctts_count].count = sc->sample_count;
02419 sc->ctts_data[sc->ctts_count].duration = 0;
02420 sc->ctts_count++;
02421 }
02422 if ((uint64_t)entries+sc->ctts_count >= UINT_MAX/sizeof(*sc->ctts_data))
02423 return AVERROR_INVALIDDATA;
02424 ctts_data = av_realloc(sc->ctts_data,
02425 (entries+sc->ctts_count)*sizeof(*sc->ctts_data));
02426 if (!ctts_data)
02427 return AVERROR(ENOMEM);
02428 sc->ctts_data = ctts_data;
02429
02430 if (flags & MOV_TRUN_DATA_OFFSET) data_offset = avio_rb32(pb);
02431 if (flags & MOV_TRUN_FIRST_SAMPLE_FLAGS) first_sample_flags = avio_rb32(pb);
02432 dts = sc->track_end - sc->time_offset;
02433 offset = frag->base_data_offset + data_offset;
02434 distance = 0;
02435 av_dlog(c->fc, "first sample flags 0x%x\n", first_sample_flags);
02436 for (i = 0; i < entries; i++) {
02437 unsigned sample_size = frag->size;
02438 int sample_flags = i ? frag->flags : first_sample_flags;
02439 unsigned sample_duration = frag->duration;
02440 int keyframe = 0;
02441
02442 if (flags & MOV_TRUN_SAMPLE_DURATION) sample_duration = avio_rb32(pb);
02443 if (flags & MOV_TRUN_SAMPLE_SIZE) sample_size = avio_rb32(pb);
02444 if (flags & MOV_TRUN_SAMPLE_FLAGS) sample_flags = avio_rb32(pb);
02445 sc->ctts_data[sc->ctts_count].count = 1;
02446 sc->ctts_data[sc->ctts_count].duration = (flags & MOV_TRUN_SAMPLE_CTS) ?
02447 avio_rb32(pb) : 0;
02448 sc->ctts_count++;
02449 if (st->codec->codec_type == AVMEDIA_TYPE_AUDIO)
02450 keyframe = 1;
02451 else if (!found_keyframe)
02452 keyframe = found_keyframe =
02453 !(sample_flags & (MOV_FRAG_SAMPLE_FLAG_IS_NON_SYNC |
02454 MOV_FRAG_SAMPLE_FLAG_DEPENDS_YES));
02455 if (keyframe)
02456 distance = 0;
02457 av_add_index_entry(st, offset, dts, sample_size, distance,
02458 keyframe ? AVINDEX_KEYFRAME : 0);
02459 av_dlog(c->fc, "AVIndex stream %d, sample %d, offset %"PRIx64", dts %"PRId64", "
02460 "size %d, distance %d, keyframe %d\n", st->index, sc->sample_count+i,
02461 offset, dts, sample_size, distance, keyframe);
02462 distance++;
02463 dts += sample_duration;
02464 offset += sample_size;
02465 sc->data_size += sample_size;
02466 }
02467 frag->moof_offset = offset;
02468 st->duration = sc->track_end = dts + sc->time_offset;
02469 return 0;
02470 }
02471
02472
02473
02474
02475 static int mov_read_wide(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02476 {
02477 int err;
02478
02479 if (atom.size < 8)
02480 return 0;
02481 if (avio_rb32(pb) != 0) {
02482 avio_skip(pb, atom.size - 4);
02483 return 0;
02484 }
02485 atom.type = avio_rl32(pb);
02486 atom.size -= 8;
02487 if (atom.type != MKTAG('m','d','a','t')) {
02488 avio_skip(pb, atom.size);
02489 return 0;
02490 }
02491 err = mov_read_mdat(c, pb, atom);
02492 return err;
02493 }
02494
02495 static int mov_read_cmov(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02496 {
02497 #if CONFIG_ZLIB
02498 AVIOContext ctx;
02499 uint8_t *cmov_data;
02500 uint8_t *moov_data;
02501 long cmov_len, moov_len;
02502 int ret = -1;
02503
02504 avio_rb32(pb);
02505 if (avio_rl32(pb) != MKTAG('d','c','o','m'))
02506 return AVERROR_INVALIDDATA;
02507 if (avio_rl32(pb) != MKTAG('z','l','i','b')) {
02508 av_log(c->fc, AV_LOG_ERROR, "unknown compression for cmov atom !");
02509 return AVERROR_INVALIDDATA;
02510 }
02511 avio_rb32(pb);
02512 if (avio_rl32(pb) != MKTAG('c','m','v','d'))
02513 return AVERROR_INVALIDDATA;
02514 moov_len = avio_rb32(pb);
02515 cmov_len = atom.size - 6 * 4;
02516
02517 cmov_data = av_malloc(cmov_len);
02518 if (!cmov_data)
02519 return AVERROR(ENOMEM);
02520 moov_data = av_malloc(moov_len);
02521 if (!moov_data) {
02522 av_free(cmov_data);
02523 return AVERROR(ENOMEM);
02524 }
02525 avio_read(pb, cmov_data, cmov_len);
02526 if (uncompress (moov_data, (uLongf *) &moov_len, (const Bytef *)cmov_data, cmov_len) != Z_OK)
02527 goto free_and_return;
02528 if (ffio_init_context(&ctx, moov_data, moov_len, 0, NULL, NULL, NULL, NULL) != 0)
02529 goto free_and_return;
02530 atom.type = MKTAG('m','o','o','v');
02531 atom.size = moov_len;
02532 ret = mov_read_default(c, &ctx, atom);
02533 free_and_return:
02534 av_free(moov_data);
02535 av_free(cmov_data);
02536 return ret;
02537 #else
02538 av_log(c->fc, AV_LOG_ERROR, "this file requires zlib support compiled in\n");
02539 return AVERROR(ENOSYS);
02540 #endif
02541 }
02542
02543
02544 static int mov_read_elst(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02545 {
02546 MOVStreamContext *sc;
02547 int i, edit_count, version, edit_start_index = 0;
02548
02549 if (c->fc->nb_streams < 1)
02550 return 0;
02551 sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
02552
02553 version = avio_r8(pb);
02554 avio_rb24(pb);
02555 edit_count = avio_rb32(pb);
02556
02557 if ((uint64_t)edit_count*12+8 > atom.size)
02558 return AVERROR_INVALIDDATA;
02559
02560 for (i=0; i<edit_count; i++){
02561 int64_t time;
02562 int64_t duration;
02563 if (version == 1) {
02564 duration = avio_rb64(pb);
02565 time = avio_rb64(pb);
02566 } else {
02567 duration = avio_rb32(pb);
02568 time = (int32_t)avio_rb32(pb);
02569 }
02570 avio_rb32(pb);
02571 if (i == 0 && time == -1) {
02572 sc->empty_duration = duration;
02573 edit_start_index = 1;
02574 } else if (i == edit_start_index && time >= 0)
02575 sc->start_time = time;
02576 }
02577
02578 if (edit_count > 1)
02579 av_log(c->fc, AV_LOG_WARNING, "multiple edit list entries, "
02580 "a/v desync might occur, patch welcome\n");
02581
02582 av_dlog(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, edit_count);
02583 return 0;
02584 }
02585
02586 static int mov_read_chan2(MOVContext *c, AVIOContext *pb, MOVAtom atom)
02587 {
02588 if (atom.size < 16)
02589 return 0;
02590 avio_skip(pb, 4);
02591 ff_mov_read_chan(c->fc, atom.size - 4, c->fc->streams[0]->codec);
02592 return 0;
02593 }
02594
02595 static const MOVParseTableEntry mov_default_parse_table[] = {
02596 { MKTAG('A','P','R','G'), mov_read_aprg },
02597 { MKTAG('a','v','s','s'), mov_read_avss },
02598 { MKTAG('c','h','p','l'), mov_read_chpl },
02599 { MKTAG('c','o','6','4'), mov_read_stco },
02600 { MKTAG('c','t','t','s'), mov_read_ctts },
02601 { MKTAG('d','i','n','f'), mov_read_default },
02602 { MKTAG('d','r','e','f'), mov_read_dref },
02603 { MKTAG('e','d','t','s'), mov_read_default },
02604 { MKTAG('e','l','s','t'), mov_read_elst },
02605 { MKTAG('e','n','d','a'), mov_read_enda },
02606 { MKTAG('f','i','e','l'), mov_read_fiel },
02607 { MKTAG('f','t','y','p'), mov_read_ftyp },
02608 { MKTAG('g','l','b','l'), mov_read_glbl },
02609 { MKTAG('h','d','l','r'), mov_read_hdlr },
02610 { MKTAG('i','l','s','t'), mov_read_ilst },
02611 { MKTAG('j','p','2','h'), mov_read_jp2h },
02612 { MKTAG('m','d','a','t'), mov_read_mdat },
02613 { MKTAG('m','d','h','d'), mov_read_mdhd },
02614 { MKTAG('m','d','i','a'), mov_read_default },
02615 { MKTAG('m','e','t','a'), mov_read_meta },
02616 { MKTAG('m','i','n','f'), mov_read_default },
02617 { MKTAG('m','o','o','f'), mov_read_moof },
02618 { MKTAG('m','o','o','v'), mov_read_moov },
02619 { MKTAG('m','v','e','x'), mov_read_default },
02620 { MKTAG('m','v','h','d'), mov_read_mvhd },
02621 { MKTAG('S','M','I',' '), mov_read_smi },
02622 { MKTAG('a','l','a','c'), mov_read_alac },
02623 { MKTAG('a','v','c','C'), mov_read_glbl },
02624 { MKTAG('p','a','s','p'), mov_read_pasp },
02625 { MKTAG('s','t','b','l'), mov_read_default },
02626 { MKTAG('s','t','c','o'), mov_read_stco },
02627 { MKTAG('s','t','p','s'), mov_read_stps },
02628 { MKTAG('s','t','r','f'), mov_read_strf },
02629 { MKTAG('s','t','s','c'), mov_read_stsc },
02630 { MKTAG('s','t','s','d'), mov_read_stsd },
02631 { MKTAG('s','t','s','s'), mov_read_stss },
02632 { MKTAG('s','t','s','z'), mov_read_stsz },
02633 { MKTAG('s','t','t','s'), mov_read_stts },
02634 { MKTAG('s','t','z','2'), mov_read_stsz },
02635 { MKTAG('t','k','h','d'), mov_read_tkhd },
02636 { MKTAG('t','f','h','d'), mov_read_tfhd },
02637 { MKTAG('t','r','a','k'), mov_read_trak },
02638 { MKTAG('t','r','a','f'), mov_read_default },
02639 { MKTAG('t','r','e','f'), mov_read_default },
02640 { MKTAG('c','h','a','p'), mov_read_chap },
02641 { MKTAG('t','r','e','x'), mov_read_trex },
02642 { MKTAG('t','r','u','n'), mov_read_trun },
02643 { MKTAG('u','d','t','a'), mov_read_default },
02644 { MKTAG('w','a','v','e'), mov_read_wave },
02645 { MKTAG('e','s','d','s'), mov_read_esds },
02646 { MKTAG('d','a','c','3'), mov_read_dac3 },
02647 { MKTAG('d','e','c','3'), mov_read_dec3 },
02648 { MKTAG('w','i','d','e'), mov_read_wide },
02649 { MKTAG('w','f','e','x'), mov_read_wfex },
02650 { MKTAG('c','m','o','v'), mov_read_cmov },
02651 { MKTAG('c','h','a','n'), mov_read_chan },
02652 { MKTAG('d','v','c','1'), mov_read_dvc1 },
02653 { 0, NULL }
02654 };
02655
02656 static int mov_probe(AVProbeData *p)
02657 {
02658 unsigned int offset;
02659 uint32_t tag;
02660 int score = 0;
02661
02662
02663 offset = 0;
02664 for (;;) {
02665
02666 if ((offset + 8) > (unsigned int)p->buf_size)
02667 return score;
02668 tag = AV_RL32(p->buf + offset + 4);
02669 switch(tag) {
02670
02671 case MKTAG('j','P',' ',' '):
02672 case MKTAG('m','o','o','v'):
02673 case MKTAG('m','d','a','t'):
02674 case MKTAG('p','n','o','t'):
02675 case MKTAG('u','d','t','a'):
02676 case MKTAG('f','t','y','p'):
02677 return AVPROBE_SCORE_MAX;
02678
02679 case MKTAG('e','d','i','w'):
02680 case MKTAG('w','i','d','e'):
02681 case MKTAG('f','r','e','e'):
02682 case MKTAG('j','u','n','k'):
02683 case MKTAG('p','i','c','t'):
02684 return AVPROBE_SCORE_MAX - 5;
02685 case MKTAG(0x82,0x82,0x7f,0x7d):
02686 case MKTAG('s','k','i','p'):
02687 case MKTAG('u','u','i','d'):
02688 case MKTAG('p','r','f','l'):
02689 offset = AV_RB32(p->buf+offset) + offset;
02690
02691 score = AVPROBE_SCORE_MAX - 50;
02692 break;
02693 default:
02694
02695 return score;
02696 }
02697 }
02698 }
02699
02700
02701 static void mov_read_chapters(AVFormatContext *s)
02702 {
02703 MOVContext *mov = s->priv_data;
02704 AVStream *st = NULL;
02705 MOVStreamContext *sc;
02706 int64_t cur_pos;
02707 int i;
02708
02709 for (i = 0; i < s->nb_streams; i++)
02710 if (s->streams[i]->id == mov->chapter_track) {
02711 st = s->streams[i];
02712 break;
02713 }
02714 if (!st) {
02715 av_log(s, AV_LOG_ERROR, "Referenced QT chapter track not found\n");
02716 return;
02717 }
02718
02719 st->discard = AVDISCARD_ALL;
02720 sc = st->priv_data;
02721 cur_pos = avio_tell(sc->pb);
02722
02723 for (i = 0; i < st->nb_index_entries; i++) {
02724 AVIndexEntry *sample = &st->index_entries[i];
02725 int64_t end = i+1 < st->nb_index_entries ? st->index_entries[i+1].timestamp : st->duration;
02726 uint8_t *title;
02727 uint16_t ch;
02728 int len, title_len;
02729
02730 if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
02731 av_log(s, AV_LOG_ERROR, "Chapter %d not found in file\n", i);
02732 goto finish;
02733 }
02734
02735
02736 len = avio_rb16(sc->pb);
02737 if (len > sample->size-2)
02738 continue;
02739 title_len = 2*len + 1;
02740 if (!(title = av_mallocz(title_len)))
02741 goto finish;
02742
02743
02744
02745
02746 if (!len) {
02747 title[0] = 0;
02748 } else {
02749 ch = avio_rb16(sc->pb);
02750 if (ch == 0xfeff)
02751 avio_get_str16be(sc->pb, len, title, title_len);
02752 else if (ch == 0xfffe)
02753 avio_get_str16le(sc->pb, len, title, title_len);
02754 else {
02755 AV_WB16(title, ch);
02756 if (len == 1 || len == 2)
02757 title[len] = 0;
02758 else
02759 avio_get_str(sc->pb, INT_MAX, title + 2, len - 1);
02760 }
02761 }
02762
02763 avpriv_new_chapter(s, i, st->time_base, sample->timestamp, end, title);
02764 av_freep(&title);
02765 }
02766 finish:
02767 avio_seek(sc->pb, cur_pos, SEEK_SET);
02768 }
02769
02770 static int parse_timecode_in_framenum_format(AVFormatContext *s, AVStream *st,
02771 uint32_t value, int flags)
02772 {
02773 AVTimecode tc;
02774 char buf[AV_TIMECODE_STR_SIZE];
02775 AVRational rate = {st->codec->time_base.den,
02776 st->codec->time_base.num};
02777 int ret = av_timecode_init(&tc, rate, flags, 0, s);
02778 if (ret < 0)
02779 return ret;
02780 av_dict_set(&st->metadata, "timecode",
02781 av_timecode_make_string(&tc, buf, value), 0);
02782 return 0;
02783 }
02784
02785 static int mov_read_timecode_track(AVFormatContext *s, AVStream *st)
02786 {
02787 MOVStreamContext *sc = st->priv_data;
02788 int flags = 0;
02789 int64_t cur_pos = avio_tell(sc->pb);
02790 uint32_t value;
02791
02792 if (!st->nb_index_entries)
02793 return -1;
02794
02795 avio_seek(sc->pb, st->index_entries->pos, SEEK_SET);
02796 value = avio_rb32(s->pb);
02797
02798 if (sc->tmcd_flags & 0x0001) flags |= AV_TIMECODE_FLAG_DROPFRAME;
02799 if (sc->tmcd_flags & 0x0002) flags |= AV_TIMECODE_FLAG_24HOURSMAX;
02800 if (sc->tmcd_flags & 0x0004) flags |= AV_TIMECODE_FLAG_ALLOWNEGATIVE;
02801
02802
02803
02804
02805
02806
02807 parse_timecode_in_framenum_format(s, st, value, flags);
02808
02809 avio_seek(sc->pb, cur_pos, SEEK_SET);
02810 return 0;
02811 }
02812
02813 static int mov_read_close(AVFormatContext *s)
02814 {
02815 MOVContext *mov = s->priv_data;
02816 int i, j;
02817
02818 for (i = 0; i < s->nb_streams; i++) {
02819 AVStream *st = s->streams[i];
02820 MOVStreamContext *sc = st->priv_data;
02821
02822 av_freep(&sc->ctts_data);
02823 for (j = 0; j < sc->drefs_count; j++) {
02824 av_freep(&sc->drefs[j].path);
02825 av_freep(&sc->drefs[j].dir);
02826 }
02827 av_freep(&sc->drefs);
02828 if (sc->pb && sc->pb != s->pb)
02829 avio_close(sc->pb);
02830 sc->pb = NULL;
02831 av_freep(&sc->chunk_offsets);
02832 av_freep(&sc->keyframes);
02833 av_freep(&sc->sample_sizes);
02834 av_freep(&sc->stps_data);
02835 av_freep(&sc->stsc_data);
02836 av_freep(&sc->stts_data);
02837 }
02838
02839 if (mov->dv_demux) {
02840 for (i = 0; i < mov->dv_fctx->nb_streams; i++) {
02841 av_freep(&mov->dv_fctx->streams[i]->codec);
02842 av_freep(&mov->dv_fctx->streams[i]);
02843 }
02844 av_freep(&mov->dv_fctx);
02845 av_freep(&mov->dv_demux);
02846 }
02847
02848 av_freep(&mov->trex_data);
02849
02850 return 0;
02851 }
02852
02853 static int mov_read_header(AVFormatContext *s)
02854 {
02855 MOVContext *mov = s->priv_data;
02856 AVIOContext *pb = s->pb;
02857 int err;
02858 MOVAtom atom = { AV_RL32("root") };
02859
02860 mov->fc = s;
02861
02862 if (pb->seekable)
02863 atom.size = avio_size(pb);
02864 else
02865 atom.size = INT64_MAX;
02866
02867
02868 if ((err = mov_read_default(mov, pb, atom)) < 0) {
02869 av_log(s, AV_LOG_ERROR, "error reading header: %d\n", err);
02870 mov_read_close(s);
02871 return err;
02872 }
02873 if (!mov->found_moov) {
02874 av_log(s, AV_LOG_ERROR, "moov atom not found\n");
02875 mov_read_close(s);
02876 return AVERROR_INVALIDDATA;
02877 }
02878 av_dlog(mov->fc, "on_parse_exit_offset=%"PRId64"\n", avio_tell(pb));
02879
02880 if (pb->seekable) {
02881 int i;
02882 if (mov->chapter_track > 0)
02883 mov_read_chapters(s);
02884 for (i = 0; i < s->nb_streams; i++)
02885 if (s->streams[i]->codec->codec_tag == AV_RL32("tmcd"))
02886 mov_read_timecode_track(s, s->streams[i]);
02887 }
02888
02889 if (mov->trex_data) {
02890 int i;
02891 for (i = 0; i < s->nb_streams; i++) {
02892 AVStream *st = s->streams[i];
02893 MOVStreamContext *sc = st->priv_data;
02894 if (st->duration)
02895 st->codec->bit_rate = sc->data_size * 8 * sc->time_scale / st->duration;
02896 }
02897 }
02898
02899 return 0;
02900 }
02901
02902 static AVIndexEntry *mov_find_next_sample(AVFormatContext *s, AVStream **st)
02903 {
02904 AVIndexEntry *sample = NULL;
02905 int64_t best_dts = INT64_MAX;
02906 int i;
02907 for (i = 0; i < s->nb_streams; i++) {
02908 AVStream *avst = s->streams[i];
02909 MOVStreamContext *msc = avst->priv_data;
02910 if (msc->pb && msc->current_sample < avst->nb_index_entries) {
02911 AVIndexEntry *current_sample = &avst->index_entries[msc->current_sample];
02912 int64_t dts = av_rescale(current_sample->timestamp, AV_TIME_BASE, msc->time_scale);
02913 av_dlog(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
02914 if (!sample || (!s->pb->seekable && current_sample->pos < sample->pos) ||
02915 (s->pb->seekable &&
02916 ((msc->pb != s->pb && dts < best_dts) || (msc->pb == s->pb &&
02917 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
02918 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))))) {
02919 sample = current_sample;
02920 best_dts = dts;
02921 *st = avst;
02922 }
02923 }
02924 }
02925 return sample;
02926 }
02927
02928 static int mov_read_packet(AVFormatContext *s, AVPacket *pkt)
02929 {
02930 MOVContext *mov = s->priv_data;
02931 MOVStreamContext *sc;
02932 AVIndexEntry *sample;
02933 AVStream *st = NULL;
02934 int ret;
02935 mov->fc = s;
02936 retry:
02937 sample = mov_find_next_sample(s, &st);
02938 if (!sample) {
02939 mov->found_mdat = 0;
02940 if (!mov->next_root_atom)
02941 return AVERROR_EOF;
02942 avio_seek(s->pb, mov->next_root_atom, SEEK_SET);
02943 mov->next_root_atom = 0;
02944 if (mov_read_default(mov, s->pb, (MOVAtom){ AV_RL32("root"), INT64_MAX }) < 0 ||
02945 url_feof(s->pb))
02946 return AVERROR_EOF;
02947 av_dlog(s, "read fragments, offset 0x%"PRIx64"\n", avio_tell(s->pb));
02948 goto retry;
02949 }
02950 sc = st->priv_data;
02951
02952 sc->current_sample++;
02953
02954 if (st->discard != AVDISCARD_ALL) {
02955 if (avio_seek(sc->pb, sample->pos, SEEK_SET) != sample->pos) {
02956 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n",
02957 sc->ffindex, sample->pos);
02958 return AVERROR_INVALIDDATA;
02959 }
02960 ret = av_get_packet(sc->pb, pkt, sample->size);
02961 if (ret < 0)
02962 return ret;
02963 if (sc->has_palette) {
02964 uint8_t *pal;
02965
02966 pal = av_packet_new_side_data(pkt, AV_PKT_DATA_PALETTE, AVPALETTE_SIZE);
02967 if (!pal) {
02968 av_log(mov->fc, AV_LOG_ERROR, "Cannot append palette to packet\n");
02969 } else {
02970 memcpy(pal, sc->palette, AVPALETTE_SIZE);
02971 sc->has_palette = 0;
02972 }
02973 }
02974 #if CONFIG_DV_DEMUXER
02975 if (mov->dv_demux && sc->dv_audio_container) {
02976 avpriv_dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size, pkt->pos);
02977 av_free(pkt->data);
02978 pkt->size = 0;
02979 ret = avpriv_dv_get_packet(mov->dv_demux, pkt);
02980 if (ret < 0)
02981 return ret;
02982 }
02983 #endif
02984 }
02985
02986 pkt->stream_index = sc->ffindex;
02987 pkt->dts = sample->timestamp;
02988 if (sc->ctts_data && sc->ctts_index < sc->ctts_count) {
02989 pkt->pts = pkt->dts + sc->dts_shift + sc->ctts_data[sc->ctts_index].duration;
02990
02991 sc->ctts_sample++;
02992 if (sc->ctts_index < sc->ctts_count &&
02993 sc->ctts_data[sc->ctts_index].count == sc->ctts_sample) {
02994 sc->ctts_index++;
02995 sc->ctts_sample = 0;
02996 }
02997 if (sc->wrong_dts)
02998 pkt->dts = AV_NOPTS_VALUE;
02999 } else {
03000 int64_t next_dts = (sc->current_sample < st->nb_index_entries) ?
03001 st->index_entries[sc->current_sample].timestamp : st->duration;
03002 pkt->duration = next_dts - pkt->dts;
03003 pkt->pts = pkt->dts;
03004 }
03005 if (st->discard == AVDISCARD_ALL)
03006 goto retry;
03007 pkt->flags |= sample->flags & AVINDEX_KEYFRAME ? AV_PKT_FLAG_KEY : 0;
03008 pkt->pos = sample->pos;
03009 av_dlog(s, "stream %d, pts %"PRId64", dts %"PRId64", pos 0x%"PRIx64", duration %d\n",
03010 pkt->stream_index, pkt->pts, pkt->dts, pkt->pos, pkt->duration);
03011 return 0;
03012 }
03013
03014 static int mov_seek_stream(AVFormatContext *s, AVStream *st, int64_t timestamp, int flags)
03015 {
03016 MOVStreamContext *sc = st->priv_data;
03017 int sample, time_sample;
03018 int i;
03019
03020 sample = av_index_search_timestamp(st, timestamp, flags);
03021 av_dlog(s, "stream %d, timestamp %"PRId64", sample %d\n", st->index, timestamp, sample);
03022 if (sample < 0 && st->nb_index_entries && timestamp < st->index_entries[0].timestamp)
03023 sample = 0;
03024 if (sample < 0)
03025 return AVERROR_INVALIDDATA;
03026 sc->current_sample = sample;
03027 av_dlog(s, "stream %d, found sample %d\n", st->index, sc->current_sample);
03028
03029 if (sc->ctts_data) {
03030 time_sample = 0;
03031 for (i = 0; i < sc->ctts_count; i++) {
03032 int next = time_sample + sc->ctts_data[i].count;
03033 if (next > sc->current_sample) {
03034 sc->ctts_index = i;
03035 sc->ctts_sample = sc->current_sample - time_sample;
03036 break;
03037 }
03038 time_sample = next;
03039 }
03040 }
03041 return sample;
03042 }
03043
03044 static int mov_read_seek(AVFormatContext *s, int stream_index, int64_t sample_time, int flags)
03045 {
03046 AVStream *st;
03047 int64_t seek_timestamp, timestamp;
03048 int sample;
03049 int i;
03050
03051 if (stream_index >= s->nb_streams)
03052 return AVERROR_INVALIDDATA;
03053 if (sample_time < 0)
03054 sample_time = 0;
03055
03056 st = s->streams[stream_index];
03057 sample = mov_seek_stream(s, st, sample_time, flags);
03058 if (sample < 0)
03059 return sample;
03060
03061
03062 seek_timestamp = st->index_entries[sample].timestamp;
03063
03064 for (i = 0; i < s->nb_streams; i++) {
03065 st = s->streams[i];
03066 if (stream_index == i)
03067 continue;
03068
03069 timestamp = av_rescale_q(seek_timestamp, s->streams[stream_index]->time_base, st->time_base);
03070 mov_seek_stream(s, st, timestamp, flags);
03071 }
03072 return 0;
03073 }
03074
03075 static const AVOption options[] = {
03076 {"use_absolute_path",
03077 "allow using absolute path when opening alias, this is a possible security issue",
03078 offsetof(MOVContext, use_absolute_path), FF_OPT_TYPE_INT, {.dbl = 0},
03079 0, 1, AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_DECODING_PARAM},
03080 {NULL}
03081 };
03082 static const AVClass class = {"mov,mp4,m4a,3gp,3g2,mj2", av_default_item_name, options, LIBAVUTIL_VERSION_INT};
03083
03084
03085 AVInputFormat ff_mov_demuxer = {
03086 .name = "mov,mp4,m4a,3gp,3g2,mj2",
03087 .long_name = NULL_IF_CONFIG_SMALL("QuickTime/MPEG-4/Motion JPEG 2000 format"),
03088 .priv_data_size = sizeof(MOVContext),
03089 .read_probe = mov_probe,
03090 .read_header = mov_read_header,
03091 .read_packet = mov_read_packet,
03092 .read_close = mov_read_close,
03093 .read_seek = mov_read_seek,
03094 .priv_class = &class,
03095 };