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 | 10 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 | 152 |
| 153 void AudioManagerCras::GetAudioDeviceNamesImpl(bool is_input, | 153 void AudioManagerCras::GetAudioDeviceNamesImpl(bool is_input, |
| 154 AudioDeviceNames* device_names) { | 154 AudioDeviceNames* device_names) { |
| 155 DCHECK(device_names->empty()); | 155 DCHECK(device_names->empty()); |
| 156 // At least two mic positions indicates we have a beamforming capable mic | 156 // At least two mic positions indicates we have a beamforming capable mic |
| 157 // array. Add the virtual beamforming device to the list. When this device is | 157 // array. Add the virtual beamforming device to the list. When this device is |
| 158 // queried through GetInputStreamParameters, provide the cached mic positions. | 158 // queried through GetInputStreamParameters, provide the cached mic positions. |
| 159 if (is_input && mic_positions_.size() > 1) | 159 if (is_input && mic_positions_.size() > 1) |
| 160 AddBeamformingDevices(device_names); | 160 AddBeamformingDevices(device_names); |
| 161 else | 161 else |
| 162 device_names->push_back(media::AudioDeviceName::CreateDefault()); | 162 device_names->push_back(AudioDeviceName::CreateDefault()); |
| 163 | 163 |
| 164 if (base::FeatureList::IsEnabled(features::kEnumerateAudioDevices)) { | 164 if (base::FeatureList::IsEnabled(features::kEnumerateAudioDevices)) { |
| 165 chromeos::AudioDeviceList devices; | 165 chromeos::AudioDeviceList devices; |
| 166 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); | 166 chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| 167 for (const auto& device : devices) { | 167 for (const auto& device : devices) { |
| 168 if (device.is_input == is_input && device.is_for_simple_usage()) { | 168 if (device.is_input == is_input && device.is_for_simple_usage()) { |
| 169 device_names->emplace_back(device.display_name, | 169 device_names->emplace_back(device.display_name, |
| 170 base::Uint64ToString(device.id)); | 170 base::Uint64ToString(device.id)); |
| 171 } | 171 } |
| 172 } | 172 } |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 229 } | 229 } |
| 230 | 230 |
| 231 const char* AudioManagerCras::GetName() { | 231 const char* AudioManagerCras::GetName() { |
| 232 return "CRAS"; | 232 return "CRAS"; |
| 233 } | 233 } |
| 234 | 234 |
| 235 AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( | 235 AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( |
| 236 const AudioParameters& params, | 236 const AudioParameters& params, |
| 237 const LogCallback& log_callback) { | 237 const LogCallback& log_callback) { |
| 238 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 238 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 239 return MakeOutputStream(params); | 239 // (warx): pinning stream is not supported for MakeLinearOutputStream. |
|
tommi (sloooow) - chröme
2017/01/25 22:05:28
nit: as is this reads like it was meant to be a TO
Qiang(Joe) Xu
2017/01/25 22:50:18
Done.
| |
| 240 return MakeOutputStream(params, AudioDeviceDescription::kDefaultDeviceId); | |
| 240 } | 241 } |
| 241 | 242 |
| 242 AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( | 243 AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( |
| 243 const AudioParameters& params, | 244 const AudioParameters& params, |
| 244 const std::string& device_id, | 245 const std::string& device_id, |
| 245 const LogCallback& log_callback) { | 246 const LogCallback& log_callback) { |
| 246 DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; | |
| 247 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 247 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 248 // TODO(dgreid): Open the correct input device for unified IO. | 248 // TODO(dgreid): Open the correct input device for unified IO. |
| 249 return MakeOutputStream(params); | 249 return MakeOutputStream(params, device_id); |
| 250 } | 250 } |
| 251 | 251 |
| 252 AudioInputStream* AudioManagerCras::MakeLinearInputStream( | 252 AudioInputStream* AudioManagerCras::MakeLinearInputStream( |
| 253 const AudioParameters& params, | 253 const AudioParameters& params, |
| 254 const std::string& device_id, | 254 const std::string& device_id, |
| 255 const LogCallback& log_callback) { | 255 const LogCallback& log_callback) { |
| 256 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); | 256 DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| 257 return MakeInputStream(params, device_id); | 257 return MakeInputStream(params, device_id); |
| 258 } | 258 } |
| 259 | 259 |
| 260 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( | 260 AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( |
| 261 const AudioParameters& params, | 261 const AudioParameters& params, |
| 262 const std::string& device_id, | 262 const std::string& device_id, |
| 263 const LogCallback& log_callback) { | 263 const LogCallback& log_callback) { |
| 264 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); | 264 DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| 265 return MakeInputStream(params, device_id); | 265 return MakeInputStream(params, device_id); |
| 266 } | 266 } |
| 267 | 267 |
| 268 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( | 268 AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
| 269 const std::string& output_device_id, | 269 const std::string& output_device_id, |
| 270 const AudioParameters& input_params) { | 270 const AudioParameters& input_params) { |
| 271 // TODO(tommi): Support |output_device_id|. | |
| 272 DLOG_IF(ERROR, !output_device_id.empty()) << "Not implemented!"; | |
| 273 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; | 271 ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| 274 int sample_rate = kDefaultSampleRate; | 272 int sample_rate = kDefaultSampleRate; |
| 275 int buffer_size = kMinimumOutputBufferSize; | 273 int buffer_size = kMinimumOutputBufferSize; |
| 276 int bits_per_sample = 16; | 274 int bits_per_sample = 16; |
| 277 if (input_params.IsValid()) { | 275 if (input_params.IsValid()) { |
| 278 sample_rate = input_params.sample_rate(); | 276 sample_rate = input_params.sample_rate(); |
| 279 bits_per_sample = input_params.bits_per_sample(); | 277 bits_per_sample = input_params.bits_per_sample(); |
| 280 channel_layout = input_params.channel_layout(); | 278 channel_layout = input_params.channel_layout(); |
| 281 buffer_size = | 279 buffer_size = |
| 282 std::min(kMaximumOutputBufferSize, | 280 std::min(kMaximumOutputBufferSize, |
| 283 std::max(buffer_size, input_params.frames_per_buffer())); | 281 std::max(buffer_size, input_params.frames_per_buffer())); |
| 284 } | 282 } |
| 285 | 283 |
| 286 int user_buffer_size = GetUserBufferSize(); | 284 int user_buffer_size = GetUserBufferSize(); |
| 287 if (user_buffer_size) | 285 if (user_buffer_size) |
| 288 buffer_size = user_buffer_size; | 286 buffer_size = user_buffer_size; |
| 289 | 287 |
| 290 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, | 288 return AudioParameters(AudioParameters::AUDIO_PCM_LOW_LATENCY, channel_layout, |
| 291 sample_rate, bits_per_sample, buffer_size); | 289 sample_rate, bits_per_sample, buffer_size); |
| 292 } | 290 } |
| 293 | 291 |
| 294 AudioOutputStream* AudioManagerCras::MakeOutputStream( | 292 AudioOutputStream* AudioManagerCras::MakeOutputStream( |
| 295 const AudioParameters& params) { | 293 const AudioParameters& params, |
| 296 return new CrasUnifiedStream(params, this); | 294 const std::string& device_id) { |
| 295 return new CrasUnifiedStream(params, this, device_id); | |
| 297 } | 296 } |
| 298 | 297 |
| 299 AudioInputStream* AudioManagerCras::MakeInputStream( | 298 AudioInputStream* AudioManagerCras::MakeInputStream( |
| 300 const AudioParameters& params, const std::string& device_id) { | 299 const AudioParameters& params, const std::string& device_id) { |
| 301 return new CrasInputStream(params, this, device_id); | 300 return new CrasInputStream(params, this, device_id); |
| 302 } | 301 } |
| 303 | 302 |
| 304 snd_pcm_format_t AudioManagerCras::BitsToFormat(int bits_per_sample) { | 303 snd_pcm_format_t AudioManagerCras::BitsToFormat(int bits_per_sample) { |
| 305 switch (bits_per_sample) { | 304 switch (bits_per_sample) { |
| 306 case 8: | 305 case 8: |
| 307 return SND_PCM_FORMAT_U8; | 306 return SND_PCM_FORMAT_U8; |
| 308 case 16: | 307 case 16: |
| 309 return SND_PCM_FORMAT_S16; | 308 return SND_PCM_FORMAT_S16; |
| 310 case 24: | 309 case 24: |
| 311 return SND_PCM_FORMAT_S24; | 310 return SND_PCM_FORMAT_S24; |
| 312 case 32: | 311 case 32: |
| 313 return SND_PCM_FORMAT_S32; | 312 return SND_PCM_FORMAT_S32; |
| 314 default: | 313 default: |
| 315 return SND_PCM_FORMAT_UNKNOWN; | 314 return SND_PCM_FORMAT_UNKNOWN; |
| 316 } | 315 } |
| 317 } | 316 } |
| 318 | 317 |
| 318 bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { | |
| 319 AudioDeviceNames device_names; | |
| 320 GetAudioDeviceNamesImpl(is_input, &device_names); | |
| 321 DCHECK(!device_names.empty()); | |
| 322 AudioDeviceName device_name = device_names.front(); | |
|
tommi (sloooow) - chröme
2017/01/25 22:05:28
nit: no need to copy to a new AudioDeviceName inst
Qiang(Joe) Xu
2017/01/25 22:50:18
Done.
| |
| 323 return device_name.unique_id == device_id; | |
| 324 } | |
| 325 | |
| 319 } // namespace media | 326 } // namespace media |
| OLD | NEW |