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/mac/audio_manager_mac.h" | 5 #include "media/audio/mac/audio_manager_mac.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 377 FROM_HERE, base::Bind(&AudioManagerMac::InitializeOnAudioThread, | 377 FROM_HERE, base::Bind(&AudioManagerMac::InitializeOnAudioThread, |
| 378 base::Unretained(this))); | 378 base::Unretained(this))); |
| 379 } | 379 } |
| 380 | 380 |
| 381 AudioManagerMac::~AudioManagerMac() { | 381 AudioManagerMac::~AudioManagerMac() { |
| 382 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 382 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 383 // We are now in shutdown mode. This flag disables MaybeChangeBufferSize() | 383 // We are now in shutdown mode. This flag disables MaybeChangeBufferSize() |
| 384 // and IncreaseIOBufferSizeIfPossible() which both touches native Core Audio | 384 // and IncreaseIOBufferSizeIfPossible() which both touches native Core Audio |
| 385 // APIs and they can fail and disrupt tests during shutdown. | 385 // APIs and they can fail and disrupt tests during shutdown. |
| 386 in_shutdown_ = true; | 386 in_shutdown_ = true; |
| 387 Shutdown(); | |
|
alokp
2016/11/15 14:29:38
Moved here so that proxy streams are closed before
| |
| 387 // We have seen cases where active input audio is not closed down properly | 388 // We have seen cases where active input audio is not closed down properly |
| 388 // at browser shutdown. AudioInputController::Close() is called but tasks | 389 // at browser shutdown. AudioInputController::Close() is called but tasks |
| 389 // in AudioInputController::DoClose() are not executed. Hence, input streams | 390 // in AudioInputController::DoClose() are not executed. Hence, input streams |
| 390 // might remain even at this late state. |low_latency_input_streams_| will be | 391 // might remain even at this late state. |low_latency_input_streams_| will be |
| 391 // modified during the call to stream->Close(), so we can't iterate over it | 392 // modified during the call to stream->Close(), so we can't iterate over it |
| 392 // here. Instead iterate over a copy. | 393 // here. Instead iterate over a copy. |
| 393 // TODO(henrika): figure out the real cause why streams are not closed | 394 // TODO(henrika): figure out the real cause why streams are not closed |
| 394 // properly by the AIC for all cases and then remove this loop. | 395 // properly by the AIC for all cases and then remove this loop. |
| 395 auto low_latency_input_streams_copy = low_latency_input_streams_; | 396 auto low_latency_input_streams_copy = low_latency_input_streams_; |
| 396 for (auto* stream : low_latency_input_streams_copy) { | 397 for (auto* stream : low_latency_input_streams_copy) { |
| 397 LOG(WARNING) << "Closing existing audio input stream at destruction"; | 398 LOG(WARNING) << "Closing existing audio input stream at destruction"; |
| 398 // Prevents active Core Audio callbacks to use possibly invalid objects | 399 // Prevents active Core Audio callbacks to use possibly invalid objects |
| 399 // in its OnData() callback. | 400 // in its OnData() callback. |
| 400 stream->Stop(); | 401 stream->Stop(); |
| 401 // Avoids hitting CHECK in dtor of AudioManagerBase. | 402 // Avoids hitting CHECK in dtor of AudioManagerBase. |
| 402 stream->Close(); | 403 stream->Close(); |
| 403 } | 404 } |
| 404 // Perform same type of cleanup as above but for high-latency input streams. | 405 // Perform same type of cleanup as above but for high-latency input streams. |
| 405 auto basic_input_streams_copy = basic_input_streams_; | 406 auto basic_input_streams_copy = basic_input_streams_; |
| 406 for (auto* stream : basic_input_streams_copy) { | 407 for (auto* stream : basic_input_streams_copy) { |
| 407 LOG(WARNING) | 408 LOG(WARNING) |
| 408 << "Closing existing high-latency audio input stream at destruction"; | 409 << "Closing existing high-latency audio input stream at destruction"; |
| 409 // Prevents active AudioQueue callbacks to use possibly invalid objects | 410 // Prevents active AudioQueue callbacks to use possibly invalid objects |
| 410 // in its OnData() callback. | 411 // in its OnData() callback. |
| 411 stream->Stop(); | 412 stream->Stop(); |
| 412 // Avoids hitting CHECK in dtor of AudioManagerBase. | 413 // Avoids hitting CHECK in dtor of AudioManagerBase. |
| 413 stream->Close(); | 414 stream->Close(); |
| 414 } | 415 } |
| 415 Shutdown(); | |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool AudioManagerMac::HasAudioOutputDevices() { | 418 bool AudioManagerMac::HasAudioOutputDevices() { |
| 419 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); | 419 return HasAudioHardware(kAudioHardwarePropertyDefaultOutputDevice); |
| 420 } | 420 } |
| 421 | 421 |
| 422 bool AudioManagerMac::HasAudioInputDevices() { | 422 bool AudioManagerMac::HasAudioInputDevices() { |
| 423 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); | 423 return HasAudioHardware(kAudioHardwarePropertyDefaultInputDevice); |
| 424 } | 424 } |
| 425 | 425 |
| (...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 ScopedAudioManagerPtr CreateAudioManager( | 1108 ScopedAudioManagerPtr CreateAudioManager( |
| 1109 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 1109 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 1110 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, | 1110 scoped_refptr<base::SingleThreadTaskRunner> worker_task_runner, |
| 1111 AudioLogFactory* audio_log_factory) { | 1111 AudioLogFactory* audio_log_factory) { |
| 1112 return ScopedAudioManagerPtr( | 1112 return ScopedAudioManagerPtr( |
| 1113 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), | 1113 new AudioManagerMac(std::move(task_runner), std::move(worker_task_runner), |
| 1114 audio_log_factory)); | 1114 audio_log_factory)); |
| 1115 } | 1115 } |
| 1116 | 1116 |
| 1117 } // namespace media | 1117 } // namespace media |
| OLD | NEW |