Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: media/audio/audio_input_controller.cc

Issue 2885173002: Make AudioDebugFileWriter create its own file worker thread. (Closed)
Patch Set: Remove useless include Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "media/audio/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <limits> 10 #include <limits>
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 172
173 // static 173 // static
174 AudioInputController::Factory* AudioInputController::factory_ = nullptr; 174 AudioInputController::Factory* AudioInputController::factory_ = nullptr;
175 175
176 AudioInputController::AudioInputController( 176 AudioInputController::AudioInputController(
177 scoped_refptr<base::SingleThreadTaskRunner> task_runner, 177 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
178 EventHandler* handler, 178 EventHandler* handler,
179 SyncWriter* sync_writer, 179 SyncWriter* sync_writer,
180 UserInputMonitor* user_input_monitor, 180 UserInputMonitor* user_input_monitor,
181 const AudioParameters& params, 181 const AudioParameters& params,
182 StreamType type, 182 StreamType type)
183 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner)
184 : creator_task_runner_(base::ThreadTaskRunnerHandle::Get()), 183 : creator_task_runner_(base::ThreadTaskRunnerHandle::Get()),
185 task_runner_(std::move(task_runner)), 184 task_runner_(std::move(task_runner)),
186 handler_(handler), 185 handler_(handler),
187 stream_(nullptr), 186 stream_(nullptr),
188 sync_writer_(sync_writer), 187 sync_writer_(sync_writer),
189 type_(type), 188 type_(type),
190 user_input_monitor_(user_input_monitor), 189 user_input_monitor_(user_input_monitor),
191 #if BUILDFLAG(ENABLE_WEBRTC) 190 #if BUILDFLAG(ENABLE_WEBRTC)
192 debug_recording_helper_(params, 191 debug_recording_helper_(params, task_runner_, base::OnceClosure()),
193 task_runner_,
194 std::move(file_task_runner),
195 base::OnceClosure()),
196 #endif 192 #endif
197 weak_ptr_factory_(this) { 193 weak_ptr_factory_(this) {
198 DCHECK(creator_task_runner_.get()); 194 DCHECK(creator_task_runner_.get());
199 DCHECK(handler_); 195 DCHECK(handler_);
200 DCHECK(sync_writer_); 196 DCHECK(sync_writer_);
201 } 197 }
202 198
203 AudioInputController::~AudioInputController() { 199 AudioInputController::~AudioInputController() {
204 DCHECK(!audio_callback_); 200 DCHECK(!audio_callback_);
205 DCHECK(!stream_); 201 DCHECK(!stream_);
206 } 202 }
207 203
208 // static 204 // static
209 scoped_refptr<AudioInputController> AudioInputController::Create( 205 scoped_refptr<AudioInputController> AudioInputController::Create(
210 AudioManager* audio_manager, 206 AudioManager* audio_manager,
211 EventHandler* event_handler, 207 EventHandler* event_handler,
212 SyncWriter* sync_writer, 208 SyncWriter* sync_writer,
213 UserInputMonitor* user_input_monitor, 209 UserInputMonitor* user_input_monitor,
214 const AudioParameters& params, 210 const AudioParameters& params,
215 const std::string& device_id, 211 const std::string& device_id,
216 bool enable_agc, 212 bool enable_agc) {
217 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner) {
218 DCHECK(audio_manager); 213 DCHECK(audio_manager);
219 DCHECK(sync_writer); 214 DCHECK(sync_writer);
220 DCHECK(event_handler); 215 DCHECK(event_handler);
221 216
222 if (!params.IsValid() || (params.channels() > kMaxInputChannels)) 217 if (!params.IsValid() || (params.channels() > kMaxInputChannels))
223 return nullptr; 218 return nullptr;
224 219
225 if (factory_) { 220 if (factory_) {
226 return factory_->Create(audio_manager->GetTaskRunner(), sync_writer, 221 return factory_->Create(audio_manager->GetTaskRunner(), sync_writer,
227 audio_manager, event_handler, params, 222 audio_manager, event_handler, params,
228 user_input_monitor, ParamsToStreamType(params)); 223 user_input_monitor, ParamsToStreamType(params));
229 } 224 }
230 225
231 // Create the AudioInputController object and ensure that it runs on 226 // Create the AudioInputController object and ensure that it runs on
232 // the audio-manager thread. 227 // the audio-manager thread.
233 scoped_refptr<AudioInputController> controller(new AudioInputController( 228 scoped_refptr<AudioInputController> controller(new AudioInputController(
234 audio_manager->GetTaskRunner(), event_handler, sync_writer, 229 audio_manager->GetTaskRunner(), event_handler, sync_writer,
235 user_input_monitor, params, ParamsToStreamType(params), 230 user_input_monitor, params, ParamsToStreamType(params)));
236 std::move(file_task_runner)));
237 231
238 // Create and open a new audio input stream from the existing 232 // Create and open a new audio input stream from the existing
239 // audio-device thread. Use the provided audio-input device. 233 // audio-device thread. Use the provided audio-input device.
240 if (!controller->task_runner_->PostTask( 234 if (!controller->task_runner_->PostTask(
241 FROM_HERE, base::Bind(&AudioInputController::DoCreate, controller, 235 FROM_HERE, base::Bind(&AudioInputController::DoCreate, controller,
242 base::Unretained(audio_manager), params, 236 base::Unretained(audio_manager), params,
243 device_id, enable_agc))) { 237 device_id, enable_agc))) {
244 controller = nullptr; 238 controller = nullptr;
245 } 239 }
246 240
247 return controller; 241 return controller;
248 } 242 }
249 243
250 // static 244 // static
251 scoped_refptr<AudioInputController> AudioInputController::CreateForStream( 245 scoped_refptr<AudioInputController> AudioInputController::CreateForStream(
252 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner, 246 const scoped_refptr<base::SingleThreadTaskRunner>& task_runner,
253 EventHandler* event_handler, 247 EventHandler* event_handler,
254 AudioInputStream* stream, 248 AudioInputStream* stream,
255 SyncWriter* sync_writer, 249 SyncWriter* sync_writer,
256 UserInputMonitor* user_input_monitor, 250 UserInputMonitor* user_input_monitor,
257 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner,
258 const AudioParameters& params) { 251 const AudioParameters& params) {
259 DCHECK(sync_writer); 252 DCHECK(sync_writer);
260 DCHECK(stream); 253 DCHECK(stream);
261 DCHECK(event_handler); 254 DCHECK(event_handler);
262 255
263 if (factory_) { 256 if (factory_) {
264 return factory_->Create(task_runner, sync_writer, AudioManager::Get(), 257 return factory_->Create(task_runner, sync_writer, AudioManager::Get(),
265 event_handler, 258 event_handler,
266 AudioParameters::UnavailableDeviceParams(), 259 AudioParameters::UnavailableDeviceParams(),
267 user_input_monitor, VIRTUAL); 260 user_input_monitor, VIRTUAL);
268 } 261 }
269 262
270 // Create the AudioInputController object and ensure that it runs on 263 // Create the AudioInputController object and ensure that it runs on
271 // the audio-manager thread. 264 // the audio-manager thread.
272 scoped_refptr<AudioInputController> controller(new AudioInputController( 265 scoped_refptr<AudioInputController> controller(
273 task_runner, event_handler, sync_writer, user_input_monitor, params, 266 new AudioInputController(task_runner, event_handler, sync_writer,
274 VIRTUAL, std::move(file_task_runner))); 267 user_input_monitor, params, VIRTUAL));
275 268
276 if (!controller->task_runner_->PostTask( 269 if (!controller->task_runner_->PostTask(
277 FROM_HERE, base::Bind(&AudioInputController::DoCreateForStream, 270 FROM_HERE, base::Bind(&AudioInputController::DoCreateForStream,
278 controller, stream, /*enable_agc*/ false))) { 271 controller, stream, /*enable_agc*/ false))) {
279 controller = nullptr; 272 controller = nullptr;
280 } 273 }
281 274
282 return controller; 275 return controller;
283 } 276 }
284 277
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY: 661 case AudioParameters::Format::AUDIO_PCM_LOW_LATENCY:
669 return AudioInputController::StreamType::LOW_LATENCY; 662 return AudioInputController::StreamType::LOW_LATENCY;
670 default: 663 default:
671 // Currently, the remaining supported type is fake. Reconsider if other 664 // Currently, the remaining supported type is fake. Reconsider if other
672 // formats become supported. 665 // formats become supported.
673 return AudioInputController::StreamType::FAKE; 666 return AudioInputController::StreamType::FAKE;
674 } 667 }
675 } 668 }
676 669
677 } // namespace media 670 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.h ('k') | media/audio/audio_input_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698