OLD | NEW |
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_manager_base.h" | 5 #include "media/audio/audio_manager_base.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 // dispatcher are the same as the request dispatcher. | 77 // dispatcher are the same as the request dispatcher. |
78 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && | 78 return (dispatcher_->input_params.Equals(dispatcher_in->input_params) && |
79 dispatcher_->output_params.Equals(dispatcher_in->output_params) && | 79 dispatcher_->output_params.Equals(dispatcher_in->output_params) && |
80 dispatcher_->output_device_id == dispatcher_in->output_device_id); | 80 dispatcher_->output_device_id == dispatcher_in->output_device_id); |
81 } | 81 } |
82 | 82 |
83 private: | 83 private: |
84 const DispatcherParams* dispatcher_; | 84 const DispatcherParams* dispatcher_; |
85 }; | 85 }; |
86 | 86 |
87 AudioManagerBase::AudioManagerBase( | 87 AudioManagerBase::AudioManagerBase(std::unique_ptr<AudioThread> audio_thread, |
88 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 88 AudioLogFactory* audio_log_factory) |
89 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 89 : AudioManager(std::move(audio_thread)), |
90 AudioLogFactory* audio_log_factory) | |
91 : AudioManager(std::move(task_runner), std::move(worker_task_runner)), | |
92 max_num_output_streams_(kDefaultMaxOutputStreams), | 90 max_num_output_streams_(kDefaultMaxOutputStreams), |
93 max_num_input_streams_(kDefaultMaxInputStreams), | 91 max_num_input_streams_(kDefaultMaxInputStreams), |
94 num_output_streams_(0), | 92 num_output_streams_(0), |
95 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we | 93 // TODO(dalecurtis): Switch this to an base::ObserverListThreadSafe, so we |
96 // don't block the UI thread when swapping devices. | 94 // don't block the UI thread when swapping devices. |
97 output_listeners_( | 95 output_listeners_( |
98 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), | 96 base::ObserverList<AudioDeviceListener>::NOTIFY_EXISTING_ONLY), |
99 audio_log_factory_(audio_log_factory) {} | 97 audio_log_factory_(audio_log_factory) {} |
100 | 98 |
101 AudioManagerBase::~AudioManagerBase() { | 99 AudioManagerBase::~AudioManagerBase() { |
102 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | |
103 | |
104 // All the output streams should have been deleted. | 100 // All the output streams should have been deleted. |
105 CHECK_EQ(0, num_output_streams_); | 101 CHECK_EQ(0, num_output_streams_); |
106 // All the input streams should have been deleted. | 102 // All the input streams should have been deleted. |
107 CHECK(input_streams_.empty()); | 103 CHECK(input_streams_.empty()); |
108 } | 104 } |
109 | 105 |
110 base::string16 AudioManagerBase::GetAudioInputDeviceModel() { | 106 base::string16 AudioManagerBase::GetAudioInputDeviceModel() { |
111 return base::string16(); | 107 return base::string16(); |
112 } | 108 } |
113 | 109 |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 auto it = std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), | 281 auto it = std::find_if(output_dispatchers_.begin(), output_dispatchers_.end(), |
286 CompareByParams(dispatcher_params.get())); | 282 CompareByParams(dispatcher_params.get())); |
287 if (it != output_dispatchers_.end()) | 283 if (it != output_dispatchers_.end()) |
288 return (*it)->dispatcher->CreateStreamProxy(); | 284 return (*it)->dispatcher->CreateStreamProxy(); |
289 | 285 |
290 const base::TimeDelta kCloseDelay = | 286 const base::TimeDelta kCloseDelay = |
291 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); | 287 base::TimeDelta::FromSeconds(kStreamCloseDelaySeconds); |
292 std::unique_ptr<AudioOutputDispatcher> dispatcher; | 288 std::unique_ptr<AudioOutputDispatcher> dispatcher; |
293 if (output_params.format() != AudioParameters::AUDIO_FAKE) { | 289 if (output_params.format() != AudioParameters::AUDIO_FAKE) { |
294 // Using unretained for |debug_recording_manager_| is safe since it | 290 // Using unretained for |debug_recording_manager_| is safe since it |
295 // outlives the dispatchers (cleared in Shutdown()). | 291 // outlives the dispatchers (cleared in ShutdownOnAudioThread()). |
296 dispatcher = base::MakeUnique<AudioOutputResampler>( | 292 dispatcher = base::MakeUnique<AudioOutputResampler>( |
297 this, params, output_params, output_device_id, kCloseDelay, | 293 this, params, output_params, output_device_id, kCloseDelay, |
298 debug_recording_manager_ | 294 debug_recording_manager_ |
299 ? base::BindRepeating( | 295 ? base::BindRepeating( |
300 &AudioDebugRecordingManager::RegisterDebugRecordingSource, | 296 &AudioDebugRecordingManager::RegisterDebugRecordingSource, |
301 base::Unretained(debug_recording_manager_.get()), | 297 base::Unretained(debug_recording_manager_.get()), |
302 FILE_PATH_LITERAL("output")) | 298 FILE_PATH_LITERAL("output")) |
303 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); | 299 : base::BindRepeating(&GetNullptrAudioDebugRecorder)); |
304 } else { | 300 } else { |
305 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( | 301 dispatcher = base::MakeUnique<AudioOutputDispatcherImpl>( |
(...skipping 28 matching lines...) Expand all Loading... |
334 } | 330 } |
335 | 331 |
336 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { | 332 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
337 CHECK(GetTaskRunner()->BelongsToCurrentThread()); | 333 CHECK(GetTaskRunner()->BelongsToCurrentThread()); |
338 DCHECK(stream); | 334 DCHECK(stream); |
339 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. | 335 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
340 CHECK_EQ(1u, input_streams_.erase(stream)); | 336 CHECK_EQ(1u, input_streams_.erase(stream)); |
341 delete stream; | 337 delete stream; |
342 } | 338 } |
343 | 339 |
344 void AudioManagerBase::Shutdown() { | 340 void AudioManagerBase::ShutdownOnAudioThread() { |
345 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 341 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
346 | 342 |
347 // Close all output streams. | 343 // Close all output streams. |
348 output_dispatchers_.clear(); | 344 output_dispatchers_.clear(); |
349 | 345 |
350 #if defined(OS_MACOSX) | 346 #if defined(OS_MACOSX) |
351 // On mac, AudioManager runs on the main thread, loop for which stops | 347 // On mac, AudioManager runs on the main thread, loop for which stops |
352 // processing task queue at this point. So even if tasks to close the | 348 // processing task queue at this point. So even if tasks to close the |
353 // streams are enqueued, they would not run leading to CHECKs getting hit | 349 // streams are enqueued, they would not run leading to CHECKs getting hit |
354 // in the destructor about open streams. Close them explicitly here. | 350 // in the destructor about open streams. Close them explicitly here. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 std::move(task_runner), std::move(file_task_runner)); | 482 std::move(task_runner), std::move(file_task_runner)); |
487 } | 483 } |
488 | 484 |
489 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 485 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
490 int max_output) { | 486 int max_output) { |
491 max_num_output_streams_ = max_output; | 487 max_num_output_streams_ = max_output; |
492 max_num_input_streams_ = max_input; | 488 max_num_input_streams_ = max_input; |
493 } | 489 } |
494 | 490 |
495 } // namespace media | 491 } // namespace media |
OLD | NEW |