Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/chromeos/audio/audio_mixer_alsa.h

Issue 10873085: Implement two new policies to control muting the audio I/O. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 15 matching lines...) Expand all
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 muted) 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
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
78 // Guards |min_volume_db_|, |max_volume_db_|, |volume_db_|, |is_muted_|, 84 // Guards |min_volume_db_|, |max_volume_db_|, |volume_db_|, the mute state,
Mattias Nissler (ping if slow) 2012/08/28 12:24:24 I'd just list the additional members for clarity.
pastarmovj 2012/08/28 15:11:50 Done.
79 // |apply_is_pending_|, and |initial_volume_percent_|. 85 // |apply_is_pending_|, and |initial_volume_percent_|.
80 base::Lock lock_; 86 base::Lock lock_;
81 87
82 // Volume range limits are computed once in ConnectInternal(). 88 // Volume range limits are computed once in ConnectInternal().
83 double min_volume_db_; 89 double min_volume_db_;
84 double max_volume_db_; 90 double max_volume_db_;
85 91
86 // Most recently-requested volume, in decibels. This variable is updated 92 // Most recently-requested volume, in decibels. This variable is updated
87 // immediately by SetVolumePercent() (post-initialization); the actual mixer 93 // immediately by SetVolumePercent() (post-initialization); the actual mixer
88 // volume is updated later on |thread_| by ApplyState(). 94 // volume is updated later on |thread_| by ApplyState().
89 double volume_db_; 95 double volume_db_;
90 96
91 // Most recently-requested muting state. 97 // Most recently-requested muting state. We don't have control over ALSA so
98 // other sound clients might unmute channels but we can do best effort to
99 // mimic CRASes locking functionality.
Daniel Erat 2012/08/27 17:38:35 nit: s/CRASes/CRAS's/
pastarmovj 2012/08/28 15:11:50 Done.
92 bool is_muted_; 100 bool is_muted_;
101 bool is_mute_locked_;
Daniel Erat 2012/08/27 17:38:35 nit: move is_mute_locked_ and is_capture_mute_lock
pastarmovj 2012/08/28 15:11:50 Done.
102 bool is_capture_muted_;
103 bool is_capture_mute_locked_;
93 104
94 // Is there already a pending call to ApplyState() scheduled on |thread_|? 105 // Is there already a pending call to ApplyState() scheduled on |thread_|?
95 bool apply_is_pending_; 106 bool apply_is_pending_;
96 107
97 // Before |min_volume_db_| and |max_volume_db_| are fetched from ALSA, we 108 // 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 109 // 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 110 // subsequent requests we get early on are stored here and then applied during
100 // initialization. This variable is unused after initialization. 111 // initialization. This variable is unused after initialization.
101 double initial_volume_percent_; 112 double initial_volume_percent_;
102 113
103 // Connection to ALSA. NULL if not connected. 114 // Connection to ALSA. NULL if not connected.
104 _snd_mixer* alsa_mixer_; 115 _snd_mixer* alsa_mixer_;
105 116
106 // Master mixer. 117 // Master mixer.
107 _snd_mixer_elem* master_element_; 118 _snd_mixer_elem* master_element_;
108 119
109 // PCM mixer. May be NULL if the driver doesn't expose one. 120 // PCM mixer. May be NULL if the driver doesn't expose one.
110 _snd_mixer_elem* pcm_element_; 121 _snd_mixer_elem* pcm_element_;
111 122
123 // Mic mixers. Used to mute capture. Both might be NULL on some drivers.
Mattias Nissler (ping if slow) 2012/08/28 12:24:24 nit: Two spaces after period seems to be the rule
pastarmovj 2012/08/28 15:11:50 Done.
124 _snd_mixer_elem* mic_element_;
125 _snd_mixer_elem* front_mic_element_;
126
112 // Signalled after Disconnect() finishes (which is itself invoked by the 127 // Signalled after Disconnect() finishes (which is itself invoked by the
113 // d'tor). 128 // d'tor).
114 base::WaitableEvent disconnected_event_; 129 base::WaitableEvent disconnected_event_;
115 130
116 // Background thread used for interacting with ALSA. 131 // Background thread used for interacting with ALSA.
117 scoped_ptr<base::Thread> thread_; 132 scoped_ptr<base::Thread> thread_;
118 133
119 // Number of times that we've attempted to connect to ALSA. Just used to keep 134 // Number of times that we've attempted to connect to ALSA. Just used to keep
120 // us from spamming the logs. 135 // us from spamming the logs.
121 int num_connection_attempts_; 136 int num_connection_attempts_;
122 137
123 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); 138 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa);
124 }; 139 };
125 140
126 } // namespace chromeos 141 } // namespace chromeos
127 142
128 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_ 143 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_MIXER_ALSA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698