Commit 35c8e86d authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Fix a few minor race conditions

parent 03f87d80
...@@ -755,23 +755,23 @@ static void Close( vlc_object_t *p_this ) ...@@ -755,23 +755,23 @@ static void Close( vlc_object_t *p_this )
*****************************************************************************/ *****************************************************************************/
static int ALSAThread( aout_instance_t * p_aout ) static int ALSAThread( aout_instance_t * p_aout )
{ {
p_aout->output.p_sys->p_status = struct aout_sys_t * p_sys = p_aout->output.p_sys;
(snd_pcm_status_t *)malloc(snd_pcm_status_sizeof()); p_sys->p_status = (snd_pcm_status_t *)malloc(snd_pcm_status_sizeof());
/* Wait for the exact time to start playing (avoids resampling) */ /* Wait for the exact time to start playing (avoids resampling) */
vlc_mutex_lock( &p_aout->output.p_sys->lock ); vlc_mutex_lock( &p_sys->lock );
if( !p_aout->output.p_sys->start_date ) while( !p_sys->start_date )
vlc_cond_wait( &p_aout->output.p_sys->wait, vlc_cond_wait( &p_sys->wait, &p_sys->lock );
&p_aout->output.p_sys->lock ); vlc_mutex_unlock( &p_sys->lock );
vlc_mutex_unlock( &p_aout->output.p_sys->lock );
mwait( p_aout->output.p_sys->start_date - AOUT_PTS_TOLERANCE / 4 ); mwait( p_sys->start_date - AOUT_PTS_TOLERANCE / 4 );
while ( !p_aout->b_die ) while ( !p_aout->b_die )
{ {
ALSAFill( p_aout ); ALSAFill( p_aout );
} }
snd_pcm_drop( p_sys->p_snd_pcm );
free( p_aout->output.p_sys->p_status ); free( p_aout->output.p_sys->p_status );
return 0; return 0;
} }
...@@ -871,12 +871,15 @@ static void ALSAFill( aout_instance_t * p_aout ) ...@@ -871,12 +871,15 @@ static void ALSAFill( aout_instance_t * p_aout )
return; return;
} }
i_snd_rc = snd_pcm_writei( p_sys->p_snd_pcm, p_buffer->p_buffer, for (;;)
p_buffer->i_nb_samples ); {
i_snd_rc = snd_pcm_writei( p_sys->p_snd_pcm, p_buffer->p_buffer,
p_buffer->i_nb_samples );
if( i_snd_rc != -ESTRPIPE )
break;
if( i_snd_rc == -ESTRPIPE ) /* a suspend event occurred
{ /* a suspend event occurred * (stream is suspended and waiting for an application recovery) */
* (stream is suspended and waiting for an application recovery) */
msg_Dbg( p_aout, "entering in suspend mode, trying to resume..." ); msg_Dbg( p_aout, "entering in suspend mode, trying to resume..." );
while( !p_aout->b_die && !p_aout->p_libvlc->b_die && while( !p_aout->b_die && !p_aout->p_libvlc->b_die &&
...@@ -886,12 +889,6 @@ static void ALSAFill( aout_instance_t * p_aout ) ...@@ -886,12 +889,6 @@ static void ALSAFill( aout_instance_t * p_aout )
if( i_snd_rc < 0 ) if( i_snd_rc < 0 )
/* Device does not supprot resuming, restart it */ /* Device does not supprot resuming, restart it */
i_snd_rc = snd_pcm_prepare( p_sys->p_snd_pcm ); i_snd_rc = snd_pcm_prepare( p_sys->p_snd_pcm );
if( i_snd_rc == 0 )
i_snd_rc = snd_pcm_writei( p_sys->p_snd_pcm,
p_buffer->p_buffer,
p_buffer->i_nb_samples );
} }
if( i_snd_rc < 0 ) if( i_snd_rc < 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