# HG changeset patch # User bcoudurier # Date 1237513485 0 # Node ID aa67c9d6b180f5476882489b52b83684f7d67a16 # Parent 02a9d3d1345b281d34bb792e4153eecb70171d97 resync ffm if error in stream diff -r 02a9d3d1345b -r aa67c9d6b180 ffmdec.c --- a/ffmdec.c Fri Mar 20 01:39:55 2009 +0000 +++ b/ffmdec.c Fri Mar 20 01:44:45 2009 +0000 @@ -87,13 +87,26 @@ return AVERROR(EAGAIN); } +static int ffm_resync(AVFormatContext *s, int state) +{ + av_log(s, AV_LOG_ERROR, "resyncing\n"); + while (state != PACKET_ID) { + if (url_feof(s->pb)) { + av_log(s, AV_LOG_ERROR, "cannot find FFM syncword\n"); + return -1; + } + state = (state << 8) | get_byte(s->pb); + } + return 0; +} + /* first is true if we read the frame header */ static int ffm_read_data(AVFormatContext *s, uint8_t *buf, int size, int header) { FFMContext *ffm = s->priv_data; ByteIOContext *pb = s->pb; - int len, fill_size, size1, frame_offset; + int len, fill_size, size1, frame_offset, id; size1 = size; while (size > 0) { @@ -107,7 +120,10 @@ if (url_ftell(pb) == ffm->file_size) url_fseek(pb, ffm->packet_size, SEEK_SET); retry_read: - get_be16(pb); /* PACKET_ID */ + id = get_be16(pb); /* PACKET_ID */ + if (id != PACKET_ID) + if (ffm_resync(s, id) < 0) + return -1; fill_size = get_be16(pb); ffm->dts = get_be64(pb); frame_offset = get_be16(pb);