diff options
author | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2005-01-29 12:55:56 +0000 |
---|---|---|
committer | reimar <reimar@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2005-01-29 12:55:56 +0000 |
commit | 78dda735d5d3a4287aecc3830efbbfde551a36f6 (patch) | |
tree | 59a448f192891542f8533a90dffd7a0eafa2d9e2 | |
parent | 80d8313b709dd356f9dfdb3303da4611eda0a911 (diff) |
Fix possible hang when playing broken MP3 from linear stream and remove
duplicate code.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@14609 b3059339-0415-0410-9bf9-f77b7e298cf2
-rw-r--r-- | libmpdemux/demux_audio.c | 55 |
1 files changed, 26 insertions, 29 deletions
diff --git a/libmpdemux/demux_audio.c b/libmpdemux/demux_audio.c index 2e3f4790cf..1f0d7a32ef 100644 --- a/libmpdemux/demux_audio.c +++ b/libmpdemux/demux_audio.c @@ -364,6 +364,8 @@ int demux_audio_open(demuxer_t* demuxer) { int demux_audio_fill_buffer(demux_stream_t *ds) { + int l; + demux_packet_t* dp; sh_audio_t* sh_audio; demuxer_t* demux; da_priv_t* priv; @@ -383,52 +385,47 @@ int demux_audio_fill_buffer(demux_stream_t *ds) { switch(priv->frmt) { case MP3 : - while(! s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) { + while(1) { uint8_t hdr[4]; - int len; stream_read(s,hdr,4); - len = mp_decode_mp3_header(hdr); - if(len < 0) { + if (s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end)) + return 0; + l = mp_decode_mp3_header(hdr); + if(l < 0) { stream_skip(s,-3); } else { - demux_packet_t* dp; - if(s->eof || (demux->movi_end && stream_tell(s) >= demux->movi_end) ) - return 0; - dp = new_demux_packet(len); + dp = new_demux_packet(l); memcpy(dp->buffer,hdr,4); - stream_read(s,dp->buffer + 4,len-4); - priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + 1152/(float)sh_audio->samplerate; - ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; - ds_add_packet(ds,dp); - return 1; + stream_read(s,dp->buffer + 4,l-4); + break; } } break; case WAV : { - int l = sh_audio->wf->nAvgBytesPerSec; - demux_packet_t* dp = new_demux_packet(l); + l = sh_audio->wf->nAvgBytesPerSec; + dp = new_demux_packet(l); l = stream_read(s,dp->buffer,l); - resize_demux_packet(dp, l); - priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps; - ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; - ds_add_packet(ds,dp); - return 1; + break; } case fLaC: { - int l = 65535; - demux_packet_t* dp = new_demux_packet(l); + l = 65535; + dp = new_demux_packet(l); l = stream_read(s,dp->buffer,l); - resize_demux_packet(dp, l); - priv->last_pts = priv->last_pts < 0 ? 0 : priv->last_pts + l/(float)sh_audio->i_bps; - ds->pts = priv->last_pts - (ds_tell_pts(demux->audio)-sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; - ds_add_packet(ds,dp); - return 1; + break; } default: printf("Audio demuxer : unknown format %d\n",priv->frmt); + return 0; } - - return 0; + resize_demux_packet(dp, l); + if (priv->last_pts < 0) + priv->last_pts = 0; + else + priv->last_pts += l/(float)sh_audio->i_bps; + ds->pts = priv->last_pts - (ds_tell_pts(demux->audio) - + sh_audio->a_in_buffer_len)/(float)sh_audio->i_bps; + ds_add_packet(ds, dp); + return 1; } static void high_res_mp3_seek(demuxer_t *demuxer,float time) { |