X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavformat%2Futils.c;h=6c985af1a01707727ff7f841e74007423a153169;hb=d5ed5e7d0c1fa46de348db0de4c82b0f621db3d4;hp=effefd551a28a72c0c60c9c4d5764501ac0b531b;hpb=f35f8eeb0dd65bd24b479bc5d48759007aba3d29;p=ffmpeg diff --git a/libavformat/utils.c b/libavformat/utils.c index effefd551a2..6c985af1a01 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -480,7 +480,7 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o if (s->pb) { s->flags |= AVFMT_FLAG_CUSTOM_IO; if (!s->iformat) - return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0); + return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, s->probesize); else if (s->iformat->flags & AVFMT_NOFILE) return AVERROR(EINVAL); return 0; @@ -495,7 +495,7 @@ static int init_input(AVFormatContext *s, const char *filename, AVDictionary **o return ret; if (s->iformat) return 0; - return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, 0); + return av_probe_input_buffer(s->pb, &s->iformat, filename, s, 0, s->probesize); } static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, @@ -515,10 +515,22 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt, return &pktl->pkt; } +static void queue_attached_pictures(AVFormatContext *s) +{ + int i; + for (i = 0; i < s->nb_streams; i++) + if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC && + s->streams[i]->discard < AVDISCARD_ALL) { + AVPacket copy = s->streams[i]->attached_pic; + copy.destruct = NULL; + add_to_pktbuf(&s->raw_packet_buffer, ©, &s->raw_packet_buffer_end); + } +} + int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options) { AVFormatContext *s = *ps; - int i, ret = 0; + int ret = 0; AVDictionary *tmp = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL; @@ -574,13 +586,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma goto fail; ff_id3v2_free_extra_meta(&id3v2_extra_meta); - /* queue attached pictures */ - for (i = 0; i < s->nb_streams; i++) - if (s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC) { - AVPacket copy = s->streams[i]->attached_pic; - copy.destruct = NULL; - add_to_pktbuf(&s->raw_packet_buffer, ©, &s->raw_packet_buffer_end); - } + queue_attached_pictures(s); if (s->pb && !s->data_offset) s->data_offset = avio_tell(s->pb); @@ -606,7 +612,7 @@ fail: /*******************************************************/ -int av_read_packet(AVFormatContext *s, AVPacket *pkt) +int ff_read_packet(AVFormatContext *s, AVPacket *pkt) { int ret, i; AVStream *st; @@ -692,6 +698,14 @@ int av_read_packet(AVFormatContext *s, AVPacket *pkt) } } +#if FF_API_READ_PACKET +int av_read_packet(AVFormatContext *s, AVPacket *pkt) +{ + return ff_read_packet(s, pkt); +} +#endif + + /**********************************************************/ /** @@ -1150,7 +1164,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) AVPacket cur_pkt; /* read next packet */ - ret = av_read_packet(s, &cur_pkt); + ret = ff_read_packet(s, &cur_pkt); if (ret < 0) { if (ret == AVERROR(EAGAIN)) return ret; @@ -1177,7 +1191,7 @@ static int read_frame_internal(AVFormatContext *s, AVPacket *pkt) cur_pkt.size); } if (s->debug & FF_FDEBUG_TS) - av_log(s, AV_LOG_DEBUG, "av_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", + av_log(s, AV_LOG_DEBUG, "ff_read_packet stream=%d, pts=%"PRId64", dts=%"PRId64", size=%d, duration=%d, flags=%d\n", cur_pkt.stream_index, cur_pkt.pts, cur_pkt.dts, @@ -1640,14 +1654,6 @@ int64_t ff_gen_search(AVFormatContext *s, int stream_index, int64_t target_ts, static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, int flags){ int64_t pos_min, pos_max; -#if 0 - AVStream *st; - - if (stream_index < 0) - return -1; - - st= s->streams[stream_index]; -#endif pos_min = s->data_offset; pos_max = avio_size(s->pb) - 1; @@ -1657,9 +1663,6 @@ static int seek_frame_byte(AVFormatContext *s, int stream_index, int64_t pos, in avio_seek(s->pb, pos, SEEK_SET); -#if 0 - av_update_cur_dts(s, st, ts); -#endif return 0; } @@ -1722,7 +1725,8 @@ static int seek_frame_generic(AVFormatContext *s, return 0; } -int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +static int seek_frame_internal(AVFormatContext *s, int stream_index, + int64_t timestamp, int flags) { int ret; AVStream *st; @@ -1765,14 +1769,29 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f return -1; } +int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) +{ + int ret = seek_frame_internal(s, stream_index, timestamp, flags); + + if (ret >= 0) + queue_attached_pictures(s); + + return ret; +} + int avformat_seek_file(AVFormatContext *s, int stream_index, int64_t min_ts, int64_t ts, int64_t max_ts, int flags) { if(min_ts > ts || max_ts < ts) return -1; if (s->iformat->read_seek2) { + int ret; ff_read_frame_flush(s); - return s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); + ret = s->iformat->read_seek2(s, stream_index, min_ts, ts, max_ts, flags); + + if (ret >= 0) + queue_attached_pictures(s); + return ret; } if(s->iformat->read_timestamp){ @@ -1945,7 +1964,7 @@ static void estimate_timings_from_pts(AVFormatContext *ic, int64_t old_offset) break; do { - ret = av_read_packet(ic, pkt); + ret = ff_read_packet(ic, pkt); } while(ret == AVERROR(EAGAIN)); if (ret != 0) break; @@ -2475,31 +2494,6 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) compute_chapters_end(ic); -#if 0 - /* correct DTS for B-frame streams with no timestamps */ - for(i=0;inb_streams;i++) { - st = ic->streams[i]; - if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) { - if(b-frames){ - ppktl = &ic->packet_buffer; - while(ppkt1){ - if(ppkt1->stream_index != i) - continue; - if(ppkt1->pkt->dts < 0) - break; - if(ppkt1->pkt->pts != AV_NOPTS_VALUE) - break; - ppkt1->pkt->dts -= delta; - ppkt1= ppkt1->next; - } - if(ppkt1) - continue; - st->cur_dts -= delta; - } - } - } -#endif - find_stream_info_err: for (i=0; i < ic->nb_streams; i++) { if (ic->streams[i]->codec) @@ -3074,7 +3068,9 @@ static int ff_interleave_compare_dts(AVFormatContext *s, AVPacket *next, AVPacke return comp > 0; } -int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pkt, int flush){ +int ff_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, + AVPacket *pkt, int flush) +{ AVPacketList *pktl; int stream_count=0; int i; @@ -3104,6 +3100,14 @@ int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, AVPacket *pk } } +#if FF_API_INTERLEAVE_PACKET +int av_interleave_packet_per_dts(AVFormatContext *s, AVPacket *out, + AVPacket *pkt, int flush) +{ + return ff_interleave_packet_per_dts(s, out, pkt, flush); +} +#endif + /** * Interleave an AVPacket correctly so it can be muxed. * @param out the interleaved packet will be output here @@ -3120,7 +3124,7 @@ static int interleave_packet(AVFormatContext *s, AVPacket *out, AVPacket *in, in av_free_packet(in); return ret; } else - return av_interleave_packet_per_dts(s, out, in, flush); + return ff_interleave_packet_per_dts(s, out, in, flush); } int av_interleaved_write_frame(AVFormatContext *s, AVPacket *pkt){