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/macros.h" | 10 #include "base/macros.h" |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
42 // AudioManager. After this is called, all static AudioManager::Create* | 42 // AudioManager. After this is called, all static AudioManager::Create* |
43 // methods will return an instance of AudioManager provided by |factory|. This | 43 // methods will return an instance of AudioManager provided by |factory|. This |
44 // call may be made at most once per process, and before any calls to static | 44 // call may be made at most once per process, and before any calls to static |
45 // AudioManager::Create* methods. This method takes ownership of |factory|, | 45 // AudioManager::Create* methods. This method takes ownership of |factory|, |
46 // which must not be NULL. | 46 // which must not be NULL. |
47 static void SetFactory(AudioManagerFactory* factory); | 47 static void SetFactory(AudioManagerFactory* factory); |
48 | 48 |
49 // Construct the audio manager; only one instance is allowed. The manager | 49 // Construct the audio manager; only one instance is allowed. The manager |
50 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as | 50 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as |
51 // such |audio_log_factory| must outlive the AudioManager. | 51 // such |audio_log_factory| must outlive the AudioManager. |
52 // DO NOT DELETE the returned instance. Use AudioManager::Destroy. | |
52 static AudioManager* Create(AudioLogFactory* audio_log_factory); | 53 static AudioManager* Create(AudioLogFactory* audio_log_factory); |
DaleCurtis
2016/03/18 00:19:10
Hmm, I thought you were changing this to Create(..
alokp
2016/03/18 00:35:19
I wanted to keep task_runner an internal detail of
DaleCurtis
2016/03/18 00:40:41
No, I was expecting that you would require the tas
alokp
2016/03/18 06:46:52
I was under the impression that those tests were i
| |
53 | 54 |
54 // Similar to Create() except also schedules a monitor on the given task | 55 // Similar to Create() except also schedules a monitor on the given task |
55 // runner to ensure the audio thread is not stuck for more than 60 seconds; if | 56 // runner to ensure the audio thread is not stuck for more than 60 seconds; if |
56 // a hang is detected, the process will be crashed. See EnableHangMonitor(). | 57 // a hang is detected, the process will be crashed. See EnableHangMonitor(). |
58 // DO NOT DELETE the returned instance. Use AudioManager::Destroy. | |
57 static AudioManager* CreateWithHangTimer( | 59 static AudioManager* CreateWithHangTimer( |
58 AudioLogFactory* audio_log_factory, | 60 AudioLogFactory* audio_log_factory, |
59 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); | 61 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); |
60 | 62 |
61 // Similar to Create() except uses a FakeAudioLogFactory for testing. | 63 // Similar to Create() except uses a FakeAudioLogFactory for testing. |
64 // DO NOT DELETE the returned instance. Use AudioManager::Destroy. | |
62 static AudioManager* CreateForTesting(); | 65 static AudioManager* CreateForTesting(); |
63 | 66 |
67 // Helper function to ensure that AudioManager is properly shutdown | |
68 // and destroyed on the audio thread. | |
69 static void Destroy(AudioManager* instance); | |
70 | |
64 // Enables non-crash dumps when audio thread hangs are detected. | 71 // Enables non-crash dumps when audio thread hangs are detected. |
65 // TODO(dalecurtis): There are no callers to this function at present. A list | 72 // TODO(dalecurtis): There are no callers to this function at present. A list |
66 // of bad drivers has been given to Microsoft. This should be re-enabled in | 73 // of bad drivers has been given to Microsoft. This should be re-enabled in |
67 // the future if Microsoft is able to triage third party drivers. | 74 // the future if Microsoft is able to triage third party drivers. |
68 // See http://crbug.com/422522 | 75 // See http://crbug.com/422522 |
69 static void EnableCrashKeyLoggingForAudioThreadHangs(); | 76 static void EnableCrashKeyLoggingForAudioThreadHangs(); |
70 | 77 |
71 #if defined(OS_LINUX) | 78 #if defined(OS_LINUX) |
72 // Sets the name of the audio source as seen by external apps. Only actually | 79 // Sets the name of the audio source as seen by external apps. Only actually |
73 // used with PulseAudio as of this writing. | 80 // used with PulseAudio as of this writing. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 // Returns NULL if the combination of the parameters is not supported, or if | 178 // Returns NULL if the combination of the parameters is not supported, or if |
172 // we have reached some other platform specific limit. | 179 // we have reached some other platform specific limit. |
173 // | 180 // |
174 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 181 // Do not free the returned AudioInputStream. It is owned by AudioManager. |
175 // When you are done with it, call |Stop()| and |Close()| to release it. | 182 // When you are done with it, call |Stop()| and |Close()| to release it. |
176 virtual AudioInputStream* MakeAudioInputStream( | 183 virtual AudioInputStream* MakeAudioInputStream( |
177 const AudioParameters& params, | 184 const AudioParameters& params, |
178 const std::string& device_id) = 0; | 185 const std::string& device_id) = 0; |
179 | 186 |
180 // Returns the task runner used for audio IO. | 187 // Returns the task runner used for audio IO. |
181 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; | 188 // TODO(alokp): Rename to task_runner(). |
189 scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() const { | |
190 return task_runner_; | |
191 } | |
182 | 192 |
183 // Heavyweight tasks should use GetWorkerTaskRunner() instead of | 193 // Heavyweight tasks should use GetWorkerTaskRunner() instead of |
184 // GetTaskRunner(). On most platforms they are the same, but some share the | 194 // GetTaskRunner(). On most platforms they are the same, but some share the |
185 // UI loop with the audio IO loop. | 195 // UI loop with the audio IO loop. |
186 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; | 196 // TODO(alokp): Rename to worker_task_runner(). |
197 scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() const { | |
198 return worker_task_runner_; | |
199 } | |
187 | 200 |
188 // Allows clients to listen for device state changes; e.g. preferred sample | 201 // Allows clients to listen for device state changes; e.g. preferred sample |
189 // rate or channel layout changes. The typical response to receiving this | 202 // rate or channel layout changes. The typical response to receiving this |
190 // callback is to recreate the stream. | 203 // callback is to recreate the stream. |
191 class AudioDeviceListener { | 204 class AudioDeviceListener { |
192 public: | 205 public: |
193 virtual void OnDeviceChange() = 0; | 206 virtual void OnDeviceChange() = 0; |
194 }; | 207 }; |
195 | 208 |
196 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; | 209 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; |
(...skipping 26 matching lines...) Expand all Loading... | |
223 // GetWorkerTaskRunner()). | 236 // GetWorkerTaskRunner()). |
224 virtual std::string GetAssociatedOutputDeviceID( | 237 virtual std::string GetAssociatedOutputDeviceID( |
225 const std::string& input_device_id) = 0; | 238 const std::string& input_device_id) = 0; |
226 | 239 |
227 // Create a new AudioLog object for tracking the behavior for one or more | 240 // Create a new AudioLog object for tracking the behavior for one or more |
228 // instances of the given component. See AudioLogFactory for more details. | 241 // instances of the given component. See AudioLogFactory for more details. |
229 virtual scoped_ptr<AudioLog> CreateAudioLog( | 242 virtual scoped_ptr<AudioLog> CreateAudioLog( |
230 AudioLogFactory::AudioComponent component) = 0; | 243 AudioLogFactory::AudioComponent component) = 0; |
231 | 244 |
232 protected: | 245 protected: |
233 AudioManager(); | 246 AudioManager( |
247 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, | |
248 const scoped_refptr<base::SingleThreadTaskRunner>& worker_task_runner); | |
234 | 249 |
235 private: | 250 private: |
251 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | |
252 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | |
236 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 253 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
237 }; | 254 }; |
238 | 255 |
239 } // namespace media | 256 } // namespace media |
240 | 257 |
241 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 258 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
OLD | NEW |