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

Side by Side Diff: media/audio/mac/audio_manager_mac.cc

Issue 2908073002: Make OS audio buffer size limits visible. (Closed)
Patch Set: Different approach as suggested by olka. Created 3 years, 6 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
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/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 16 matching lines...) Expand all
27 #include "media/base/bind_to_current_loop.h" 27 #include "media/base/bind_to_current_loop.h"
28 #include "media/base/channel_layout.h" 28 #include "media/base/channel_layout.h"
29 #include "media/base/limits.h" 29 #include "media/base/limits.h"
30 #include "media/base/media_switches.h" 30 #include "media/base/media_switches.h"
31 31
32 namespace media { 32 namespace media {
33 33
34 // Maximum number of output streams that can be open simultaneously. 34 // Maximum number of output streams that can be open simultaneously.
35 static const int kMaxOutputStreams = 50; 35 static const int kMaxOutputStreams = 50;
36 36
37 // Define bounds for for low-latency input and output streams.
38 static const int kMinimumInputOutputBufferSize = 128;
39 static const int kMaximumInputOutputBufferSize = 4096;
40
41 // Default sample-rate on most Apple hardware. 37 // Default sample-rate on most Apple hardware.
42 static const int kFallbackSampleRate = 44100; 38 static const int kFallbackSampleRate = 44100;
43 39
44 // Helper method to construct AudioObjectPropertyAddress structure given 40 // Helper method to construct AudioObjectPropertyAddress structure given
45 // property selector and scope. The property element is always set to 41 // property selector and scope. The property element is always set to
46 // kAudioObjectPropertyElementMaster. 42 // kAudioObjectPropertyElementMaster.
47 static AudioObjectPropertyAddress GetAudioObjectPropertyAddress( 43 static AudioObjectPropertyAddress GetAudioObjectPropertyAddress(
48 AudioObjectPropertySelector selector, 44 AudioObjectPropertySelector selector,
49 bool is_input) { 45 bool is_input) {
50 AudioObjectPropertyScope scope = is_input ? kAudioObjectPropertyScopeInput 46 AudioObjectPropertyScope scope = is_input ? kAudioObjectPropertyScopeInput
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 kFallbackSampleRate, 16, ChooseBufferSize(false, kFallbackSampleRate)); 826 kFallbackSampleRate, 16, ChooseBufferSize(false, kFallbackSampleRate));
831 } 827 }
832 828
833 const bool has_valid_input_params = input_params.IsValid(); 829 const bool has_valid_input_params = input_params.IsValid();
834 const int hardware_sample_rate = HardwareSampleRateForDevice(device); 830 const int hardware_sample_rate = HardwareSampleRateForDevice(device);
835 831
836 // Allow pass through buffer sizes. If concurrent input and output streams 832 // Allow pass through buffer sizes. If concurrent input and output streams
837 // exist, they will use the smallest buffer size amongst them. As such, each 833 // exist, they will use the smallest buffer size amongst them. As such, each
838 // stream must be able to FIFO requests appropriately when this happens. 834 // stream must be able to FIFO requests appropriately when this happens.
839 int buffer_size = ChooseBufferSize(false, hardware_sample_rate); 835 int buffer_size = ChooseBufferSize(false, hardware_sample_rate);
840 if (has_valid_input_params) { 836 if (has_valid_input_params) {
o1ka 2017/06/09 10:52:39 combine into a conditional assignment? int buffer_
Andrew MacPherson 2017/06/12 11:23:32 Done.
841 buffer_size = 837 // If passed in via the input_params we allow buffer sizes to go as low as
842 std::min(kMaximumInputOutputBufferSize, 838 // the the kMinimumInputOutputBufferSize, ignoring what ChooseBufferSize()
843 std::max(input_params.frames_per_buffer(), buffer_size)); 839 // normally returns.
840 buffer_size = std::min(
o1ka 2017/06/09 10:52:39 Add a test to media/audio/audio_manager_unittest.c
Andrew MacPherson 2017/06/12 11:23:32 No problem, as soon as we agree that this approach
841 static_cast<int>(limits::kMaximumInputOutputBufferSize),
842 std::max(input_params.frames_per_buffer(),
843 static_cast<int>(limits::kMinimumInputOutputBufferSize)));
844 } 844 }
845 845
846 int hardware_channels; 846 int hardware_channels;
847 if (!GetDeviceChannels(device, AUElement::OUTPUT, &hardware_channels)) 847 if (!GetDeviceChannels(device, AUElement::OUTPUT, &hardware_channels))
848 hardware_channels = 2; 848 hardware_channels = 2;
849 849
850 // Use the input channel count and channel layout if possible. Let OSX take 850 // Use the input channel count and channel layout if possible. Let OSX take
851 // care of remapping the channels; this lets user specified channel layouts 851 // care of remapping the channels; this lets user specified channel layouts
852 // work correctly. 852 // work correctly.
853 int output_channels = input_params.channels(); 853 int output_channels = input_params.channels();
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 888
889 int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) { 889 int AudioManagerMac::ChooseBufferSize(bool is_input, int sample_rate) {
890 // kMinimumInputOutputBufferSize is too small for the output side because 890 // kMinimumInputOutputBufferSize is too small for the output side because
891 // CoreAudio can get into under-run if the renderer fails delivering data 891 // CoreAudio can get into under-run if the renderer fails delivering data
892 // to the browser within the allowed time by the OS. The workaround is to 892 // to the browser within the allowed time by the OS. The workaround is to
893 // use 256 samples as the default output buffer size for sample rates 893 // use 256 samples as the default output buffer size for sample rates
894 // smaller than 96KHz. 894 // smaller than 96KHz.
895 // TODO(xians): Remove this workaround after WebAudio supports user defined 895 // TODO(xians): Remove this workaround after WebAudio supports user defined
896 // buffer size. See https://github.com/WebAudio/web-audio-api/issues/348 896 // buffer size. See https://github.com/WebAudio/web-audio-api/issues/348
897 // for details. 897 // for details.
898 int buffer_size = is_input ? 898 int buffer_size = is_input ? limits::kMinimumInputOutputBufferSize
899 kMinimumInputOutputBufferSize : 2 * kMinimumInputOutputBufferSize; 899 : 2 * limits::kMinimumInputOutputBufferSize;
900 const int user_buffer_size = GetUserBufferSize(); 900 const int user_buffer_size = GetUserBufferSize();
901 if (user_buffer_size) { 901 if (user_buffer_size) {
902 buffer_size = user_buffer_size; 902 buffer_size = user_buffer_size;
903 } else if (sample_rate > 48000) { 903 } else if (sample_rate > 48000) {
904 // The default buffer size is too small for higher sample rates and may lead 904 // The default buffer size is too small for higher sample rates and may lead
905 // to glitching. Adjust upwards by multiples of the default size. 905 // to glitching. Adjust upwards by multiples of the default size.
906 if (sample_rate <= 96000) 906 if (sample_rate <= 96000)
907 buffer_size = 2 * kMinimumInputOutputBufferSize; 907 buffer_size = 2 * limits::kMinimumInputOutputBufferSize;
908 else if (sample_rate <= 192000) 908 else if (sample_rate <= 192000)
909 buffer_size = 4 * kMinimumInputOutputBufferSize; 909 buffer_size = 4 * limits::kMinimumInputOutputBufferSize;
910 } 910 }
911 911
912 return buffer_size; 912 return buffer_size;
913 } 913 }
914 914
915 bool AudioManagerMac::IsSuspending() const { 915 bool AudioManagerMac::IsSuspending() const {
916 DCHECK(GetTaskRunner()->BelongsToCurrentThread()); 916 DCHECK(GetTaskRunner()->BelongsToCurrentThread());
917 return power_observer_->IsSuspending(); 917 return power_observer_->IsSuspending();
918 } 918 }
919 919
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1183 } 1183 }
1184 1184
1185 std::unique_ptr<AudioManager> CreateAudioManager( 1185 std::unique_ptr<AudioManager> CreateAudioManager(
1186 std::unique_ptr<AudioThread> audio_thread, 1186 std::unique_ptr<AudioThread> audio_thread,
1187 AudioLogFactory* audio_log_factory) { 1187 AudioLogFactory* audio_log_factory) {
1188 return base::MakeUnique<AudioManagerMac>(std::move(audio_thread), 1188 return base::MakeUnique<AudioManagerMac>(std::move(audio_thread),
1189 audio_log_factory); 1189 audio_log_factory);
1190 } 1190 }
1191 1191
1192 } // namespace media 1192 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698