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" |
11 #include "media/audio/audio_manager.h" | 11 #include "media/audio/audio_manager.h" |
12 #include "media/base/bind_to_current_loop.h" | |
12 | 13 |
13 // Using base::Unretained for |audio_manager_| is safe since it is deleted after | 14 // Using base::Unretained for |audio_manager_| is safe since it is deleted after |
14 // its task runner, and AudioSystemImpl is deleted on the UI thread after the IO | 15 // its task runner, and AudioSystemImpl is deleted on the UI thread after the IO |
15 // thread has been stopped and before |audio_manager_| deletion is scheduled. | 16 // thread has been stopped and before |audio_manager_| deletion is scheduled. |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 namespace { | 19 namespace { |
19 | 20 |
20 AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager, | 21 AudioParameters GetInputParametersOnDeviceThread(AudioManager* audio_manager, |
21 const std::string& device_id) { | 22 const std::string& device_id) { |
(...skipping 28 matching lines...) Expand all Loading... | |
50 bool for_input) { | 51 bool for_input) { |
51 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); | 52 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); |
52 AudioDeviceDescriptions descriptions; | 53 AudioDeviceDescriptions descriptions; |
53 if (for_input) | 54 if (for_input) |
54 audio_manager->GetAudioInputDeviceDescriptions(&descriptions); | 55 audio_manager->GetAudioInputDeviceDescriptions(&descriptions); |
55 else | 56 else |
56 audio_manager->GetAudioOutputDeviceDescriptions(&descriptions); | 57 audio_manager->GetAudioOutputDeviceDescriptions(&descriptions); |
57 return descriptions; | 58 return descriptions; |
58 } | 59 } |
59 | 60 |
61 void GetInputDeviceInfoOnDeviceThread( | |
62 AudioManager* audio_manager, | |
63 const std::string& input_device_id, | |
64 AudioSystem::OnInputDeviceInfoCallback on_input_device_info_cb) { | |
65 DCHECK(audio_manager->GetTaskRunner()->BelongsToCurrentThread()); | |
66 const std::string associated_output_device_id = | |
67 audio_manager->GetAssociatedOutputDeviceID(input_device_id); | |
68 | |
69 on_input_device_info_cb.Run( | |
70 GetInputParametersOnDeviceThread(audio_manager, input_device_id), | |
71 associated_output_device_id.empty() | |
72 ? AudioParameters() | |
73 : GetOutputParametersOnDeviceThread(audio_manager, | |
74 associated_output_device_id), | |
75 associated_output_device_id); | |
76 } | |
77 | |
60 } // namespace | 78 } // namespace |
61 | 79 |
62 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) | 80 AudioSystemImpl::AudioSystemImpl(AudioManager* audio_manager) |
63 : audio_manager_(audio_manager) { | 81 : audio_manager_(audio_manager) { |
64 DCHECK(audio_manager_); | 82 DCHECK(audio_manager_); |
65 AudioSystem::SetInstance(this); | 83 AudioSystem::SetInstance(this); |
66 } | 84 } |
67 | 85 |
68 AudioSystemImpl::~AudioSystemImpl() { | 86 AudioSystemImpl::~AudioSystemImpl() { |
69 AudioSystem::ClearInstance(this); | 87 AudioSystem::ClearInstance(this); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 return; | 133 return; |
116 } | 134 } |
117 base::PostTaskAndReplyWithResult( | 135 base::PostTaskAndReplyWithResult( |
118 GetTaskRunner(), FROM_HERE, | 136 GetTaskRunner(), FROM_HERE, |
119 base::Bind(&AudioManager::HasAudioInputDevices, | 137 base::Bind(&AudioManager::HasAudioInputDevices, |
120 base::Unretained(audio_manager_)), | 138 base::Unretained(audio_manager_)), |
121 std::move(on_has_devices_cb)); | 139 std::move(on_has_devices_cb)); |
122 } | 140 } |
123 | 141 |
124 void AudioSystemImpl::GetDeviceDescriptions( | 142 void AudioSystemImpl::GetDeviceDescriptions( |
125 OnDeviceDescriptionsCallback on_descriptions_cp, | 143 OnDeviceDescriptionsCallback on_descriptions_cb, |
126 bool for_input) { | 144 bool for_input) { |
127 if (GetTaskRunner()->BelongsToCurrentThread()) { | 145 if (GetTaskRunner()->BelongsToCurrentThread()) { |
128 GetTaskRunner()->PostTask( | 146 GetTaskRunner()->PostTask( |
129 FROM_HERE, base::Bind(on_descriptions_cp, | 147 FROM_HERE, base::Bind(on_descriptions_cb, |
130 base::Passed(GetDeviceDescriptionsOnDeviceThread( | 148 base::Passed(GetDeviceDescriptionsOnDeviceThread( |
131 audio_manager_, for_input)))); | 149 audio_manager_, for_input)))); |
132 return; | 150 return; |
133 } | 151 } |
134 | 152 |
135 base::PostTaskAndReplyWithResult( | 153 base::PostTaskAndReplyWithResult( |
136 GetTaskRunner(), FROM_HERE, | 154 GetTaskRunner(), FROM_HERE, |
137 base::Bind(&GetDeviceDescriptionsOnDeviceThread, | 155 base::Bind(&GetDeviceDescriptionsOnDeviceThread, |
138 base::Unretained(audio_manager_), for_input), | 156 base::Unretained(audio_manager_), for_input), |
139 std::move(on_descriptions_cp)); | 157 std::move(on_descriptions_cb)); |
158 } | |
159 | |
160 void AudioSystemImpl::GetAssociatedOutputDeviceID( | |
161 const std::string& input_device_id, | |
162 OnDeviceIdCallback on_device_id_cb) { | |
163 if (GetTaskRunner()->BelongsToCurrentThread()) { | |
164 GetTaskRunner()->PostTask( | |
165 FROM_HERE, | |
166 base::Bind(on_device_id_cb, audio_manager_->GetAssociatedOutputDeviceID( | |
167 input_device_id))); | |
168 return; | |
169 } | |
170 base::PostTaskAndReplyWithResult( | |
171 GetTaskRunner(), FROM_HERE, | |
172 base::Bind(&AudioManager::GetAssociatedOutputDeviceID, | |
173 base::Unretained(audio_manager_), input_device_id), | |
174 std::move(on_device_id_cb)); | |
175 } | |
176 | |
177 void AudioSystemImpl::GetInputDeviceInfo( | |
178 const std::string& input_device_id, | |
179 OnInputDeviceInfoCallback on_input_device_info_cb) { | |
180 GetTaskRunner()->PostTask( | |
DaleCurtis
2017/03/28 18:22:11
Hmm, seems like either the PostTask or BelongsToCu
o1ka
2017/03/30 15:11:53
We may be either already on the audio thread (for
| |
181 FROM_HERE, base::Bind(&GetInputDeviceInfoOnDeviceThread, | |
182 base::Unretained(audio_manager_), input_device_id, | |
183 GetTaskRunner()->BelongsToCurrentThread() | |
184 ? std::move(on_input_device_info_cb) | |
185 : media::BindToCurrentLoop( | |
186 std::move(on_input_device_info_cb)))); | |
187 } | |
188 | |
189 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { | |
190 return audio_manager_->GetTaskRunner(); | |
140 } | 191 } |
141 | 192 |
142 AudioManager* AudioSystemImpl::GetAudioManager() const { | 193 AudioManager* AudioSystemImpl::GetAudioManager() const { |
143 return audio_manager_; | 194 return audio_manager_; |
144 } | 195 } |
145 | 196 |
146 base::SingleThreadTaskRunner* AudioSystemImpl::GetTaskRunner() const { | |
147 return audio_manager_->GetTaskRunner(); | |
148 } | |
149 | |
150 } // namespace media | 197 } // namespace media |
OLD | NEW |