Commit 5d339b42 authored by Derk-Jan Hartman's avatar Derk-Jan Hartman

SetProperty in CoreAudio is not only Asynchronious, but also not atomic in...

SetProperty in CoreAudio is not only Asynchronious, but also not atomic in it's bahaviour. Check the actual set format multiple times to make sure the SetProperty completly finished.
parent a148e917
......@@ -797,12 +797,17 @@ static int OpenSPDIF( aout_instance_t * p_aout )
if( err != noErr )
{
msg_Err( p_aout, "could not set the stream format: [%4.4s]", (char *)&err );
vlc_mutex_unlock( &w.lock );
vlc_mutex_destroy( &w.lock );
vlc_cond_destroy( &w.cond );
return VLC_FALSE;
}
/* The AudioStreamSetProperty is not only asynchronious (requiring the locks)
* it is also not Atomic, in it's behaviour.
* Therefore we check 5 times before we really give up.
* FIXME: failing isn't actually implemented yet. */
for( i = 0; i < 5; i++ )
{
AudioStreamBasicDescription actual_format;
gettimeofday( &now, NULL );
timeout.tv_sec = now.tv_sec;
timeout.tv_nsec = (now.tv_usec + 900000) * 1000;
......@@ -810,30 +815,39 @@ static int OpenSPDIF( aout_instance_t * p_aout )
if( pthread_cond_timedwait( &w.cond.cond, &w.lock.mutex, &timeout ) )
{
msg_Dbg( p_aout, "reached timeout" );
}
vlc_mutex_unlock( &w.lock );
err = AudioStreamRemovePropertyListener( p_sys->i_stream_id, 0,
kAudioStreamPropertyPhysicalFormat,
StreamListener );
if( err != noErr )
{
msg_Err( p_aout, "AudioStreamRemovePropertyListener failed: [%4.4s]", (char *)&err );
vlc_mutex_destroy( &w.lock );
vlc_cond_destroy( &w.cond );
return VLC_FALSE;
}
vlc_mutex_destroy( &w.lock );
vlc_cond_destroy( &w.cond );
i_param_size = sizeof( AudioStreamBasicDescription );
err = AudioStreamGetProperty( p_sys->i_stream_id, 0,
kAudioStreamPropertyPhysicalFormat,
&i_param_size,
&p_sys->stream_format );
&actual_format );
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "actual format in use: ", p_sys->stream_format ) );
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "actual format in use: ", actual_format ) );
if( actual_format.mSampleRate == p_sys->stream_format.mSampleRate &&
actual_format.mFormatID == p_sys->stream_format.mFormatID &&
actual_format.mFramesPerPacket == p_sys->stream_format.mFramesPerPacket )
{
/* The right format is now active */
break;
}
/* We need to check again */
vlc_cond_init( p_aout, &w.cond );
vlc_mutex_init( p_aout, &w.lock );
vlc_mutex_lock( &w.lock );
}
err = AudioStreamRemovePropertyListener( p_sys->i_stream_id, 0,
kAudioStreamPropertyPhysicalFormat,
StreamListener );
if( err != noErr )
{
msg_Err( p_aout, "AudioStreamRemovePropertyListener failed: [%4.4s]", (char *)&err );
return VLC_FALSE;
}
/* set the format flags */
if( p_sys->stream_format.mFormatFlags & kAudioFormatFlagIsBigEndian )
......
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