~xavi-garcia-mena/indicator-sound/bug-pressing-cancel-accounts-service

« back to all changes in this revision

Viewing changes to src/volume-control-pulse.vala

  • Committer: CI Train Bot
  • Author(s): Xavi Garcia Mena
  • Date: 2016-03-07 10:13:52 UTC
  • mfrom: (529.1.11 last-runnin-player-charles)
  • Revision ID: ci-train-bot@canonical.com-20160307101352-jg9eqeccolp2rcfs
Add changes to show up the microphone controls when an external microphone is detected.
Approved by: PS Jenkins bot, Charles Kerr

Show diffs side-by-side

added added

removed removed

Lines of Context:
54
54
        private double _account_service_volume = 0.0;
55
55
        private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS;
56
56
        private AccountsServiceAccess _accounts_service_access;
 
57
        private bool _external_mic_detected = false;
 
58
        private bool _source_sink_mic_activated = false;
57
59
 
58
60
        /** true when a microphone is active **/
59
61
        public override bool active_mic { get; private set; default = false; }
139
141
                return ret_output;
140
142
        }
141
143
 
 
144
        private bool is_external_mic (SourceInfo? sink) {
 
145
                if (sink.name.contains ("indicator_sound_test_mic")) {
 
146
                        return true;
 
147
                }
 
148
                if (sink.active_port != null && 
 
149
                                ( (sink.active_port.name.contains ("headphone") || 
 
150
                                   sink.active_port.name.contains ("headset") ||
 
151
                                   sink.active_port.name.contains ("mic") ) &&
 
152
                                  (!sink.active_port.name.contains ("internal") &&
 
153
                                   !sink.active_port.name.contains ("builtin")) )) {
 
154
                        return true;
 
155
                }
 
156
                return false;
 
157
        }
 
158
 
 
159
 
142
160
        /* PulseAudio logic*/
143
161
        private void context_events_cb (Context c, Context.SubscriptionEventType t, uint32 index)
144
162
        {
180
198
                                                break;
181
199
 
182
200
                                        case Context.SubscriptionEventType.REMOVE:
183
 
                                                this.active_mic = false;
 
201
                                                this._source_sink_mic_activated = false;
 
202
                                                this.active_mic = _external_mic_detected;
184
203
                                                break;
185
204
                                }
186
205
                                break;
229
248
                if (i == null)
230
249
                        return;
231
250
 
 
251
                if (is_external_mic (i)) {
 
252
                        this.active_mic = true;
 
253
                        _external_mic_detected = true;
 
254
                } else {
 
255
                        this.active_mic = _source_sink_mic_activated;
 
256
                        _external_mic_detected = false;
 
257
                }
 
258
 
232
259
                if (_mic_volume != volume_to_double (i.volume.values[0]))
233
260
                {
234
261
                        _mic_volume = volume_to_double (i.volume.values[0]);
434
461
                        return;
435
462
 
436
463
                unowned string role = i.proplist.gets (PulseAudio.Proplist.PROP_MEDIA_ROLE);
437
 
                if (role == "phone" || role == "production")
 
464
                if (role == "phone" || role == "production") {
438
465
                        this.active_mic = true;
 
466
                        this._source_sink_mic_activated = true;
 
467
                }
439
468
        }
440
469
 
441
470
        private void context_state_callback (Context c)