| 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 "base/memory/weak_ptr.h" |
| 9 #include "media/audio/audio_device_description.h" | 10 #include "media/audio/audio_device_description.h" |
| 10 #include "media/base/audio_parameters.h" | 11 #include "media/base/audio_parameters.h" |
| 11 #include "media/base/media_export.h" | 12 #include "media/base/media_export.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 class SingleThreadTaskRunner; | 15 class SingleThreadTaskRunner; |
| 15 } | 16 } |
| 16 | 17 |
| 17 namespace media { | 18 namespace media { |
| 18 class AudioManager; | 19 class AudioManager; |
| 19 | 20 |
| 20 // Work in progress: Provides asynchronous interface to AudioManager. All the | 21 // Work in progress: Provides asynchronous interface to AudioManager. All the |
| 21 // AudioManager clients will be switched to it, in preparation for moving | 22 // AudioManager clients will be switched to it, in preparation for moving |
| 22 // to Mojo audio service. | 23 // to Mojo audio service. |
| 23 class MEDIA_EXPORT AudioSystem { | 24 class MEDIA_EXPORT AudioSystem { |
| 24 public: | 25 public: |
| 25 // Replies are asynchronously sent from audio system thread to the thread the | 26 // Replies are asynchronously sent from audio system thread to the thread the |
| 26 // call is issued on. Attention! Since audio system thread may outlive all the | 27 // call is issued on. Attention! Since audio system thread may outlive all the |
| 27 // others, callbacks must always be bound to weak pointers! | 28 // others, callbacks must always be bound to weak pointers! |
| 28 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; | 29 using OnAudioParamsCallback = base::Callback<void(const AudioParameters&)>; |
| 29 using OnBoolCallback = base::Callback<void(bool)>; | 30 using OnBoolCallback = base::Callback<void(bool)>; |
| 30 using OnDeviceDescriptionsCallback = | 31 using OnDeviceDescriptionsCallback = |
| 31 base::Callback<void(AudioDeviceDescriptions)>; | 32 base::Callback<void(AudioDeviceDescriptions)>; |
| 33 using OnDeviceIdCallback = base::Callback<void(const std::string&)>; |
| 34 using OnInputDeviceInfoCallback = base::Callback< |
| 35 void(const AudioParameters&, const AudioParameters&, const std::string&)>; |
| 32 | 36 |
| 33 static AudioSystem* Get(); | 37 static AudioSystem* Get(); |
| 34 | 38 |
| 35 virtual ~AudioSystem(); | 39 virtual ~AudioSystem(); |
| 36 | 40 |
| 37 // Callback may receive invalid parameters, it means the specified device is | 41 // Callback may receive invalid parameters, it means the specified device is |
| 38 // not found. This is best-effort: valid parameters do not guarantee existance | 42 // not found. This is best-effort: valid parameters do not guarantee existance |
| 39 // of the device. | 43 // of the device. |
| 40 // TODO(olka,tommi): fix all AudioManager implementations to return invalid | 44 // TODO(olka,tommi): fix all AudioManager implementations to return invalid |
| 41 // parameters if the device is not found. | 45 // parameters if the device is not found. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 52 // parameters if the device is not found. | 56 // parameters if the device is not found. |
| 53 virtual void GetOutputStreamParameters( | 57 virtual void GetOutputStreamParameters( |
| 54 const std::string& device_id, | 58 const std::string& device_id, |
| 55 OnAudioParamsCallback on_params_cb) const = 0; | 59 OnAudioParamsCallback on_params_cb) const = 0; |
| 56 | 60 |
| 57 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; | 61 virtual void HasInputDevices(OnBoolCallback on_has_devices_cb) const = 0; |
| 58 | 62 |
| 59 // Replies with device descriptions of input audio devices if |for_input| is | 63 // Replies with device descriptions of input audio devices if |for_input| is |
| 60 // true, and of output audio devices otherwise. | 64 // true, and of output audio devices otherwise. |
| 61 virtual void GetDeviceDescriptions( | 65 virtual void GetDeviceDescriptions( |
| 62 OnDeviceDescriptionsCallback on_descriptions_cp, | 66 OnDeviceDescriptionsCallback on_descriptions_cb, |
| 63 bool for_input) = 0; | 67 bool for_input) = 0; |
| 64 | 68 |
| 69 // Replies with an empty string if there is no associated output device found. |
| 70 virtual void GetAssociatedOutputDeviceID( |
| 71 const std::string& input_device_id, |
| 72 OnDeviceIdCallback on_device_id_cb) = 0; |
| 73 |
| 74 // Replies with audio parameters for the specified input device and audio |
| 75 // parameters and device ID of the associated output device, if any (otherwise |
| 76 // it's AudioParameters() and an empty string). |
| 77 virtual void GetInputDeviceInfo( |
| 78 const std::string& input_device_id, |
| 79 OnInputDeviceInfoCallback on_input_device_info_cb) = 0; |
| 80 |
| 65 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; | 81 virtual base::SingleThreadTaskRunner* GetTaskRunner() const = 0; |
| 66 | 82 |
| 67 // Must not be used for anything but stream creation. | 83 // Must not be used for anything but stream creation. |
| 68 virtual AudioManager* GetAudioManager() const = 0; | 84 virtual AudioManager* GetAudioManager() const = 0; |
| 69 | 85 |
| 70 protected: | 86 protected: |
| 71 // Sets the global AudioSystem pointer to the specified non-null value. | 87 // Sets the global AudioSystem pointer to the specified non-null value. |
| 72 static void SetInstance(AudioSystem* audio_system); | 88 static void SetInstance(AudioSystem* audio_system); |
| 73 | 89 |
| 74 // Sets the global AudioSystem pointer to null if it equals the specified one. | 90 // Sets the global AudioSystem pointer to null if it equals the specified one. |
| 75 static void ClearInstance(const AudioSystem* audio_system); | 91 static void ClearInstance(const AudioSystem* audio_system); |
| 76 }; | 92 }; |
| 77 | 93 |
| 78 } // namespace media | 94 } // namespace media |
| 79 | 95 |
| 80 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ | 96 #endif // MEDIA_AUDIO_AUDIO_SYSTEM_H_ |
| OLD | NEW |