[vlc-commits] auhal: add headphone detection

Felix Paul Kühne git at videolan.org
Sat Jul 22 15:54:29 CEST 2017


vlc | branch: master | Felix Paul Kühne <fkuehne at videolan.org> | Sat Jul 22 15:42:05 2017 +0200| [9051ab015b7286b54ff1c9072f280e8ce63a84a1] | committer: Felix Paul Kühne

auhal: add headphone detection

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

 modules/audio_output/auhal.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/modules/audio_output/auhal.c b/modules/audio_output/auhal.c
index c1382a7911..db3a36c52a 100644
--- a/modules/audio_output/auhal.c
+++ b/modules/audio_output/auhal.c
@@ -401,6 +401,42 @@ ReportDevice(audio_output_t *p_aout, UInt32 i_id, char *name)
 }
 
 /*
+ * AudioDeviceIsAHeadphone: Checks if device is a headphone
+ */
+
+static bool
+AudioDeviceIsAHeadphone(audio_output_t *p_aout, AudioDeviceID i_dev_id)
+{
+    UInt32 defaultSize = sizeof(AudioDeviceID);
+
+    const AudioObjectPropertyAddress defaultAddr = {
+        kAudioHardwarePropertyDefaultOutputDevice,
+        kAudioObjectPropertyScopeGlobal,
+        kAudioObjectPropertyElementMaster
+    };
+
+    AudioObjectGetPropertyData(kAudioObjectSystemObject, &defaultAddr, 0, NULL, &defaultSize, &i_dev_id);
+
+    AudioObjectPropertyAddress property;
+    property.mSelector = kAudioDevicePropertyDataSource;
+    property.mScope = kAudioDevicePropertyScopeOutput;
+    property.mElement = kAudioObjectPropertyElementMaster;
+
+    UInt32 data;
+    UInt32 size = sizeof(UInt32);
+    AudioObjectGetPropertyData(i_dev_id, &property, 0, NULL, &size, &data);
+
+    /*
+     'hdpn' == headphone
+     'ispk' == internal speaker
+     '61pd' == HDMI
+     '    ' == Bluetooth accessory or AirPlay
+    */
+
+    return data == 'hdpn';
+}
+
+/*
  * AudioDeviceHasOutput: Checks if the device is actually an output device
  */
 static int
@@ -962,6 +998,8 @@ StartAnalog(audio_output_t *p_aout, audio_sample_format_t *fmt,
     if (p_sys->au_unit == NULL)
         return VLC_EGENERIC;
 
+    p_aout->current_sink_info.headphones = AudioDeviceIsAHeadphone(p_aout, p_sys->i_selected_dev);
+
     /* Set the device we will use for this output unit */
     err = AudioUnitSetProperty(p_sys->au_unit,
                                kAudioOutputUnitProperty_CurrentDevice,



More information about the vlc-commits mailing list