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

Side by Side 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: fix comment 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/chromeos/audio_mixer.h ('k') | chrome/browser/chromeos/audio_mixer_alsa.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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
27 virtual void 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 GetState() 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_Locked() const;
50 void DoSetVolumeDb_Locked(double vol_db);
51
52 _snd_mixer_elem* FindElementWithName_Locked(_snd_mixer* handle,
53 const char* element_name) const;
54
55 bool GetElementVolume_Locked(_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_Locked(_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_Locked(_snd_mixer_elem* elem) const;
70 void SetElementMuted_Locked(_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 _snd_mixer* alsa_mixer_;
87 _snd_mixer_elem* elem_master_;
88 _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
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/audio_mixer.h ('k') | chrome/browser/chromeos/audio_mixer_alsa.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698