Index: libao2/ao_coreaudio.c =================================================================== --- libao2/ao_coreaudio.c (revision 31057) +++ libao2/ao_coreaudio.c (working copy) @@ -827,78 +922,15 @@ static int AudioStreamChangeFormat( AudioStreamID i_stream_id, AudioStreamBasicDescription change_format ) { OSStatus err = noErr; - UInt32 i_param_size = 0; - int i; - - static volatile int stream_format_changed; - stream_format_changed = 0; - print_format(MSGL_V, "setting stream format:", &change_format); - - /* Install the callback. */ - err = AudioStreamAddPropertyListener(i_stream_id, 0, - kAudioStreamPropertyPhysicalFormat, - StreamListener, - (void *)&stream_format_changed); + err = SetAudioProperty(i_stream_id, + kAudioStreamPropertyPhysicalFormat, + sizeof(AudioStreamBasicDescription), &change_format); if (err != noErr) { - ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamAddPropertyListener failed: [%4.4s]\n", (char *)&err); - return CONTROL_FALSE; - } - - /* Change the format. */ - err = AudioStreamSetProperty(i_stream_id, 0, 0, - kAudioStreamPropertyPhysicalFormat, - sizeof(AudioStreamBasicDescription), - &change_format); - if (err != noErr) - { ao_msg(MSGT_AO, MSGL_WARN, "could not set the stream format: [%4.4s]\n", (char *)&err); return CONTROL_FALSE; } - - /* The AudioStreamSetProperty is not only asynchronious, - * it is also not Atomic, in its 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; - int j; - for (j = 0; !stream_format_changed && j < 50; ++j) - usec_sleep(10000); - if (stream_format_changed) - stream_format_changed = 0; - else - ao_msg(MSGT_AO, MSGL_V, "reached timeout\n" ); - - i_param_size = sizeof(AudioStreamBasicDescription); - err = AudioStreamGetProperty(i_stream_id, 0, - kAudioStreamPropertyPhysicalFormat, - &i_param_size, - &actual_format); - - print_format(MSGL_V, "actual format in use:", &actual_format); - if (actual_format.mSampleRate == change_format.mSampleRate && - actual_format.mFormatID == change_format.mFormatID && - actual_format.mFramesPerPacket == change_format.mFramesPerPacket) - { - /* The right format is now active. */ - break; - } - /* We need to check again. */ - } - - /* Removing the property listener. */ - err = AudioStreamRemovePropertyListener(i_stream_id, 0, - kAudioStreamPropertyPhysicalFormat, - StreamListener); - if (err != noErr) - { - ao_msg(MSGT_AO, MSGL_WARN, "AudioStreamRemovePropertyListener failed: [%4.4s]\n", (char *)&err); - return CONTROL_FALSE; - } - return CONTROL_TRUE; }