asynchronous change of kAudioStreamPropertyPhysicalFormat
asynchronous change of kAudioStreamPropertyPhysicalFormat
- Subject: asynchronous change of kAudioStreamPropertyPhysicalFormat
- From: Derk-Jan Hartman <email@hidden>
- Date: Wed, 21 Dec 2005 20:35:59 +0100
For VLC I change the kAudioStreamPropertyPhysicalFormat so i can do
cac3 output:
I retrieve the original format, so that I can back it up
Set the new format, enter a conditional lock.
The Streamlistener listens for the
kAudioStreamPropertyPhysicalFormat, and unlocks the condition.
Then the main method continues, and will query the "fresh/new"
kAudioStreamPropertyPhysicalFormat.
Usually it works, however sometimes the following occurs...
[00000319] auhal audio output debug: original stream format: [44100]
[lpcm][30][4][1][4][2][16]
[00000319] auhal audio output debug: setting stream format: [48000]
[cac3][94][6144][1536][0][2][16]
[00000319] auhal audio output debug: actual format in use: [44100]
[lpcm][94][4][1][4][2][16]
So naturally this has me confused... I receive the "callback" that
the property changed, but apparently it's not changed yet sometimes
(a timeout did not occur, i checked). However, later on, when the
playback actually commenced (the IOProc is running), the format HAS
changed. What is going on here. anyone have an idea?
below is part of the code in question.
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "original stream format: ",
p_sys->sfmt_revert ) );
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "setting stream format: ",
p_sys->stream_format ) );
/* Install the callback */
err = AudioStreamAddPropertyListener( p_sys->i_stream_id, 0,
kAudioStreamPropertyPhysicalFormat,
StreamListener, (void *)&w );
if( err != noErr )
{
msg_Err( p_aout, "AudioStreamAddPropertyListener failed: [%
4.4s]", (char *)&err );
return VLC_FALSE;
}
/* Condition because SetProperty is asynchronious */
vlc_cond_init( p_aout, &w.cond );
vlc_mutex_init( p_aout, &w.lock );
vlc_mutex_lock( &w.lock );
/* change the format */
err = AudioStreamSetProperty( p_sys->i_stream_id, 0, 0,
kAudioStreamPropertyPhysicalFormat,
sizeof
( AudioStreamBasicDescription ),
&p_sys->stream_format );
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;
}
gettimeofday( &now, NULL );
timeout.tv_sec = now.tv_sec;
timeout.tv_nsec = (now.tv_usec + 900000) * 1000;
if( pthread_cond_timedwait( &w.cond.cond, &w.lock.mutex,
&timeout ) )
{
msg_Dbg( p_aout, "there was some sort of problem" );
}
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 );
msg_Dbg( p_aout, STREAM_FORMAT_MSG( "actual format in use: ",
p_sys->stream_format ) );
static OSStatus StreamListener( AudioStreamID inStream,
UInt32 inChannel,
AudioDevicePropertyID inPropertyID,
void * inClientData )
{
OSStatus err = noErr;
struct { vlc_mutex_t lock; vlc_cond_t cond; } * w = inClientData;
switch( inPropertyID )
{
case kAudioStreamPropertyPhysicalFormat:
vlc_mutex_lock( &w->lock );
vlc_cond_signal( &w->cond );
vlc_mutex_unlock( &w->lock );
break;
default:
break;
}
return( err );
}
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden