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" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // Called to do initialization in background from worker thread. | 37 // Called to do initialization in background from worker thread. |
38 void DoInit(InitDoneCallback* callback); | 38 void DoInit(InitDoneCallback* callback); |
39 | 39 |
40 // Helper function to just get our message loop thread going. | 40 // Helper function to just get our message loop thread going. |
41 bool InitThread(); | 41 bool InitThread(); |
42 | 42 |
43 // Try to connect to the ALSA mixer through their simple controls interface, | 43 // Try to connect to the ALSA mixer through their simple controls interface, |
44 // and cache mixer handle and mixer elements we'll be using. | 44 // and cache mixer handle and mixer elements we'll be using. |
45 bool InitializeAlsaMixer(); | 45 bool InitializeAlsaMixer(); |
46 void FreeAlsaMixer(); | 46 void FreeAlsaMixer(); |
| 47 void DoSetVolumeMute(double volume, bool mute); |
47 | 48 |
48 // All these internal volume commands must be called with the lock held. | 49 // All these internal volume commands must be called with the lock held. |
49 double DoGetVolumeDb_Locked() const; | 50 double DoGetVolumeDb_Locked() const; |
50 void DoSetVolumeDb_Locked(double vol_db); | 51 void DoSetVolumeDb_Locked(double vol_db); |
51 | 52 |
52 _snd_mixer_elem* FindElementWithName_Locked(_snd_mixer* handle, | 53 _snd_mixer_elem* FindElementWithName_Locked(_snd_mixer* handle, |
53 const char* element_name) const; | 54 const char* element_name) const; |
54 | 55 |
55 bool GetElementVolume_Locked(_snd_mixer_elem* elem, | 56 bool GetElementVolume_Locked(_snd_mixer_elem* elem, |
56 double* current_vol) const; | 57 double* current_vol) const; |
57 | 58 |
58 // Since volume is done in steps, we may not get the exact volume asked for, | 59 // Since volume is done in steps, we may not get the exact volume asked for, |
59 // so actual_vol will contain the true volume that was set. This information | 60 // so actual_vol will contain the true volume that was set. This information |
60 // can be used to further refine the volume by adjust a different mixer | 61 // can be used to further refine the volume by adjust a different mixer |
61 // element. The rounding_bias is added in before rounding to the nearest | 62 // element. The rounding_bias is added in before rounding to the nearest |
62 // volume step (use 0.5 to round to nearest). | 63 // volume step (use 0.5 to round to nearest). |
63 bool SetElementVolume_Locked(_snd_mixer_elem* elem, | 64 bool SetElementVolume_Locked(_snd_mixer_elem* elem, |
64 double new_vol, | 65 double new_vol, |
65 double* actual_vol, | 66 double* actual_vol, |
66 double rounding_bias); | 67 double rounding_bias); |
67 | 68 |
68 // In ALSA, the mixer element's 'switch' is turned off to mute. | 69 // In ALSA, the mixer element's 'switch' is turned off to mute. |
69 bool GetElementMuted_Locked(_snd_mixer_elem* elem) const; | 70 bool GetElementMuted_Locked(_snd_mixer_elem* elem) const; |
70 void SetElementMuted_Locked(_snd_mixer_elem* elem, bool mute); | 71 void SetElementMuted_Locked(_snd_mixer_elem* elem, bool mute); |
71 | 72 |
| 73 // Volume and Mute state are persisted in the browser prefs kAudioMute and |
| 74 // kAudioVolume. These must be run on the UI thread. |
| 75 void RestoreVolumeMute(); |
| 76 void SaveVolume(double volume); |
| 77 void SaveMute(bool mute); |
| 78 |
72 // Volume range limits are computed once during InitializeAlsaMixer. | 79 // Volume range limits are computed once during InitializeAlsaMixer. |
73 double min_volume_; | 80 double min_volume_; |
74 double max_volume_; | 81 double max_volume_; |
75 | 82 |
76 // Muting is done by setting volume to minimum, so we must save the original. | 83 // Muting is done by setting volume to minimum, so we must save the original. |
77 // This is the only state information kept in this object. In some cases, | 84 // This is the only state information kept in this object. In some cases, |
78 // ALSA can report it has a volume switch and we can turn it off, but it has | 85 // ALSA can report it has a volume switch and we can turn it off, but it has |
79 // no effect. | 86 // no effect. |
80 double save_volume_; | 87 double save_volume_; |
81 | 88 |
82 mutable Lock mixer_state_lock_; | 89 mutable Lock mixer_state_lock_; |
83 mutable State mixer_state_; | 90 mutable State mixer_state_; |
84 | 91 |
85 // Cached contexts for use in ALSA calls. | 92 // Cached contexts for use in ALSA calls. |
86 _snd_mixer* alsa_mixer_; | 93 _snd_mixer* alsa_mixer_; |
87 _snd_mixer_elem* elem_master_; | 94 _snd_mixer_elem* elem_master_; |
88 _snd_mixer_elem* elem_pcm_; | 95 _snd_mixer_elem* elem_pcm_; |
89 | 96 |
90 scoped_ptr<base::Thread> thread_; | 97 scoped_ptr<base::Thread> thread_; |
91 | 98 |
92 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); | 99 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); |
93 }; | 100 }; |
94 | 101 |
95 } // namespace chromeos | 102 } // namespace chromeos |
96 | 103 |
97 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); | 104 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); |
98 | 105 |
99 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | 106 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
100 | 107 |
OLD | NEW |