OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_MIXER_ALSA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
6 #define CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
11 #include "base/lock.h" | 11 #include "base/lock.h" |
12 #include "base/scoped_ptr.h" | 12 #include "base/scoped_ptr.h" |
13 #include "base/threading/thread.h" | 13 #include "base/threading/thread.h" |
14 #include "chrome/browser/chromeos/audio_mixer.h" | 14 #include "chrome/browser/chromeos/audio_mixer.h" |
| 15 #include "chrome/browser/prefs/pref_member.h" |
15 | 16 |
16 struct _snd_mixer_elem; | 17 struct _snd_mixer_elem; |
17 struct _snd_mixer; | 18 struct _snd_mixer; |
18 | 19 |
19 namespace chromeos { | 20 namespace chromeos { |
20 | 21 |
21 class AudioMixerAlsa : public AudioMixer { | 22 class AudioMixerAlsa : public AudioMixer { |
22 public: | 23 public: |
23 AudioMixerAlsa(); | 24 AudioMixerAlsa(); |
24 virtual ~AudioMixerAlsa(); | 25 virtual ~AudioMixerAlsa(); |
25 | 26 |
26 // Implementation of AudioMixer | 27 // Implementation of AudioMixer |
27 virtual void Init(InitDoneCallback* callback); | 28 virtual void Init(InitDoneCallback* callback); |
28 virtual bool InitSync(); | 29 virtual bool InitSync(); |
29 virtual double GetVolumeDb() const; | 30 virtual double GetVolumeDb() const; |
30 virtual bool GetVolumeLimits(double* vol_min, double* vol_max); | 31 virtual bool GetVolumeLimits(double* vol_min, double* vol_max); |
31 virtual void SetVolumeDb(double vol_db); | 32 virtual void SetVolumeDb(double vol_db); |
32 virtual bool IsMute() const; | 33 virtual bool IsMute() const; |
33 virtual void SetMute(bool mute); | 34 virtual void SetMute(bool mute); |
34 virtual State GetState() const; | 35 virtual State GetState() const; |
35 | 36 |
| 37 // Registers volume and mute in preferences |
| 38 static void RegisterPrefs(PrefService* local_state); |
| 39 |
36 private: | 40 private: |
37 // Called to do initialization in background from worker thread. | 41 // Called to do initialization in background from worker thread. |
38 void DoInit(InitDoneCallback* callback); | 42 void DoInit(InitDoneCallback* callback); |
39 | 43 |
40 // Helper function to just get our message loop thread going. | 44 // Helper functions to get our message loop thread and prefs initialized. |
41 bool InitThread(); | 45 bool InitThread(); |
| 46 void InitPrefs(); |
42 | 47 |
43 // Try to connect to the ALSA mixer through their simple controls interface, | 48 // Try to connect to the ALSA mixer through their simple controls interface, |
44 // and cache mixer handle and mixer elements we'll be using. | 49 // and cache mixer handle and mixer elements we'll be using. |
45 bool InitializeAlsaMixer(); | 50 bool InitializeAlsaMixer(); |
46 void FreeAlsaMixer(); | 51 void FreeAlsaMixer(); |
| 52 void DoSetVolumeMute(double pref_volume, int pref_mute); |
| 53 |
| 54 // Access to PrefMember variables must be done on UI thread. |
| 55 void RestoreVolumeMuteOnUIThread(); |
47 | 56 |
48 // All these internal volume commands must be called with the lock held. | 57 // All these internal volume commands must be called with the lock held. |
49 double DoGetVolumeDb_Locked() const; | 58 double DoGetVolumeDb_Locked() const; |
50 void DoSetVolumeDb_Locked(double vol_db); | 59 void DoSetVolumeDb_Locked(double vol_db); |
51 | 60 |
52 _snd_mixer_elem* FindElementWithName_Locked(_snd_mixer* handle, | 61 _snd_mixer_elem* FindElementWithName_Locked(_snd_mixer* handle, |
53 const char* element_name) const; | 62 const char* element_name) const; |
54 | 63 |
55 bool GetElementVolume_Locked(_snd_mixer_elem* elem, | 64 bool GetElementVolume_Locked(_snd_mixer_elem* elem, |
56 double* current_vol) const; | 65 double* current_vol) const; |
(...skipping 23 matching lines...) Expand all Loading... |
80 double save_volume_; | 89 double save_volume_; |
81 | 90 |
82 mutable Lock mixer_state_lock_; | 91 mutable Lock mixer_state_lock_; |
83 mutable State mixer_state_; | 92 mutable State mixer_state_; |
84 | 93 |
85 // Cached contexts for use in ALSA calls. | 94 // Cached contexts for use in ALSA calls. |
86 _snd_mixer* alsa_mixer_; | 95 _snd_mixer* alsa_mixer_; |
87 _snd_mixer_elem* elem_master_; | 96 _snd_mixer_elem* elem_master_; |
88 _snd_mixer_elem* elem_pcm_; | 97 _snd_mixer_elem* elem_pcm_; |
89 | 98 |
| 99 IntegerPrefMember mute_pref_; |
| 100 RealPrefMember volume_pref_; |
| 101 |
90 scoped_ptr<base::Thread> thread_; | 102 scoped_ptr<base::Thread> thread_; |
91 | 103 |
92 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); | 104 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); |
93 }; | 105 }; |
94 | 106 |
95 } // namespace chromeos | 107 } // namespace chromeos |
96 | 108 |
97 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); | 109 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); |
98 | 110 |
99 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | 111 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
100 | 112 |
OLD | NEW |