Chromium Code Reviews| 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 // Used to override the defualt implementation. After this is called, all | |
|
DaleCurtis
2015/04/23 16:18:25
default.
Add some more details about why this is
slan
2015/04/23 18:11:33
Done.
| |
| 34 // static AudioManager::Create* methods will return an instance of | |
| 35 // AudioManager provided by |factory|. This method takes ownership of | |
| 36 // |factory|, which must not be NULL. | |
| 37 static void SetFactory(AudioManagerFactory* factory); | |
| 31 | 38 |
| 32 // Construct the audio manager; only one instance is allowed. The manager | 39 // Construct the audio manager; only one instance is allowed. The manager |
| 33 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as | 40 // will forward CreateAudioLog() calls to the provided AudioLogFactory; as |
| 34 // such |audio_log_factory| must outlive the AudioManager. | 41 // such |audio_log_factory| must outlive the AudioManager. |
| 35 static AudioManager* Create(AudioLogFactory* audio_log_factory); | 42 static AudioManager* Create(AudioLogFactory* audio_log_factory); |
| 36 | 43 |
| 37 // Similar to Create() except also schedules a monitor on the given task | 44 // 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 | 45 // 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. | 46 // a hang is detected, the process will be crashed. |
| 40 static AudioManager* CreateWithHangTimer( | 47 static AudioManager* CreateWithHangTimer( |
| 41 AudioLogFactory* audio_log_factory, | 48 AudioLogFactory* audio_log_factory, |
| 42 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); | 49 const scoped_refptr<base::SingleThreadTaskRunner>& monitor_task_runner); |
| 43 | 50 |
| 44 // Similar to Create() except uses a FakeAudioLogFactory for testing. | 51 // Similar to Create() except uses a FakeAudioLogFactory for testing. |
| 45 static AudioManager* CreateForTesting(); | 52 static AudioManager* CreateForTesting(); |
| 46 | 53 |
| 54 // Should only be used for testing. Resets a previously-set | |
| 55 // AudioManagerFactory. The instance of AudioManager is not affected. | |
| 56 static void ResetFactory(); | |
|
DaleCurtis
2015/04/23 16:18:25
Name it ResetFactoryForTesting, so presubmit catch
slan
2015/04/23 18:11:33
Done.
| |
| 57 | |
| 47 // Returns the pointer to the last created instance, or NULL if not yet | 58 // 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, | 59 // created. This is a utility method for the code outside of media directory, |
| 49 // like src/chrome. | 60 // like src/chrome. |
| 50 static AudioManager* Get(); | 61 static AudioManager* Get(); |
| 51 | 62 |
| 52 // Returns true if the OS reports existence of audio devices. This does not | 63 // 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. | 64 // guarantee that the existing devices support all formats and sample rates. |
| 54 virtual bool HasAudioOutputDevices() = 0; | 65 virtual bool HasAudioOutputDevices() = 0; |
| 55 | 66 |
| 56 // Returns true if the OS reports existence of audio recording devices. This | 67 // 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. | 134 // |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|, | 135 // |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 | 136 // with 0 suggesting that the implementation use a default value for that |
| 126 // platform. | 137 // platform. |
| 127 // Returns NULL if the combination of the parameters is not supported, or if | 138 // Returns NULL if the combination of the parameters is not supported, or if |
| 128 // we have reached some other platform specific limit. | 139 // we have reached some other platform specific limit. |
| 129 // | 140 // |
| 130 // Do not free the returned AudioInputStream. It is owned by AudioManager. | 141 // 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. | 142 // When you are done with it, call |Stop()| and |Close()| to release it. |
| 132 virtual AudioInputStream* MakeAudioInputStream( | 143 virtual AudioInputStream* MakeAudioInputStream( |
| 133 const AudioParameters& params, const std::string& device_id) = 0; | 144 const AudioParameters& params, |
| 145 const std::string& device_id) = 0; | |
| 134 | 146 |
| 135 // Returns the task runner used for audio IO. | 147 // Returns the task runner used for audio IO. |
| 136 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; | 148 virtual scoped_refptr<base::SingleThreadTaskRunner> GetTaskRunner() = 0; |
| 137 | 149 |
| 138 // Heavyweight tasks should use GetWorkerTaskRunner() instead of | 150 // Heavyweight tasks should use GetWorkerTaskRunner() instead of |
| 139 // GetTaskRunner(). On most platforms they are the same, but some share the | 151 // GetTaskRunner(). On most platforms they are the same, but some share the |
| 140 // UI loop with the audio IO loop. | 152 // UI loop with the audio IO loop. |
| 141 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; | 153 virtual scoped_refptr<base::SingleThreadTaskRunner> GetWorkerTaskRunner() = 0; |
| 142 | 154 |
| 143 // Allows clients to listen for device state changes; e.g. preferred sample | 155 // 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: | 204 protected: |
| 193 AudioManager(); | 205 AudioManager(); |
| 194 | 206 |
| 195 private: | 207 private: |
| 196 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 208 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
| 197 }; | 209 }; |
| 198 | 210 |
| 199 } // namespace media | 211 } // namespace media |
| 200 | 212 |
| 201 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 213 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| OLD | NEW |