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