[vlc-commits] auhal: clean-up HardwareListener callback

Felix Paul Kühne git at videolan.org
Mon Dec 24 13:15:01 CET 2012


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Mon Dec 24 12:23:46 2012 +0100| [aa73cad32152dc4594ceb0f97e9fb7c531376bd7] | committer: Felix Paul Kühne

auhal: clean-up HardwareListener callback

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=aa73cad32152dc4594ceb0f97e9fb7c531376bd7
---

 modules/audio_output/auhal.c |   44 ++++++++++++++++++++++++++----------------
 1 file changed, 27 insertions(+), 17 deletions(-)

diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index bd05909..e130e60 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -823,13 +823,13 @@ static void Stop(audio_output_t *p_aout)
     UInt32              i_param_size = 0;
 
     AudioObjectPropertyAddress deviceAliveAddress = { kAudioDevicePropertyDeviceIsAlive, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
-    err = AudioObjectRemovePropertyListener(p_sys->i_selected_dev, &deviceAliveAddress, HardwareListener, NULL);
+    err = AudioObjectRemovePropertyListener(p_sys->i_selected_dev, &deviceAliveAddress, HardwareListener, (void *)p_aout);
     if (err != noErr)
         msg_Err(p_aout, "failed to remove audio device life checker: [%4.4s]", (char *)&err);
 
     if (p_sys->b_digital) {
         AudioObjectPropertyAddress physicalFormatsAddress = { kAudioStreamPropertyAvailablePhysicalFormats, kAudioObjectPropertyScopeGlobal, 0 };
-        err = AudioObjectRemovePropertyListener(p_sys->i_stream_id, &physicalFormatsAddress, HardwareListener, NULL);
+        err = AudioObjectRemovePropertyListener(p_sys->i_stream_id, &physicalFormatsAddress, HardwareListener, (void *)p_aout);
         if (err != noErr)
             msg_Err(p_aout, "failed to remove audio device property streams callback: [%4.4s]", (char *)&err);
     }
@@ -876,7 +876,7 @@ static void Stop(audio_output_t *p_aout)
     }
 
     AudioObjectPropertyAddress audioDevicesAddress = { kAudioHardwarePropertyDevices, kAudioObjectPropertyScopeGlobal, kAudioObjectPropertyElementMaster };
-    err = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, NULL);
+    err = AudioObjectRemovePropertyListener(kAudioObjectSystemObject, &audioDevicesAddress, HardwareListener, (void *)p_aout);
 
     if (err != noErr)
         msg_Err(p_aout, "AudioHardwareRemovePropertyListener failed: [%4.4s]", (char *)&err);
@@ -1359,23 +1359,33 @@ static OSStatus HardwareListener(AudioObjectID inObjectID,  UInt32 inNumberAddre
     audio_output_t     *p_aout = (audio_output_t *)inClientData;
     VLC_UNUSED(inObjectID);
 
+    if (!p_aout)
+        return -1;
+
+#ifndef NDEBUG
     for (unsigned int i = 0; i < inNumberAddresses; i++) {
-        if (inAddresses[i].mSelector == kAudioHardwarePropertyDevices) {
-            /* something changed in the list of devices */
-            /* 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_Destroy(p_aout, "audio-device");
-        } else if (inAddresses[i].mSelector == kAudioStreamPropertyAvailablePhysicalFormats) {
-            msg_Warn(p_aout, "available physical formats for audio device changed, resetting aout");
-            var_TriggerCallback(p_aout, "audio-device");
-            var_Destroy(p_aout, "audio-device");
+        switch (inAddresses[i].mSelector) {
+            case kAudioHardwarePropertyDevices:
+                msg_Warn(p_aout, "audio device configuration changed, resetting cache");
+                break;
+
+            case kAudioDevicePropertyDeviceIsAlive:
+                msg_Warn(p_aout, "audio device died, resetting aout");
+                break;
+
+            case kAudioStreamPropertyAvailablePhysicalFormats:
+                msg_Warn(p_aout, "available physical formats for audio device changed, resetting aout");
+                break;
+
+            default:
+                msg_Warn(p_aout, "device reset for unknown reason (%i)", inAddresses[i].mSelector);
+                break;
         }
     }
+#endif
+
+    var_TriggerCallback(p_aout, "audio-device");
+    var_Destroy(p_aout, "audio-device");
 
     return err;
 }



More information about the vlc-commits mailing list