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" | |
20 #include "chromeos/audio/audio_device.h" | 19 #include "chromeos/audio/audio_device.h" |
21 #include "chromeos/audio/cras_audio_handler.h" | 20 #include "chromeos/audio/cras_audio_handler.h" |
22 #include "media/audio/audio_device_description.h" | 21 #include "media/audio/audio_device_description.h" |
23 #include "media/audio/audio_features.h" | 22 #include "media/audio/audio_features.h" |
24 #include "media/audio/cras/cras_input.h" | 23 #include "media/audio/cras/cras_input.h" |
25 #include "media/audio/cras/cras_unified.h" | 24 #include "media/audio/cras/cras_unified.h" |
26 #include "media/base/channel_layout.h" | 25 #include "media/base/channel_layout.h" |
27 #include "media/base/localized_strings.h" | 26 #include "media/base/localized_strings.h" |
28 | 27 |
29 // cras_util.h headers pull in min/max macros... | 28 // cras_util.h headers pull in min/max macros... |
30 // TODO(dgreid): Fix headers such that these aren't imported. | 29 // TODO(dgreid): Fix headers such that these aren't imported. |
31 #undef min | 30 #undef min |
32 #undef max | 31 #undef max |
33 | 32 |
34 namespace media { | 33 namespace media { |
35 namespace { | 34 namespace { |
36 | 35 |
37 // Maximum number of output streams that can be open simultaneously. | 36 // Maximum number of output streams that can be open simultaneously. |
38 const int kMaxOutputStreams = 50; | 37 const int kMaxOutputStreams = 50; |
39 | 38 |
40 // Default sample rate for input and output streams. | 39 // Default sample rate for input and output streams. |
41 const int kDefaultSampleRate = 48000; | 40 const int kDefaultSampleRate = 48000; |
42 | 41 |
43 // Define bounds for the output buffer size. | |
44 const int kMinimumOutputBufferSize = 512; | |
45 const int kMaximumOutputBufferSize = 8192; | |
46 | |
47 // Default input buffer size. | 42 // Default input buffer size. |
48 const int kDefaultInputBufferSize = 1024; | 43 const int kDefaultInputBufferSize = 1024; |
49 | 44 |
50 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; | 45 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
51 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; | 46 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
52 | 47 |
53 const char kInternalInputVirtualDevice[] = "Built-in mic"; | 48 const char kInternalInputVirtualDevice[] = "Built-in mic"; |
54 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; | 49 const char kInternalOutputVirtualDevice[] = "Built-in speaker"; |
55 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; | 50 const char kHeadphoneLineOutVirtualDevice[] = "Headphone/Line Out"; |
56 | 51 |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 } | 288 } |
294 | 289 |
295 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( | 290 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( |
296 const AudioParameters& params, | 291 const AudioParameters& params, |
297 const std::string& device_id, | 292 const std::string& device_id, |
298 const LogCallback& log_callback) { | 293 const LogCallback& log_callback) { |
299 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 294 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
300 return MakeInputStream(params, device_id); | 295 return MakeInputStream(params, device_id); |
301 } | 296 } |
302 | 297 |
303 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { | |
304 // 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. | |
306 std::string board = base::SysInfo::GetLsbReleaseBoard(); | |
307 if (board == "kevin") | |
308 return 768; | |
309 else if (board == "samus") | |
310 return 256; | |
311 return kMinimumOutputBufferSize; | |
312 } | |
313 | |
314 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( | 298 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
315 const std::string& output_device_id, | 299 const std::string& output_device_id, |
316 const AudioParameters& input_params) { | 300 const AudioParameters& input_params) { |
317 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 301 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
318 int sample_rate = kDefaultSampleRate; | 302 int sample_rate = kDefaultSampleRate; |
319 int buffer_size = GetMinimumOutputBufferSizePerBoard(); | 303 int buffer_size = AudioLatency::GetDefaultAudioBufferSize(false, sample_rate); |
o1ka
2017/05/30 16:04:33
Sorry, now I lost the track of what is going on.
W
| |
320 int bits_per_sample = 16; | 304 int bits_per_sample = 16; |
321 if (input_params.IsValid()) { | 305 if (input_params.IsValid()) { |
322 sample_rate = input_params.sample_rate(); | 306 sample_rate = input_params.sample_rate(); |
323 bits_per_sample = input_params.bits_per_sample(); | 307 bits_per_sample = input_params.bits_per_sample(); |
324 channel_layout = input_params.channel_layout(); | 308 channel_layout = input_params.channel_layout(); |
325 buffer_size = | 309 buffer_size = |
326 std::min(kMaximumOutputBufferSize, | 310 std::min(AudioLatency::GetMaximumAudioBufferSize(sample_rate), |
327 std::max(buffer_size, input_params.frames_per_buffer())); | 311 std::max(buffer_size, input_params.frames_per_buffer())); |
328 } | 312 } |
329 | 313 |
330 int user_buffer_size = GetUserBufferSize(); | 314 int user_buffer_size = GetUserBufferSize(); |
331 if (user_buffer_size) | 315 if (user_buffer_size) |
332 buffer_size = user_buffer_size; | 316 buffer_size = user_buffer_size; |
333 | 317 |
334 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 318 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
335 sample_rate, bits_per_sample, buffer_size); | 319 sample_rate, bits_per_sample, buffer_size); |
336 } | 320 } |
(...skipping 26 matching lines...) Expand all Loading... | |
363 | 347 |
364 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | 348 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
365 AudioDeviceNames device_names; | 349 AudioDeviceNames device_names; |
366 GetAudioDeviceNamesImpl(is_input, &device_names); | 350 GetAudioDeviceNamesImpl(is_input, &device_names); |
367 DCHECK(!device_names.empty()); | 351 DCHECK(!device_names.empty()); |
368 const AudioDeviceName& device_name = device_names.front(); | 352 const AudioDeviceName& device_name = device_names.front(); |
369 return device_name.unique_id == device_id; | 353 return device_name.unique_id == device_id; |
370 } | 354 } |
371 | 355 |
372 } // namespace media | 356 } // namespace media |
OLD | NEW |