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 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> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "media/audio/audio_device_name.h" | 13 #include "media/audio/audio_device_name.h" |
14 #include "media/audio/audio_logging.h" | 14 #include "media/audio/audio_logging.h" |
15 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 class SingleThreadTaskRunner; | 18 class SingleThreadTaskRunner; |
19 } | 19 } |
20 | 20 |
21 namespace media { | 21 namespace media { |
22 | 22 |
23 class AudioInputStream; | 23 class AudioInputStream; |
| 24 class AudioManagerFactory; |
24 class AudioOutputStream; | 25 class AudioOutputStream; |
25 | 26 |
26 // Manages all audio resources. Provides some convenience functions that avoid | 27 // Manages all audio resources. Provides some convenience functions that avoid |
27 // the need to provide iterators over the existing streams. | 28 // the need to provide iterators over the existing streams. |
28 class MEDIA_EXPORT AudioManager { | 29 class MEDIA_EXPORT AudioManager { |
29 public: | 30 public: |
30 virtual ~AudioManager(); | 31 virtual ~AudioManager(); |
| 32 |
| 33 // This provides an alternative to the statically linked factory method used |
| 34 // to create AudioManager. This is useful for dynamically-linked third |
| 35 // party clients seeking to provide a platform-specific implementation of |
| 36 // AudioManager. After this is called, all static AudioManager::Create* |
| 37 // methods will return an instance of AudioManager provided by |factory|. This |
| 38 // call may be made at most once per process, and before any calls to static |
| 39 // AudioManager::Create* methods. This method takes ownership of |factory|, |
| 40 // which must not be NULL. |
| 41 static void SetFactory(AudioManagerFactory* factory); |
31 | 42 |
32 // Construct the audio manager; only one instance is allowed. The manager | 43 // Construct the audio manager; only one instance is allowed. The manager |
33 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as | 44 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as |
34 // such |audio_log_factory| must outlive the AudioManager. | 45 // such |audio_log_factory| must outlive the AudioManager. |
35 static AudioManager* Create(AudioLogFactory* audio_log_factory); | 46 static AudioManager* Create(AudioLogFactory* audio_log_factory); |
36 | 47 |
37 // Similar to Create() except also schedules a monitor on the given task | 48 // Similar to Create() except also schedules a monitor on the given task |
38 // runner to ensure the audio thread is not stuck for more than 60 seconds; if | 49 // runner to ensure the audio thread is not stuck for more than 60 seconds; if |
39 // a hang is detected, the process will be crashed. | 50 // a hang is detected, the process will be crashed. |
40 static AudioManager* CreateWithHangTimer( | 51 static AudioManager* CreateWithHangTimer( |
41 AudioLogFactory* audio_log_factory, | 52 AudioLogFactory* audio_log_factory, |
42 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); | 53 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); |
43 | 54 |
44 // Similar to Create() except uses a FakeAudioLogFactory for testing. | 55 // Similar to Create() except uses a FakeAudioLogFactory for testing. |
45 static AudioManager* CreateForTesting(); | 56 static AudioManager* CreateForTesting(); |
46 | 57 |
| 58 // Should only be used for testing. Resets a previously-set |
| 59 // AudioManagerFactory. The instance of AudioManager is not affected. |
| 60 static void ResetFactoryForTesting(); |
| 61 |
47 // Returns the pointer to the last created instance, or NULL if not yet | 62 // Returns the pointer to the last created instance, or NULL if not yet |
48 // created. This is a utility method for the code outside of media directory, | 63 // created. This is a utility method for the code outside of media directory, |
49 // like src/chrome. | 64 // like src/chrome. |
50 static AudioManager* Get(); | 65 static AudioManager* Get(); |
51 | 66 |
52 // Returns true if the OS reports existence of audio devices. This does not | 67 // Returns true if the OS reports existence of audio devices. This does not |
53 // guarantee that the existing devices support all formats and sample rates. | 68 // guarantee that the existing devices support all formats and sample rates. |
54 virtual bool HasAudioOutputDevices() = 0; | 69 virtual bool HasAudioOutputDevices() = 0; |
55 | 70 |
56 // Returns true if the OS reports existence of audio recording devices. This | 71 // Returns true if the OS reports existence of audio recording devices. This |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 // |bits_per_sample| can be any value supported by the platform. | 138 // |bits_per_sample| can be any value supported by the platform. |
124 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, | 139 // |samples_per_packet| is in hertz as well and can be 0 to |sample_rate|, |
125 // with 0 suggesting that the implementation use a default value for that | 140 // with 0 suggesting that the implementation use a default value for that |
126 // platform. | 141 // platform. |
127 // Returns NULL if the combination of the parameters is not supported, or if | 142 // Returns NULL if the combination of the parameters is not supported, or if |
128 // we have reached some other platform specific limit. | 143 // we have reached some other platform specific limit. |
129 // | 144 // |
130 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 145 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
131 // When you are done with it, call |Stop()| and |Close()| to release it. | 146 // When you are done with it, call |Stop()| and |Close()| to release it. |
132 virtual AudioInputStream* MakeAudioInputStream( | 147 virtual AudioInputStream* MakeAudioInputStream( |
133 const AudioParameters& params, const std::string& device_id) = 0; | 148 const AudioParameters& params, |
| 149 const std::string& device_id) = 0; |
134 | 150 |
135 // Returns the task runner used for audio IO. | 151 // Returns the task runner used for audio IO. |
136 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; | 152 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; |
137 | 153 |
138 // Heavyweight tasks should use GetWorkerTaskRunner() instead of | 154 // Heavyweight tasks should use GetWorkerTaskRunner() instead of |
139 // GetTaskRunner(). On most platforms they are the same, but some share the | 155 // GetTaskRunner(). On most platforms they are the same, but some share the |
140 // UI loop with the audio IO loop. | 156 // UI loop with the audio IO loop. |
141 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; | 157 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; |
142 | 158 |
143 // Allows clients to listen for device state changes; e.g. preferred sample | 159 // Allows clients to listen for device state changes; e.g. preferred sample |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 protected: | 208 protected: |
193 AudioManager(); | 209 AudioManager(); |
194 | 210 |
195 private: | 211 private: |
196 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 212 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
197 }; | 213 }; |
198 | 214 |
199 } // namespace media | 215 } // namespace media |
200 | 216 |
201 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 217 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |