Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: media/audio/cras/audio_manager_cras.cc

Issue 2516813002: Enable pinning stream output routing for webapp request on ChromeOS (Closed)
Patch Set: comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a05789037e0089ccea1b275c063c3f7b819fff17 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,48 @@ 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);
+
+ // Find if there exists |AUDIO_TYPE_INTERNAL_MIC| or
+ // |AUDIO_TYPE_INTERNAL_SPEAKER|. If so, labeling the audio nodes that are
+ // on internal devices using kInternalInputDevice or kInternalOutputDevice
+ // and skip duplicates since pinning stream is pinned on device not node.
+ // We only need to take care whenever there exists internal mic or internal
+ // speaker since only internal device supports two nodes.
+ 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(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));
+ }
}
}
}
@@ -232,17 +269,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 +301,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 +323,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 +348,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

Powered by Google App Engine
This is Rietveld 408576698