From 01fcc42b909e7328e177748ffb21f2846b924a09 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sun, 18 Mar 2012 17:34:14 +0100 Subject: lavf: requeue attached pictures after seeking. This allows the caller to get them without special code even after seeking before receiving any data. --- libavformat/utils.c | 41 +++++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 10 deletions(-) (limited to 'libavformat') diff --git a/libavformat/utils.c b/libavformat/utils.c index f67d2d47c1..7fd425f1cc 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -515,10 +515,21 @@ 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) { + 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 +585,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); @@ -1711,7 +1716,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; @@ -1754,14 +1760,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){ -- cgit v1.2.3