| 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_ALSA_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ |
| 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ | 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 class AudioMixerAlsa : public AudioMixer { | 25 class AudioMixerAlsa : public AudioMixer { |
| 26 public: | 26 public: |
| 27 AudioMixerAlsa(); | 27 AudioMixerAlsa(); |
| 28 virtual ~AudioMixerAlsa(); | 28 virtual ~AudioMixerAlsa(); |
| 29 | 29 |
| 30 // AudioMixer implementation. | 30 // AudioMixer implementation. |
| 31 virtual void Init() OVERRIDE; | 31 virtual void Init() OVERRIDE; |
| 32 virtual double GetVolumePercent() OVERRIDE; | 32 virtual double GetVolumePercent() OVERRIDE; |
| 33 virtual void SetVolumePercent(double percent) OVERRIDE; | 33 virtual void SetVolumePercent(double percent) OVERRIDE; |
| 34 virtual bool IsMuted() OVERRIDE; | 34 virtual bool IsMuted() OVERRIDE; |
| 35 virtual void SetMuted(bool muted) OVERRIDE; | 35 virtual void SetMuted(bool mute) OVERRIDE; |
| 36 virtual bool IsMuteLocked() OVERRIDE; |
| 37 virtual void SetMuteLocked(bool locked) OVERRIDE; |
| 38 virtual bool IsCaptureMuted() OVERRIDE; |
| 39 virtual void SetCaptureMuted(bool mute) OVERRIDE; |
| 40 virtual bool IsCaptureMuteLocked() OVERRIDE; |
| 41 virtual void SetCaptureMuteLocked(bool locked) OVERRIDE; |
| 36 | 42 |
| 37 private: | 43 private: |
| 38 // Tries to connect to ALSA. On failure, posts a delayed Connect() task to | 44 // Tries to connect to ALSA. On failure, posts a delayed Connect() task to |
| 39 // try again. | 45 // try again. |
| 40 void Connect(); | 46 void Connect(); |
| 41 | 47 |
| 42 // Helper method called by Connect(). On success, initializes | 48 // Helper method called by Connect(). On success, initializes |
| 43 // |min_volume_db_|, |max_volume_db_|, |alsa_mixer_|, and |element_*| and | 49 // |min_volume_db_|, |max_volume_db_|, |alsa_mixer_|, and |element_*| and |
| 44 // returns true. | 50 // returns true. |
| 45 bool ConnectInternal(); | 51 bool ConnectInternal(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 68 double rounding_bias); | 74 double rounding_bias); |
| 69 | 75 |
| 70 // Mutes or unmutes |element|. | 76 // Mutes or unmutes |element|. |
| 71 void SetElementMuted(_snd_mixer_elem* element, bool mute); | 77 void SetElementMuted(_snd_mixer_elem* element, bool mute); |
| 72 | 78 |
| 73 // Converts between percentages (in the range [0.0, 100.0]) and decibels. | 79 // Converts between percentages (in the range [0.0, 100.0]) and decibels. |
| 74 // |lock_| must be held. | 80 // |lock_| must be held. |
| 75 double DbToPercent(double db) const; | 81 double DbToPercent(double db) const; |
| 76 double PercentToDb(double percent) const; | 82 double PercentToDb(double percent) const; |
| 77 | 83 |
| 84 // Calls ApplyState on the proper thread only if no other call is currently |
| 85 // pending. |
| 86 void ApplyStateIfNeeded(); |
| 87 |
| 78 // Guards |min_volume_db_|, |max_volume_db_|, |volume_db_|, |is_muted_|, | 88 // Guards |min_volume_db_|, |max_volume_db_|, |volume_db_|, |is_muted_|, |
| 89 // |is_mute_locked_|, |is_capture_muted_|, |is_capture_mute_locked_|, |
| 79 // |apply_is_pending_|, and |initial_volume_percent_|. | 90 // |apply_is_pending_|, and |initial_volume_percent_|. |
| 80 base::Lock lock_; | 91 base::Lock lock_; |
| 81 | 92 |
| 82 // Volume range limits are computed once in ConnectInternal(). | 93 // Volume range limits are computed once in ConnectInternal(). |
| 83 double min_volume_db_; | 94 double min_volume_db_; |
| 84 double max_volume_db_; | 95 double max_volume_db_; |
| 85 | 96 |
| 86 // Most recently-requested volume, in decibels. This variable is updated | 97 // Most recently-requested volume, in decibels. This variable is updated |
| 87 // immediately by SetVolumePercent() (post-initialization); the actual mixer | 98 // immediately by SetVolumePercent() (post-initialization); the actual mixer |
| 88 // volume is updated later on |thread_| by ApplyState(). | 99 // volume is updated later on |thread_| by ApplyState(). |
| 89 double volume_db_; | 100 double volume_db_; |
| 90 | 101 |
| 91 // Most recently-requested muting state. | 102 // Most recently-requested muting state. |
| 92 bool is_muted_; | 103 bool is_muted_; |
| 104 bool is_capture_muted_; |
| 105 |
| 106 // If set to true the mute state of the respective channel is locked and can |
| 107 // not be changed until it is unlocked. We don't have control over ALSA so |
| 108 // other sound clients might unmute channels but we can do best effort to |
| 109 // mimic CRAS's locking functionality. |
| 110 bool is_mute_locked_; |
| 111 bool is_capture_mute_locked_; |
| 93 | 112 |
| 94 // Is there already a pending call to ApplyState() scheduled on |thread_|? | 113 // Is there already a pending call to ApplyState() scheduled on |thread_|? |
| 95 bool apply_is_pending_; | 114 bool apply_is_pending_; |
| 96 | 115 |
| 97 // Before |min_volume_db_| and |max_volume_db_| are fetched from ALSA, we | 116 // Before |min_volume_db_| and |max_volume_db_| are fetched from ALSA, we |
| 98 // can't convert percentages to decibels. The default initial volume and any | 117 // can't convert percentages to decibels. The default initial volume and any |
| 99 // subsequent requests we get early on are stored here and then applied during | 118 // subsequent requests we get early on are stored here and then applied during |
| 100 // initialization. This variable is unused after initialization. | 119 // initialization. This variable is unused after initialization. |
| 101 double initial_volume_percent_; | 120 double initial_volume_percent_; |
| 102 | 121 |
| 103 // Connection to ALSA. NULL if not connected. | 122 // Connection to ALSA. NULL if not connected. |
| 104 _snd_mixer* alsa_mixer_; | 123 _snd_mixer* alsa_mixer_; |
| 105 | 124 |
| 106 // Master mixer. | 125 // Master mixer. |
| 107 _snd_mixer_elem* master_element_; | 126 _snd_mixer_elem* master_element_; |
| 108 | 127 |
| 109 // PCM mixer. May be NULL if the driver doesn't expose one. | 128 // PCM mixer. May be NULL if the driver doesn't expose one. |
| 110 _snd_mixer_elem* pcm_element_; | 129 _snd_mixer_elem* pcm_element_; |
| 111 | 130 |
| 131 // Mic mixers. Used to mute capture. Both might be NULL on some drivers. |
| 132 _snd_mixer_elem* mic_element_; |
| 133 _snd_mixer_elem* front_mic_element_; |
| 134 |
| 112 // Signalled after Disconnect() finishes (which is itself invoked by the | 135 // Signalled after Disconnect() finishes (which is itself invoked by the |
| 113 // d'tor). | 136 // d'tor). |
| 114 base::WaitableEvent disconnected_event_; | 137 base::WaitableEvent disconnected_event_; |
| 115 | 138 |
| 116 // Background thread used for interacting with ALSA. | 139 // Background thread used for interacting with ALSA. |
| 117 scoped_ptr<base::Thread> thread_; | 140 scoped_ptr<base::Thread> thread_; |
| 118 | 141 |
| 119 // Number of times that we've attempted to connect to ALSA. Just used to keep | 142 // Number of times that we've attempted to connect to ALSA. Just used to keep |
| 120 // us from spamming the logs. | 143 // us from spamming the logs. |
| 121 int num_connection_attempts_; | 144 int num_connection_attempts_; |
| 122 | 145 |
| 123 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); | 146 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); |
| 124 }; | 147 }; |
| 125 | 148 |
| 126 } // namespace chromeos | 149 } // namespace chromeos |
| 127 | 150 |
| 128 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ | 151 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ |
| OLD | NEW |