OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ | 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
7 | 7 |
8 #include <cras_client.h> | 8 #include <cras_client.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/synchronization/lock.h" | 13 #include "base/synchronization/lock.h" |
14 #include "base/threading/thread.h" | 14 #include "base/threading/thread.h" |
15 #include "chrome/browser/chromeos/audio/audio_mixer.h" | 15 #include "chrome/browser/chromeos/audio/audio_mixer.h" |
16 | 16 |
17 namespace chromeos { | 17 namespace chromeos { |
18 | 18 |
19 // Simple wrapper for sending volume and mute commands to the audio server on | 19 // Simple wrapper for sending volume and mute commands to the audio server on |
20 // ChromeOS. Interaction happens on a background thread so that initialization | 20 // ChromeOS. Interaction happens on a background thread so that initialization |
21 // can poll until the server is started. | 21 // can poll until the server is started. |
22 class AudioMixerCras : public AudioMixer { | 22 class AudioMixerCras : public AudioMixer { |
23 public: | 23 public: |
24 AudioMixerCras(); | 24 AudioMixerCras(); |
25 virtual ~AudioMixerCras(); | 25 virtual ~AudioMixerCras(); |
26 | 26 |
27 // AudioMixer implementation. | 27 // AudioMixer implementation. |
28 virtual void Init() OVERRIDE; | 28 virtual void Init(const base::Closure& on_connected) OVERRIDE; |
29 virtual double GetVolumePercent() OVERRIDE; | 29 virtual double GetVolumePercent() OVERRIDE; |
30 virtual void SetVolumePercent(double percent) OVERRIDE; | 30 virtual void SetVolumePercent(double percent) OVERRIDE; |
31 virtual bool IsMuted() OVERRIDE; | 31 virtual bool IsMuted() OVERRIDE; |
32 virtual void SetMuted(bool mute) OVERRIDE; | 32 virtual void SetMuted(bool mute) OVERRIDE; |
33 virtual bool IsMuteLocked() OVERRIDE; | 33 virtual bool IsMuteLocked() OVERRIDE; |
34 virtual void SetMuteLocked(bool locked) OVERRIDE; | 34 virtual void SetMuteLocked(bool locked) OVERRIDE; |
35 virtual bool IsCaptureMuted() OVERRIDE; | 35 virtual bool IsCaptureMuted() OVERRIDE; |
36 virtual void SetCaptureMuted(bool mute) OVERRIDE; | 36 virtual void SetCaptureMuted(bool mute) OVERRIDE; |
37 virtual bool IsCaptureMuteLocked() OVERRIDE; | 37 virtual bool IsCaptureMuteLocked() OVERRIDE; |
38 virtual void SetCaptureMuteLocked(bool locked) OVERRIDE; | 38 virtual void SetCaptureMuteLocked(bool locked) OVERRIDE; |
39 | 39 |
40 private: | 40 private: |
41 // Tries to connect to CRAS. On failure, posts a delayed Connect() task to | 41 // Tries to connect to CRAS. On failure, posts a delayed Connect() task to |
42 // try again. Failure could occur if the CRAS server isn't running yet. | 42 // try again. Failure could occur if the CRAS server isn't running yet. |
43 void Connect(); | 43 void Connect(const base::Closure& on_connected); |
44 | 44 |
45 // Updates |client_| for current values of |volume_percent_| and | 45 // Updates |client_| for current values of |volume_percent_| and |
46 // |is_muted_|. No-op if not connected. | 46 // |is_muted_|. No-op if not connected. |
47 void ApplyState(); | 47 void ApplyState(); |
48 | 48 |
49 // Calls ApplyState on the proper thread only if no other call is currently | 49 // Calls ApplyState on the proper thread only if no other call is currently |
50 // pending. | 50 // pending. |
51 void ApplyStateIfNeeded(); | 51 void ApplyStateIfNeeded(); |
52 | 52 |
53 // Interfaces to the audio server. | 53 // Interfaces to the audio server. |
(...skipping 22 matching lines...) Expand all Loading... |
76 // Guards |volume_percent_|, |is_muted_|, |is_mute_locked_|, | 76 // Guards |volume_percent_|, |is_muted_|, |is_mute_locked_|, |
77 // |is_capture_muted_|, |is_capture_mute_locked_|, and |apply_is_pending_|. | 77 // |is_capture_muted_|, |is_capture_mute_locked_|, and |apply_is_pending_|. |
78 base::Lock lock_; | 78 base::Lock lock_; |
79 | 79 |
80 DISALLOW_COPY_AND_ASSIGN(AudioMixerCras); | 80 DISALLOW_COPY_AND_ASSIGN(AudioMixerCras); |
81 }; | 81 }; |
82 | 82 |
83 } // namespace chromeos | 83 } // namespace chromeos |
84 | 84 |
85 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ | 85 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_CRAS_H_ |
OLD | NEW |