OLD | NEW |
---|---|
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/threading/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 AudioMixer; |
17 | 18 |
18 class AudioHandler { | 19 class AudioHandler { |
19 public: | 20 public: |
20 static AudioHandler* GetInstance(); | 21 static AudioHandler* GetInstance(); |
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: |
47 enum MixerType { | |
48 MIXER_TYPE_PULSEAUDIO = 0, | |
49 MIXER_TYPE_ALSA, | |
50 MIXER_TYPE_NONE | |
scherkus (not reviewing)
2011/01/11 00:24:12
nit: add trailing ,
| |
51 }; | |
52 | |
46 // Defines the delete on exit Singleton traits we like. Best to have this | 53 // Defines the delete on exit Singleton traits we like. Best to have this |
47 // and constructor/destructor private as recommended for Singletons. | 54 // and constructor/destructor private as recommended for Singletons. |
48 friend struct DefaultSingletonTraits<AudioHandler>; | 55 friend struct DefaultSingletonTraits<AudioHandler>; |
49 | 56 |
57 // Connect to the current mixer_type_. | |
58 bool TryToConnect(bool async); | |
59 void UseNextMixer(); | |
60 | |
50 void OnMixerInitialized(bool success); | 61 void OnMixerInitialized(bool success); |
51 | 62 |
52 AudioHandler(); | 63 AudioHandler(); |
53 virtual ~AudioHandler(); | 64 virtual ~AudioHandler(); |
54 bool VerifyMixerConnection(); | 65 bool VerifyMixerConnection(); |
55 | 66 |
56 // Conversion between our internal scaling (0-100%) and decibels. | 67 // Conversion between our internal scaling (0-100%) and decibels. |
57 static double VolumeDbToPercent(double volume_db); | 68 double VolumeDbToPercent(double volume_db) const; |
58 static double PercentToVolumeDb(double volume_percent); | 69 double PercentToVolumeDb(double volume_percent) const; |
59 | 70 |
60 scoped_ptr<PulseAudioMixer> mixer_; | 71 scoped_ptr<AudioMixer> mixer_; |
72 | |
61 bool connected_; | 73 bool connected_; |
62 int reconnect_tries_; | 74 int reconnect_tries_; |
63 | 75 |
76 // The min and max volume in decibels, limited to the maximum range of the | |
77 // audio system being used. | |
78 double max_volume_db_; | |
79 double min_volume_db_; | |
80 | |
81 // Which mixer is being used, PulseAudio or ALSA | |
scherkus (not reviewing)
2011/01/11 00:24:12
nit: period for comments
| |
82 MixerType mixer_type_; | |
83 | |
64 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 84 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
65 }; | 85 }; |
66 | 86 |
67 } // namespace chromeos | 87 } // namespace chromeos |
68 | 88 |
89 DISABLE_RUNNABLE_METHOD_REFCOUNT(chromeos::AudioHandler); | |
90 | |
69 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ | 91 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_HANDLER_H_ |
70 | 92 |
OLD | NEW |