Chromium Code Reviews| 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 #include <map> | |
| 10 | 11 |
| 11 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 12 #include "base/environment.h" | 13 #include "base/environment.h" |
| 13 #include "base/logging.h" | 14 #include "base/logging.h" |
| 14 #include "base/metrics/field_trial.h" | 15 #include "base/metrics/field_trial.h" |
| 15 #include "base/metrics/histogram_macros.h" | 16 #include "base/metrics/histogram_macros.h" |
| 16 #include "base/nix/xdg_util.h" | 17 #include "base/nix/xdg_util.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| 18 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 20 #include "base/sys_info.h" | |
| 19 #include "chromeos/audio/audio_device.h" | 21 #include "chromeos/audio/audio_device.h" |
| 20 #include "chromeos/audio/cras_audio_handler.h" | 22 #include "chromeos/audio/cras_audio_handler.h" |
| 21 #include "media/audio/audio_device_description.h" | 23 #include "media/audio/audio_device_description.h" |
| 22 #include "media/audio/audio_features.h" | 24 #include "media/audio/audio_features.h" |
| 23 #include "media/audio/cras/cras_input.h" | 25 #include "media/audio/cras/cras_input.h" |
| 24 #include "media/audio/cras/cras_unified.h" | 26 #include "media/audio/cras/cras_unified.h" |
| 25 #include "media/base/channel_layout.h" | 27 #include "media/base/channel_layout.h" |
| 26 #include "media/base/localized_strings.h" | 28 #include "media/base/localized_strings.h" |
| 27 | 29 |
| 28 // cras_util.h headers pull in min/max macros... | 30 // cras_util.h headers pull in min/max macros... |
| 29 // TODO(dgreid): Fix headers such that these aren't imported. | 31 // TODO(dgreid): Fix headers such that these aren't imported. |
| 30 #undef min | 32 #undef min |
| 31 #undef max | 33 #undef max |
| 32 | 34 |
| 33 namespace media { | 35 namespace media { |
| 34 namespace { | 36 namespace { |
| 35 | 37 |
| 36 // Maximum number of output streams that can be open simultaneously. | 38 // Maximum number of output streams that can be open simultaneously. |
| 37 const int kMaxOutputStreams = 50; | 39 const int kMaxOutputStreams = 50; |
| 38 | 40 |
| 39 // Default sample rate for input and output streams. | 41 // Default sample rate for input and output streams. |
| 40 const int kDefaultSampleRate = 48000; | 42 const int kDefaultSampleRate = 48000; |
| 41 | 43 |
| 42 // Define bounds for the output buffer size. | 44 // Define bounds for the output buffer size. |
| 43 const int kMinimumOutputBufferSize = 512; | 45 const int kMinimumOutputBufferSize = 512; |
| 44 const int kMaximumOutputBufferSize = 8192; | 46 const int kMaximumOutputBufferSize = 8192; |
| 45 | 47 |
| 48 // Boards with customized minimum output buffer size. | |
| 49 const std::map<std::string, int> kCustomizedOutputBufferSizeMap = { | |
|
DaleCurtis
2017/03/30 16:17:42
This is a static initializer, you should instead j
cychiang
2017/04/07 08:45:41
Done.
| |
| 50 {"samus", 256}, | |
| 51 {"kevin", 768}}; | |
| 52 | |
| 46 // Default input buffer size. | 53 // Default input buffer size. |
| 47 const int kDefaultInputBufferSize = 1024; | 54 const int kDefaultInputBufferSize = 1024; |
| 48 | 55 |
| 49 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; | 56 const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
| 50 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; | 57 const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
| 51 | 58 |
| 52 enum CrosBeamformingDeviceState { | 59 enum CrosBeamformingDeviceState { |
| 53 BEAMFORMING_DEFAULT_ENABLED = 0, | 60 BEAMFORMING_DEFAULT_ENABLED = 0, |
| 54 BEAMFORMING_USER_ENABLED, | 61 BEAMFORMING_USER_ENABLED, |
| 55 BEAMFORMING_DEFAULT_DISABLED, | 62 BEAMFORMING_DEFAULT_DISABLED, |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 258 } | 265 } |
| 259 | 266 |
| 260 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( | 267 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( |
| 261 const AudioParameters& params, | 268 const AudioParameters& params, |
| 262 const std::string& device_id, | 269 const std::string& device_id, |
| 263 const LogCallback& log_callback) { | 270 const LogCallback& log_callback) { |
| 264 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 271 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 265 return MakeInputStream(params, device_id); | 272 return MakeInputStream(params, device_id); |
| 266 } | 273 } |
| 267 | 274 |
| 275 int AudioManagerCras::GetMinimumOutputBufferSizePerBoard() { | |
| 276 std::string board = base::SysInfo::GetLsbReleaseBoard(); | |
| 277 if (kCustomizedOutputBufferSizeMap.find(board) != | |
| 278 kCustomizedOutputBufferSizeMap.end()) { | |
| 279 return kCustomizedOutputBufferSizeMap.at(board); | |
| 280 } | |
| 281 return kMinimumOutputBufferSize; | |
| 282 } | |
| 283 | |
| 268 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( | 284 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
| 269 const std::string& output_device_id, | 285 const std::string& output_device_id, |
| 270 const AudioParameters& input_params) { | 286 const AudioParameters& input_params) { |
| 271 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 287 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 272 int sample_rate = kDefaultSampleRate; | 288 int sample_rate = kDefaultSampleRate; |
| 273 int buffer_size = kMinimumOutputBufferSize; | 289 int buffer_size = GetMinimumOutputBufferSizePerBoard(); |
| 274 int bits_per_sample = 16; | 290 int bits_per_sample = 16; |
| 275 if (input_params.IsValid()) { | 291 if (input_params.IsValid()) { |
| 276 sample_rate = input_params.sample_rate(); | 292 sample_rate = input_params.sample_rate(); |
| 277 bits_per_sample = input_params.bits_per_sample(); | 293 bits_per_sample = input_params.bits_per_sample(); |
| 278 channel_layout = input_params.channel_layout(); | 294 channel_layout = input_params.channel_layout(); |
| 279 buffer_size = | 295 buffer_size = |
| 280 std::min(kMaximumOutputBufferSize, | 296 std::min(kMaximumOutputBufferSize, |
| 281 std::max(buffer_size, input_params.frames_per_buffer())); | 297 std::max(buffer_size, input_params.frames_per_buffer())); |
| 282 } | 298 } |
| 283 | 299 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 317 | 333 |
| 318 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | 334 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
| 319 AudioDeviceNames device_names; | 335 AudioDeviceNames device_names; |
| 320 GetAudioDeviceNamesImpl(is_input, &device_names); | 336 GetAudioDeviceNamesImpl(is_input, &device_names); |
| 321 DCHECK(!device_names.empty()); | 337 DCHECK(!device_names.empty()); |
| 322 const AudioDeviceName& device_name = device_names.front(); | 338 const AudioDeviceName& device_name = device_names.front(); |
| 323 return device_name.unique_id == device_id; | 339 return device_name.unique_id == device_id; |
| 324 } | 340 } |
| 325 | 341 |
| 326 } // namespace media | 342 } // namespace media |
| OLD | NEW |