OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
| 7 #pragma once |
| 8 |
| 9 #include <cras_client.h> |
| 10 |
| 11 #include "base/basictypes.h" |
| 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/synchronization/lock.h" |
| 15 #include "base/threading/thread.h" |
| 16 #include "chrome/browser/chromeos/audio/audio_mixer.h" |
| 17 |
| 18 namespace chromeos { |
| 19 |
| 20 // Simple wrapper for sending volume and mute commands to the audio server on |
| 21 // ChromeOS. Interaction happens on a background thread so that initialization |
| 22 // can poll until the server is started. |
| 23 class AudioMixerCras : public AudioMixer { |
| 24 public: |
| 25 AudioMixerCras(); |
| 26 virtual ~AudioMixerCras(); |
| 27 |
| 28 // AudioMixer implementation. |
| 29 virtual void Init() OVERRIDE; |
| 30 virtual double GetVolumePercent() OVERRIDE; |
| 31 virtual void SetVolumePercent(double percent) OVERRIDE; |
| 32 virtual bool IsMuted() OVERRIDE; |
| 33 virtual void SetMuted(bool muted) OVERRIDE; |
| 34 |
| 35 private: |
| 36 // Tries to connect to CRAS. On failure, posts a delayed Connect() task to |
| 37 // try again. Failure could occur if the CRAS server isn't running yet. |
| 38 void Connect(); |
| 39 |
| 40 // Updates |client_| for current values of |volume_percent_| and |
| 41 // |is_muted_|. No-op if not connected. |
| 42 void ApplyState(); |
| 43 |
| 44 // Interfaces to the audio server. |
| 45 struct cras_client *client_; |
| 46 |
| 47 // Indicates if we have connected |client_| to the server. |
| 48 bool client_connected_; |
| 49 |
| 50 // Most recently-requested volume, in percent. This variable is updated |
| 51 // immediately by SetVolumePercent() (post-initialization); the actual mixer |
| 52 // volume is updated later on |thread_| by ApplyState(). |
| 53 double volume_percent_; |
| 54 |
| 55 // Most recently-requested muting state. |
| 56 bool is_muted_; |
| 57 |
| 58 // Is there already a pending call to ApplyState() scheduled on |thread_|? |
| 59 bool apply_is_pending_; |
| 60 |
| 61 // Background thread used for interacting with CRAS. |
| 62 scoped_ptr<base::Thread> thread_; |
| 63 |
| 64 // Guards |volume_percent_|, |is_muted_|, and |apply_is_pending_|. |
| 65 base::Lock lock_; |
| 66 |
| 67 DISALLOW_COPY_AND_ASSIGN(AudioMixerCras); |
| 68 }; |
| 69 |
| 70 } // namespace chromeos |
| 71 |
| 72 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
OLD | NEW |