diff options
Diffstat (limited to 'src/mp3-c.c')
-rw-r--r-- | src/mp3-c.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/src/mp3-c.c b/src/mp3-c.c index b4dc6b6..1ac47bc 100644 --- a/src/mp3-c.c +++ b/src/mp3-c.c @@ -1632,6 +1632,7 @@ c_decode_mp3 (mp3tl * tl) gint diff; fr_header *hdr; guint8 side_info[32]; /* At most 32 bytes side info for MPEG-1 stereo */ + gboolean MainDataOK; hdr = &tl->fr_ps.header; bb = &tl->c_impl.bb; @@ -1650,27 +1651,34 @@ c_decode_mp3 (mp3tl * tl) if (bs_bits_avail (tl->bs) < hdr->main_slots * 8) return MP3TL_ERR_NEED_DATA; - /* Check that we have enough main_data between the bit reservoir - * and the incoming data */ + /* Verify that sufficient main_data was extracted from */ + /* the previous sync interval */ diff = tl->c_impl.main_data_end - III_side_info.main_data_begin; - if (diff < 0) { - /* Usually happens after a seek. We can't decode this frame */ - GST_LOG ("Not enough main data available to decode frame"); - return MP3TL_ERR_NEED_DATA; + MainDataOK = (diff >= 0); + if (!MainDataOK) { + GST_DEBUG ("MainDataEnd: %d MainDataBegin: %d delta: %d", + tl->c_impl.main_data_end, III_side_info.main_data_begin, diff); } /* Copy the remaining main data in the bit reservoir to the start of the * huffman bit buffer, and then append the incoming bytes */ - memmove (tl->c_impl.hb_buf, tl->c_impl.hb_buf + - tl->c_impl.main_data_end - III_side_info.main_data_begin, - III_side_info.main_data_begin); - tl->c_impl.main_data_end = III_side_info.main_data_begin; - + if (MainDataOK) { + if (diff > 0) { + memmove (tl->c_impl.hb_buf, tl->c_impl.hb_buf + diff, + III_side_info.main_data_begin); + tl->c_impl.main_data_end = III_side_info.main_data_begin; + } + } /* And append the incoming bytes to the reservoir */ bs_getbytes (tl->bs, tl->c_impl.hb_buf + tl->c_impl.main_data_end, hdr->main_slots); tl->c_impl.main_data_end += hdr->main_slots; + if (!MainDataOK) { + GST_DEBUG ("Bad frame - not enough main data bits"); + return MP3TL_ERR_BAD_FRAME; + } + /* And setup the huffman bitstream reader for this data */ h_setbuf (bb, tl->c_impl.hb_buf, tl->c_impl.main_data_end); |