OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_AUDIO_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 6 #define CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/observer_list.h" | |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
12 | 13 |
13 template <typename T> struct DefaultSingletonTraits; | 14 template <typename T> struct DefaultSingletonTraits; |
14 | 15 |
15 namespace chromeos { | 16 namespace chromeos { |
16 | 17 |
17 class AudioMixer; | 18 class AudioMixer; |
18 | 19 |
19 class AudioHandler { | 20 class AudioHandler { |
20 public: | 21 public: |
22 class VolumeObserver { | |
23 public: | |
24 virtual void OnVolumeChanged() = 0; | |
25 protected: | |
26 // VolumeObserver registers/de-registers itself with AudioHandler in the | |
27 // ctor/dtor. | |
28 VolumeObserver(); | |
29 virtual ~VolumeObserver(); | |
30 }; | |
31 | |
21 static void Initialize(); | 32 static void Initialize(); |
22 static void Shutdown(); | 33 static void Shutdown(); |
23 // GetInstance returns NULL if not initialized or if already shutdown. | 34 // GetInstance returns NULL if not initialized or if already shutdown. |
Daniel Erat
2012/01/27 18:03:57
not your fault, but mind updating this comment to
achuithb
2012/01/31 00:58:43
Done.
| |
24 static AudioHandler* GetInstance(); | 35 static AudioHandler* GetInstance(); |
25 | 36 |
26 // Is the mixer initialized? | 37 // GetInstanceIfInitialized returns NULL if GetInstance returns NULL or if |
38 // the mixer has not finished initializing. | |
27 // TODO(derat): All of the volume-percent methods will produce "interesting" | 39 // TODO(derat): All of the volume-percent methods will produce "interesting" |
28 // results before the mixer is initialized, since the driver's volume range | 40 // results before the mixer is initialized, since the driver's volume range |
29 // isn't known at that point. This could be avoided if AudioMixer objects | 41 // isn't known at that point. This could be avoided if AudioMixer objects |
30 // instead took percentages and did their own conversions to decibels. | 42 // instead took percentages and did their own conversions to decibels. |
31 bool IsInitialized(); | 43 static AudioHandler* GetInstanceIfInitialized(); |
32 | 44 |
33 // Gets volume level in our internal 0-100% range, 0 being pure silence. | 45 // Gets volume level in our internal 0-100% range, 0 being pure silence. |
34 double GetVolumePercent(); | 46 double GetVolumePercent(); |
35 | 47 |
36 // Sets volume level from 0-100%. | 48 // Sets volume level from 0-100%. |
37 void SetVolumePercent(double volume_percent); | 49 void SetVolumePercent(double volume_percent); |
38 | 50 |
39 // Adjusts volume up (positive percentage) or down (negative percentage). | 51 // Adjusts volume up (positive percentage) or down (negative percentage). |
40 void AdjustVolumeByPercent(double adjust_by_percent); | 52 void AdjustVolumeByPercent(double adjust_by_percent); |
41 | 53 |
42 // Is the volume currently muted? | 54 // Is the volume currently muted? |
43 bool IsMuted(); | 55 bool IsMuted(); |
44 | 56 |
45 // Mutes or unmutes all audio. | 57 // Mutes or unmutes all audio. |
46 void SetMuted(bool do_mute); | 58 void SetMuted(bool do_mute); |
47 | 59 |
48 private: | 60 private: |
49 // Defines the delete on exit Singleton traits we like. Best to have this | 61 // Defines the delete on exit Singleton traits we like. Best to have this |
50 // and constructor/destructor private as recommended for Singletons. | 62 // and constructor/destructor private as recommended for Singletons. |
51 friend struct DefaultSingletonTraits<AudioHandler>; | 63 friend struct DefaultSingletonTraits<AudioHandler>; |
64 friend class VolumeObserver; | |
52 | 65 |
53 AudioHandler(); | 66 AudioHandler(); |
54 virtual ~AudioHandler(); | 67 virtual ~AudioHandler(); |
55 | 68 |
69 bool IsMixerInitialized(); | |
70 | |
56 // Conversion between our internal scaling (0-100%) and decibels. | 71 // Conversion between our internal scaling (0-100%) and decibels. |
57 double VolumeDbToPercent(double volume_db) const; | 72 double VolumeDbToPercent(double volume_db) const; |
58 double PercentToVolumeDb(double volume_percent) const; | 73 double PercentToVolumeDb(double volume_percent) const; |
59 | 74 |
75 void AddVolumeObserver(VolumeObserver* observer); | |
76 void RemoveVolumeObserver(VolumeObserver* observer); | |
77 | |
60 scoped_ptr<AudioMixer> mixer_; | 78 scoped_ptr<AudioMixer> mixer_; |
61 | 79 |
80 ObserverList<VolumeObserver> volume_observers_; | |
81 | |
62 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 82 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
63 }; | 83 }; |
64 | 84 |
65 } // namespace chromeos | 85 } // namespace chromeos |
66 | 86 |
67 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 87 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
OLD | NEW |