Commit 0401bdcd authored by Felix Paul Kühne's avatar Felix Paul Kühne

auhal: fixed audio device configuration callback and added an additional...

auhal: fixed audio device configuration callback and added an additional callback to watch the used device's health (close #4834)
(cherry picked from commit 8fbb1fd08399f3a29c0c4850bac2c03e40997099)

Conflicts:
	modules/audio_output/auhal.c
parent be1b84a5
...@@ -12,6 +12,8 @@ Qt: ...@@ -12,6 +12,8 @@ Qt:
* Fix media info dialog update * Fix media info dialog update
Mac OS X: Mac OS X:
* Fix audio output behavior when the output device is plugged or unplugged
during playback
* Fix command-line options for the interface * Fix command-line options for the interface
* Deactivate CoreAnimation effects on Leopard * Deactivate CoreAnimation effects on Leopard
* Fix menus display and behaviour * Fix menus display and behaviour
......
...@@ -209,10 +209,9 @@ static int Open( vlc_object_t * p_this ) ...@@ -209,10 +209,9 @@ static int Open( vlc_object_t * p_this )
msg_Dbg( p_aout, "audio device supports digital output" ); msg_Dbg( p_aout, "audio device supports digital output" );
/* Check if the desired device is alive and usable */ /* Check if the desired device is alive and usable */
/* TODO: add a callback to the device to alert us if the device dies */
i_param_size = sizeof( b_alive ); i_param_size = sizeof( b_alive );
AudioObjectPropertyAddress audioDeviceAliveAddress = { kAudioDevicePropertyDeviceIsAlive, AudioObjectPropertyAddress audioDeviceAliveAddress = { kAudioDevicePropertyDeviceIsAlive,
kAudioDevicePropertyScopeOutput, kAudioObjectPropertyScopeGlobal,
kAudioObjectPropertyElementMaster }; kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyData( p_sys->i_selected_dev, &audioDeviceAliveAddress, 0, NULL, &i_param_size, &b_alive ); err = AudioObjectGetPropertyData( p_sys->i_selected_dev, &audioDeviceAliveAddress, 0, NULL, &i_param_size, &b_alive );
...@@ -230,6 +229,15 @@ static int Open( vlc_object_t * p_this ) ...@@ -230,6 +229,15 @@ static int Open( vlc_object_t * p_this )
p_sys->i_selected_dev = p_sys->i_default_dev; p_sys->i_selected_dev = p_sys->i_default_dev;
} }
/* add a callback to see if the device dies later on */
err = AudioObjectAddPropertyListener( p_sys->i_selected_dev, &audioDeviceAliveAddress, HardwareListener, (void *)p_aout );
if( err != noErr )
{
/* Be tolerant, only give a warning here */
msg_Warn( p_aout, "could not set alive check callback on device [0x%x]: %4.4s",
(unsigned int)p_sys->i_selected_dev, (char *)&err );
}
AudioObjectPropertyAddress audioDeviceHogModeAddress = { kAudioDevicePropertyHogMode, AudioObjectPropertyAddress audioDeviceHogModeAddress = { kAudioDevicePropertyHogMode,
kAudioDevicePropertyScopeOutput, kAudioDevicePropertyScopeOutput,
kAudioObjectPropertyElementMaster }; kAudioObjectPropertyElementMaster };
...@@ -841,6 +849,13 @@ static void Close( vlc_object_t * p_this ) ...@@ -841,6 +849,13 @@ static void Close( vlc_object_t * p_this )
OSStatus err = noErr; OSStatus err = noErr;
UInt32 i_param_size = 0; UInt32 i_param_size = 0;
AudioObjectPropertyAddress deviceAliveAddress = { kAudioDevicePropertyDeviceIsAlive, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
err = AudioObjectRemovePropertyListener( p_sys->i_selected_dev, &deviceAliveAddress, HardwareListener, NULL );
if( err != noErr )
{
msg_Err( p_aout, "failed to remove audio device life checker: [%4.4s]", (char *)&err );
}
if( p_sys->au_unit ) if( p_sys->au_unit )
{ {
verify_noerr( AudioOutputUnitStop( p_sys->au_unit ) ); verify_noerr( AudioOutputUnitStop( p_sys->au_unit ) );
...@@ -894,7 +909,7 @@ static void Close( vlc_object_t * p_this ) ...@@ -894,7 +909,7 @@ static void Close( vlc_object_t * p_this )
} }
} }
AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster }; AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
err = AudioObjectRemovePropertyListener( kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, NULL ); err = AudioObjectRemovePropertyListener( kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, NULL );
if( err != noErr ) if( err != noErr )
...@@ -933,7 +948,7 @@ static void Probe( audio_output_t * p_aout ) ...@@ -933,7 +948,7 @@ static void Probe( audio_output_t * p_aout )
struct aout_sys_t *p_sys = p_aout->sys; struct aout_sys_t *p_sys = p_aout->sys;
/* Get number of devices */ /* Get number of devices */
AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioDevicePropertyScopeOutput, kAudioObjectPropertyElementMaster }; AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &audioDevicesAddress, 0, NULL, &i_param_size); err = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, &audioDevicesAddress, 0, NULL, &i_param_size);
if( err != noErr ) if( err != noErr )
{ {
...@@ -1040,14 +1055,17 @@ static void Probe( audio_output_t * p_aout ) ...@@ -1040,14 +1055,17 @@ static void Probe( audio_output_t * p_aout )
var_Get( p_aout->p_libvlc, "macosx-audio-device", &val ); var_Get( p_aout->p_libvlc, "macosx-audio-device", &val );
if( val.i_int > 0 ) if( val.i_int > 0 )
{ {
msg_Dbg( p_aout, "using preselected output device %#"PRIx64, val.i_int );
var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL ); var_Change( p_aout, "audio-device", VLC_VAR_SETDEFAULT, &val, NULL );
var_Set( p_aout, "audio-device", val ); var_Set( p_aout, "audio-device", val );
} }
/* Attach a Listener so that we are notified of a change in the Device setup */ /* Attach a Listener so that we are notified of a change in the Device setup */
err = AudioObjectAddPropertyListener( kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, (void *)p_aout ); err = AudioObjectAddPropertyListener( kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, (void *)p_aout );
if( err ) if( err != noErr ) {
msg_Warn( p_aout, "failed to add listener for audio device configuration (%i)", err );
goto error; goto error;
}
free( p_devices ); free( p_devices );
return; return;
...@@ -1339,9 +1357,9 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout, ...@@ -1339,9 +1357,9 @@ static OSStatus RenderCallbackAnalog( vlc_object_t *_p_aout,
} }
else else
{ {
vlc_memset( (uint8_t *)ioData->mBuffers[0].mData +i_mData_bytes, vlc_memset( (uint8_t *)ioData->mBuffers[0].mData +i_mData_bytes,
0,ioData->mBuffers[0].mDataByteSize - i_mData_bytes ); 0,ioData->mBuffers[0].mDataByteSize - i_mData_bytes );
i_mData_bytes += ioData->mBuffers[0].mDataByteSize - i_mData_bytes; i_mData_bytes += ioData->mBuffers[0].mDataByteSize - i_mData_bytes;
} }
} }
return( noErr ); return( noErr );
...@@ -1413,6 +1431,13 @@ static OSStatus HardwareListener( AudioObjectID inObjectID, UInt32 inNumberAddr ...@@ -1413,6 +1431,13 @@ static OSStatus HardwareListener( AudioObjectID inObjectID, UInt32 inNumberAddr
{ {
/* something changed in the list of devices */ /* something changed in the list of devices */
/* We trigger the audio-device's aout_ChannelsRestart callback */ /* We trigger the audio-device's aout_ChannelsRestart callback */
msg_Warn( p_aout, "audio device configuration changed, resetting cache" );
var_TriggerCallback( p_aout, "audio-device" );
var_Destroy( p_aout, "audio-device" );
}
else if( inAddresses[i].mSelector == kAudioDevicePropertyDeviceIsAlive )
{
msg_Warn( p_aout, "audio device died, resetting aout" );
var_TriggerCallback( p_aout, "audio-device" ); var_TriggerCallback( p_aout, "audio-device" );
var_Destroy( p_aout, "audio-device" ); var_Destroy( p_aout, "audio-device" );
} }
......
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