OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/cras/audio_manager_cras.h" | 5 #include "media/audio/cras/audio_manager_cras.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 namespace media { | 34 namespace media { |
35 namespace { | 35 namespace { |
36 | 36 |
37 // Maximum number of output streams that can be open simultaneously. | 37 // Maximum number of output streams that can be open simultaneously. |
38 const int kMaxOutputStreams = 50; | 38 const int kMaxOutputStreams = 50; |
39 | 39 |
40 // Default sample rate for input and output streams. | 40 // Default sample rate for input and output streams. |
41 const int kDefaultSampleRate = 48000; | 41 const int kDefaultSampleRate = 48000; |
42 | 42 |
43 // Define bounds for the output buffer size. | |
44 const int kMinimumOutputBufferSize = 512; | |
45 const int kMaximumOutputBufferSize = 8192; | |
46 | |
47 // Default input buffer size. | 43 // Default input buffer size. |
48 const int kDefaultInputBufferSize = 1024; | 44 const int kDefaultInputBufferSize = 1024; |
49 | 45 |
50 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; | 46 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
51 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; | 47 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
52 | 48 |
53 const char kInternalInputVirtualDevice[] = "Built-in mic"; | 49 const char kInternalInputVirtualDevice[] = "Built-in mic"; |
54 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; | 50 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; |
55 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; | 51 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; |
56 | 52 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
301 } | 297 } |
302 | 298 |
303 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { | 299 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { |
304 // On faster boards we can use smaller buffer size for lower latency. | 300 // On faster boards we can use smaller buffer size for lower latency. |
305 // On slower boards we should use larger buffer size to prevent underrun. | 301 // On slower boards we should use larger buffer size to prevent underrun. |
306 std::string board = base::SysInfo::GetLsbReleaseBoard(); | 302 std::string board = base::SysInfo::GetLsbReleaseBoard(); |
307 if (board == "kevin") | 303 if (board == "kevin") |
308 return 768; | 304 return 768; |
309 else if (board == "samus") | 305 else if (board == "samus") |
310 return 256; | 306 return 256; |
311 return kMinimumOutputBufferSize; | 307 return 512; |
312 } | 308 } |
313 | 309 |
314 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( | 310 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
315 const std::string& output_device_id, | 311 const std::string& output_device_id, |
316 const AudioParameters& input_params) { | 312 const AudioParameters& input_params) { |
317 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 313 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
318 int sample_rate = kDefaultSampleRate; | 314 int sample_rate = kDefaultSampleRate; |
319 int buffer_size = GetMinimumOutputBufferSizePerBoard(); | 315 int buffer_size = GetMinimumOutputBufferSizePerBoard(); |
320 int bits_per_sample = 16; | 316 int bits_per_sample = 16; |
321 if (input_params.IsValid()) { | 317 if (input_params.IsValid()) { |
322 sample_rate = input_params.sample_rate(); | 318 sample_rate = input_params.sample_rate(); |
323 bits_per_sample = input_params.bits_per_sample(); | 319 bits_per_sample = input_params.bits_per_sample(); |
324 channel_layout = input_params.channel_layout(); | 320 channel_layout = input_params.channel_layout(); |
325 buffer_size = | 321 buffer_size = |
326 std::min(kMaximumOutputBufferSize, | 322 std::min(static_cast<int>(limits::kMaxAudioBufferSize), |
327 std::max(buffer_size, input_params.frames_per_buffer())); | 323 std::max(buffer_size, input_params.frames_per_buffer())); |
328 } | 324 } |
329 | 325 |
330 int user_buffer_size = GetUserBufferSize(); | 326 int user_buffer_size = GetUserBufferSize(); |
331 if (user_buffer_size) | 327 if (user_buffer_size) |
332 buffer_size = user_buffer_size; | 328 buffer_size = user_buffer_size; |
333 | 329 |
334 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 330 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
335 sample_rate, bits_per_sample, buffer_size); | 331 sample_rate, bits_per_sample, buffer_size); |
336 } | 332 } |
(...skipping 26 matching lines...) Expand all Loading... |
363 | 359 |
364 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | 360 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
365 AudioDeviceNames device_names; | 361 AudioDeviceNames device_names; |
366 GetAudioDeviceNamesImpl(is_input, &device_names); | 362 GetAudioDeviceNamesImpl(is_input, &device_names); |
367 DCHECK(!device_names.empty()); | 363 DCHECK(!device_names.empty()); |
368 const AudioDeviceName& device_name = device_names.front(); | 364 const AudioDeviceName& device_name = device_names.front(); |
369 return device_name.unique_id == device_id; | 365 return device_name.unique_id == device_id; |
370 } | 366 } |
371 | 367 |
372 } // namespace media | 368 } // namespace media |
OLD | NEW |