Mercurial > libavformat.hg
comparison mov.c @ 2817:b1b21255bbbb libavformat
support streamed mov/mp4
author | bcoudurier |
---|---|
date | Sun, 16 Dec 2007 18:08:06 +0000 |
parents | 3fa92d78424c |
children | f639238e2936 |
comparison
equal
deleted
inserted
replaced
2816:1523342b58b3 | 2817:b1b21255bbbb |
---|---|
191 url_fskip(pb, a.size); | 191 url_fskip(pb, a.size); |
192 } else { | 192 } else { |
193 offset_t start_pos = url_ftell(pb); | 193 offset_t start_pos = url_ftell(pb); |
194 int64_t left; | 194 int64_t left; |
195 err = (c->parse_table[i].func)(c, pb, a); | 195 err = (c->parse_table[i].func)(c, pb, a); |
196 if (c->found_moov && c->found_mdat) | |
197 break; | |
196 left = a.size - url_ftell(pb) + start_pos; | 198 left = a.size - url_ftell(pb) + start_pos; |
197 if (left > 0) /* skip garbage at atom end */ | 199 if (left > 0) /* skip garbage at atom end */ |
198 url_fskip(pb, left); | 200 url_fskip(pb, left); |
199 } | 201 } |
200 | 202 |
1509 if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { | 1511 if (s->streams[i]->discard != AVDISCARD_ALL && msc->current_sample < msc->sample_count) { |
1510 AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample]; | 1512 AVIndexEntry *current_sample = &s->streams[i]->index_entries[msc->current_sample]; |
1511 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); | 1513 int64_t dts = av_rescale(current_sample->timestamp * (int64_t)msc->time_rate, AV_TIME_BASE, msc->time_scale); |
1512 | 1514 |
1513 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); | 1515 dprintf(s, "stream %d, sample %d, dts %"PRId64"\n", i, msc->current_sample, dts); |
1514 if (!sample || | 1516 if (!sample || (url_is_streamed(s->pb) && current_sample->pos < sample->pos) || |
1515 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || | 1517 (!url_is_streamed(s->pb) && |
1516 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts))) { | 1518 ((FFABS(best_dts - dts) <= AV_TIME_BASE && current_sample->pos < sample->pos) || |
1519 (FFABS(best_dts - dts) > AV_TIME_BASE && dts < best_dts)))) { | |
1517 sample = current_sample; | 1520 sample = current_sample; |
1518 best_dts = dts; | 1521 best_dts = dts; |
1519 sc = msc; | 1522 sc = msc; |
1520 } | 1523 } |
1521 } | 1524 } |
1522 } | 1525 } |
1523 if (!sample) | 1526 if (!sample) |
1524 return -1; | 1527 return -1; |
1525 /* must be done just before reading, to avoid infinite loop on sample */ | 1528 /* must be done just before reading, to avoid infinite loop on sample */ |
1526 sc->current_sample++; | 1529 sc->current_sample++; |
1527 if (sample->pos >= url_fsize(s->pb)) { | 1530 if (url_fseek(s->pb, sample->pos, SEEK_SET) != sample->pos) { |
1528 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos); | 1531 av_log(mov->fc, AV_LOG_ERROR, "stream %d, offset 0x%"PRIx64": partial file\n", sc->ffindex, sample->pos); |
1529 return -1; | 1532 return -1; |
1530 } | 1533 } |
1531 #ifdef CONFIG_DV_DEMUXER | 1534 #ifdef CONFIG_DV_DEMUXER |
1532 if (sc->dv_audio_container) { | 1535 if (sc->dv_audio_container) { |
1533 dv_get_packet(mov->dv_demux, pkt); | 1536 dv_get_packet(mov->dv_demux, pkt); |
1534 dprintf(s, "dv audio pkt size %d\n", pkt->size); | 1537 dprintf(s, "dv audio pkt size %d\n", pkt->size); |
1535 } else { | 1538 } else { |
1536 #endif | 1539 #endif |
1537 url_fseek(s->pb, sample->pos, SEEK_SET); | |
1538 av_get_packet(s->pb, pkt, sample->size); | 1540 av_get_packet(s->pb, pkt, sample->size); |
1539 #ifdef CONFIG_DV_DEMUXER | 1541 #ifdef CONFIG_DV_DEMUXER |
1540 if (mov->dv_demux) { | 1542 if (mov->dv_demux) { |
1541 void *pkt_destruct_func = pkt->destruct; | 1543 void *pkt_destruct_func = pkt->destruct; |
1542 dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); | 1544 dv_produce_packet(mov->dv_demux, pkt, pkt->data, pkt->size); |