comparison mov.c @ 2824:ecbfaa8712a1 libavformat

do not retain useless pointers to avstream priv_data, use it directly
author bcoudurier
date Sun, 16 Dec 2007 18:45:48 +0000
parents 3f15b52fe817
children 5862d8be4c6e
comparison
equal deleted inserted replaced
2823:3f15b52fe817 2824:ecbfaa8712a1
114 int time_scale; 114 int time_scale;
115 int64_t duration; /* duration of the longest track */ 115 int64_t duration; /* duration of the longest track */
116 int found_moov; /* when both 'moov' and 'mdat' sections has been found */ 116 int found_moov; /* when both 'moov' and 'mdat' sections has been found */
117 int found_mdat; /* we suppose we have enough data to read the file */ 117 int found_mdat; /* we suppose we have enough data to read the file */
118 int64_t mdat_offset; 118 int64_t mdat_offset;
119 MOVStreamContext *streams[MAX_STREAMS];
120 AVPaletteControl palette_control; 119 AVPaletteControl palette_control;
121 MOV_mdat_t *mdat_list; 120 MOV_mdat_t *mdat_list;
122 int mdat_count; 121 int mdat_count;
123 DVDemuxContext *dv_demux; 122 DVDemuxContext *dv_demux;
124 AVFormatContext *dv_fctx; 123 AVFormatContext *dv_fctx;
1036 } 1035 }
1037 1036
1038 st->priv_data = sc; 1037 st->priv_data = sc;
1039 st->codec->codec_type = CODEC_TYPE_DATA; 1038 st->codec->codec_type = CODEC_TYPE_DATA;
1040 st->start_time = 0; /* XXX: check */ 1039 st->start_time = 0; /* XXX: check */
1041 c->streams[c->fc->nb_streams-1] = sc;
1042 1040
1043 return mov_read_default(c, pb, atom); 1041 return mov_read_default(c, pb, atom);
1044 } 1042 }
1045 1043
1046 static void mov_parse_udta_string(ByteIOContext *pb, char *str, int size) 1044 static void mov_parse_udta_string(ByteIOContext *pb, char *str, int size)
1204 } 1202 }
1205 1203
1206 /* edit list atom */ 1204 /* edit list atom */
1207 static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom) 1205 static int mov_read_elst(MOVContext *c, ByteIOContext *pb, MOV_atom_t atom)
1208 { 1206 {
1207 MOVStreamContext *sc = c->fc->streams[c->fc->nb_streams-1]->priv_data;
1209 int i, edit_count; 1208 int i, edit_count;
1210 1209
1211 get_byte(pb); /* version */ 1210 get_byte(pb); /* version */
1212 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */ 1211 get_byte(pb); get_byte(pb); get_byte(pb); /* flags */
1213 edit_count= c->streams[c->fc->nb_streams-1]->edit_count = get_be32(pb); /* entries */ 1212 edit_count= sc->edit_count = get_be32(pb); /* entries */
1214 1213
1215 for(i=0; i<edit_count; i++){ 1214 for(i=0; i<edit_count; i++){
1216 get_be32(pb); /* Track duration */ 1215 get_be32(pb); /* Track duration */
1217 get_be32(pb); /* Media time */ 1216 get_be32(pb); /* Media time */
1218 get_be32(pb); /* Media rate */ 1217 get_be32(pb); /* Media rate */
1219 } 1218 }
1220 dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, c->streams[c->fc->nb_streams-1]->edit_count); 1219 dprintf(c->fc, "track[%i].edit_count = %i\n", c->fc->nb_streams-1, sc->edit_count);
1221 return 0; 1220 return 0;
1222 } 1221 }
1223 1222
1224 static const MOVParseTableEntry mov_default_parse_table[] = { 1223 static const MOVParseTableEntry mov_default_parse_table[] = {
1225 /* mp4 atoms */ 1224 /* mp4 atoms */
1363 else if (sc->samples_per_frame > 0 && (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0)) 1362 else if (sc->samples_per_frame > 0 && (chunk_samples * sc->bytes_per_frame % sc->samples_per_frame == 0))
1364 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame; 1363 chunk_size = chunk_samples * sc->bytes_per_frame / sc->samples_per_frame;
1365 else { /* workaround to find nearest next chunk offset */ 1364 else { /* workaround to find nearest next chunk offset */
1366 chunk_size = INT_MAX; 1365 chunk_size = INT_MAX;
1367 for (j = 0; j < mov->fc->nb_streams; j++) { 1366 for (j = 0; j < mov->fc->nb_streams; j++) {
1368 MOVStreamContext *msc = mov->streams[j]; 1367 MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
1369 for (k = msc->next_chunk; k < msc->chunk_count; k++) { 1368 for (k = msc->next_chunk; k < msc->chunk_count; k++) {
1370 if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) { 1369 if (msc->chunk_offsets[k] > current_offset && msc->chunk_offsets[k] - current_offset < chunk_size) {
1371 chunk_size = msc->chunk_offsets[k] - current_offset; 1370 chunk_size = msc->chunk_offsets[k] - current_offset;
1372 msc->next_chunk = k; 1371 msc->next_chunk = k;
1373 break; 1372 break;
1382 if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset) 1381 if (mov->mdat_list[j].offset <= current_offset && mov->mdat_list[j].offset + mov->mdat_list[j].size > current_offset)
1383 chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset; 1382 chunk_size = mov->mdat_list[j].offset + mov->mdat_list[j].size - current_offset;
1384 } 1383 }
1385 assert(chunk_size != INT_MAX); 1384 assert(chunk_size != INT_MAX);
1386 for (j = 0; j < mov->fc->nb_streams; j++) { 1385 for (j = 0; j < mov->fc->nb_streams; j++) {
1387 mov->streams[j]->next_chunk = 0; 1386 MOVStreamContext *msc = mov->fc->streams[j]->priv_data;
1387 msc->next_chunk = 0;
1388 } 1388 }
1389 } 1389 }
1390 av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME); 1390 av_add_index_entry(st, current_offset, current_dts, chunk_size, 0, AVINDEX_KEYFRAME);
1391 /* get chunk duration */ 1391 /* get chunk duration */
1392 chunk_duration = 0; 1392 chunk_duration = 0;
1436 return -1; 1436 return -1;
1437 } 1437 }
1438 dprintf(mov->fc, "on_parse_exit_offset=%d\n", (int) url_ftell(pb)); 1438 dprintf(mov->fc, "on_parse_exit_offset=%d\n", (int) url_ftell(pb));
1439 1439
1440 for(i=0; i<s->nb_streams; i++) { 1440 for(i=0; i<s->nb_streams; i++) {
1441 MOVStreamContext *sc = mov->streams[i];
1442 AVStream *st = s->streams[i]; 1441 AVStream *st = s->streams[i];
1442 MOVStreamContext *sc = st->priv_data;
1443 /* sanity checks */ 1443 /* sanity checks */
1444 if(!sc->stts_count || !sc->chunk_count || !sc->sample_to_chunk_sz || 1444 if(!sc->stts_count || !sc->chunk_count || !sc->sample_to_chunk_sz ||
1445 (!sc->sample_size && !sc->sample_count)){ 1445 (!sc->sample_size && !sc->sample_count)){
1446 av_log(s, AV_LOG_ERROR, "missing mandatory atoms, broken header\n"); 1446 av_log(s, AV_LOG_ERROR, "missing mandatory atoms, broken header\n");
1447 sc->sample_count = 0; //ignore track 1447 sc->sample_count = 0; //ignore track
1463 sc->ffindex = i; 1463 sc->ffindex = i;
1464 mov_build_index(mov, st); 1464 mov_build_index(mov, st);
1465 } 1465 }
1466 1466
1467 for(i=0; i<s->nb_streams; i++) { 1467 for(i=0; i<s->nb_streams; i++) {
1468 MOVStreamContext *sc = s->streams[i]->priv_data;
1468 /* Do not need those anymore. */ 1469 /* Do not need those anymore. */
1469 av_freep(&mov->streams[i]->chunk_offsets); 1470 av_freep(&sc->chunk_offsets);
1470 av_freep(&mov->streams[i]->sample_to_chunk); 1471 av_freep(&sc->sample_to_chunk);
1471 av_freep(&mov->streams[i]->sample_sizes); 1472 av_freep(&sc->sample_sizes);
1472 av_freep(&mov->streams[i]->keyframes); 1473 av_freep(&sc->keyframes);
1473 av_freep(&mov->streams[i]->stts_data); 1474 av_freep(&sc->stts_data);
1474 } 1475 }
1475 av_freep(&mov->mdat_list); 1476 av_freep(&mov->mdat_list);
1476 return 0; 1477 return 0;
1477 } 1478 }
1478 1479
1483 AVIndexEntry *sample = 0; 1484 AVIndexEntry *sample = 0;
1484 int64_t best_dts = INT64_MAX; 1485 int64_t best_dts = INT64_MAX;
1485 int i; 1486 int i;
1486 1487
1487 for (i = 0; i < s->nb_streams; i++) { 1488 for (i = 0; i < s->nb_streams; i++) {
1488 MOVStreamContext *msc = mov->streams[i]; 1489 AVStream *st = s->streams[i];
1489 if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { 1490 MOVStreamContext *msc = st->priv_data;
1490 AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample]; 1491 if (st->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) {
1492 AVIndexEntry *current_sample = &st->index_entries[msc->current_sample];
1491 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); 1493 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale);
1492 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); 1494 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts);
1493 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || 1495 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) ||
1494 (!url_is_streamed(s->pb) && 1496 (!url_is_streamed(s->pb) &&
1495 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || 1497 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) ||
1603 static int mov_read_close(AVFormatContext *s) 1605 static int mov_read_close(AVFormatContext *s)
1604 { 1606 {
1605 int i; 1607 int i;
1606 MOVContext *mov = s->priv_data; 1608 MOVContext *mov = s->priv_data;
1607 for(i=0; i<s->nb_streams; i++) { 1609 for(i=0; i<s->nb_streams; i++) {
1608 av_freep(&mov->streams[i]->ctts_data); 1610 MOVStreamContext *sc = s->streams[i]->priv_data;
1609 av_freep(&mov->streams[i]); 1611 av_freep(&sc->ctts_data);
1610 } 1612 }
1611 if(mov->dv_demux){ 1613 if(mov->dv_demux){
1612 for(i=0; i<mov->dv_fctx->nb_streams; i++){ 1614 for(i=0; i<mov->dv_fctx->nb_streams; i++){
1613 av_freep(&mov->dv_fctx->streams[i]->codec); 1615 av_freep(&mov->dv_fctx->streams[i]->codec);
1614 av_freep(&mov->dv_fctx->streams[i]); 1616 av_freep(&mov->dv_fctx->streams[i]);