summaryrefslogtreecommitdiff
path: root/libavformat/matroskadec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavformat/matroskadec.c')
-rw-r--r--libavformat/matroskadec.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 4d7076fa26..2b0112f213 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -742,15 +742,18 @@ static int matroska_read_close(AVFormatContext *s);
static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos)
{
AVIOContext *pb = matroska->ctx->pb;
- int64_t ret;
uint32_t id;
matroska->current_id = 0;
matroska->num_levels = 0;
- /* seek to next position to resync from */
- if ((ret = avio_seek(pb, last_pos + 1, SEEK_SET)) < 0) {
- matroska->done = 1;
- return ret;
+ /* Try to seek to the last position to resync from. If this doesn't work,
+ * we resync from the earliest position available: The start of the buffer. */
+ if (last_pos < avio_tell(pb) && avio_seek(pb, last_pos + 1, SEEK_SET) < 0) {
+ av_log(matroska->ctx, AV_LOG_WARNING,
+ "Seek to desired resync point failed. Seeking to "
+ "earliest point available instead.\n");
+ avio_seek(pb, FFMAX(avio_tell(pb) + (pb->buffer - pb->buf_ptr),
+ last_pos + 1), SEEK_SET);
}
id = avio_rb32(pb);
@@ -768,7 +771,7 @@ static int matroska_resync(MatroskaDemuxContext *matroska, int64_t last_pos)
}
matroska->done = 1;
- return AVERROR_EOF;
+ return pb->error ? pb->error : AVERROR_EOF;
}
/*