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 "base/basictypes.h" | |
| 10 #include "base/callback.h" | |
| 11 #include "base/lock.h" | |
| 12 #include "base/scoped_ptr.h" | |
| 13 #include "base/threading/thread.h" | |
| 14 #include "chrome/browser/chromeos/audio_mixer.h" | |
| 15 | |
| 16 struct _snd_mixer_elem; | |
| 17 struct _snd_mixer; | |
| 18 | |
| 19 namespace chromeos { | |
| 20 | |
| 21 class AudioMixerAlsa : public AudioMixer { | |
| 22 public: | |
| 23 AudioMixerAlsa(); | |
| 24 virtual ~AudioMixerAlsa(); | |
| 25 | |
| 26 // Implementation of AudioMixer, see AudioMixerBase for explanations. | |
|
scherkus (not reviewing)
2011/01/11 00:24:12
nit: remove ", see AudioMixerBase for explanations
| |
| 27 virtual bool Init(InitDoneCallback* callback); | |
| 28 virtual bool InitSync(); | |
| 29 virtual double GetVolumeDb() const; | |
| 30 virtual bool GetVolumeLimits(double* vol_min, double* vol_max); | |
| 31 virtual void SetVolumeDb(double vol_db); | |
| 32 virtual bool IsMute() const; | |
| 33 virtual void SetMute(bool mute); | |
| 34 virtual State CheckState() const; | |
| 35 | |
| 36 private: | |
| 37 // Called to do initialization in background from worker thread. | |
| 38 void DoInit(InitDoneCallback* callback); | |
| 39 | |
| 40 // Helper function to just get our message loop thread going. | |
| 41 bool InitThread(); | |
| 42 | |
| 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. | |
| 45 bool InitializeAlsaMixer(); | |
| 46 void FreeAlsaMixer(); | |
| 47 | |
| 48 // All these internal volume commands must be called with the lock held. | |
| 49 double DoGetVolumeDb() const; | |
|
scherkus (not reviewing)
2011/01/11 00:24:12
nit: a style we've used in media code is to append
| |
| 50 void DoSetVolumeDb(double vol_db); | |
| 51 | |
| 52 struct _snd_mixer_elem* FindElementWithName(struct _snd_mixer* handle, | |
|
scherkus (not reviewing)
2011/01/11 00:24:12
question: do we actually have to use "struct _snd_
davejcool
2011/01/11 02:52:54
Eventually it'll stick that 'struct' is mostly sup
| |
| 53 const char* element_name) const; | |
|
scherkus (not reviewing)
2011/01/11 00:24:12
since params don't find drop both params to next l
| |
| 54 | |
| 55 bool GetElementVolume(struct _snd_mixer_elem* elem, | |
| 56 double* current_vol) const; | |
| 57 | |
| 58 // 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 // 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 // volume step (use 0.5 to round to nearest). | |
| 63 bool SetElementVolume(struct _snd_mixer_elem* elem, | |
| 64 double new_vol, | |
| 65 double* actual_vol, | |
| 66 double rounding_bias); | |
| 67 | |
| 68 // In ALSA, the mixer element's 'switch' is turned off to mute. | |
| 69 bool GetElementMuted(struct _snd_mixer_elem* elem) const; | |
| 70 void SetElementMuted(struct _snd_mixer_elem* elem, bool mute); | |
| 71 | |
| 72 // Volume range limits are computed once during InitializeAlsaMixer. | |
| 73 double min_volume_; | |
| 74 double max_volume_; | |
| 75 | |
| 76 // 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, | |
| 78 // ALSA can report it has a volume switch and we can turn it off, but it has | |
| 79 // no effect. | |
| 80 double save_volume_; | |
| 81 | |
| 82 mutable Lock mixer_state_lock_; | |
| 83 mutable State mixer_state_; | |
| 84 | |
| 85 // Cached contexts for use in ALSA calls. | |
| 86 struct _snd_mixer* alsa_mixer_; | |
| 87 struct _snd_mixer_elem* elem_master_; | |
| 88 struct _snd_mixer_elem* elem_pcm_; | |
| 89 | |
| 90 scoped_ptr<base::Thread> thread_; | |
| 91 | |
| 92 DISALLOW_COPY_AND_ASSIGN(AudioMixerAlsa); | |
| 93 }; | |
| 94 | |
| 95 } // namespace chromeos | |
| 96 | |
| 97 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioMixerAlsa); | |
| 98 | |
| 99 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_MIXER_ALSA_H_ | |
| 100 | |
| OLD | NEW |