|
|
|
@ -216,6 +216,7 @@ static int update_stream_avctx(AVFormatContext *s) |
|
|
|
|
int avformat_open_input(AVFormatContext **ps, const char *filename, |
|
|
|
|
const AVInputFormat *fmt, AVDictionary **options) |
|
|
|
|
{ |
|
|
|
|
FormatContextInternal *fci; |
|
|
|
|
AVFormatContext *s = *ps; |
|
|
|
|
FFFormatContext *si; |
|
|
|
|
AVDictionary *tmp = NULL; |
|
|
|
@ -224,7 +225,8 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, |
|
|
|
|
|
|
|
|
|
if (!s && !(s = avformat_alloc_context())) |
|
|
|
|
return AVERROR(ENOMEM); |
|
|
|
|
si = ffformatcontext(s); |
|
|
|
|
fci = ff_fc_internal(s); |
|
|
|
|
si = &fci->fc; |
|
|
|
|
if (!s->av_class) { |
|
|
|
|
av_log(NULL, AV_LOG_ERROR, "Input context has not been properly allocated by avformat_alloc_context() and is not NULL either\n"); |
|
|
|
|
return AVERROR(EINVAL); |
|
|
|
@ -337,7 +339,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, |
|
|
|
|
if (s->pb && !si->data_offset) |
|
|
|
|
si->data_offset = avio_tell(s->pb); |
|
|
|
|
|
|
|
|
|
si->raw_packet_buffer_size = 0; |
|
|
|
|
fci->raw_packet_buffer_size = 0; |
|
|
|
|
|
|
|
|
|
update_stream_avctx(s); |
|
|
|
|
|
|
|
|
@ -411,7 +413,7 @@ static void force_codec_ids(AVFormatContext *s, AVStream *st) |
|
|
|
|
|
|
|
|
|
static int probe_codec(AVFormatContext *s, AVStream *st, const AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFStream *const sti = ffstream(st); |
|
|
|
|
|
|
|
|
|
if (sti->request_probe > 0) { |
|
|
|
@ -441,8 +443,8 @@ no_packet: |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
end = si->raw_packet_buffer_size >= s->probesize |
|
|
|
|
|| sti->probe_packets <= 0; |
|
|
|
|
end = fci->raw_packet_buffer_size >= s->probesize || |
|
|
|
|
sti->probe_packets <= 0; |
|
|
|
|
|
|
|
|
|
if (end || av_log2(pd->buf_size) != av_log2(pd->buf_size - pkt->size)) { |
|
|
|
|
int score = set_codec_from_probe_data(s, st, pd); |
|
|
|
@ -564,7 +566,7 @@ static void update_timestamps(AVFormatContext *s, AVStream *st, AVPacket *pkt) |
|
|
|
|
*/ |
|
|
|
|
static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passthrough) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
AVStream *st; |
|
|
|
|
FFStream *sti; |
|
|
|
|
int err; |
|
|
|
@ -588,17 +590,17 @@ static int handle_new_packet(AVFormatContext *s, AVPacket *pkt, int allow_passth |
|
|
|
|
|
|
|
|
|
update_timestamps(s, st, pkt); |
|
|
|
|
|
|
|
|
|
if (sti->request_probe <= 0 && allow_passthrough && !si->raw_packet_buffer.head) |
|
|
|
|
if (sti->request_probe <= 0 && allow_passthrough && !fci->raw_packet_buffer.head) |
|
|
|
|
return 0; |
|
|
|
|
|
|
|
|
|
err = avpriv_packet_list_put(&si->raw_packet_buffer, pkt, NULL, 0); |
|
|
|
|
err = avpriv_packet_list_put(&fci->raw_packet_buffer, pkt, NULL, 0); |
|
|
|
|
if (err < 0) { |
|
|
|
|
av_packet_unref(pkt); |
|
|
|
|
return err; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
pkt = &si->raw_packet_buffer.tail->pkt; |
|
|
|
|
si->raw_packet_buffer_size += pkt->size; |
|
|
|
|
pkt = &fci->raw_packet_buffer.tail->pkt; |
|
|
|
|
fci->raw_packet_buffer_size += pkt->size; |
|
|
|
|
|
|
|
|
|
err = probe_codec(s, st, pkt); |
|
|
|
|
if (err < 0) |
|
|
|
@ -616,7 +618,7 @@ int ff_buffer_packet(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
|
|
|
|
|
int ff_read_packet(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
int err; |
|
|
|
|
|
|
|
|
|
#if FF_API_INIT_PACKET |
|
|
|
@ -630,16 +632,16 @@ FF_ENABLE_DEPRECATION_WARNINGS |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
for (;;) { |
|
|
|
|
PacketListEntry *pktl = si->raw_packet_buffer.head; |
|
|
|
|
PacketListEntry *pktl = fci->raw_packet_buffer.head; |
|
|
|
|
|
|
|
|
|
if (pktl) { |
|
|
|
|
AVStream *const st = s->streams[pktl->pkt.stream_index]; |
|
|
|
|
if (si->raw_packet_buffer_size >= s->probesize) |
|
|
|
|
if (fci->raw_packet_buffer_size >= s->probesize) |
|
|
|
|
if ((err = probe_codec(s, st, NULL)) < 0) |
|
|
|
|
return err; |
|
|
|
|
if (ffstream(st)->request_probe <= 0) { |
|
|
|
|
avpriv_packet_list_get(&si->raw_packet_buffer, pkt); |
|
|
|
|
si->raw_packet_buffer_size -= pkt->size; |
|
|
|
|
avpriv_packet_list_get(&fci->raw_packet_buffer, pkt); |
|
|
|
|
fci->raw_packet_buffer_size -= pkt->size; |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -766,11 +768,12 @@ static int has_decode_delay_been_guessed(AVStream *st) |
|
|
|
|
static PacketListEntry *get_next_pkt(AVFormatContext *s, AVStream *st, |
|
|
|
|
PacketListEntry *pktl) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
if (pktl->next) |
|
|
|
|
return pktl->next; |
|
|
|
|
if (pktl == si->packet_buffer.tail) |
|
|
|
|
return si->parse_queue.head; |
|
|
|
|
return fci->parse_queue.head; |
|
|
|
|
return NULL; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -850,10 +853,11 @@ static void update_dts_from_pts(AVFormatContext *s, int stream_index, |
|
|
|
|
static void update_initial_timestamps(AVFormatContext *s, int stream_index, |
|
|
|
|
int64_t dts, int64_t pts, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
AVStream *const st = s->streams[stream_index]; |
|
|
|
|
FFStream *const sti = ffstream(st); |
|
|
|
|
PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; |
|
|
|
|
PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
|
|
|
|
|
|
|
|
|
uint64_t shift; |
|
|
|
|
|
|
|
|
@ -903,9 +907,10 @@ static void update_initial_timestamps(AVFormatContext *s, int stream_index, |
|
|
|
|
static void update_initial_durations(AVFormatContext *s, AVStream *st, |
|
|
|
|
int stream_index, int64_t duration) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
FFStream *const sti = ffstream(st); |
|
|
|
|
PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; |
|
|
|
|
PacketListEntry *pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
|
|
|
|
int64_t cur_dts = RELATIVE_TS_BASE; |
|
|
|
|
|
|
|
|
|
if (sti->first_dts != AV_NOPTS_VALUE) { |
|
|
|
@ -931,7 +936,7 @@ static void update_initial_durations(AVFormatContext *s, AVStream *st, |
|
|
|
|
av_log(s, AV_LOG_DEBUG, "first_dts %s but no packet with dts in the queue\n", av_ts2str(sti->first_dts)); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
pktl = si->packet_buffer.head ? si->packet_buffer.head : si->parse_queue.head; |
|
|
|
|
pktl = si->packet_buffer.head ? si->packet_buffer.head : fci->parse_queue.head; |
|
|
|
|
sti->first_dts = cur_dts; |
|
|
|
|
} else if (sti->cur_dts != RELATIVE_TS_BASE) |
|
|
|
|
return; |
|
|
|
@ -963,7 +968,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, |
|
|
|
|
AVCodecParserContext *pc, AVPacket *pkt, |
|
|
|
|
int64_t next_dts, int64_t next_pts) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
FFStream *const sti = ffstream(st); |
|
|
|
|
int num, den, presentation_delayed, delay; |
|
|
|
|
int64_t offset; |
|
|
|
@ -1048,7 +1054,7 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (pkt->duration > 0 && (si->packet_buffer.head || si->parse_queue.head)) |
|
|
|
|
if (pkt->duration > 0 && (si->packet_buffer.head || fci->parse_queue.head)) |
|
|
|
|
update_initial_durations(s, st, pkt->stream_index, pkt->duration); |
|
|
|
|
|
|
|
|
|
/* Correct timestamps with byte offset if demuxers only have timestamps
|
|
|
|
@ -1156,7 +1162,8 @@ static void compute_pkt_fields(AVFormatContext *s, AVStream *st, |
|
|
|
|
static int parse_packet(AVFormatContext *s, AVPacket *pkt, |
|
|
|
|
int stream_index, int flush) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
AVPacket *out_pkt = si->parse_pkt; |
|
|
|
|
AVStream *st = s->streams[stream_index]; |
|
|
|
|
FFStream *const sti = ffstream(st); |
|
|
|
@ -1249,7 +1256,7 @@ static int parse_packet(AVFormatContext *s, AVPacket *pkt, |
|
|
|
|
|
|
|
|
|
compute_pkt_fields(s, st, sti->parser, out_pkt, next_dts, next_pts); |
|
|
|
|
|
|
|
|
|
ret = avpriv_packet_list_put(&si->parse_queue, |
|
|
|
|
ret = avpriv_packet_list_put(&fci->parse_queue, |
|
|
|
|
out_pkt, NULL, 0); |
|
|
|
|
if (ret < 0) |
|
|
|
|
goto fail; |
|
|
|
@ -1324,11 +1331,12 @@ static int extract_extradata(FFFormatContext *si, AVStream *st, const AVPacket * |
|
|
|
|
|
|
|
|
|
static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
{ |
|
|
|
|
FFFormatContext *const si = ffformatcontext(s); |
|
|
|
|
FormatContextInternal *const fci = ff_fc_internal(s); |
|
|
|
|
FFFormatContext *const si = &fci->fc; |
|
|
|
|
int ret, got_packet = 0; |
|
|
|
|
AVDictionary *metadata = NULL; |
|
|
|
|
|
|
|
|
|
while (!got_packet && !si->parse_queue.head) { |
|
|
|
|
while (!got_packet && !fci->parse_queue.head) { |
|
|
|
|
AVStream *st; |
|
|
|
|
FFStream *sti; |
|
|
|
|
|
|
|
|
@ -1456,8 +1464,8 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!got_packet && si->parse_queue.head) |
|
|
|
|
ret = avpriv_packet_list_get(&si->parse_queue, pkt); |
|
|
|
|
if (!got_packet && fci->parse_queue.head) |
|
|
|
|
ret = avpriv_packet_list_get(&fci->parse_queue, pkt); |
|
|
|
|
|
|
|
|
|
if (ret >= 0) { |
|
|
|
|
AVStream *const st = s->streams[pkt->stream_index]; |
|
|
|
@ -1508,7 +1516,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!si->metafree) { |
|
|
|
|
if (!fci->metafree) { |
|
|
|
|
int metaret = av_opt_get_dict_val(s, "metadata", AV_OPT_SEARCH_CHILDREN, &metadata); |
|
|
|
|
if (metadata) { |
|
|
|
|
s->event_flags |= AVFMT_EVENT_FLAG_METADATA_UPDATED; |
|
|
|
@ -1516,7 +1524,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) |
|
|
|
|
av_dict_free(&metadata); |
|
|
|
|
av_opt_set_dict_val(s, "metadata", NULL, AV_OPT_SEARCH_CHILDREN); |
|
|
|
|
} |
|
|
|
|
si->metafree = metaret == AVERROR_OPTION_NOT_FOUND; |
|
|
|
|
fci->metafree = metaret == AVERROR_OPTION_NOT_FOUND; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (s->debug & FF_FDEBUG_TS) |
|
|
|
|