OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 MEDIA_AUDIO_AUDIO_MANAGER_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_MANAGER_H_ |
6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ | 6 #define MEDIA_AUDIO_AUDIO_MANAGER_H_ |
7 | 7 |
| 8 #include <string> |
| 9 |
8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/memory/ref_counted.h" |
9 #include "base/string16.h" | 12 #include "base/string16.h" |
10 #include "base/task.h" | 13 #include "base/task.h" |
11 #include "media/audio/audio_device_name.h" | 14 #include "media/audio/audio_device_name.h" |
12 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
13 | 16 |
14 class AudioInputStream; | 17 class AudioInputStream; |
15 class AudioOutputStream; | 18 class AudioOutputStream; |
16 class MessageLoop; | 19 class MessageLoop; |
17 | 20 |
18 // TODO(sergeyu): In this interface and some other places AudioParameters struct | |
19 // is passed by value. It is better to change it to const reference. | |
20 | |
21 // Manages all audio resources. In particular it owns the AudioOutputStream | 21 // Manages all audio resources. In particular it owns the AudioOutputStream |
22 // objects. Provides some convenience functions that avoid the need to provide | 22 // objects. Provides some convenience functions that avoid the need to provide |
23 // iterators over the existing streams. | 23 // iterators over the existing streams. |
24 class MEDIA_EXPORT AudioManager { | 24 // TODO(tommi): Make the manager non-refcounted when it's safe to do so. |
| 25 // -> Bug 107087. |
| 26 class MEDIA_EXPORT AudioManager |
| 27 : public base::RefCountedThreadSafe<AudioManager> { |
25 public: | 28 public: |
| 29 AudioManager(); |
| 30 |
| 31 #ifndef NDEBUG |
| 32 // Allow base classes in debug builds to override the reference counting |
| 33 // functions. This allows us to protect against regressions and enforce |
| 34 // correct usage. The default implementation just calls the base class. |
| 35 virtual void AddRef() const; |
| 36 virtual void Release() const; |
| 37 #endif |
| 38 |
| 39 // Use to construct the audio manager. |
| 40 // NOTE: There should only be one instance. If you try to create more than |
| 41 // one instance, it will hit a CHECK(). |
| 42 static scoped_refptr<AudioManager> Create(); |
| 43 |
26 // Returns true if the OS reports existence of audio devices. This does not | 44 // Returns true if the OS reports existence of audio devices. This does not |
27 // guarantee that the existing devices support all formats and sample rates. | 45 // guarantee that the existing devices support all formats and sample rates. |
28 virtual bool HasAudioOutputDevices() = 0; | 46 virtual bool HasAudioOutputDevices() = 0; |
29 | 47 |
30 // Returns true if the OS reports existence of audio recording devices. This | 48 // Returns true if the OS reports existence of audio recording devices. This |
31 // does not guarantee that the existing devices support all formats and | 49 // does not guarantee that the existing devices support all formats and |
32 // sample rates. | 50 // sample rates. |
33 virtual bool HasAudioInputDevices() = 0; | 51 virtual bool HasAudioInputDevices() = 0; |
34 | 52 |
35 // Returns a human readable string for the model/make of the active audio | 53 // Returns a human readable string for the model/make of the active audio |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 // Un-muting returns the volume to the previous level. | 117 // Un-muting returns the volume to the previous level. |
100 virtual void MuteAll() = 0; | 118 virtual void MuteAll() = 0; |
101 virtual void UnMuteAll() = 0; | 119 virtual void UnMuteAll() = 0; |
102 | 120 |
103 // Used to determine if something else is currently making use of audio input. | 121 // Used to determine if something else is currently making use of audio input. |
104 virtual bool IsRecordingInProcess() = 0; | 122 virtual bool IsRecordingInProcess() = 0; |
105 | 123 |
106 // Returns message loop used for audio IO. | 124 // Returns message loop used for audio IO. |
107 virtual MessageLoop* GetMessageLoop() = 0; | 125 virtual MessageLoop* GetMessageLoop() = 0; |
108 | 126 |
109 // Get AudioManager singleton. | |
110 // TODO(cpu): Define threading requirements for interacting with AudioManager. | |
111 static AudioManager* GetAudioManager(); | |
112 | |
113 protected: | 127 protected: |
114 virtual ~AudioManager() {} | 128 // Called from Create() to initialize the instance. |
115 | |
116 // Called from GetAudioManager() to initialiaze the instance. | |
117 virtual void Init() = 0; | 129 virtual void Init() = 0; |
118 | 130 |
119 // Called by Destroy() to cleanup the instance before destruction. | 131 friend class base::RefCountedThreadSafe<AudioManager>; |
120 virtual void Cleanup() = 0; | 132 virtual ~AudioManager(); |
121 | |
122 private: | |
123 // Allow unit tests to delete and recreate the singleton. | |
124 friend class AutoAudioManagerCleanup; | |
125 static void Destroy(void*); | |
126 static bool SingletonExists(); | |
127 static void Resurrect(); | |
128 | |
129 // Called by GetAudioManager() to create platform-specific audio manager. | |
130 static AudioManager* CreateAudioManager(); | |
131 }; | 133 }; |
132 | 134 |
133 DISABLE_RUNNABLE_METHOD_REFCOUNT(AudioManager); | 135 DISABLE_RUNNABLE_METHOD_REFCOUNT(AudioManager); |
134 | 136 |
135 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 137 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |