+ return avio_seek(s->pb, best_pos, SEEK_SET);
+}
+
+static int mp3_seek(AVFormatContext *s, int stream_index, int64_t timestamp,
+ int flags)
+{
+ MP3DecContext *mp3 = s->priv_data;
+ AVIndexEntry *ie, ie1;
+ AVStream *st = s->streams[0];
+ int64_t ret = av_index_search_timestamp(st, timestamp, flags);
+ int64_t best_pos;
+
+ if (mp3->usetoc == 2)
+ return -1; // generic index code
+
+ if ( mp3->is_cbr
+ && (mp3->usetoc == 0 || !mp3->xing_toc)
+ && st->duration > 0
+ && mp3->header_filesize > s->internal->data_offset
+ && mp3->frames) {
+ ie = &ie1;
+ timestamp = av_clip64(timestamp, 0, st->duration);
+ ie->timestamp = timestamp;
+ ie->pos = av_rescale(timestamp, mp3->header_filesize, st->duration) + s->internal->data_offset;
+ } else if (mp3->xing_toc) {
+ if (ret < 0)
+ return ret;
+
+ ie = &st->index_entries[ret];
+ } else {
+ return -1;
+ }
+
+ best_pos = mp3_sync(s, ie->pos, flags);
+ if (best_pos < 0)
+ return best_pos;