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

Side by Side Diff: chrome/browser/chromeos/audio_handler.h

Issue 5859003: Add ALSA support to volume keys (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/browser/chromeos
Patch Set: Adding ALSA volume support Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_
6 #define CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/scoped_ptr.h" 10 #include "base/scoped_ptr.h"
11 #include "base/thread.h"
11 12
12 template <typename T> struct DefaultSingletonTraits; 13 template <typename T> struct DefaultSingletonTraits;
13 14
14 namespace chromeos { 15 namespace chromeos {
15 16
16 class PulseAudioMixer; 17 class AudioMixerBase;
17 18
18 class AudioHandler { 19 class AudioHandler {
19 public: 20 public:
20 static AudioHandler* instance(); 21 static AudioHandler* instance();
21 22
22 // Get volume level in our internal 0-100% range, 0 being pure silence. 23 // Get volume level in our internal 0-100% range, 0 being pure silence.
23 // Volume may go above 100% if another process changes PulseAudio's volume. 24 // Volume may go above 100% if another process changes PulseAudio's volume.
24 // Returns default of 0 on error. This function will block until the volume 25 // Returns default of 0 on error. This function will block until the volume
25 // is retrieved or fails. Blocking call. 26 // is retrieved or fails. Blocking call.
26 double GetVolumePercent(); 27 double GetVolumePercent();
27 28
28 // Set volume level from 0-100%. Volumes above 100% are OK and boost volume, 29 // Set volume level from 0-100%. Volumes above 100% are OK and boost volume,
29 // although clipping will occur more at higher volumes. Volume gets quieter 30 // although clipping will occur more at higher volumes. Volume gets quieter
30 // as the percentage gets lower, and then switches to silence at 0%. 31 // as the percentage gets lower, and then switches to silence at 0%.
31 void SetVolumePercent(double volume_percent); 32 void SetVolumePercent(double volume_percent);
32 33
33 // Adust volume up (positive percentage) or down (negative percentage), 34 // Adjust volume up (positive percentage) or down (negative percentage),
34 // capping at 100%. GetVolumePercent() will be accurate after this 35 // capping at 100%. GetVolumePercent() will be accurate after this
35 // blocking call. 36 // blocking call.
36 void AdjustVolumeByPercent(double adjust_by_percent); 37 void AdjustVolumeByPercent(double adjust_by_percent);
37 38
38 // Just returns true if mute, false if not or an error occurred. 39 // Just returns true if mute, false if not or an error occurred.
39 // Blocking call. 40 // Blocking call.
40 bool IsMute(); 41 bool IsMute();
41 42
42 // Mutes all audio. Non-blocking call. 43 // Mutes all audio. Non-blocking call.
43 void SetMute(bool do_mute); 44 void SetMute(bool do_mute);
44 45
45 private: 46 private:
46 // Defines the delete on exit Singleton traits we like. Best to have this 47 // Defines the delete on exit Singleton traits we like. Best to have this
47 // and constructor/destructor private as recommended for Singletons. 48 // and constructor/destructor private as recommended for Singletons.
48 friend struct DefaultSingletonTraits<AudioHandler>; 49 friend struct DefaultSingletonTraits<AudioHandler>;
49 50
51 // Connect to the current using_mixer_.
52 bool TryToConnect(bool async);
53
50 void OnMixerInitialized(bool success); 54 void OnMixerInitialized(bool success);
51 55
52 AudioHandler(); 56 AudioHandler();
53 virtual ~AudioHandler(); 57 virtual ~AudioHandler();
54 bool VerifyMixerConnection(); 58 bool VerifyMixerConnection();
55 59
56 // Conversion between our internal scaling (0-100%) and decibels. 60 // Conversion between our internal scaling (0-100%) and decibels.
57 static double VolumeDbToPercent(double volume_db); 61 double VolumeDbToPercent(double volume_db) const;
58 static double PercentToVolumeDb(double volume_percent); 62 double PercentToVolumeDb(double volume_percent) const;
59 63
60 scoped_ptr<PulseAudioMixer> mixer_; 64 scoped_ptr<AudioMixerBase> mixer_;
65
61 bool connected_; 66 bool connected_;
62 int reconnect_tries_; 67 int reconnect_tries_;
63 68
69 // The min and max volume in decibels, limited to the maximum range of the
70 // audio system being used.
71 double max_volume_db_;
72 double min_volume_db_;
73
74 // Which mixer is being used, PulseAudio or ALSA
75 int using_mixer_;
Daniel Erat 2010/12/20 22:01:12 use an enum instead, e.g. MixerType with MIXER_TYP
davejcool 2010/12/21 02:00:21 Funny, I went back and forth on that one... but it
76
64 DISALLOW_COPY_AND_ASSIGN(AudioHandler); 77 DISALLOW_COPY_AND_ASSIGN(AudioHandler);
65 }; 78 };
66 79
67 } // namespace chromeos 80 } // namespace chromeos
68 81
82 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioHandler);
83
69 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ 84 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_
70 85
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/audio_handler.cc » ('j') | chrome/browser/chromeos/audio_handler.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698