Commit 4b0e0dcd authored by Jean-Paul Saman's avatar Jean-Paul Saman

access/alsa.c: Read first before using snd_pcm_wait(), just like arecord does.

Read first before using snd_pcm_wait(), just like arecord does.
parent ed94986f
...@@ -343,32 +343,10 @@ static int Demux( demux_t *p_demux ) ...@@ -343,32 +343,10 @@ static int Demux( demux_t *p_demux )
p_block = NULL; p_block = NULL;
} }
/* Wait for data */
int i_wait = snd_pcm_wait( p_sys->p_alsa_pcm, 10 ); /* See poll() comment in oss.c */
switch( i_wait )
{
case 1:
{
p_block = GrabAudio( p_demux ); p_block = GrabAudio( p_demux );
if( p_block ) if( p_block )
es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts ); es_out_Control( p_demux->out, ES_OUT_SET_PCR, p_block->i_pts );
}
/* FIXME: this is a copy paste from below. Shouldn't be needed
* twice. */
case -EPIPE:
/* xrun */
snd_pcm_prepare( p_sys->p_alsa_pcm );
break;
case -ESTRPIPE:
{
/* suspend */
int i_resume = snd_pcm_resume( p_sys->p_alsa_pcm );
if( i_resume < 0 && i_resume != -EAGAIN ) snd_pcm_prepare( p_sys->p_alsa_pcm );
break;
}
/* </FIXME> */
}
} while( p_block && p_sys->i_next_demux_date > 0 && } while( p_block && p_sys->i_next_demux_date > 0 &&
p_block->i_pts < p_sys->i_next_demux_date ); p_block->i_pts < p_sys->i_next_demux_date );
...@@ -385,7 +363,7 @@ static int Demux( demux_t *p_demux ) ...@@ -385,7 +363,7 @@ static int Demux( demux_t *p_demux )
static block_t* GrabAudio( demux_t *p_demux ) static block_t* GrabAudio( demux_t *p_demux )
{ {
demux_sys_t *p_sys = p_demux->p_sys; demux_sys_t *p_sys = p_demux->p_sys;
int i_read, i_correct; int i_read, i_correct, i_error;
block_t *p_block; block_t *p_block;
if( p_sys->p_block ) p_block = p_sys->p_block; if( p_sys->p_block ) p_block = p_sys->p_block;
...@@ -401,22 +379,25 @@ static block_t* GrabAudio( demux_t *p_demux ) ...@@ -401,22 +379,25 @@ static block_t* GrabAudio( demux_t *p_demux )
/* ALSA */ /* ALSA */
i_read = snd_pcm_readi( p_sys->p_alsa_pcm, p_block->p_buffer, p_sys->i_alsa_chunk_size ); i_read = snd_pcm_readi( p_sys->p_alsa_pcm, p_block->p_buffer, p_sys->i_alsa_chunk_size );
if( i_read <= 0 ) if( i_read == -EAGAIN || ((i_read >= 0) && (i_read < p_sys->i_alsa_chunk_size)) )
i_error = snd_pcm_wait( p_sys->p_alsa_pcm, 10 ); /* See poll() comment in oss.c */
else i_error = i_read;
if( i_error <= 0 )
{ {
int i_resume; switch( i_error )
switch( i_read )
{ {
case -EAGAIN:
break;
case -EPIPE: case -EPIPE:
/* xrun */ /* xrun */
snd_pcm_prepare( p_sys->p_alsa_pcm ); snd_pcm_prepare( p_sys->p_alsa_pcm );
break; break;
case -ESTRPIPE: case -ESTRPIPE:
{
/* suspend */ /* suspend */
i_resume = snd_pcm_resume( p_sys->p_alsa_pcm ); int i_resume = snd_pcm_resume( p_sys->p_alsa_pcm );
if( i_resume < 0 && i_resume != -EAGAIN ) snd_pcm_prepare( p_sys->p_alsa_pcm ); if( i_resume < 0 && i_resume != -EAGAIN ) snd_pcm_prepare( p_sys->p_alsa_pcm );
break; break;
}
default: default:
msg_Err( p_demux, "Failed to read alsa frame (%s)", snd_strerror( i_read ) ); msg_Err( p_demux, "Failed to read alsa frame (%s)", snd_strerror( i_read ) );
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment