Index: chrome/browser/chromeos/audio_mixer_alsa.h |
diff --git a/chrome/browser/chromeos/audio_mixer_alsa.h b/chrome/browser/chromeos/audio_mixer_alsa.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..51b7ecd60097986ff5ecad86f65378a8a96409b6 |
--- /dev/null |
+++ b/chrome/browser/chromeos/audio_mixer_alsa.h |
@@ -0,0 +1,102 @@ |
+// Copyright (c) 2010 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
+#define CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
+#pragma once |
+ |
+#include <alsa/asoundlib.h> |
+ |
+#include "base/basictypes.h" |
+#include "base/callback.h" |
+#include "base/lock.h" |
+#include "base/scoped_ptr.h" |
+#include "base/thread.h" |
+ |
+#include "chrome/browser/chromeos/audio_mixer_base.h" |
+ |
+namespace chromeos { |
+ |
+class AudioMixerAlsa : public AudioMixerBase { |
+ public: |
+ |
+ AudioMixerAlsa(); |
+ ~AudioMixerAlsa(); |
+ |
+ // Implementation of AudioMixer, see AudioMixerBase for explanations. |
+ bool Init(InitDoneCallback* callback); |
Daniel Erat
2010/12/20 22:01:12
chrome style is to put "virtual" in front of all i
davejcool
2010/12/21 02:00:21
Thanks, done.
|
+ bool InitSync(); |
+ double GetVolumeDb() const; |
+ void GetVolumeLimits(double* vol_min, double* vol_max); |
+ void SetVolumeDb(double vol_db); |
+ bool IsMute() const; |
+ void SetMute(bool mute); |
+ State CheckState() const; |
+ |
+ private: |
+ // Called to do initialization in background from worker thread. |
+ void DoInit(InitDoneCallback* callback); |
+ |
+ // Helper function to just get our message loop thread going. |
+ bool InitThread(); |
+ |
+ // Try to connect to the ALSA mixer through their simple controls interface, |
+ // and cache mixer handle and mixer elements we'll be using. |
+ bool InitializeAlsaMixer(); |
+ void FreeAlsaMixer(); |
+ |
+ snd_mixer_elem_t* FindElementWithName(snd_mixer_t* handle, |
+ const char* element_name) const; |
+ |
+ bool GetElementVolume(snd_mixer_elem_t* elem, |
+ float* current_vol) const; |
+ |
+ // Since volume is done in steps, we may not get the exact volume asked for, |
+ // so actual_vol will contain the true volume that was set. This information |
+ // can be used to further refine the volume by adjust a different mixer |
+ // element. The rounding_bias is added in before rounding to the nearest |
+ // volume step (use 0.5 to round to nearest). |
+ bool SetElementVolume(snd_mixer_elem_t* elem, |
+ float new_vol, |
+ float* actual_vol, |
+ float rounding_bias); |
+ |
+ // In ALSA, the mixer element's 'switch' is turned off for mute. |
+ bool GetElementSwitched(snd_mixer_elem_t* elem, |
+ int* switched) const; |
+ |
+ bool SetElementSwitched(snd_mixer_elem_t* elem, |
+ int switched); |
+ |
+ bool MixerReady() const; |
+ |
+ // Volume range limits are computed once during InitializeAlsaMixer. |
+ float min_volume_; |
+ float max_volume_; |
+ |
+ // Muting is done by setting volume to minimum, so we must save the original. |
+ // This is the only state information kept in this object. In some cases, |
+ // ALSA can report it has a volume switch and we can turn it off, but it has |
+ // no effect. |
+ float save_volume_; |
+ |
+ mutable Lock mixer_state_lock_; |
+ mutable State mixer_state_; |
+ |
+ // Cached contexts for use in ALSA calls. |
+ snd_mixer_t* alsa_mixer_; |
+ snd_mixer_elem_t* elem_master_; |
+ snd_mixer_elem_t* elem_pcm_; |
+ |
+ scoped_ptr<base::Thread> thread_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); |
+}; |
+ |
+} // namespace chromeos |
+ |
+DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); |
+ |
+#endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ |
+ |