lavf: requeue attached pictures after seeking.

This allows the caller to get them without special code even after
seeking before receiving any data.
pull/3/merge
Anton Khirnov 13 years ago
parent 713f3062a7
commit 01fcc42b90
  1. 41
      libavformat/utils.c

@ -515,10 +515,21 @@ static AVPacket *add_to_pktbuf(AVPacketList **packet_buffer, AVPacket *pkt,
return &pktl->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, &copy, &s->raw_packet_buffer_end);
}
}
int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options) int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputFormat *fmt, AVDictionary **options)
{ {
AVFormatContext *s = *ps; AVFormatContext *s = *ps;
int i, ret = 0; int ret = 0;
AVDictionary *tmp = NULL; AVDictionary *tmp = NULL;
ID3v2ExtraMeta *id3v2_extra_meta = NULL; ID3v2ExtraMeta *id3v2_extra_meta = NULL;
@ -574,13 +585,7 @@ int avformat_open_input(AVFormatContext **ps, const char *filename, AVInputForma
goto fail; goto fail;
ff_id3v2_free_extra_meta(&id3v2_extra_meta); ff_id3v2_free_extra_meta(&id3v2_extra_meta);
/* queue attached pictures */ queue_attached_pictures(s);
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, &copy, &s->raw_packet_buffer_end);
}
if (s->pb && !s->data_offset) if (s->pb && !s->data_offset)
s->data_offset = avio_tell(s->pb); s->data_offset = avio_tell(s->pb);
@ -1711,7 +1716,8 @@ static int seek_frame_generic(AVFormatContext *s,
return 0; 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; int ret;
AVStream *st; AVStream *st;
@ -1754,14 +1760,29 @@ int av_seek_frame(AVFormatContext *s, int stream_index, int64_t timestamp, int f
return -1; 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) 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) if(min_ts > ts || max_ts < ts)
return -1; return -1;
if (s->iformat->read_seek2) { if (s->iformat->read_seek2) {
int ret;
ff_read_frame_flush(s); 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){ if(s->iformat->read_timestamp){

Loading…
Cancel
Save