Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | |
| 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include <alsa/asoundlib.h> | |
| 10 | |
| 11 #include "base/basictypes.h" | |
| 12 #include "base/callback.h" | |
| 13 #include "base/lock.h" | |
| 14 #include "base/scoped_ptr.h" | |
| 15 #include "base/thread.h" | |
| 16 | |
| 17 #include "chrome/browser/chromeos/audio_mixer_base.h" | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 class AudioMixerAlsa : public AudioMixerBase { | |
| 22 public: | |
| 23 | |
| 24 AudioMixerAlsa(); | |
| 25 ~AudioMixerAlsa(); | |
| 26 | |
| 27 // Implementation of AudioMixer, see AudioMixerBase for explanations. | |
| 28 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.
| |
| 29 bool InitSync(); | |
| 30 double GetVolumeDb() const; | |
| 31 void GetVolumeLimits(double* vol_min, double* vol_max); | |
| 32 void SetVolumeDb(double vol_db); | |
| 33 bool IsMute() const; | |
| 34 void SetMute(bool mute); | |
| 35 State CheckState() const; | |
| 36 | |
| 37 private: | |
| 38 // Called to do initialization in background from worker thread. | |
| 39 void DoInit(InitDoneCallback* callback); | |
| 40 | |
| 41 // Helper function to just get our message loop thread going. | |
| 42 bool InitThread(); | |
| 43 | |
| 44 // Try to connect to the ALSA mixer through their simple controls interface, | |
| 45 // and cache mixer handle and mixer elements we'll be using. | |
| 46 bool InitializeAlsaMixer(); | |
| 47 void FreeAlsaMixer(); | |
| 48 | |
| 49 snd_mixer_elem_t* FindElementWithName(snd_mixer_t* handle, | |
| 50 const char* element_name) const; | |
| 51 | |
| 52 bool GetElementVolume(snd_mixer_elem_t* elem, | |
| 53 float* current_vol) const; | |
| 54 | |
| 55 // Since volume is done in steps, we may not get the exact volume asked for, | |
| 56 // so actual_vol will contain the true volume that was set. This information | |
| 57 // can be used to further refine the volume by adjust a different mixer | |
| 58 // element. The rounding_bias is added in before rounding to the nearest | |
| 59 // volume step (use 0.5 to round to nearest). | |
| 60 bool SetElementVolume(snd_mixer_elem_t* elem, | |
| 61 float new_vol, | |
| 62 float* actual_vol, | |
| 63 float rounding_bias); | |
| 64 | |
| 65 // In ALSA, the mixer element's 'switch' is turned off for mute. | |
| 66 bool GetElementSwitched(snd_mixer_elem_t* elem, | |
| 67 int* switched) const; | |
| 68 | |
| 69 bool SetElementSwitched(snd_mixer_elem_t* elem, | |
| 70 int switched); | |
| 71 | |
| 72 bool MixerReady() const; | |
| 73 | |
| 74 // Volume range limits are computed once during InitializeAlsaMixer. | |
| 75 float min_volume_; | |
| 76 float max_volume_; | |
| 77 | |
| 78 // Muting is done by setting volume to minimum, so we must save the original. | |
| 79 // This is the only state information kept in this object. In some cases, | |
| 80 // ALSA can report it has a volume switch and we can turn it off, but it has | |
| 81 // no effect. | |
| 82 float save_volume_; | |
| 83 | |
| 84 mutable Lock mixer_state_lock_; | |
| 85 mutable State mixer_state_; | |
| 86 | |
| 87 // Cached contexts for use in ALSA calls. | |
| 88 snd_mixer_t* alsa_mixer_; | |
| 89 snd_mixer_elem_t* elem_master_; | |
| 90 snd_mixer_elem_t* elem_pcm_; | |
| 91 | |
| 92 scoped_ptr<base::Thread> thread_; | |
| 93 | |
| 94 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); | |
| 95 }; | |
| 96 | |
| 97 } // namespace chromeos | |
| 98 | |
| 99 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); | |
| 100 | |
| 101 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | |
| 102 | |
| OLD | NEW |