| 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 <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 | 88 |
| 89 // Returns the app name or an empty string if it is not set. | 89 // Returns the app name or an empty string if it is not set. |
| 90 static const std::string& GetGlobalAppName(); | 90 static const std::string& GetGlobalAppName(); |
| 91 #endif | 91 #endif |
| 92 | 92 |
| 93 // Returns the pointer to the last created instance, or NULL if not yet | 93 // Returns the pointer to the last created instance, or NULL if not yet |
| 94 // created. This is a utility method for the code outside of media directory, | 94 // created. This is a utility method for the code outside of media directory, |
| 95 // like src/chrome. | 95 // like src/chrome. |
| 96 static AudioManager* Get(); | 96 static AudioManager* Get(); |
| 97 | 97 |
| 98 // Returns true if the OS reports existence of audio devices. This does not | |
| 99 // guarantee that the existing devices support all formats and sample rates. | |
| 100 virtual bool HasAudioOutputDevices() = 0; | |
| 101 | |
| 102 // Returns true if the OS reports existence of audio recording devices. This | |
| 103 // does not guarantee that the existing devices support all formats and | |
| 104 // sample rates. | |
| 105 virtual bool HasAudioInputDevices() = 0; | |
| 106 | |
| 107 // Returns a human readable string for the model/make of the active audio | |
| 108 // input device for this computer. | |
| 109 virtual base::string16 GetAudioInputDeviceModel() = 0; | |
| 110 | |
| 111 // Opens the platform default audio input settings UI. | |
| 112 // Note: This could invoke an external application/preferences pane, so | |
| 113 // ideally must not be called from the UI thread or other time sensitive | |
| 114 // threads to avoid blocking the rest of the application. | |
| 115 virtual void ShowAudioInputSettings() = 0; | |
| 116 | |
| 117 // Appends a list of available input devices to |device_descriptions|, | |
| 118 // which must initially be empty. It is not guaranteed that all the | |
| 119 // devices in the list support all formats and sample rates for | |
| 120 // recording. | |
| 121 // | |
| 122 // Not threadsafe; in production this should only be called from the | |
| 123 // Audio worker thread (see GetTaskRunner()). | |
| 124 virtual void GetAudioInputDeviceDescriptions( | |
| 125 AudioDeviceDescriptions* device_descriptions) = 0; | |
| 126 | |
| 127 // Appends a list of available output devices to |device_descriptions|, | |
| 128 // which must initially be empty. | |
| 129 // | |
| 130 // Not threadsafe; in production this should only be called from the | |
| 131 // Audio worker thread (see GetTaskRunner()). | |
| 132 virtual void GetAudioOutputDeviceDescriptions( | |
| 133 AudioDeviceDescriptions* device_descriptions) = 0; | |
| 134 | |
| 135 // Log callback used for sending log messages from a stream to the object | 98 // Log callback used for sending log messages from a stream to the object |
| 136 // that manages the stream. | 99 // that manages the stream. |
| 137 using LogCallback = base::Callback<void(const std::string&)>; | 100 using LogCallback = base::Callback<void(const std::string&)>; |
| 138 | 101 |
| 139 // Factory for all the supported stream formats. |params| defines parameters | 102 // Factory for all the supported stream formats. |params| defines parameters |
| 140 // of the audio stream to be created. | 103 // of the audio stream to be created. |
| 141 // | 104 // |
| 142 // |params.sample_per_packet| is the requested buffer allocation which the | 105 // |params.sample_per_packet| is the requested buffer allocation which the |
| 143 // audio source thinks it can usually fill without blocking. Internally two | 106 // audio source thinks it can usually fill without blocking. Internally two |
| 144 // or three buffers are created, one will be locked for playback and one will | 107 // or three buffers are created, one will be locked for playback and one will |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 // callback is to recreate the stream. | 169 // callback is to recreate the stream. |
| 207 class AudioDeviceListener { | 170 class AudioDeviceListener { |
| 208 public: | 171 public: |
| 209 virtual void OnDeviceChange() = 0; | 172 virtual void OnDeviceChange() = 0; |
| 210 }; | 173 }; |
| 211 | 174 |
| 212 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; | 175 virtual void AddOutputDeviceChangeListener(AudioDeviceListener* listener) = 0; |
| 213 virtual void RemoveOutputDeviceChangeListener( | 176 virtual void RemoveOutputDeviceChangeListener( |
| 214 AudioDeviceListener* listener) = 0; | 177 AudioDeviceListener* listener) = 0; |
| 215 | 178 |
| 216 // Returns the default output hardware audio parameters for opening output | |
| 217 // streams. It is a convenience interface to | |
| 218 // AudioManagerBase::GetPreferredOutputStreamParameters and each AudioManager | |
| 219 // does not need their own implementation to this interface. | |
| 220 // TODO(tommi): Remove this method and use GetOutputStreamParameteres instead. | |
| 221 virtual AudioParameters GetDefaultOutputStreamParameters() = 0; | |
| 222 | |
| 223 // Returns the output hardware audio parameters for a specific output device. | |
| 224 virtual AudioParameters GetOutputStreamParameters( | |
| 225 const std::string& device_id) = 0; | |
| 226 | |
| 227 // Returns the input hardware audio parameters of the specific device | |
| 228 // for opening input streams. Each AudioManager needs to implement their own | |
| 229 // version of this interface. | |
| 230 virtual AudioParameters GetInputStreamParameters( | |
| 231 const std::string& device_id) = 0; | |
| 232 | |
| 233 // Returns the device id of an output device that belongs to the same hardware | |
| 234 // as the specified input device. | |
| 235 // If the hardware has only an input device (e.g. a webcam), the return value | |
| 236 // will be empty (which the caller can then interpret to be the default output | |
| 237 // device). Implementations that don't yet support this feature, must return | |
| 238 // an empty string. Must be called on the audio worker thread (see | |
| 239 // GetTaskRunner()). | |
| 240 virtual std::string GetAssociatedOutputDeviceID( | |
| 241 const std::string& input_device_id) = 0; | |
| 242 | |
| 243 // Create a new AudioLog object for tracking the behavior for one or more | 179 // Create a new AudioLog object for tracking the behavior for one or more |
| 244 // instances of the given component. See AudioLogFactory for more details. | 180 // instances of the given component. See AudioLogFactory for more details. |
| 245 virtual std::unique_ptr<AudioLog> CreateAudioLog( | 181 virtual std::unique_ptr<AudioLog> CreateAudioLog( |
| 246 AudioLogFactory::AudioComponent component) = 0; | 182 AudioLogFactory::AudioComponent component) = 0; |
| 247 | 183 |
| 248 // Enable output debug recording. InitializeOutputDebugRecording() must be | 184 // Enable output debug recording. InitializeOutputDebugRecording() must be |
| 249 // called before this function. | 185 // called before this function. |
| 250 // TODO(grunell): Control input debug recording via these functions too. | 186 // TODO(grunell): Control input debug recording via these functions too. |
| 251 virtual void EnableOutputDebugRecording( | 187 virtual void EnableOutputDebugRecording( |
| 252 const base::FilePath& base_file_name) = 0; | 188 const base::FilePath& base_file_name) = 0; |
| 253 | 189 |
| 254 // Disable output debug recording. | 190 // Disable output debug recording. |
| 255 virtual void DisableOutputDebugRecording() = 0; | 191 virtual void DisableOutputDebugRecording() = 0; |
| 256 | 192 |
| 257 // Gets the name of the audio manager (e.g., Windows, Mac, PulseAudio). | 193 // Gets the name of the audio manager (e.g., Windows, Mac, PulseAudio). |
| 258 virtual const char* GetName() = 0; | 194 virtual const char* GetName() = 0; |
| 259 | 195 |
| 260 // Limits the number of streams that can be created for testing purposes. | 196 // Limits the number of streams that can be created for testing purposes. |
| 261 virtual void SetMaxStreamCountForTesting(int max_input, int max_output); | 197 virtual void SetMaxStreamCountForTesting(int max_input, int max_output); |
| 262 | 198 |
| 263 protected: | 199 protected: |
| 264 FRIEND_TEST_ALL_PREFIXES(AudioManagerTest, AudioDebugRecording); | 200 FRIEND_TEST_ALL_PREFIXES(AudioManagerTest, AudioDebugRecording); |
| 201 friend class AudioDeviceInfoAccessorForTests; |
| 265 | 202 |
| 266 AudioManager(scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 203 AudioManager(scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 267 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner); | 204 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner); |
| 268 virtual ~AudioManager(); | 205 virtual ~AudioManager(); |
| 269 | 206 |
| 270 // Initializes output debug recording. Can be called on any thread; will post | 207 // Initializes output debug recording. Can be called on any thread; will post |
| 271 // to the audio thread if not called on it. | 208 // to the audio thread if not called on it. |
| 272 virtual void InitializeOutputDebugRecording( | 209 virtual void InitializeOutputDebugRecording( |
| 273 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) = 0; | 210 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) = 0; |
| 274 | 211 |
| 212 // Returns true if the OS reports existence of audio devices. This does not |
| 213 // guarantee that the existing devices support all formats and sample rates. |
| 214 virtual bool HasAudioOutputDevices() = 0; |
| 215 |
| 216 // Returns true if the OS reports existence of audio recording devices. This |
| 217 // does not guarantee that the existing devices support all formats and |
| 218 // sample rates. |
| 219 virtual bool HasAudioInputDevices() = 0; |
| 220 |
| 221 // Returns a human readable string for the model/make of the active audio |
| 222 // input device for this computer. |
| 223 virtual base::string16 GetAudioInputDeviceModel() = 0; |
| 224 |
| 225 // Opens the platform default audio input settings UI. |
| 226 // Note: This could invoke an external application/preferences pane, so |
| 227 // ideally must not be called from the UI thread or other time sensitive |
| 228 // threads to avoid blocking the rest of the application. |
| 229 virtual void ShowAudioInputSettings() = 0; |
| 230 |
| 231 // Appends a list of available input devices to |device_descriptions|, |
| 232 // which must initially be empty. It is not guaranteed that all the |
| 233 // devices in the list support all formats and sample rates for |
| 234 // recording. |
| 235 // |
| 236 // Not threadsafe; in production this should only be called from the |
| 237 // Audio worker thread (see GetTaskRunner()). |
| 238 virtual void GetAudioInputDeviceDescriptions( |
| 239 AudioDeviceDescriptions* device_descriptions) = 0; |
| 240 |
| 241 // Appends a list of available output devices to |device_descriptions|, |
| 242 // which must initially be empty. |
| 243 // |
| 244 // Not threadsafe; in production this should only be called from the |
| 245 // Audio worker thread (see GetTaskRunner()). |
| 246 virtual void GetAudioOutputDeviceDescriptions( |
| 247 AudioDeviceDescriptions* device_descriptions) = 0; |
| 248 |
| 249 // Returns the default output hardware audio parameters for opening output |
| 250 // streams. It is a convenience interface to |
| 251 // AudioManagerBase::GetPreferredOutputStreamParameters and each AudioManager |
| 252 // does not need their own implementation to this interface. |
| 253 // TODO(tommi): Remove this method and use GetOutputStreamParameteres instead. |
| 254 virtual AudioParameters GetDefaultOutputStreamParameters() = 0; |
| 255 |
| 256 // Returns the output hardware audio parameters for a specific output device. |
| 257 virtual AudioParameters GetOutputStreamParameters( |
| 258 const std::string& device_id) = 0; |
| 259 |
| 260 // Returns the input hardware audio parameters of the specific device |
| 261 // for opening input streams. Each AudioManager needs to implement their own |
| 262 // version of this interface. |
| 263 virtual AudioParameters GetInputStreamParameters( |
| 264 const std::string& device_id) = 0; |
| 265 |
| 266 // Returns the device id of an output device that belongs to the same hardware |
| 267 // as the specified input device. |
| 268 // If the hardware has only an input device (e.g. a webcam), the return value |
| 269 // will be empty (which the caller can then interpret to be the default output |
| 270 // device). Implementations that don't yet support this feature, must return |
| 271 // an empty string. Must be called on the audio worker thread (see |
| 272 // GetTaskRunner()). |
| 273 virtual std::string GetAssociatedOutputDeviceID( |
| 274 const std::string& input_device_id) = 0; |
| 275 |
| 275 private: | 276 private: |
| 276 friend class base::DeleteHelper<AudioManager>; | 277 friend class base::DeleteHelper<AudioManager>; |
| 277 friend class AudioManagerDeleter; | 278 friend class AudioManagerDeleter; |
| 279 friend class AudioSystemImpl; |
| 278 | 280 |
| 279 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 281 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 280 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; | 282 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner_; |
| 281 DISALLOW_COPY_AND_ASSIGN(AudioManager); | 283 DISALLOW_COPY_AND_ASSIGN(AudioManager); |
| 282 }; | 284 }; |
| 283 | 285 |
| 284 } // namespace media | 286 } // namespace media |
| 285 | 287 |
| 286 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ | 288 #endif // MEDIA_AUDIO_AUDIO_MANAGER_H_ |
| OLD | NEW |