Chromium Code Reviews| Index: media/audio/cras/audio_manager_cras.cc |
| diff --git a/media/audio/cras/audio_manager_cras.cc b/media/audio/cras/audio_manager_cras.cc |
| index 6df14bc87191ff8ac16eed8ed3482fca43d53ada..7d11aa19ec930699f017d6efb5feaf36fb6d4250 100644 |
| --- a/media/audio/cras/audio_manager_cras.cc |
| +++ b/media/audio/cras/audio_manager_cras.cc |
| @@ -49,6 +49,10 @@ const int kDefaultInputBufferSize = 1024; |
| const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
| const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
| +// Labels for showing audio devices with internal nodes. |
| +const char kInternalInputDevice[] = "Headset/Front Mic"; |
| +const char kInternalOutputDevice[] = "HP/Speaker"; |
| + |
| enum CrosBeamformingDeviceState { |
| BEAMFORMING_DEFAULT_ENABLED = 0, |
| BEAMFORMING_USER_ENABLED, |
| @@ -159,15 +163,42 @@ void AudioManagerCras::GetAudioDeviceNamesImpl(bool is_input, |
| if (is_input && mic_positions_.size() > 1) |
| AddBeamformingDevices(device_names); |
| else |
| - device_names->push_back(media::AudioDeviceName::CreateDefault()); |
| + device_names->push_back(AudioDeviceName::CreateDefault()); |
| if (base::FeatureList::IsEnabled(features::kEnumerateAudioDevices)) { |
| chromeos::AudioDeviceList devices; |
| chromeos::CrasAudioHandler::Get()->GetAudioDevices(&devices); |
| + |
| + int internal_input_dev_index = 0; |
| + int internal_output_dev_index = 0; |
| + for (const auto& device : devices) { |
| + if (device.type == chromeos::AUDIO_TYPE_INTERNAL_MIC) |
| + internal_input_dev_index = dev_index_of(device.id); |
| + else if (device.type == chromeos::AUDIO_TYPE_INTERNAL_SPEAKER) |
|
dgreid
2016/11/29 19:38:44
How does this work on devices without a speaker no
Qiang(Joe) Xu
2016/11/29 21:57:47
For devices without a speaker node or internal mic
dgreid
2016/11/29 23:23:18
Got it. Yes, I hadn't fully understood the code h
|
| + internal_output_dev_index = dev_index_of(device.id); |
| + } |
| + |
| + bool has_internal_input = false; |
| + bool has_internal_output = false; |
| for (const auto& device : devices) { |
| if (device.is_input == is_input && device.is_for_simple_usage()) { |
| - device_names->emplace_back(device.display_name, |
| - base::Uint64ToString(device.id)); |
| + int dev_index = dev_index_of(device.id); |
| + if (dev_index == internal_input_dev_index) { |
| + if (!has_internal_input) { |
| + device_names->emplace_back(kInternalInputDevice, |
| + base::Uint64ToString(device.id)); |
| + has_internal_input = true; |
| + } |
| + } else if (dev_index == internal_output_dev_index) { |
| + if (!has_internal_output) { |
| + device_names->emplace_back(kInternalOutputDevice, |
| + base::Uint64ToString(device.id)); |
| + has_internal_output = true; |
| + } |
| + } else { |
| + device_names->emplace_back(device.display_name, |
| + base::Uint64ToString(device.id)); |
| + } |
|
dgreid
2016/11/29 19:38:44
Can you summarize what this code does?
Is "Replac
Qiang(Joe) Xu
2016/11/29 21:57:47
"Replace the internal and external device names wi
dgreid
2016/11/29 23:23:18
OK, can you add a comment with a summary? It was
Qiang(Joe) Xu
2016/11/30 01:01:17
Done.
|
| } |
| } |
| } |
| @@ -232,17 +263,17 @@ AudioOutputStream* AudioManagerCras::MakeLinearOutputStream( |
| const AudioParameters& params, |
| const LogCallback& log_callback) { |
| DCHECK_EQ(AudioParameters::AUDIO_PCM_LINEAR, params.format()); |
| - return MakeOutputStream(params); |
| + // (warx): pinning stream is not supported for MakeLinearOutputStream. |
| + return MakeOutputStream(params, AudioDeviceDescription::kDefaultDeviceId); |
| } |
| AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( |
| const AudioParameters& params, |
| const std::string& device_id, |
| const LogCallback& log_callback) { |
| - DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; |
| DCHECK_EQ(AudioParameters::AUDIO_PCM_LOW_LATENCY, params.format()); |
| // TODO(dgreid): Open the correct input device for unified IO. |
| - return MakeOutputStream(params); |
| + return MakeOutputStream(params, device_id); |
| } |
| AudioInputStream* AudioManagerCras::MakeLinearInputStream( |
| @@ -264,8 +295,6 @@ AudioInputStream* AudioManagerCras::MakeLowLatencyInputStream( |
| AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
| const std::string& output_device_id, |
| const AudioParameters& input_params) { |
| - // TODO(tommi): Support |output_device_id|. |
| - DLOG_IF(ERROR, !output_device_id.empty()) << "Not implemented!"; |
| ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| int sample_rate = kDefaultSampleRate; |
| int buffer_size = kMinimumOutputBufferSize; |
| @@ -288,8 +317,9 @@ AudioParameters AudioManagerCras::GetPreferredOutputStreamParameters( |
| } |
| AudioOutputStream* AudioManagerCras::MakeOutputStream( |
| - const AudioParameters& params) { |
| - return new CrasUnifiedStream(params, this); |
| + const AudioParameters& params, |
| + const std::string& device_id) { |
| + return new CrasUnifiedStream(params, this, device_id); |
| } |
| AudioInputStream* AudioManagerCras::MakeInputStream( |
| @@ -312,4 +342,12 @@ snd_pcm_format_t AudioManagerCras::BitsToFormat(int bits_per_sample) { |
| } |
| } |
| +bool AudioManagerCras::IsDefault(const std::string& device_id, bool is_input) { |
| + AudioDeviceNames device_names; |
| + GetAudioDeviceNamesImpl(is_input, &device_names); |
| + DCHECK(!device_names.empty()); |
| + AudioDeviceName device_name = device_names.front(); |
| + return device_name.unique_id == device_id; |
| +} |
| + |
| } // namespace media |