Commit 18393545 authored by Yu-Hsuan Hsu's avatar Yu-Hsuan Hsu Committed by Commit Bot

Enable AEC in lacros-chrome

Make acros-chrome able to use AEC. The code is modified from
audio_manager_chromeos.

BUG=b:172639327

Change-Id: I812d1bef12d02ec96dfc5d84783c63dfdd1cfc68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2522016
Commit-Queue: Yu-Hsuan Hsu <yuhsuan@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825184}
parent e3be351b
......@@ -32,7 +32,7 @@ const base::Feature kUseAAudioDriver{"UseAAudioDriver",
base::FEATURE_ENABLED_BY_DEFAULT};
#endif
#if BUILDFLAG(IS_ASH)
#if BUILDFLAG(IS_ASH) || BUILDFLAG(IS_LACROS)
const base::Feature kCrOSSystemAEC{"CrOSSystemAEC",
base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kCrOSSystemAECDeactivatedGroups{
......
......@@ -19,7 +19,7 @@ MEDIA_EXPORT extern const base::Feature kDumpOnAudioServiceHang;
MEDIA_EXPORT extern const base::Feature kUseAAudioDriver;
#endif
#if BUILDFLAG(IS_ASH)
#if BUILDFLAG(IS_ASH) || BUILDFLAG(IS_LACROS)
MEDIA_EXPORT extern const base::Feature kCrOSSystemAEC;
MEDIA_EXPORT extern const base::Feature kCrOSSystemAECDeactivatedGroups;
#endif
......
......@@ -91,6 +91,28 @@ AudioParameters AudioManagerCras::GetInputStreamParameters(
kDefaultSampleRate, buffer_size,
AudioParameters::HardwareCapabilities(limits::kMinAudioBufferSize,
limits::kMaxAudioBufferSize));
// Allow experimentation with system echo cancellation with all devices,
// but enable it by default on devices that actually support it.
params.set_effects(params.effects() |
AudioParameters::EXPERIMENTAL_ECHO_CANCELLER);
if (base::FeatureList::IsEnabled(features::kCrOSSystemAEC)) {
if (CrasGetAecSupported()) {
const int32_t aec_group_id = CrasGetAecGroupId();
// Check if the system AEC has a group ID which is flagged to be
// deactivated by the field trial.
const bool system_aec_deactivated =
base::GetFieldTrialParamByFeatureAsBool(
features::kCrOSSystemAECDeactivatedGroups,
base::NumberToString(aec_group_id), false);
if (!system_aec_deactivated) {
params.set_effects(params.effects() | AudioParameters::ECHO_CANCELLER);
}
}
}
return params;
}
......
......@@ -108,4 +108,25 @@ std::vector<CrasDevice> CrasGetAudioDevices(DeviceType type) {
return devices;
}
int CrasGetAecSupported() {
cras_client* client = CrasConnect();
if (!client)
return 0;
int rc = cras_client_get_aec_supported(client);
CrasDisconnect(&client);
return rc;
}
int CrasGetAecGroupId() {
cras_client* client = CrasConnect();
if (!client)
return -1;
int rc = cras_client_get_aec_group_id(client);
CrasDisconnect(&client);
return rc;
}
} // namespace media
......@@ -28,6 +28,13 @@ struct CrasDevice {
// Enumerates all devices of |type|.
std::vector<CrasDevice> CrasGetAudioDevices(DeviceType type);
// Returns if system AEC is supported in CRAS.
int CrasGetAecSupported();
// Returns the system AEC group ID. If no group ID is specified, -1 is
// returned.
int CrasGetAecGroupId();
} // namespace media
#endif // MEDIA_AUDIO_CRAS_CRAS_UTIL_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment