| 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 #include "media/audio/audio_system_impl.h" | 5 #include "media/audio/audio_system_impl.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/single_thread_task_runner.h" | 8 #include "base/single_thread_task_runner.h" |
| 9 #include "base/task_runner_util.h" | 9 #include "base/task_runner_util.h" |
| 10 #include "media/audio/audio_device_description.h" | 10 #include "media/audio/audio_device_description.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 // static | 90 // static |
| 91 std::unique_ptr<AudioSystem> AudioSystemImpl::Create( | 91 std::unique_ptr<AudioSystem> AudioSystemImpl::Create( |
| 92 AudioManager* audio_manager) { | 92 AudioManager* audio_manager) { |
| 93 return base::WrapUnique(new AudioSystemImpl(audio_manager)); | 93 return base::WrapUnique(new AudioSystemImpl(audio_manager)); |
| 94 } | 94 } |
| 95 | 95 |
| 96 void AudioSystemImpl::GetInputStreamParameters( | 96 void AudioSystemImpl::GetInputStreamParameters( |
| 97 const std::string& device_id, | 97 const std::string& device_id, |
| 98 OnAudioParamsCallback on_params_cb) const { | 98 OnAudioParamsCallback on_params_cb) const { |
| 99 if (GetTaskRunner()->BelongsToCurrentThread()) { | 99 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 100 GetTaskRunner()->PostTask( | 100 GetTaskRunner()->PostTask(FROM_HERE, |
| 101 FROM_HERE, base::Bind(on_params_cb, GetInputParametersOnDeviceThread( | 101 base::BindOnce(std::move(on_params_cb), |
| 102 audio_manager_, device_id))); | 102 GetInputParametersOnDeviceThread( |
| 103 audio_manager_, device_id))); |
| 103 return; | 104 return; |
| 104 } | 105 } |
| 105 base::PostTaskAndReplyWithResult( | 106 base::PostTaskAndReplyWithResult( |
| 106 GetTaskRunner(), FROM_HERE, | 107 GetTaskRunner(), FROM_HERE, |
| 107 base::Bind(&GetInputParametersOnDeviceThread, | 108 base::Bind(&GetInputParametersOnDeviceThread, |
| 108 base::Unretained(audio_manager_), device_id), | 109 base::Unretained(audio_manager_), device_id), |
| 109 std::move(on_params_cb)); | 110 std::move(on_params_cb)); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void AudioSystemImpl::GetOutputStreamParameters( | 113 void AudioSystemImpl::GetOutputStreamParameters( |
| 113 const std::string& device_id, | 114 const std::string& device_id, |
| 114 OnAudioParamsCallback on_params_cb) const { | 115 OnAudioParamsCallback on_params_cb) const { |
| 115 if (GetTaskRunner()->BelongsToCurrentThread()) { | 116 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 116 GetTaskRunner()->PostTask( | 117 GetTaskRunner()->PostTask(FROM_HERE, |
| 117 FROM_HERE, base::Bind(on_params_cb, GetOutputParametersOnDeviceThread( | 118 base::BindOnce(std::move(on_params_cb), |
| 118 audio_manager_, device_id))); | 119 GetOutputParametersOnDeviceThread( |
| 120 audio_manager_, device_id))); |
| 119 return; | 121 return; |
| 120 } | 122 } |
| 121 base::PostTaskAndReplyWithResult( | 123 base::PostTaskAndReplyWithResult( |
| 122 GetTaskRunner(), FROM_HERE, | 124 GetTaskRunner(), FROM_HERE, |
| 123 base::Bind(&GetOutputParametersOnDeviceThread, | 125 base::Bind(&GetOutputParametersOnDeviceThread, |
| 124 base::Unretained(audio_manager_), device_id), | 126 base::Unretained(audio_manager_), device_id), |
| 125 std::move(on_params_cb)); | 127 std::move(on_params_cb)); |
| 126 } | 128 } |
| 127 | 129 |
| 128 void AudioSystemImpl::HasInputDevices(OnBoolCallback on_has_devices_cb) const { | 130 void AudioSystemImpl::HasInputDevices(OnBoolCallback on_has_devices_cb) const { |
| 129 if (GetTaskRunner()->BelongsToCurrentThread()) { | 131 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 130 GetTaskRunner()->PostTask( | 132 GetTaskRunner()->PostTask( |
| 131 FROM_HERE, | 133 FROM_HERE, base::BindOnce(std::move(on_has_devices_cb), |
| 132 base::Bind(on_has_devices_cb, audio_manager_->HasAudioInputDevices())); | 134 audio_manager_->HasAudioInputDevices())); |
| 133 return; | 135 return; |
| 134 } | 136 } |
| 135 base::PostTaskAndReplyWithResult( | 137 base::PostTaskAndReplyWithResult( |
| 136 GetTaskRunner(), FROM_HERE, | 138 GetTaskRunner(), FROM_HERE, |
| 137 base::Bind(&AudioManager::HasAudioInputDevices, | 139 base::Bind(&AudioManager::HasAudioInputDevices, |
| 138 base::Unretained(audio_manager_)), | 140 base::Unretained(audio_manager_)), |
| 139 std::move(on_has_devices_cb)); | 141 std::move(on_has_devices_cb)); |
| 140 } | 142 } |
| 141 | 143 |
| 142 void AudioSystemImpl::HasOutputDevices(OnBoolCallback on_has_devices_cb) const { | 144 void AudioSystemImpl::HasOutputDevices(OnBoolCallback on_has_devices_cb) const { |
| 143 if (GetTaskRunner()->BelongsToCurrentThread()) { | 145 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 144 GetTaskRunner()->PostTask( | 146 GetTaskRunner()->PostTask( |
| 145 FROM_HERE, | 147 FROM_HERE, base::BindOnce(std::move(on_has_devices_cb), |
| 146 base::Bind(on_has_devices_cb, audio_manager_->HasAudioOutputDevices())); | 148 audio_manager_->HasAudioOutputDevices())); |
| 147 return; | 149 return; |
| 148 } | 150 } |
| 149 base::PostTaskAndReplyWithResult( | 151 base::PostTaskAndReplyWithResult( |
| 150 GetTaskRunner(), FROM_HERE, | 152 GetTaskRunner(), FROM_HERE, |
| 151 base::Bind(&AudioManager::HasAudioOutputDevices, | 153 base::Bind(&AudioManager::HasAudioOutputDevices, |
| 152 base::Unretained(audio_manager_)), | 154 base::Unretained(audio_manager_)), |
| 153 std::move(on_has_devices_cb)); | 155 std::move(on_has_devices_cb)); |
| 154 } | 156 } |
| 155 | 157 |
| 156 void AudioSystemImpl::GetDeviceDescriptions( | 158 void AudioSystemImpl::GetDeviceDescriptions( |
| 157 OnDeviceDescriptionsCallback on_descriptions_cb, | 159 OnDeviceDescriptionsCallback on_descriptions_cb, |
| 158 bool for_input) { | 160 bool for_input) { |
| 159 if (GetTaskRunner()->BelongsToCurrentThread()) { | 161 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 160 GetTaskRunner()->PostTask( | 162 GetTaskRunner()->PostTask( |
| 161 FROM_HERE, base::Bind(on_descriptions_cb, | 163 FROM_HERE, |
| 162 base::Passed(GetDeviceDescriptionsOnDeviceThread( | 164 base::BindOnce(std::move(on_descriptions_cb), |
| 163 audio_manager_, for_input)))); | 165 base::Passed(GetDeviceDescriptionsOnDeviceThread( |
| 166 audio_manager_, for_input)))); |
| 164 return; | 167 return; |
| 165 } | 168 } |
| 166 | 169 |
| 167 base::PostTaskAndReplyWithResult( | 170 base::PostTaskAndReplyWithResult( |
| 168 GetTaskRunner(), FROM_HERE, | 171 GetTaskRunner(), FROM_HERE, |
| 169 base::Bind(&GetDeviceDescriptionsOnDeviceThread, | 172 base::Bind(&GetDeviceDescriptionsOnDeviceThread, |
| 170 base::Unretained(audio_manager_), for_input), | 173 base::Unretained(audio_manager_), for_input), |
| 171 std::move(on_descriptions_cb)); | 174 std::move(on_descriptions_cb)); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void AudioSystemImpl::GetAssociatedOutputDeviceID( | 177 void AudioSystemImpl::GetAssociatedOutputDeviceID( |
| 175 const std::string& input_device_id, | 178 const std::string& input_device_id, |
| 176 OnDeviceIdCallback on_device_id_cb) { | 179 OnDeviceIdCallback on_device_id_cb) { |
| 177 if (GetTaskRunner()->BelongsToCurrentThread()) { | 180 if (GetTaskRunner()->BelongsToCurrentThread()) { |
| 178 GetTaskRunner()->PostTask( | 181 GetTaskRunner()->PostTask( |
| 179 FROM_HERE, | 182 FROM_HERE, base::BindOnce(std::move(on_device_id_cb), |
| 180 base::Bind(on_device_id_cb, audio_manager_->GetAssociatedOutputDeviceID( | 183 audio_manager_->GetAssociatedOutputDeviceID( |
| 181 input_device_id))); | 184 input_device_id))); |
| 182 return; | 185 return; |
| 183 } | 186 } |
| 184 base::PostTaskAndReplyWithResult( | 187 base::PostTaskAndReplyWithResult( |
| 185 GetTaskRunner(), FROM_HERE, | 188 GetTaskRunner(), FROM_HERE, |
| 186 base::Bind(&AudioManager::GetAssociatedOutputDeviceID, | 189 base::Bind(&AudioManager::GetAssociatedOutputDeviceID, |
| 187 base::Unretained(audio_manager_), input_device_id), | 190 base::Unretained(audio_manager_), input_device_id), |
| 188 std::move(on_device_id_cb)); | 191 std::move(on_device_id_cb)); |
| 189 } | 192 } |
| 190 | 193 |
| 191 void AudioSystemImpl::GetInputDeviceInfo( | 194 void AudioSystemImpl::GetInputDeviceInfo( |
| 192 const std::string& input_device_id, | 195 const std::string& input_device_id, |
| 193 OnInputDeviceInfoCallback on_input_device_info_cb) { | 196 OnInputDeviceInfoCallback on_input_device_info_cb) { |
| 194 // No need to bind |on_input_device_info_cb| to the current loop if we are on | 197 // No need to bind |on_input_device_info_cb| to the current loop if we are on |
| 195 // the audio thread. However, the client still expect to receive the reply | 198 // the audio thread. However, the client still expect to receive the reply |
| 196 // asynchronously, so we always post GetInputDeviceInfoOnDeviceThread(), which | 199 // asynchronously, so we always post GetInputDeviceInfoOnDeviceThread(), which |
| 197 // will syncronously call the (bound to current loop or not) callback. | 200 // will syncronously call the (bound to current loop or not) callback. |
| 198 GetTaskRunner()->PostTask( | 201 GetTaskRunner()->PostTask( |
| 199 FROM_HERE, base::Bind(&GetInputDeviceInfoOnDeviceThread, | 202 FROM_HERE, |
| 200 base::Unretained(audio_manager_), input_device_id, | 203 base::BindOnce( |
| 201 GetTaskRunner()->BelongsToCurrentThread() | 204 &GetInputDeviceInfoOnDeviceThread, base::Unretained(audio_manager_), |
| 202 ? std::move(on_input_device_info_cb) | 205 input_device_id, |
| 203 : media::BindToCurrentLoop( | 206 GetTaskRunner()->BelongsToCurrentThread() |
| 204 std::move(on_input_device_info_cb)))); | 207 ? std::move(on_input_device_info_cb) |
| 208 : media::BindToCurrentLoop(std::move(on_input_device_info_cb)))); |
| 205 } | 209 } |
| 206 | 210 |
| 207 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { | 211 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { |
| 208 return audio_manager_->GetTaskRunner(); | 212 return audio_manager_->GetTaskRunner(); |
| 209 } | 213 } |
| 210 | 214 |
| 211 } // namespace media | 215 } // namespace media |
| OLD | NEW |