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..8b29b619a2a82482e171331f35f2ac225a8406b7 100644 |
| --- a/media/audio/cras/audio_manager_cras.cc |
| +++ b/media/audio/cras/audio_manager_cras.cc |
| @@ -49,6 +49,8 @@ const int kDefaultInputBufferSize = 1024; |
| const char kBeamformingOnDeviceId[] = "default-beamforming-on"; |
| const char kBeamformingOffDeviceId[] = "default-beamforming-off"; |
| +const char kInternal[] = "Internal"; |
| + |
| enum CrosBeamformingDeviceState { |
| BEAMFORMING_DEFAULT_ENABLED = 0, |
| BEAMFORMING_USER_ENABLED, |
| @@ -159,15 +161,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) |
| + 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(kInternal, |
| + base::Uint64ToString(device.id)); |
| + has_internal_input = true; |
| + } |
| + } else if (dev_index == internal_output_dev_index) { |
| + if (!has_internal_output) { |
| + device_names->emplace_back(kInternal, |
| + base::Uint64ToString(device.id)); |
| + has_internal_output = true; |
| + } |
| + } else { |
| + device_names->emplace_back(device.display_name, |
| + base::Uint64ToString(device.id)); |
| + } |
| } |
| } |
| } |
| @@ -232,17 +261,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. |
|
Qiang(Joe) Xu
2016/11/19 00:41:44
shall we open a new bug to track this? I don't hav
|
| + return MakeOutputStream(params, AudioDeviceName::CreateDefault().unique_id); |
| } |
| AudioOutputStream* AudioManagerCras::MakeLowLatencyOutputStream( |
| const AudioParameters& params, |
| const std::string& device_id, |
| const LogCallback& log_callback) { |
| - DLOG_IF(ERROR, !device_id.empty()) << "Not implemented!"; |
|
Qiang(Joe) Xu
2016/11/19 00:41:44
it is now supported
|
| 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 +293,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!"; |
|
Qiang(Joe) Xu
2016/11/19 00:41:44
it is now supported
|
| ChannelLayout channel_layout = CHANNEL_LAYOUT_STEREO; |
| int sample_rate = kDefaultSampleRate; |
| int buffer_size = kMinimumOutputBufferSize; |
| @@ -288,8 +315,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 +340,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 |