~ubuntu-branches/ubuntu/utopic/indicator-sound/utopic

« back to all changes in this revision

Viewing changes to src/volume-control.vala

  • Committer: Package Import Robot
  • Author(s): Ubuntu daily release, Michael Terry, Nick Dedekind
  • Date: 2014-05-09 14:43:21 UTC
  • mfrom: (28.220.34)
  • Revision ID: package-import@ubuntu.com-20140509144321-7ge2qonxcy22x4xe
Tags: 12.10.2+14.10.20140509-0ubuntu1
[ Michael Terry ]
* Added timers to volume changes to settle frequent updates from
  account services. (LP: #1306499)

[ Nick Dedekind ]
* Added timers to volume changes to settle frequent updates from
  account services. (LP: #1306499)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
        private GreeterListInterface _greeter_proxy;
48
48
        private Cancellable _mute_cancellable;
49
49
        private Cancellable _volume_cancellable;
 
50
        private uint _local_volume_timer = 0;
 
51
        private uint _accountservice_volume_timer = 0;
 
52
        private bool _send_next_local_volume = false;
 
53
        private double _account_service_volume = 0.0;
50
54
 
51
55
        public signal void volume_changed (double v);
52
56
        public signal void mic_volume_changed (double v);
75
79
                        Source.remove (_reconnect_timer);
76
80
                        _reconnect_timer = 0;
77
81
                }
 
82
                stop_local_volume_timer();
 
83
                stop_account_service_volume_timer();
78
84
        }
79
85
 
80
86
        /* PulseAudio logic*/
193
199
                                        _reconnect_timer = Timeout.add_seconds (2, reconnect_timeout);
194
200
                                break;
195
201
 
196
 
                        default: 
 
202
                        default:
197
203
                                this.ready = false;
198
204
                                break;
199
205
                }
335
341
        public void set_volume (double volume)
336
342
        {
337
343
                if (set_volume_internal (volume))
338
 
                        sync_volume_to_accountsservice.begin (volume);
 
344
                        start_local_volume_timer();
339
345
        }
340
346
 
341
347
        void set_mic_volume_success_cb (Context c, int success)
377
383
                Variant volume_variant = changed_properties.lookup_value ("Volume", new VariantType ("d"));
378
384
                if (volume_variant != null) {
379
385
                        var volume = volume_variant.get_double ();
380
 
                        if (volume >= 0)
381
 
                                set_volume_internal (volume);
 
386
                        if (volume >= 0) {
 
387
                                _account_service_volume = volume;
 
388
                                // we need to wait for this to settle.
 
389
                                start_account_service_volume_timer();
 
390
                        }
382
391
                }
383
392
 
384
393
                Variant mute_variant = changed_properties.lookup_value ("Muted", new VariantType ("b"));
487
496
                        warning ("unable to sync volume to AccountsService: %s", e.message);
488
497
                }
489
498
        }
 
499
 
 
500
        private void start_local_volume_timer()
 
501
        {
 
502
                // perform a slow sync with the accounts service. max at 1 per second.
 
503
 
 
504
                // stop the AS update timer, as since we're going to be setting the volume.
 
505
                stop_account_service_volume_timer();
 
506
 
 
507
                if (_local_volume_timer == 0) {
 
508
                        sync_volume_to_accountsservice.begin (_volume);
 
509
                        _local_volume_timer = Timeout.add_seconds (1, local_volume_changed_timeout);
 
510
                } else {
 
511
                        _send_next_local_volume = true;
 
512
                }
 
513
        }
 
514
 
 
515
        private void stop_local_volume_timer()
 
516
        {
 
517
                if (_local_volume_timer != 0) {
 
518
                        Source.remove (_local_volume_timer);
 
519
                        _local_volume_timer = 0;
 
520
                }
 
521
        }
 
522
 
 
523
        bool local_volume_changed_timeout()
 
524
        {
 
525
                _local_volume_timer = 0;
 
526
                if (_send_next_local_volume) {
 
527
                        _send_next_local_volume = false;
 
528
                        start_local_volume_timer ();
 
529
                }
 
530
                return false; // G_SOURCE_REMOVE
 
531
        }
 
532
 
 
533
        private void start_account_service_volume_timer()
 
534
        {
 
535
                if (_accountservice_volume_timer == 0) {
 
536
                        // If we haven't been messing with local volume recently, apply immediately.
 
537
                        if (_local_volume_timer == 0 && !set_volume_internal (_account_service_volume)) {
 
538
                                return;
 
539
                        }
 
540
                        // Else check again in another second if needed.
 
541
                        // (if AS is throwing us lots of notifications, we update at most once a second)
 
542
                        _accountservice_volume_timer = Timeout.add_seconds (1, accountservice_volume_changed_timeout);
 
543
                }
 
544
        }
 
545
 
 
546
        private void stop_account_service_volume_timer()
 
547
        {
 
548
                if (_accountservice_volume_timer != 0) {
 
549
                        Source.remove (_accountservice_volume_timer);
 
550
                        _accountservice_volume_timer = 0;
 
551
                }
 
552
        }
 
553
 
 
554
        bool accountservice_volume_changed_timeout ()
 
555
        {
 
556
                _accountservice_volume_timer = 0;
 
557
                start_account_service_volume_timer ();
 
558
                return false; // G_SOURCE_REMOVE
 
559
        }
490
560
}