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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
Daniel Erat
2012/01/26 17:55:21
add base/observer_list.h
achuithb
2012/01/27 01:48:05
Done.
| |
11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
12 | 12 |
13 template <typename T> struct DefaultSingletonTraits; | 13 template <typename T> struct DefaultSingletonTraits; |
14 | 14 |
15 namespace chromeos { | 15 namespace chromeos { |
16 | 16 |
17 class AudioMixer; | 17 class AudioMixer; |
18 | 18 |
19 class AudioHandler { | 19 class AudioHandler { |
20 public: | 20 public: |
21 class VolumeObserver { | |
22 public: | |
23 VolumeObserver(); | |
xiyuan
2012/01/26 18:07:10
nit: move this into protected as we don't expect p
achuithb
2012/01/27 01:48:05
Done.
| |
24 virtual void OnVolumeChanged() = 0; | |
25 protected: | |
26 virtual ~VolumeObserver(); | |
27 }; | |
28 | |
21 static void Initialize(); | 29 static void Initialize(); |
22 static void Shutdown(); | 30 static void Shutdown(); |
23 // GetInstance returns NULL if not initialized or if already shutdown. | 31 // GetInstance returns NULL if not initialized or if already shutdown. |
24 static AudioHandler* GetInstance(); | 32 static AudioHandler* GetInstance(); |
25 | 33 |
26 // Is the mixer initialized? | 34 // GetInitialized returns NULL if GetInstance returns NULL or if the |
35 // mixer has not finished initializing. | |
27 // TODO(derat): All of the volume-percent methods will produce "interesting" | 36 // TODO(derat): All of the volume-percent methods will produce "interesting" |
28 // results before the mixer is initialized, since the driver's volume range | 37 // 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 | 38 // isn't known at that point. This could be avoided if AudioMixer objects |
30 // instead took percentages and did their own conversions to decibels. | 39 // instead took percentages and did their own conversions to decibels. |
31 bool IsInitialized(); | 40 static AudioHandler* GetInitialized(); |
Daniel Erat
2012/01/26 17:55:21
chrome os code includes too many static methods.
xiyuan
2012/01/26 18:07:10
Yeah, let's reuse the GetInstance() above.
achuithb
2012/01/26 23:19:34
Both SystemKeyEventListener and VolumeMenuBotton h
xiyuan
2012/01/26 23:41:58
Okay. In this case, I am okay to have it here so t
Daniel Erat
2012/01/26 23:53:28
Well, my preference would be for the above TODO to
achuithb
2012/01/27 01:48:05
Done.
| |
32 | 41 |
33 // Gets volume level in our internal 0-100% range, 0 being pure silence. | 42 // Gets volume level in our internal 0-100% range, 0 being pure silence. |
34 double GetVolumePercent(); | 43 double GetVolumePercent(); |
35 | 44 |
36 // Sets volume level from 0-100%. | 45 // Sets volume level from 0-100%. |
37 void SetVolumePercent(double volume_percent); | 46 void SetVolumePercent(double volume_percent); |
38 | 47 |
39 // Adjusts volume up (positive percentage) or down (negative percentage). | 48 // Adjusts volume up (positive percentage) or down (negative percentage). |
40 void AdjustVolumeByPercent(double adjust_by_percent); | 49 void AdjustVolumeByPercent(double adjust_by_percent); |
41 | 50 |
42 // Is the volume currently muted? | 51 // Is the volume currently muted? |
43 bool IsMuted(); | 52 bool IsMuted(); |
44 | 53 |
45 // Mutes or unmutes all audio. | 54 // Mutes or unmutes all audio. |
46 void SetMuted(bool do_mute); | 55 void SetMuted(bool do_mute); |
47 | 56 |
57 // Adds/Removes a VolumeObserver. | |
Daniel Erat
2012/01/26 17:55:21
nit: remove unnecessary comment
| |
58 void AddVolumeObserver(VolumeObserver* observer); | |
59 void RemoveVolumeObserver(VolumeObserver* observer); | |
60 | |
48 private: | 61 private: |
49 // Defines the delete on exit Singleton traits we like. Best to have this | 62 // Defines the delete on exit Singleton traits we like. Best to have this |
50 // and constructor/destructor private as recommended for Singletons. | 63 // and constructor/destructor private as recommended for Singletons. |
51 friend struct DefaultSingletonTraits<AudioHandler>; | 64 friend struct DefaultSingletonTraits<AudioHandler>; |
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 VolumeChanged(); | |
76 | |
60 scoped_ptr<AudioMixer> mixer_; | 77 scoped_ptr<AudioMixer> mixer_; |
61 | 78 |
79 ObserverList<VolumeObserver> volume_observers_; | |
80 | |
62 DISALLOW_COPY_AND_ASSIGN(AudioHandler); | 81 DISALLOW_COPY_AND_ASSIGN(AudioHandler); |
63 }; | 82 }; |
64 | 83 |
65 } // namespace chromeos | 84 } // namespace chromeos |
66 | 85 |
67 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ | 86 #endif // CHROME_BROWSER_CHROMEOS_AUDIO_AUDIO_HANDLER_H_ |
OLD | NEW |