Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_SYSTEM_H_ | 5 #ifndef MEDIA_AUDIO_AUDIO_SYSTEM_H_ |
| 6 #define MEDIA_AUDIO_AUDIO_SYSTEM_H_ | 6 #define MEDIA_AUDIO_AUDIO_SYSTEM_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "media/audio/audio_device_description.h" | |
| 9 #include "media/base/audio_parameters.h" | 10 #include "media/base/audio_parameters.h" |
| 10 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 class SingleThreadTaskRunner; | 14 class SingleThreadTaskRunner; |
| 14 } | 15 } |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 class AudioManager; | 18 class AudioManager; |
| 18 | 19 |
| 19 // Work in progress: Provides asynchronous interface to AudioManager. All the | 20 // Work in progress: Provides asynchronous interface to AudioManager. All the |
| 20 // AudioManager clients will be switched to it, in preparation for moving | 21 // AudioManager clients will be switched to it, in preparation for moving |
| 21 // to Mojo audio service. | 22 // to Mojo audio service. |
| 22 class MEDIA_EXPORT AudioSystem { | 23 class MEDIA_EXPORT AudioSystem { |
| 23 public: | 24 public: |
| 24 // Replies are asynchronously sent from audio system thread to the thread the | 25 // Replies are asynchronously sent from audio system thread to the thread the |
| 25 // call is issued on. Attention! Since audio system thread may outlive all the | 26 // call is issued on. Attention! Since audio system thread may outlive all the |
| 26 // others, callbacks must always be bound to weak pointers! | 27 // others, callbacks must always be bound to weak pointers! |
| 27 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; | 28 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; |
| 28 using OnBoolCallback = base::Callback<void(bool)>; | 29 using OnBoolCallback = base::Callback<void(bool)>; |
| 30 using OnDeviceDescriptionsCallback = | |
| 31 base::Callback<void(std::unique_ptr<AudioDeviceDescriptions>)>; | |
|
Max Morin
2017/03/21 10:44:00
Why is unique_ptr needed?
| |
| 29 | 32 |
| 30 static AudioSystem* Get(); | 33 static AudioSystem* Get(); |
| 31 | 34 |
| 32 virtual ~AudioSystem(); | 35 virtual ~AudioSystem(); |
| 33 | 36 |
| 34 // Callback may receive invalid parameters, it means the specified device is | 37 // Callback may receive invalid parameters, it means the specified device is |
| 35 // not found. This is best-effort: valid parameters do not guarantee existance | 38 // not found. This is best-effort: valid parameters do not guarantee existance |
| 36 // of the device. | 39 // of the device. |
| 37 // TODO(olka,tommi): fix all AudioManager implementations to return invalid | 40 // TODO(olka,tommi): fix all AudioManager implementations to return invalid |
| 38 // parameters if the device is not found. | 41 // parameters if the device is not found. |
| 39 virtual void GetInputStreamParameters( | 42 virtual void GetInputStreamParameters( |
| 40 const std::string& device_id, | 43 const std::string& device_id, |
| 41 OnAudioParamsCallback on_params_cb) const = 0; | 44 OnAudioParamsCallback on_params_cb) const = 0; |
| 42 | 45 |
| 43 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true, | 46 // If media::AudioDeviceDescription::IsDefaultDevice(device_id) is true, |
| 44 // callback will receive the parameters of the default output device. | 47 // callback will receive the parameters of the default output device. |
| 45 // Callback may receive invalid parameters, it means the specified device is | 48 // Callback may receive invalid parameters, it means the specified device is |
| 46 // not found. This is best-effort: valid parameters do not guarantee existance | 49 // not found. This is best-effort: valid parameters do not guarantee existance |
| 47 // of the device. | 50 // of the device. |
| 48 // TODO(olka,tommi): fix all AudioManager implementations to return invalid | 51 // TODO(olka,tommi): fix all AudioManager implementations to return invalid |
| 49 // parameters if the device is not found. | 52 // parameters if the device is not found. |
| 50 virtual void GetOutputStreamParameters( | 53 virtual void GetOutputStreamParameters( |
| 51 const std::string& device_id, | 54 const std::string& device_id, |
| 52 OnAudioParamsCallback on_params_cb) const = 0; | 55 OnAudioParamsCallback on_params_cb) const = 0; |
| 53 | 56 |
| 54 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; | 57 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; |
| 55 | 58 |
| 59 // Replies with device descriptions of input audio devices if |for_input| is | |
| 60 // true, and of output audio devices otherwise. | |
| 61 virtual void GetDeviceDescriptions( | |
| 62 OnDeviceDescriptionsCallback on_descriptions_cp, | |
| 63 bool for_input) = 0; | |
| 64 | |
| 56 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; | 65 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; |
| 57 | 66 |
| 58 // Must not be used for anything but stream creation. | 67 // Must not be used for anything but stream creation. |
| 59 virtual AudioManager* GetAudioManager() const = 0; | 68 virtual AudioManager* GetAudioManager() const = 0; |
| 60 | 69 |
| 61 protected: | 70 protected: |
| 62 // Sets the global AudioSystem pointer to the specified non-null value. | 71 // Sets the global AudioSystem pointer to the specified non-null value. |
| 63 static void SetInstance(AudioSystem* audio_system); | 72 static void SetInstance(AudioSystem* audio_system); |
| 64 | 73 |
| 65 // Sets the global AudioSystem pointer to null if it equals the specified one. | 74 // Sets the global AudioSystem pointer to null if it equals the specified one. |
| 66 static void ClearInstance(const AudioSystem* audio_system); | 75 static void ClearInstance(const AudioSystem* audio_system); |
| 67 }; | 76 }; |
| 68 | 77 |
| 69 } // namespace media | 78 } // namespace media |
| 70 | 79 |
| 71 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ | 80 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ |
| OLD | NEW |