Chromium Code Reviews| 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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 } | 336 } |
| 337 | 337 |
| 338 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { | 338 void AudioManagerBase::ReleaseInputStream(AudioInputStream* stream) { |
| 339 CHECK(GetTaskRunner()->BelongsToCurrentThread()); | 339 CHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 340 DCHECK(stream); | 340 DCHECK(stream); |
| 341 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. | 341 // TODO(xians) : Have a clearer destruction path for the AudioInputStream. |
| 342 CHECK_EQ(1u, input_streams_.erase(stream)); | 342 CHECK_EQ(1u, input_streams_.erase(stream)); |
| 343 delete stream; | 343 delete stream; |
| 344 } | 344 } |
| 345 | 345 |
| 346 void AudioManagerBase::ShutdownOnAudioThread() { | 346 void AudioManagerBase::ShutdownOnAudioThread(bool immediately) { |
| 347 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 347 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 348 | 348 |
| 349 // Close all output streams. | 349 // Close all output streams. |
| 350 output_dispatchers_.clear(); | 350 output_dispatchers_.clear(); |
| 351 | 351 |
| 352 #if defined(OS_MACOSX) | 352 if (immediately) { |
| 353 // On mac, AudioManager runs on the main thread, loop for which stops | 353 // Even if tasks to close the streams are enqueued, they would not run |
|
alokp
2017/06/09 16:59:17
nit: Would it be better to run this block of code
o1ka
2017/06/09 17:15:48
Hmm.. Won't open streams be a problem on other pla
| |
| 354 // processing task queue at this point. So even if tasks to close the | 354 // leading to CHECKs getting hit in the destructor about open streams. Close |
| 355 // streams are enqueued, they would not run leading to CHECKs getting hit | 355 // them explicitly here. crbug.com/608049. |
| 356 // in the destructor about open streams. Close them explicitly here. | 356 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) { |
| 357 // crbug.com/608049. | 357 // Note: Closing the stream will invalidate the iterator. |
| 358 for (auto iter = input_streams_.begin(); iter != input_streams_.end();) { | 358 // Increment the iterator before closing the stream. |
| 359 // Note: Closing the stream will invalidate the iterator. | 359 AudioInputStream* stream = *iter++; |
| 360 // Increment the iterator before closing the stream. | 360 stream->Close(); |
| 361 AudioInputStream* stream = *iter++; | 361 } |
| 362 stream->Close(); | 362 CHECK(input_streams_.empty()); |
| 363 } | 363 } |
| 364 CHECK(input_streams_.empty()); | |
| 365 #endif // OS_MACOSX | |
| 366 } | 364 } |
| 367 | 365 |
| 368 void AudioManagerBase::AddOutputDeviceChangeListener( | 366 void AudioManagerBase::AddOutputDeviceChangeListener( |
| 369 AudioDeviceListener* listener) { | 367 AudioDeviceListener* listener) { |
| 370 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 368 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 371 output_listeners_.AddObserver(listener); | 369 output_listeners_.AddObserver(listener); |
| 372 } | 370 } |
| 373 | 371 |
| 374 void AudioManagerBase::RemoveOutputDeviceChangeListener( | 372 void AudioManagerBase::RemoveOutputDeviceChangeListener( |
| 375 AudioDeviceListener* listener) { | 373 AudioDeviceListener* listener) { |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 483 return base::MakeUnique<AudioDebugRecordingManager>(std::move(task_runner)); | 481 return base::MakeUnique<AudioDebugRecordingManager>(std::move(task_runner)); |
| 484 } | 482 } |
| 485 | 483 |
| 486 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, | 484 void AudioManagerBase::SetMaxStreamCountForTesting(int max_input, |
| 487 int max_output) { | 485 int max_output) { |
| 488 max_num_output_streams_ = max_output; | 486 max_num_output_streams_ = max_output; |
| 489 max_num_input_streams_ = max_input; | 487 max_num_input_streams_ = max_input; |
| 490 } | 488 } |
| 491 | 489 |
| 492 } // namespace media | 490 } // namespace media |
| OLD | NEW |