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 <CoreAudio/AudioHardware.h> | 7 #include <CoreAudio/AudioHardware.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 710 | 710 |
| 711 if (current_sample_rate_ == new_sample_rate && | 711 if (current_sample_rate_ == new_sample_rate && |
| 712 current_output_device_ == new_output_device) | 712 current_output_device_ == new_output_device) |
| 713 return; | 713 return; |
| 714 | 714 |
| 715 current_sample_rate_ = new_sample_rate; | 715 current_sample_rate_ = new_sample_rate; |
| 716 current_output_device_ = new_output_device; | 716 current_output_device_ = new_output_device; |
| 717 NotifyAllOutputDeviceChangeListeners(); | 717 NotifyAllOutputDeviceChangeListeners(); |
| 718 } | 718 } |
| 719 | 719 |
| 720 int AudioManagerMac::ChooseBufferSize(int output_sample_rate) { | 720 int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) { |
| 721 int buffer_size = kMinimumInputOutputBufferSize; | 721 // kMinimumInputOutputBufferSize is too small for the output side because |
| 722 // CoreAudio can get into under-run if the renderer fails delivering data | |
| 723 // to the browser within the allowed time by the OS. The workaround is to | |
| 724 // use 256 samples as the default output buffer size for sample rates | |
| 725 // smaller than 96KHz. | |
| 726 // TODO(xians): Remove this workaround after WebAudio supports user defined | |
| 727 // buffer size. | |
|
DaleCurtis
2014/10/24 17:04:43
Link to tracking bug?
no longer working on chromium
2014/10/27 10:58:51
Done.
| |
| 728 int buffer_size = is_input ? | |
|
no longer working on chromium
2014/10/24 10:05:29
Dale, for the input side, we still want 128 sample
| |
| 729 kMinimumInputOutputBufferSize : 2 * kMinimumInputOutputBufferSize; | |
| 722 const int user_buffer_size = GetUserBufferSize(); | 730 const int user_buffer_size = GetUserBufferSize(); |
| 723 if (user_buffer_size) { | 731 if (user_buffer_size) { |
| 724 buffer_size = user_buffer_size; | 732 buffer_size = user_buffer_size; |
| 725 } else if (output_sample_rate > 48000) { | 733 } else if (sample_rate > 48000) { |
| 726 // The default buffer size is too small for higher sample rates and may lead | 734 // The default buffer size is too small for higher sample rates and may lead |
| 727 // to glitching. Adjust upwards by multiples of the default size. | 735 // to glitching. Adjust upwards by multiples of the default size. |
| 728 if (output_sample_rate <= 96000) | 736 if (sample_rate <= 96000) |
| 729 buffer_size = 2 * kMinimumInputOutputBufferSize; | 737 buffer_size = 2 * kMinimumInputOutputBufferSize; |
| 730 else if (output_sample_rate <= 192000) | 738 else if (sample_rate <= 192000) |
| 731 buffer_size = 4 * kMinimumInputOutputBufferSize; | 739 buffer_size = 4 * kMinimumInputOutputBufferSize; |
| 732 } | 740 } |
| 733 | 741 |
| 734 return buffer_size; | 742 return buffer_size; |
| 735 } | 743 } |
| 736 | 744 |
| 737 bool AudioManagerMac::ShouldDeferStreamStart() { | 745 bool AudioManagerMac::ShouldDeferStreamStart() { |
| 738 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); | 746 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); |
| 739 return power_observer_->ShouldDeferStreamStart(); | 747 return power_observer_->ShouldDeferStreamStart(); |
| 740 } | 748 } |
| 741 | 749 |
| 742 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { | 750 void AudioManagerMac::ReleaseOutputStream(AudioOutputStream* stream) { |
| 743 output_streams_.remove(stream); | 751 output_streams_.remove(stream); |
| 744 AudioManagerBase::ReleaseOutputStream(stream); | 752 AudioManagerBase::ReleaseOutputStream(stream); |
| 745 } | 753 } |
| 746 | 754 |
| 747 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { | 755 void AudioManagerMac::ReleaseInputStream(AudioInputStream* stream) { |
| 748 input_streams_.remove(stream); | 756 input_streams_.remove(stream); |
| 749 AudioManagerBase::ReleaseInputStream(stream); | 757 AudioManagerBase::ReleaseInputStream(stream); |
| 750 } | 758 } |
| 751 | 759 |
| 752 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { | 760 AudioManager* CreateAudioManager(AudioLogFactory* audio_log_factory) { |
| 753 return new AudioManagerMac(audio_log_factory); | 761 return new AudioManagerMac(audio_log_factory); |
| 754 } | 762 } |
| 755 | 763 |
| 756 } // namespace media | 764 } // namespace media |
| OLD | NEW |