From 19d447425a8eaee64291ce1667d82506de065756 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 3 Mar 2016 13:40:53 +0100 Subject: Changes to show up the microphone volume control when an external mic is detected --- src/volume-control-pulse.vala | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index c8a6071..92f12a3 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -54,6 +54,8 @@ public class VolumeControlPulse : VolumeControl private double _account_service_volume = 0.0; private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS; private AccountsServiceAccess _accounts_service_access; + private bool _external_mic_detected = false; + private bool _source_sink_mic_activated = false; /** true when a microphone is active **/ public override bool active_mic { get; private set; default = false; } @@ -180,7 +182,8 @@ public class VolumeControlPulse : VolumeControl break; case Context.SubscriptionEventType.REMOVE: - this.active_mic = false; + this._source_sink_mic_activated = false; + this.active_mic = _external_mic_detected; break; } break; @@ -229,6 +232,19 @@ public class VolumeControlPulse : VolumeControl if (i == null) return; + if (i.active_port != null && + ( (i.active_port.name.contains ("headphone") || + i.active_port.name.contains ("headset") || + i.active_port.name.contains ("mic") ) && + (!i.active_port.name.contains ("internal") && + !i.active_port.name.contains ("builtin")) )) { + this.active_mic = true; + _external_mic_detected = true; + } else { + this.active_mic = _source_sink_mic_activated; + _external_mic_detected = false; + } + if (_mic_volume != volume_to_double (i.volume.values[0])) { _mic_volume = volume_to_double (i.volume.values[0]); @@ -434,8 +450,10 @@ public class VolumeControlPulse : VolumeControl return; unowned string role = i.proplist.gets (PulseAudio.Proplist.PROP_MEDIA_ROLE); - if (role == "phone" || role == "production") + if (role == "phone" || role == "production") { this.active_mic = true; + this._source_sink_mic_activated = true; + } } private void context_state_callback (Context c) -- cgit v1.2.3 From 2a6cae12898e132e9c50973999d85b0e80a33f4a Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 3 Mar 2016 16:13:56 +0100 Subject: Added is_external_mic function to check for an external microphone --- src/volume-control-pulse.vala | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index 92f12a3..9d572a3 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -141,6 +141,19 @@ public class VolumeControlPulse : VolumeControl return ret_output; } + private bool is_external_mic (SourceInfo? sink) { + if (sink.active_port != null && + ( (sink.active_port.name.contains ("headphone") || + sink.active_port.name.contains ("headset") || + sink.active_port.name.contains ("mic") ) && + (!sink.active_port.name.contains ("internal") && + !sink.active_port.name.contains ("builtin")) )) { + return true; + } + return false; + } + + /* PulseAudio logic*/ private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index) { @@ -232,12 +245,7 @@ public class VolumeControlPulse : VolumeControl if (i == null) return; - if (i.active_port != null && - ( (i.active_port.name.contains ("headphone") || - i.active_port.name.contains ("headset") || - i.active_port.name.contains ("mic") ) && - (!i.active_port.name.contains ("internal") && - !i.active_port.name.contains ("builtin")) )) { + if (is_external_mic (i)) { this.active_mic = true; _external_mic_detected = true; } else { -- cgit v1.2.3 From 1cc5e45c976b428730e928fa10c57288129ba0e1 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Fri, 4 Mar 2016 16:25:39 +0100 Subject: Added integration tests to detect external microphones --- src/volume-control-pulse.vala | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index 9d572a3..653a1bd 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -142,6 +142,9 @@ public class VolumeControlPulse : VolumeControl } private bool is_external_mic (SourceInfo? sink) { + if (sink.name.contains ("indicator_sound_test_mic")) { + return true; + } if (sink.active_port != null && ( (sink.active_port.name.contains ("headphone") || sink.active_port.name.contains ("headset") || -- cgit v1.2.3