Commit 2afeb1a6 authored by Sergei Datsenko's avatar Sergei Datsenko Committed by Chromium LUCI CQ

Revert "Move |AudioInputHost| to |AssistantManagerServiceImpl|"

This reverts commit c307ddb3.

Reason for revert: Blocks revert of crrev.com/c/2610953

Original change's description:
> Move |AudioInputHost| to |AssistantManagerServiceImpl|
>
> The main goal is to ensure we can create |AudioInputHost| independently
> of |PlatformApiImpl|.
>
> This CL also makes |AudioInputHost| virtual so it can be faked during
> the unittests of |AssistantManagerServiceImpl|.
>
> Bug: b/171748795
> Test: chromeos_unittests --gtest_filter="Assistant*:Audio*"
> Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
> Change-Id: Ic41ff343b28dae801b0c5f4c8c6417267270d8a2
> Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2610047
> Commit-Queue: Jeroen Dhollander <jeroendh@chromium.org>
> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#841226}

TBR=xiaohuic@chromium.org,meilinw@chromium.org,chromium-scoped@luci-project-accounts.iam.gserviceaccount.com,jeroendh@chromium.org

Change-Id: Ibd2ba5ed1a0388bbf80289812f356ba353015b9c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/171748795
Cq-Include-Trybots: luci.chrome.try:linux-chromeos-chrome
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2615735Reviewed-by: default avatarSergei Datsenko <dats@chromium.org>
Commit-Queue: Sergei Datsenko <dats@chromium.org>
Cr-Commit-Position: refs/heads/master@{#841457}
parent a82bd4e7
...@@ -82,8 +82,8 @@ component("lib") { ...@@ -82,8 +82,8 @@ component("lib") {
"media_session/assistant_media_session.h", "media_session/assistant_media_session.h",
"platform/audio_device_owner.cc", "platform/audio_device_owner.cc",
"platform/audio_device_owner.h", "platform/audio_device_owner.h",
"platform/audio_input_host_impl.cc", "platform/audio_input_host.cc",
"platform/audio_input_host_impl.h", "platform/audio_input_host.h",
"platform/audio_input_impl.cc", "platform/audio_input_impl.cc",
"platform/audio_input_impl.h", "platform/audio_input_impl.h",
"platform/audio_input_provider_impl.cc", "platform/audio_input_provider_impl.cc",
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <utility> #include <utility>
#include "ash/public/cpp/assistant/assistant_state_base.h" #include "ash/public/cpp/assistant/assistant_state_base.h"
#include "chromeos/services/assistant/platform/audio_input_host_impl.h"
#include "chromeos/services/assistant/platform_api_impl.h" #include "chromeos/services/assistant/platform_api_impl.h"
#include "chromeos/services/assistant/service_context.h" #include "chromeos/services/assistant/service_context.h"
#include "libassistant/shared/internal_api/assistant_manager_internal.h" #include "libassistant/shared/internal_api/assistant_manager_internal.h"
...@@ -21,26 +20,21 @@ namespace assistant { ...@@ -21,26 +20,21 @@ namespace assistant {
AssistantManagerServiceDelegateImpl::AssistantManagerServiceDelegateImpl( AssistantManagerServiceDelegateImpl::AssistantManagerServiceDelegateImpl(
mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor, mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor,
ServiceContext* context) ServiceContext* context)
: battery_monitor_(std::move(battery_monitor)), context_(context) {} : battery_monitor_(std::move(battery_monitor)),
context_(context) {}
AssistantManagerServiceDelegateImpl::~AssistantManagerServiceDelegateImpl() = AssistantManagerServiceDelegateImpl::~AssistantManagerServiceDelegateImpl() =
default; default;
std::unique_ptr<AudioInputHost>
AssistantManagerServiceDelegateImpl::CreateAudioInputHost() {
return std::make_unique<AudioInputHostImpl>(
context_->cras_audio_handler(), context_->power_manager_client(),
context_->assistant_state()->locale().value());
}
std::unique_ptr<CrosPlatformApi> std::unique_ptr<CrosPlatformApi>
AssistantManagerServiceDelegateImpl::CreatePlatformApi( AssistantManagerServiceDelegateImpl::CreatePlatformApi(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner) { scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner) {
return std::make_unique<PlatformApiImpl>( return std::make_unique<PlatformApiImpl>(
media_session, context_->power_manager_client(), media_session, context_->power_manager_client(),
std::move(battery_monitor_), context_->main_task_runner(), context_->cras_audio_handler(), std::move(battery_monitor_),
background_thread_task_runner); context_->main_task_runner(), background_thread_task_runner,
context_->assistant_state()->locale().value());
} }
std::unique_ptr<assistant_client::AssistantManager> std::unique_ptr<assistant_client::AssistantManager>
......
...@@ -25,15 +25,15 @@ class AssistantManagerServiceDelegateImpl ...@@ -25,15 +25,15 @@ class AssistantManagerServiceDelegateImpl
ServiceContext* context); ServiceContext* context);
~AssistantManagerServiceDelegateImpl() override; ~AssistantManagerServiceDelegateImpl() override;
// AssistantManagerServiceDelegate implementation:
std::unique_ptr<AudioInputHost> CreateAudioInputHost() override;
std::unique_ptr<CrosPlatformApi> CreatePlatformApi( std::unique_ptr<CrosPlatformApi> CreatePlatformApi(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner) scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner)
override; override;
std::unique_ptr<assistant_client::AssistantManager> CreateAssistantManager( std::unique_ptr<assistant_client::AssistantManager> CreateAssistantManager(
assistant_client::PlatformApi* platform_api, assistant_client::PlatformApi* platform_api,
const std::string& lib_assistant_config) override; const std::string& lib_assistant_config) override;
assistant_client::AssistantManagerInternal* UnwrapAssistantManagerInternal( assistant_client::AssistantManagerInternal* UnwrapAssistantManagerInternal(
assistant_client::AssistantManager* assistant_manager) override; assistant_client::AssistantManager* assistant_manager) override;
......
...@@ -40,7 +40,6 @@ ...@@ -40,7 +40,6 @@
#include "chromeos/services/assistant/public/cpp/device_actions.h" #include "chromeos/services/assistant/public/cpp/device_actions.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/services/assistant/public/cpp/migration/assistant_manager_service_delegate.h" #include "chromeos/services/assistant/public/cpp/migration/assistant_manager_service_delegate.h"
#include "chromeos/services/assistant/public/cpp/migration/audio_input_host.h"
#include "chromeos/services/assistant/public/cpp/migration/libassistant_v1_api.h" #include "chromeos/services/assistant/public/cpp/migration/libassistant_v1_api.h"
#include "chromeos/services/assistant/public/shared/utils.h" #include "chromeos/services/assistant/public/shared/utils.h"
#include "chromeos/services/assistant/service_context.h" #include "chromeos/services/assistant/service_context.h"
...@@ -199,10 +198,6 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl( ...@@ -199,10 +198,6 @@ AssistantManagerServiceImpl::AssistantManagerServiceImpl(
// To solve this chicken-and-egg problem, we need a separe Initialize() call. // To solve this chicken-and-egg problem, we need a separe Initialize() call.
assistant_proxy_->Initialize(libassistant_service_host_.get()); assistant_proxy_->Initialize(libassistant_service_host_.get());
audio_input_host_ = delegate_->CreateAudioInputHost();
platform_api_->InitializeAudioInputHost(*audio_input_host_);
settings_delegate_ = settings_delegate_ =
std::make_unique<AssistantDeviceSettingsDelegate>(context); std::make_unique<AssistantDeviceSettingsDelegate>(context);
...@@ -366,7 +361,7 @@ void AssistantManagerServiceImpl::EnableListening(bool enable) { ...@@ -366,7 +361,7 @@ void AssistantManagerServiceImpl::EnableListening(bool enable) {
} }
void AssistantManagerServiceImpl::EnableHotword(bool enable) { void AssistantManagerServiceImpl::EnableHotword(bool enable) {
audio_input_host_->OnHotwordEnabled(enable); platform_api_->OnHotwordEnabled(enable);
} }
void AssistantManagerServiceImpl::SetArcPlayStoreEnabled(bool enable) { void AssistantManagerServiceImpl::SetArcPlayStoreEnabled(bool enable) {
...@@ -454,14 +449,14 @@ void AssistantManagerServiceImpl::StartVoiceInteraction() { ...@@ -454,14 +449,14 @@ void AssistantManagerServiceImpl::StartVoiceInteraction() {
DCHECK(assistant_manager()); DCHECK(assistant_manager());
DVLOG(1) << __func__; DVLOG(1) << __func__;
audio_input_host_->SetMicState(true); platform_api_->SetMicState(true);
assistant_manager()->StartAssistantInteraction(); assistant_manager()->StartAssistantInteraction();
} }
void AssistantManagerServiceImpl::StopActiveInteraction( void AssistantManagerServiceImpl::StopActiveInteraction(
bool cancel_conversation) { bool cancel_conversation) {
DVLOG(1) << __func__; DVLOG(1) << __func__;
audio_input_host_->SetMicState(false); platform_api_->SetMicState(false);
if (!assistant_manager_internal()) { if (!assistant_manager_internal()) {
VLOG(1) << "Stopping interaction without assistant manager."; VLOG(1) << "Stopping interaction without assistant manager.";
...@@ -583,7 +578,7 @@ void AssistantManagerServiceImpl::OnConversationTurnStartedInternal( ...@@ -583,7 +578,7 @@ void AssistantManagerServiceImpl::OnConversationTurnStartedInternal(
&AssistantManagerServiceImpl::OnConversationTurnStartedInternal, &AssistantManagerServiceImpl::OnConversationTurnStartedInternal,
metadata); metadata);
audio_input_host_->OnConversationTurnStarted(); platform_api_->OnConversationTurnStarted();
// Retrieve the cached interaction metadata associated with this conversation // Retrieve the cached interaction metadata associated with this conversation
// turn or construct a new instance if there's no match in the cache. // turn or construct a new instance if there's no match in the cache.
...@@ -612,10 +607,10 @@ void AssistantManagerServiceImpl::OnConversationTurnFinished( ...@@ -612,10 +607,10 @@ void AssistantManagerServiceImpl::OnConversationTurnFinished(
if (resolution != Resolution::NORMAL_WITH_FOLLOW_ON && if (resolution != Resolution::NORMAL_WITH_FOLLOW_ON &&
resolution != Resolution::CANCELLED && resolution != Resolution::CANCELLED &&
resolution != Resolution::BARGE_IN) { resolution != Resolution::BARGE_IN) {
audio_input_host_->SetMicState(false); platform_api_->SetMicState(false);
} }
audio_input_host_->OnConversationTurnFinished(); platform_api_->OnConversationTurnFinished();
switch (resolution) { switch (resolution) {
// Interaction ended normally. // Interaction ended normally.
...@@ -1401,11 +1396,6 @@ AssistantManagerServiceImpl::assistant_manager_internal() { ...@@ -1401,11 +1396,6 @@ AssistantManagerServiceImpl::assistant_manager_internal() {
return api ? api->assistant_manager_internal() : nullptr; return api ? api->assistant_manager_internal() : nullptr;
} }
void AssistantManagerServiceImpl::SetMicState(bool mic_open) {
DCHECK(audio_input_host_);
audio_input_host_->SetMicState(mic_open);
}
ServiceControllerProxy& AssistantManagerServiceImpl::service_controller() { ServiceControllerProxy& AssistantManagerServiceImpl::service_controller() {
return assistant_proxy_->service_controller(); return assistant_proxy_->service_controller();
} }
......
...@@ -63,7 +63,6 @@ class AssistantMediaSession; ...@@ -63,7 +63,6 @@ class AssistantMediaSession;
class AssistantDeviceSettingsDelegate; class AssistantDeviceSettingsDelegate;
class AssistantManagerServiceDelegate; class AssistantManagerServiceDelegate;
class AssistantProxy; class AssistantProxy;
class AudioInputHost;
class CrosPlatformApi; class CrosPlatformApi;
class ServiceContext; class ServiceContext;
class ServiceControllerProxy; class ServiceControllerProxy;
...@@ -221,7 +220,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl ...@@ -221,7 +220,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl
assistant_client::AssistantManager* assistant_manager(); assistant_client::AssistantManager* assistant_manager();
assistant_client::AssistantManagerInternal* assistant_manager_internal(); assistant_client::AssistantManagerInternal* assistant_manager_internal();
void SetMicState(bool mic_open); CrosPlatformApi* platform_api() { return platform_api_.get(); }
// assistant_client::MediaManager::Listener overrides: // assistant_client::MediaManager::Listener overrides:
void OnPlaybackStateChange( void OnPlaybackStateChange(
...@@ -314,7 +313,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl ...@@ -314,7 +313,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AssistantManagerServiceImpl
std::unique_ptr<AssistantSettingsImpl> assistant_settings_; std::unique_ptr<AssistantSettingsImpl> assistant_settings_;
std::unique_ptr<AssistantProxy> assistant_proxy_; std::unique_ptr<AssistantProxy> assistant_proxy_;
std::unique_ptr<AudioInputHost> audio_input_host_;
base::ObserverList<AssistantInteractionSubscriber> interaction_subscribers_; base::ObserverList<AssistantInteractionSubscriber> interaction_subscribers_;
mojo::Remote<media_session::mojom::MediaController> media_controller_; mojo::Remote<media_session::mojom::MediaController> media_controller_;
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#include "chromeos/dbus/util/version_loader.h" #include "chromeos/dbus/util/version_loader.h"
#include "chromeos/services/assistant/assistant_manager_service_impl.h" #include "chromeos/services/assistant/assistant_manager_service_impl.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/services/assistant/public/cpp/migration/cros_platform_api.h"
#include "chromeos/services/assistant/public/proto/assistant_device_settings_ui.pb.h" #include "chromeos/services/assistant/public/proto/assistant_device_settings_ui.pb.h"
#include "chromeos/services/assistant/public/proto/settings_ui.pb.h" #include "chromeos/services/assistant/public/proto/settings_ui.pb.h"
#include "chromeos/services/assistant/service_context.h" #include "chromeos/services/assistant/service_context.h"
...@@ -123,7 +124,7 @@ void AssistantSettingsImpl::StartSpeakerIdEnrollment( ...@@ -123,7 +124,7 @@ void AssistantSettingsImpl::StartSpeakerIdEnrollment(
DCHECK(main_task_runner()->RunsTasksInCurrentSequence()); DCHECK(main_task_runner()->RunsTasksInCurrentSequence());
DCHECK(!speaker_id_enrollment_client_); DCHECK(!speaker_id_enrollment_client_);
assistant_manager_service_->SetMicState(true); assistant_manager_service_->platform_api()->SetMicState(true);
if (!assistant_manager_service_->assistant_manager_internal()) if (!assistant_manager_service_->assistant_manager_internal())
return; return;
...@@ -152,7 +153,7 @@ void AssistantSettingsImpl::StopSpeakerIdEnrollment() { ...@@ -152,7 +153,7 @@ void AssistantSettingsImpl::StopSpeakerIdEnrollment() {
DCHECK(HasStarted(assistant_manager_service_)); DCHECK(HasStarted(assistant_manager_service_));
DCHECK(main_task_runner()->RunsTasksInCurrentSequence()); DCHECK(main_task_runner()->RunsTasksInCurrentSequence());
assistant_manager_service_->SetMicState(false); assistant_manager_service_->platform_api()->SetMicState(false);
if (!assistant_manager_service_->assistant_manager_internal()) if (!assistant_manager_service_->assistant_manager_internal())
return; return;
......
// Copyright 2021 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chromeos/services/assistant/platform/audio_input_host_impl.h" #include "chromeos/services/assistant/platform/audio_input_host.h"
#include "base/check.h" #include "base/check.h"
#include "base/optional.h" #include "base/optional.h"
...@@ -30,38 +30,35 @@ AudioInputImpl::LidState ConvertLidState( ...@@ -30,38 +30,35 @@ AudioInputImpl::LidState ConvertLidState(
} // namespace } // namespace
chromeos::assistant::AudioInputHostImpl::AudioInputHostImpl( chromeos::assistant::AudioInputHost::AudioInputHost(
AudioInputImpl* audio_input,
CrasAudioHandler* cras_audio_handler, CrasAudioHandler* cras_audio_handler,
chromeos::PowerManagerClient* power_manager_client, chromeos::PowerManagerClient* power_manager_client,
const std::string& locale) const std::string& locale)
: power_manager_client_(power_manager_client), : audio_input_(audio_input),
power_manager_client_(power_manager_client),
power_manager_client_observer_(this), power_manager_client_observer_(this),
audio_devices_(cras_audio_handler, locale) { audio_devices_(cras_audio_handler, locale) {
DCHECK(audio_input_);
DCHECK(power_manager_client_); DCHECK(power_manager_client_);
}
AudioInputHostImpl::~AudioInputHostImpl() = default;
void AudioInputHostImpl::Initialize(AudioInputImpl* audio_input) {
DCHECK(audio_input);
audio_input_ = audio_input;
audio_devices_observation_.Observe(&audio_devices_); audio_devices_observation_.Observe(&audio_devices_);
power_manager_client_observer_.Observe(power_manager_client_); power_manager_client_observer_.Observe(power_manager_client);
power_manager_client_->GetSwitchStates( power_manager_client->GetSwitchStates(base::BindOnce(
base::BindOnce(&AudioInputHostImpl::OnInitialLidStateReceived, &AudioInputHost::OnInitialLidStateReceived, weak_factory_.GetWeakPtr()));
weak_factory_.GetWeakPtr()));
} }
void AudioInputHostImpl::SetMicState(bool mic_open) { AudioInputHost::~AudioInputHost() = default;
void AudioInputHost::SetMicState(bool mic_open) {
audio_input_->SetMicState(mic_open); audio_input_->SetMicState(mic_open);
} }
void AudioInputHostImpl::SetDeviceId( void AudioInputHost::SetDeviceId(const base::Optional<std::string>& device_id) {
const base::Optional<std::string>& device_id) {
audio_input_->SetDeviceId(device_id.value_or("")); audio_input_->SetDeviceId(device_id.value_or(""));
} }
void AudioInputHostImpl::OnConversationTurnStarted() { void AudioInputHost::OnConversationTurnStarted() {
audio_input_->OnConversationTurnStarted(); audio_input_->OnConversationTurnStarted();
// Inform power manager of a wake notification when Libassistant // Inform power manager of a wake notification when Libassistant
// recognized hotword and started a conversation. We intentionally // recognized hotword and started a conversation. We intentionally
...@@ -70,20 +67,20 @@ void AudioInputHostImpl::OnConversationTurnStarted() { ...@@ -70,20 +67,20 @@ void AudioInputHostImpl::OnConversationTurnStarted() {
power_manager_client_->NotifyWakeNotification(); power_manager_client_->NotifyWakeNotification();
} }
void AudioInputHostImpl::OnConversationTurnFinished() { void AudioInputHost::OnConversationTurnFinished() {
audio_input_->OnConversationTurnFinished(); audio_input_->OnConversationTurnFinished();
} }
void AudioInputHostImpl::OnHotwordEnabled(bool enable) { void AudioInputHost::OnHotwordEnabled(bool enable) {
audio_input_->OnHotwordEnabled(enable); audio_input_->OnHotwordEnabled(enable);
} }
void AudioInputHostImpl::SetHotwordDeviceId( void AudioInputHost::SetHotwordDeviceId(
const base::Optional<std::string>& device_id) { const base::Optional<std::string>& device_id) {
audio_input_->SetHotwordDeviceId(device_id.value_or("")); audio_input_->SetHotwordDeviceId(device_id.value_or(""));
} }
void AudioInputHostImpl::LidEventReceived( void AudioInputHost::LidEventReceived(
chromeos::PowerManagerClient::LidState state, chromeos::PowerManagerClient::LidState state,
base::TimeTicks timestamp) { base::TimeTicks timestamp) {
// Lid switch event still gets fired during system suspend, which enables // Lid switch event still gets fired during system suspend, which enables
...@@ -92,7 +89,7 @@ void AudioInputHostImpl::LidEventReceived( ...@@ -92,7 +89,7 @@ void AudioInputHostImpl::LidEventReceived(
audio_input_->OnLidStateChanged(ConvertLidState(state)); audio_input_->OnLidStateChanged(ConvertLidState(state));
} }
void AudioInputHostImpl::OnInitialLidStateReceived( void AudioInputHost::OnInitialLidStateReceived(
base::Optional<chromeos::PowerManagerClient::SwitchStates> switch_states) { base::Optional<chromeos::PowerManagerClient::SwitchStates> switch_states) {
if (switch_states.has_value()) if (switch_states.has_value())
audio_input_->OnLidStateChanged(ConvertLidState(switch_states->lid_state)); audio_input_->OnLidStateChanged(ConvertLidState(switch_states->lid_state));
......
// Copyright 2021 The Chromium Authors. All rights reserved. // Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_IMPL_H_ #ifndef CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_H_
#define CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_IMPL_H_ #define CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_H_
#include "chromeos/services/assistant/public/cpp/migration/audio_input_host.h"
#include <string> #include <string>
#include "base/component_export.h" #include "base/component_export.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "base/scoped_observation.h" #include "base/scoped_observation.h"
#include "base/time/time.h"
#include "chromeos/dbus/power/power_manager_client.h" #include "chromeos/dbus/power/power_manager_client.h"
#include "chromeos/services/assistant/platform/audio_devices.h" #include "chromeos/services/assistant/platform/audio_devices.h"
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHostImpl class AudioInputImpl;
: public AudioInputHost,
private chromeos::PowerManagerClient::Observer, // Class that provides the bridge between the ChromeOS UI thread and the
private AudioDevices::Observer { // Libassistant audio input class.
// The goal is that |AudioInputImpl| no longer depends on any external events.
// This will allow us to move it to the Libassistant mojom service (at which
// point this class will talk to the Libassistant mojom service).
class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHost
: private chromeos::PowerManagerClient::Observer,
private AudioDevices::Observer
{
public: public:
AudioInputHostImpl(CrasAudioHandler* cras_audio_handler, AudioInputHost(AudioInputImpl* audio_input,
chromeos::PowerManagerClient* power_manager_client, CrasAudioHandler* cras_audio_handler,
const std::string& locale); chromeos::PowerManagerClient* power_manager_client,
AudioInputHostImpl(const AudioInputHostImpl&) = delete; const std::string& locale);
AudioInputHostImpl& operator=(const AudioInputHostImpl&) = delete; AudioInputHost(AudioInputHost&) = delete;
~AudioInputHostImpl() override; AudioInputHost& operator=(AudioInputHost&) = delete;
~AudioInputHost() override;
// AudioInputHost implementation:
void Initialize(AudioInputImpl* audio_input) override; // Called when the mic state associated with the interaction is changed.
void SetMicState(bool mic_open) override; void SetMicState(bool mic_open);
void OnHotwordEnabled(bool enable) override;
void OnConversationTurnStarted() override; // Called when hotword enabled status changed.
void OnConversationTurnFinished() override; void OnHotwordEnabled(bool enable);
void OnConversationTurnStarted();
void OnConversationTurnFinished();
// AudioDevices::Observer implementation: // AudioDevices::Observer implementation:
void SetDeviceId(const base::Optional<std::string>& device_id) override; void SetDeviceId(const base::Optional<std::string>& device_id) override;
...@@ -53,7 +60,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHostImpl ...@@ -53,7 +60,7 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHostImpl
base::Optional<chromeos::PowerManagerClient::SwitchStates> switch_states); base::Optional<chromeos::PowerManagerClient::SwitchStates> switch_states);
// Owned by |PlatformApiImpl| which also owns |this|. // Owned by |PlatformApiImpl| which also owns |this|.
AudioInputImpl* audio_input_ = nullptr; AudioInputImpl* const audio_input_;
chromeos::PowerManagerClient* const power_manager_client_; chromeos::PowerManagerClient* const power_manager_client_;
base::ScopedObservation<chromeos::PowerManagerClient, base::ScopedObservation<chromeos::PowerManagerClient,
chromeos::PowerManagerClient::Observer> chromeos::PowerManagerClient::Observer>
...@@ -64,10 +71,10 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHostImpl ...@@ -64,10 +71,10 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHostImpl
AudioDevices audio_devices_; AudioDevices audio_devices_;
AudioDevices::ScopedObservation audio_devices_observation_{this}; AudioDevices::ScopedObservation audio_devices_observation_{this};
base::WeakPtrFactory<AudioInputHostImpl> weak_factory_{this}; base::WeakPtrFactory<AudioInputHost> weak_factory_{this};
}; };
} // namespace assistant } // namespace assistant
} // namespace chromeos } // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_IMPL_H_ #endif // CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_HOST_H_
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "chromeos/audio/cras_audio_handler.h" #include "chromeos/audio/cras_audio_handler.h"
#include "chromeos/dbus/power/fake_power_manager_client.h" #include "chromeos/dbus/power/fake_power_manager_client.h"
#include "chromeos/services/assistant/platform/audio_input_host_impl.h" #include "chromeos/services/assistant/platform/audio_input_host.h"
#include "chromeos/services/assistant/platform/audio_stream_factory_delegate.h" #include "chromeos/services/assistant/platform/audio_stream_factory_delegate.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/services/assistant/test_support/scoped_assistant_client.h" #include "chromeos/services/assistant/test_support/scoped_assistant_client.h"
...@@ -101,10 +101,9 @@ class AudioInputImplTest : public testing::Test, ...@@ -101,10 +101,9 @@ class AudioInputImplTest : public testing::Test,
audio_input_impl_ = std::make_unique<AudioInputImpl>( audio_input_impl_ = std::make_unique<AudioInputImpl>(
&audio_stream_factory_delegate_, "fake-device-id"); &audio_stream_factory_delegate_, "fake-device-id");
audio_input_host_ = std::make_unique<AudioInputHostImpl>( audio_input_host_ = std::make_unique<AudioInputHost>(
cras_audio_handler_.Get(), FakePowerManagerClient::Get(), audio_input_impl_.get(), cras_audio_handler_.Get(),
"initial-locale"); FakePowerManagerClient::Get(), "initial-locale");
audio_input_host_->Initialize(audio_input_impl_.get());
audio_input_host_->SetDeviceId("initial-device-id"); audio_input_host_->SetDeviceId("initial-device-id");
audio_input_impl_->AddObserver(this); audio_input_impl_->AddObserver(this);
...@@ -153,7 +152,7 @@ class AudioInputImplTest : public testing::Test, ...@@ -153,7 +152,7 @@ class AudioInputImplTest : public testing::Test,
DefaultAudioStreamFactoryDelegate audio_stream_factory_delegate_; DefaultAudioStreamFactoryDelegate audio_stream_factory_delegate_;
ScopedCrasAudioHandler cras_audio_handler_; ScopedCrasAudioHandler cras_audio_handler_;
std::unique_ptr<AudioInputImpl> audio_input_impl_; std::unique_ptr<AudioInputImpl> audio_input_impl_;
std::unique_ptr<AudioInputHostImpl> audio_input_host_; std::unique_ptr<AudioInputHost> audio_input_host_;
DISALLOW_COPY_AND_ASSIGN(AudioInputImplTest); DISALLOW_COPY_AND_ASSIGN(AudioInputImplTest);
}; };
......
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "chromeos/services/assistant/platform/audio_devices.h" #include "chromeos/services/assistant/platform/audio_devices.h"
#include "chromeos/services/assistant/platform/power_manager_provider_impl.h" #include "chromeos/services/assistant/platform/power_manager_provider_impl.h"
#include "chromeos/services/assistant/public/cpp/features.h" #include "chromeos/services/assistant/public/cpp/features.h"
#include "chromeos/services/assistant/public/cpp/migration/audio_input_host.h"
#include "chromeos/services/assistant/utils.h" #include "chromeos/services/assistant/utils.h"
#include "libassistant/shared/public/assistant_export.h" #include "libassistant/shared/public/assistant_export.h"
#include "libassistant/shared/public/platform_api.h" #include "libassistant/shared/public/platform_api.h"
...@@ -79,13 +78,19 @@ void PlatformApiImpl::FakeAuthProvider::Reset() {} ...@@ -79,13 +78,19 @@ void PlatformApiImpl::FakeAuthProvider::Reset() {}
PlatformApiImpl::PlatformApiImpl( PlatformApiImpl::PlatformApiImpl(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
PowerManagerClient* power_manager_client, PowerManagerClient* power_manager_client,
CrasAudioHandler* cras_audio_handler,
mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor, mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor,
scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner, scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner) scoped_refptr<base::SingleThreadTaskRunner> background_task_runner,
const std::string& pref_locale)
: audio_input_provider_(), : audio_input_provider_(),
audio_output_provider_(media_session, audio_output_provider_(media_session,
background_task_runner, background_task_runner,
media::AudioDeviceDescription::kDefaultDeviceId) { media::AudioDeviceDescription::kDefaultDeviceId),
audio_input_host_(&audio_input_provider_.GetAudioInput(),
cras_audio_handler,
power_manager_client,
pref_locale) {
// Only enable native power features if they are supported by the UI. // Only enable native power features if they are supported by the UI.
std::unique_ptr<PowerManagerProviderImpl> provider; std::unique_ptr<PowerManagerProviderImpl> provider;
if (features::IsPowerManagerEnabled()) { if (features::IsPowerManagerEnabled()) {
...@@ -122,8 +127,20 @@ SystemProvider& PlatformApiImpl::GetSystemProvider() { ...@@ -122,8 +127,20 @@ SystemProvider& PlatformApiImpl::GetSystemProvider() {
return *system_provider_; return *system_provider_;
} }
void PlatformApiImpl::InitializeAudioInputHost(AudioInputHost& host) { void PlatformApiImpl::SetMicState(bool mic_open) {
host.Initialize(&audio_input_provider_.GetAudioInput()); audio_input_host_.SetMicState(mic_open);
}
void PlatformApiImpl::OnConversationTurnStarted() {
audio_input_host_.OnConversationTurnStarted();
}
void PlatformApiImpl::OnConversationTurnFinished() {
audio_input_host_.OnConversationTurnFinished();
}
void PlatformApiImpl::OnHotwordEnabled(bool enable) {
audio_input_host_.OnHotwordEnabled(enable);
} }
} // namespace assistant } // namespace assistant
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "chromeos/services/assistant/platform/audio_input_host.h"
#include "chromeos/services/assistant/platform/audio_input_provider_impl.h" #include "chromeos/services/assistant/platform/audio_input_provider_impl.h"
#include "chromeos/services/assistant/platform/audio_output_provider_impl.h" #include "chromeos/services/assistant/platform/audio_output_provider_impl.h"
#include "chromeos/services/assistant/platform/file_provider_impl.h" #include "chromeos/services/assistant/platform/file_provider_impl.h"
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
#include "services/device/public/mojom/battery_monitor.mojom.h" #include "services/device/public/mojom/battery_monitor.mojom.h"
namespace chromeos { namespace chromeos {
class CrasAudioHandler;
class PowerManagerClient; class PowerManagerClient;
namespace assistant { namespace assistant {
...@@ -34,9 +36,11 @@ class PlatformApiImpl : public CrosPlatformApi { ...@@ -34,9 +36,11 @@ class PlatformApiImpl : public CrosPlatformApi {
PlatformApiImpl( PlatformApiImpl(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
PowerManagerClient* power_manager_client, PowerManagerClient* power_manager_client,
CrasAudioHandler* cras_audio_handler,
mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor, mojo::PendingRemote<device::mojom::BatteryMonitor> battery_monitor,
scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner, scoped_refptr<base::SequencedTaskRunner> main_thread_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> background_task_runner); scoped_refptr<base::SingleThreadTaskRunner> background_task_runner,
const std::string& pref_locale);
~PlatformApiImpl() override; ~PlatformApiImpl() override;
// assistant_client::PlatformApi overrides // assistant_client::PlatformApi overrides
...@@ -47,7 +51,14 @@ class PlatformApiImpl : public CrosPlatformApi { ...@@ -47,7 +51,14 @@ class PlatformApiImpl : public CrosPlatformApi {
assistant_client::NetworkProvider& GetNetworkProvider() override; assistant_client::NetworkProvider& GetNetworkProvider() override;
assistant_client::SystemProvider& GetSystemProvider() override; assistant_client::SystemProvider& GetSystemProvider() override;
void InitializeAudioInputHost(AudioInputHost& host) override; // Called when the mic state associated with the interaction is changed.
void SetMicState(bool mic_open) override;
void OnConversationTurnStarted() override;
void OnConversationTurnFinished() override;
// Called when hotword enabled status changed.
void OnHotwordEnabled(bool enable) override;
private: private:
// ChromeOS does not use auth manager, so we don't yet need to implement a // ChromeOS does not use auth manager, so we don't yet need to implement a
...@@ -87,6 +98,7 @@ class PlatformApiImpl : public CrosPlatformApi { ...@@ -87,6 +98,7 @@ class PlatformApiImpl : public CrosPlatformApi {
FakeAuthProvider auth_provider_; FakeAuthProvider auth_provider_;
FileProviderImpl file_provider_; FileProviderImpl file_provider_;
NetworkProviderImpl network_provider_; NetworkProviderImpl network_provider_;
AudioInputHost audio_input_host_;
std::unique_ptr<SystemProviderImpl> system_provider_; std::unique_ptr<SystemProviderImpl> system_provider_;
DISALLOW_COPY_AND_ASSIGN(PlatformApiImpl); DISALLOW_COPY_AND_ASSIGN(PlatformApiImpl);
......
...@@ -11,7 +11,6 @@ component("migration") { ...@@ -11,7 +11,6 @@ component("migration") {
sources = [ sources = [
"assistant_manager_service_delegate.h", "assistant_manager_service_delegate.h",
"audio_input_host.h",
"cros_platform_api.h", "cros_platform_api.h",
"libassistant_v1_api.cc", "libassistant_v1_api.cc",
"libassistant_v1_api.h", "libassistant_v1_api.h",
......
...@@ -20,7 +20,6 @@ namespace chromeos { ...@@ -20,7 +20,6 @@ namespace chromeos {
namespace assistant { namespace assistant {
class AssistantMediaSession; class AssistantMediaSession;
class AudioInputHost;
class CrosPlatformApi; class CrosPlatformApi;
// Interface class that provides factory methods for assistant internal // Interface class that provides factory methods for assistant internal
...@@ -30,8 +29,6 @@ class AssistantManagerServiceDelegate { ...@@ -30,8 +29,6 @@ class AssistantManagerServiceDelegate {
AssistantManagerServiceDelegate() = default; AssistantManagerServiceDelegate() = default;
virtual ~AssistantManagerServiceDelegate() = default; virtual ~AssistantManagerServiceDelegate() = default;
virtual std::unique_ptr<AudioInputHost> CreateAudioInputHost() = 0;
virtual std::unique_ptr<CrosPlatformApi> CreatePlatformApi( virtual std::unique_ptr<CrosPlatformApi> CreatePlatformApi(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
scoped_refptr<base::SingleThreadTaskRunner> scoped_refptr<base::SingleThreadTaskRunner>
......
// Copyright 2021 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROMEOS_SERVICES_ASSISTANT_PUBLIC_CPP_MIGRATION_AUDIO_INPUT_HOST_H_
#define CHROMEOS_SERVICES_ASSISTANT_PUBLIC_CPP_MIGRATION_AUDIO_INPUT_HOST_H_
#include <string>
#include "base/component_export.h"
namespace chromeos {
namespace assistant {
class AudioInputImpl;
// Class that provides the bridge between the ChromeOS UI thread and the
// Libassistant audio input class.
class COMPONENT_EXPORT(ASSISTANT_SERVICE) AudioInputHost {
public:
virtual ~AudioInputHost() = default;
// Initialize this class by setting the backend that it's supposed to use.
// TODO(b/171748795): Should be gone when the Libassistant V2 migration is
// completed.
virtual void Initialize(AudioInputImpl* audio_input) = 0;
// Called when the mic state associated with the interaction is changed.
virtual void SetMicState(bool mic_open) = 0;
// Called when hotword enabled status changed.
virtual void OnHotwordEnabled(bool enable) = 0;
virtual void OnConversationTurnStarted() = 0;
virtual void OnConversationTurnFinished() = 0;
};
} // namespace assistant
} // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_PUBLIC_CPP_MIGRATION_AUDIO_INPUT_HOST_H_
...@@ -19,8 +19,6 @@ class SystemProvider; ...@@ -19,8 +19,6 @@ class SystemProvider;
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
class AudioInputHost;
// Platform API required by the voice assistant, extended with some methods used // Platform API required by the voice assistant, extended with some methods used
// when ChromeOS needs to make changes to the platform state. // when ChromeOS needs to make changes to the platform state.
// Note that this no longer inherits from |assistant_client::PlatformApi|, // Note that this no longer inherits from |assistant_client::PlatformApi|,
...@@ -31,10 +29,14 @@ class CrosPlatformApi { ...@@ -31,10 +29,14 @@ class CrosPlatformApi {
CrosPlatformApi() = default; CrosPlatformApi() = default;
virtual ~CrosPlatformApi() = default; virtual ~CrosPlatformApi() = default;
// Initialize the AudioInputHost. // Called when the mic state associated with the interaction is changed.
// TODO(b/171748795): Should be gone when the Libassistant V2 migration is virtual void SetMicState(bool mic_open) = 0;
// completed.
virtual void InitializeAudioInputHost(AudioInputHost&) = 0; virtual void OnConversationTurnStarted() = 0;
virtual void OnConversationTurnFinished() = 0;
// Called when hotword enabled status changed.
virtual void OnHotwordEnabled(bool enable) = 0;
// Returns the platform's audio input provider. // Returns the platform's audio input provider.
virtual assistant_client::AudioInputProvider& GetAudioInputProvider() = 0; virtual assistant_client::AudioInputProvider& GetAudioInputProvider() = 0;
......
...@@ -9,30 +9,10 @@ ...@@ -9,30 +9,10 @@
#include "chromeos/assistant/internal/test_support/fake_assistant_manager.h" #include "chromeos/assistant/internal/test_support/fake_assistant_manager.h"
#include "chromeos/assistant/internal/test_support/fake_assistant_manager_internal.h" #include "chromeos/assistant/internal/test_support/fake_assistant_manager_internal.h"
#include "chromeos/services/assistant//public/cpp/migration/fake_platform_api.h" #include "chromeos/services/assistant//public/cpp/migration/fake_platform_api.h"
#include "chromeos/services/assistant/public/cpp/migration/audio_input_host.h"
namespace chromeos { namespace chromeos {
namespace assistant { namespace assistant {
namespace {
class FakeAudioInputHost : public AudioInputHost {
public:
FakeAudioInputHost() = default;
FakeAudioInputHost(const FakeAudioInputHost&) = delete;
FakeAudioInputHost& operator=(const FakeAudioInputHost&) = delete;
~FakeAudioInputHost() override = default;
// AudioInputHost implementation:
void Initialize(AudioInputImpl* audio_input) override {}
void SetMicState(bool mic_open) override {}
void OnHotwordEnabled(bool enable) override {}
void OnConversationTurnStarted() override {}
void OnConversationTurnFinished() override {}
};
} // namespace
FakeAssistantManagerServiceDelegate::FakeAssistantManagerServiceDelegate() { FakeAssistantManagerServiceDelegate::FakeAssistantManagerServiceDelegate() {
// We start by creating a pending assistant manager, as our unittests // We start by creating a pending assistant manager, as our unittests
// might need to access the assistant manager before it is created through // might need to access the assistant manager before it is created through
...@@ -43,11 +23,6 @@ FakeAssistantManagerServiceDelegate::FakeAssistantManagerServiceDelegate() { ...@@ -43,11 +23,6 @@ FakeAssistantManagerServiceDelegate::FakeAssistantManagerServiceDelegate() {
FakeAssistantManagerServiceDelegate::~FakeAssistantManagerServiceDelegate() = FakeAssistantManagerServiceDelegate::~FakeAssistantManagerServiceDelegate() =
default; default;
std::unique_ptr<AudioInputHost>
FakeAssistantManagerServiceDelegate::CreateAudioInputHost() {
return std::make_unique<FakeAudioInputHost>();
}
std::unique_ptr<CrosPlatformApi> std::unique_ptr<CrosPlatformApi>
FakeAssistantManagerServiceDelegate::CreatePlatformApi( FakeAssistantManagerServiceDelegate::CreatePlatformApi(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
......
...@@ -26,7 +26,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE_MIGRATION_TEST_SUPPORT) ...@@ -26,7 +26,6 @@ class COMPONENT_EXPORT(ASSISTANT_SERVICE_MIGRATION_TEST_SUPPORT)
FakeAssistantManager* assistant_manager(); FakeAssistantManager* assistant_manager();
// AssistantManagerServiceDelegate: // AssistantManagerServiceDelegate:
std::unique_ptr<AudioInputHost> CreateAudioInputHost() override;
std::unique_ptr<CrosPlatformApi> CreatePlatformApi( std::unique_ptr<CrosPlatformApi> CreatePlatformApi(
AssistantMediaSession* media_session, AssistantMediaSession* media_session,
scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner) scoped_refptr<base::SingleThreadTaskRunner> background_thread_task_runner)
......
...@@ -28,7 +28,10 @@ class FakePlatformApi : public CrosPlatformApi { ...@@ -28,7 +28,10 @@ class FakePlatformApi : public CrosPlatformApi {
assistant_client::FileProvider& GetFileProvider() override; assistant_client::FileProvider& GetFileProvider() override;
assistant_client::NetworkProvider& GetNetworkProvider() override; assistant_client::NetworkProvider& GetNetworkProvider() override;
assistant_client::SystemProvider& GetSystemProvider() override; assistant_client::SystemProvider& GetSystemProvider() override;
void InitializeAudioInputHost(AudioInputHost&) override {} void SetMicState(bool mic_open) override {}
void OnHotwordEnabled(bool enable) override {}
void OnConversationTurnStarted() override {}
void OnConversationTurnFinished() override {}
private: private:
DISALLOW_COPY_AND_ASSIGN(FakePlatformApi); DISALLOW_COPY_AND_ASSIGN(FakePlatformApi);
......
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