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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/environment.h" | 12 #include "base/environment.h" |
13 #include "base/logging.h" | 13 #include "base/logging.h" |
14 #include "base/metrics/field_trial.h" | 14 #include "base/metrics/field_trial.h" |
15 #include "base/metrics/histogram_macros.h" | 15 #include "base/metrics/histogram_macros.h" |
16 #include "base/nix/xdg_util.h" | 16 #include "base/nix/xdg_util.h" |
17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "chromeos/audio/audio_device.h" | 20 #include "chromeos/audio/audio_device.h" |
21 #include "chromeos/audio/cras_audio_handler.h" | 21 #include "chromeos/audio/cras_audio_handler.h" |
22 #include "media/audio/audio_device_description.h" | 22 #include "media/audio/audio_device_description.h" |
23 #include "media/audio/audio_features.h" | 23 #include "media/audio/audio_features.h" |
24 #include "media/audio/cras/cras_input.h" | 24 #include "media/audio/cras/cras_input.h" |
25 #include "media/audio/cras/cras_unified.h" | 25 #include "media/audio/cras/cras_unified.h" |
26 #include "media/base/channel_layout.h" | 26 #include "media/base/channel_layout.h" |
27 #include "media/base/limits.h" | |
28 #include "media/base/localized_strings.h" | 27 #include "media/base/localized_strings.h" |
29 | 28 |
30 // cras_util.h headers pull in min/max macros... | 29 // cras_util.h headers pull in min/max macros... |
31 // TODO(dgreid): Fix headers such that these aren't imported. | 30 // TODO(dgreid): Fix headers such that these aren't imported. |
32 #undef min | 31 #undef min |
33 #undef max | 32 #undef max |
34 | 33 |
35 namespace media { | 34 namespace media { |
36 namespace { | 35 namespace { |
37 | 36 |
38 // Maximum number of output streams that can be open simultaneously. | 37 // Maximum number of output streams that can be open simultaneously. |
39 const int kMaxOutputStreams = 50; | 38 const int kMaxOutputStreams = 50; |
40 | 39 |
41 // Default sample rate for input and output streams. | 40 // Default sample rate for input and output streams. |
42 const int kDefaultSampleRate = 48000; | 41 const int kDefaultSampleRate = 48000; |
43 | 42 |
| 43 // Define bounds for the output buffer size. |
| 44 const int kMinimumOutputBufferSize = 512; |
| 45 const int kMaximumOutputBufferSize = 8192; |
| 46 |
44 // Default input buffer size. | 47 // Default input buffer size. |
45 const int kDefaultInputBufferSize = 1024; | 48 const int kDefaultInputBufferSize = 1024; |
46 | 49 |
47 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; | 50 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
48 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; | 51 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
49 | 52 |
50 const char kInternalInputVirtualDevice[] = "Built-in mic"; | 53 const char kInternalInputVirtualDevice[] = "Built-in mic"; |
51 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; | 54 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; |
52 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; | 55 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; |
53 | 56 |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
298 } | 301 } |
299 | 302 |
300 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { | 303 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { |
301 // On faster boards we can use smaller buffer size for lower latency. | 304 // On faster boards we can use smaller buffer size for lower latency. |
302 // On slower boards we should use larger buffer size to prevent underrun. | 305 // On slower boards we should use larger buffer size to prevent underrun. |
303 std::string board = base::SysInfo::GetLsbReleaseBoard(); | 306 std::string board = base::SysInfo::GetLsbReleaseBoard(); |
304 if (board == "kevin") | 307 if (board == "kevin") |
305 return 768; | 308 return 768; |
306 else if (board == "samus") | 309 else if (board == "samus") |
307 return 256; | 310 return 256; |
308 return 512; | 311 return kMinimumOutputBufferSize; |
309 } | 312 } |
310 | 313 |
311 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( | 314 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
312 const std::string& output_device_id, | 315 const std::string& output_device_id, |
313 const AudioParameters& input_params) { | 316 const AudioParameters& input_params) { |
314 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 317 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
315 int sample_rate = kDefaultSampleRate; | 318 int sample_rate = kDefaultSampleRate; |
316 int buffer_size = GetMinimumOutputBufferSizePerBoard(); | 319 int buffer_size = GetMinimumOutputBufferSizePerBoard(); |
317 int bits_per_sample = 16; | 320 int bits_per_sample = 16; |
318 if (input_params.IsValid()) { | 321 if (input_params.IsValid()) { |
319 sample_rate = input_params.sample_rate(); | 322 sample_rate = input_params.sample_rate(); |
320 bits_per_sample = input_params.bits_per_sample(); | 323 bits_per_sample = input_params.bits_per_sample(); |
321 channel_layout = input_params.channel_layout(); | 324 channel_layout = input_params.channel_layout(); |
322 buffer_size = | 325 buffer_size = |
323 std::min(static_cast<int>(limits::kMaxAudioBufferSize), | 326 std::min(kMaximumOutputBufferSize, |
324 std::max(static_cast<int>(limits::kMinAudioBufferSize), | 327 std::max(buffer_size, input_params.frames_per_buffer())); |
325 input_params.frames_per_buffer())); | |
326 } | 328 } |
327 | 329 |
328 int user_buffer_size = GetUserBufferSize(); | 330 int user_buffer_size = GetUserBufferSize(); |
329 if (user_buffer_size) | 331 if (user_buffer_size) |
330 buffer_size = user_buffer_size; | 332 buffer_size = user_buffer_size; |
331 | 333 |
332 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 334 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
333 sample_rate, bits_per_sample, buffer_size); | 335 sample_rate, bits_per_sample, buffer_size); |
334 } | 336 } |
335 | 337 |
(...skipping 25 matching lines...) Expand all Loading... |
361 | 363 |
362 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | 364 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
363 AudioDeviceNames device_names; | 365 AudioDeviceNames device_names; |
364 GetAudioDeviceNamesImpl(is_input, &device_names); | 366 GetAudioDeviceNamesImpl(is_input, &device_names); |
365 DCHECK(!device_names.empty()); | 367 DCHECK(!device_names.empty()); |
366 const AudioDeviceName& device_name = device_names.front(); | 368 const AudioDeviceName& device_name = device_names.front(); |
367 return device_name.unique_id == device_id; | 369 return device_name.unique_id == device_id; |
368 } | 370 } |
369 | 371 |
370 } // namespace media | 372 } // namespace media |
OLD | NEW |