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

Unified Diff: chrome/browser/chromeos/audio_mixer_alsa.h

Issue 5859003: Add ALSA support to volume keys (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos
Patch Set: using snd_mixer_selem_id_malloc Created 9 years, 11 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 side-by-side diff with in-line comments
Download patch
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..dae0addaa552d134f1f7041811f1c4f19f4dd280
--- /dev/null
+++ b/chrome/browser/chromeos/audio_mixer_alsa.h
@@ -0,0 +1,100 @@
+// 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 "base/basictypes.h"
+#include "base/callback.h"
+#include "base/lock.h"
+#include "base/scoped_ptr.h"
+#include "base/threading/thread.h"
+#include "chrome/browser/chromeos/audio_mixer.h"
+
+struct _snd_mixer_elem;
+struct _snd_mixer;
+
+namespace chromeos {
+
+class AudioMixerAlsa : public AudioMixer {
+ public:
+ AudioMixerAlsa();
+ virtual ~AudioMixerAlsa();
+
+ // Implementation of AudioMixer, see AudioMixerBase for explanations.
scherkus (not reviewing) 2011/01/11 00:24:12 nit: remove ", see AudioMixerBase for explanations
+ virtual bool Init(InitDoneCallback* callback);
+ virtual bool InitSync();
+ virtual double GetVolumeDb() const;
+ virtual bool GetVolumeLimits(double* vol_min, double* vol_max);
+ virtual void SetVolumeDb(double vol_db);
+ virtual bool IsMute() const;
+ virtual void SetMute(bool mute);
+ virtual 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();
+
+ // All these internal volume commands must be called with the lock held.
+ double DoGetVolumeDb() const;
scherkus (not reviewing) 2011/01/11 00:24:12 nit: a style we've used in media code is to append
+ void DoSetVolumeDb(double vol_db);
+
+ 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
+ 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
+
+ bool GetElementVolume(struct _snd_mixer_elem* elem,
+ double* 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(struct _snd_mixer_elem* elem,
+ double new_vol,
+ double* actual_vol,
+ double rounding_bias);
+
+ // In ALSA, the mixer element's 'switch' is turned off to mute.
+ bool GetElementMuted(struct _snd_mixer_elem* elem) const;
+ void SetElementMuted(struct _snd_mixer_elem* elem, bool mute);
+
+ // Volume range limits are computed once during InitializeAlsaMixer.
+ double min_volume_;
+ double 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.
+ double save_volume_;
+
+ mutable Lock mixer_state_lock_;
+ mutable State mixer_state_;
+
+ // Cached contexts for use in ALSA calls.
+ struct _snd_mixer* alsa_mixer_;
+ struct _snd_mixer_elem* elem_master_;
+ struct _snd_mixer_elem* 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_
+

Powered by Google App Engine
This is Rietveld 408576698