Commit 9296cc2f authored by Yue Li's avatar Yue Li Committed by Commit Bot

Revert "assistant: add DSP support"

This reverts commit 8a49de16.

Reason for revert: <INSERT REASONING HERE>

Original change's description:
> assistant: add DSP support
> 
> Bug: b/77916222
> Change-Id: Ic2efb6e21d243bf5c19554dbdd35773ef082e12b
> Reviewed-on: https://chromium-review.googlesource.com/1132624
> Commit-Queue: Muyuan Li <muyuanli@chromium.org>
> Reviewed-by: Xiaohui Chen <xiaohuic@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#580006}

TBR=xiaohuic@chromium.org,muyuanli@chromium.org

Change-Id: I7df21aba5ee2d05efab163d291bbce943f52e5c1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/77916222
Reviewed-on: https://chromium-review.googlesource.com/1161228Reviewed-by: default avatarYue Li <updowndota@chromium.org>
Commit-Queue: Yue Li <updowndota@chromium.org>
Cr-Commit-Position: refs/heads/master@{#580377}
parent aac51288
...@@ -27,7 +27,6 @@ source_set("lib") { ...@@ -27,7 +27,6 @@ source_set("lib") {
"//build/util:webkit_version", "//build/util:webkit_version",
"//chromeos", "//chromeos",
"//chromeos/assistant:buildflags", "//chromeos/assistant:buildflags",
"//chromeos/services/assistant/public/cpp:cpp",
"//chromeos/services/assistant/public/mojom", "//chromeos/services/assistant/public/mojom",
"//components/account_id", "//components/account_id",
"//services/device/public/mojom", "//services/device/public/mojom",
......
...@@ -595,16 +595,10 @@ void AssistantManagerServiceImpl::OnConversationTurnStartedOnMainThread( ...@@ -595,16 +595,10 @@ void AssistantManagerServiceImpl::OnConversationTurnStartedOnMainThread(
interaction_subscribers_.ForAllPtrs([is_mic_open](auto* ptr) { interaction_subscribers_.ForAllPtrs([is_mic_open](auto* ptr) {
ptr->OnInteractionStarted(/*is_voice_interaction=*/is_mic_open); ptr->OnInteractionStarted(/*is_voice_interaction=*/is_mic_open);
}); });
platform_api_.GetAudioInputProvider()
.GetAudioInput()
.OnConversationTurnStarted();
} }
void AssistantManagerServiceImpl::OnConversationTurnFinishedOnMainThread( void AssistantManagerServiceImpl::OnConversationTurnFinishedOnMainThread(
assistant_client::ConversationStateListener::Resolution resolution) { Resolution resolution) {
platform_api_.GetAudioInputProvider()
.GetAudioInput()
.OnConversationTurnFinished();
switch (resolution) { switch (resolution) {
// Interaction ended normally. // Interaction ended normally.
// Note that TIMEOUT here does not refer to server timeout, but rather mic // Note that TIMEOUT here does not refer to server timeout, but rather mic
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/stl_util.h" #include "base/stl_util.h"
#include "chromeos/services/assistant/public/cpp/features.h"
#include "libassistant/shared/public/platform_audio_buffer.h" #include "libassistant/shared/public/platform_audio_buffer.h"
#include "media/audio/audio_device_description.h" #include "media/audio/audio_device_description.h"
#include "media/base/audio_parameters.h" #include "media/base/audio_parameters.h"
...@@ -25,72 +24,6 @@ constexpr assistant_client::BufferFormat kFormat{ ...@@ -25,72 +24,6 @@ constexpr assistant_client::BufferFormat kFormat{
16000 /* sample_rate */, assistant_client::INTERLEAVED_S32, 1 /* channels */ 16000 /* sample_rate */, assistant_client::INTERLEAVED_S32, 1 /* channels */
}; };
class DefaultHotwordStateManager : public AudioInputImpl::HotwordStateManager {
public:
DefaultHotwordStateManager() = default;
~DefaultHotwordStateManager() override = default;
void OnConversationTurnStarted() override {}
void OnConversationTurnFinished() override {}
void OnCaptureDataArrived() override {}
private:
DISALLOW_COPY_AND_ASSIGN(DefaultHotwordStateManager);
};
class DspHotwordStateManager : public AudioInputImpl::HotwordStateManager {
public:
DspHotwordStateManager(scoped_refptr<base::SequencedTaskRunner> task_runner,
AudioInputImpl* input)
: task_runner_(task_runner), input_(input) {
second_phase_timer_.SetTaskRunner(task_runner_);
}
// HotwordStateManager overrides:
void OnConversationTurnStarted() override {
if (second_phase_timer_.IsRunning()) {
DCHECK(stream_state_ == StreamState::HOTWORD);
second_phase_timer_.Stop();
stream_state_ = StreamState::NORMAL;
} else {
// Handles user click on mic button.
input_->RecreateAudioInputStream(false /* hotword */);
}
}
void OnConversationTurnFinished() override {
input_->RecreateAudioInputStream(true /* hotword */);
stream_state_ = StreamState::HOTWORD;
}
void OnCaptureDataArrived() override {
if (stream_state_ == StreamState::HOTWORD &&
!second_phase_timer_.IsRunning()) {
// 1s from now, if OnConversationTurnStarted is not called, we assume that
// libassistant has rejected the hotword supplied by DSP. Thus, we reset
// and reopen the device on hotword state.
second_phase_timer_.Start(
FROM_HERE, base::TimeDelta::FromSeconds(1),
base::BindRepeating(
&DspHotwordStateManager::OnConversationTurnFinished,
base::Unretained(this)));
}
}
private:
enum class StreamState {
HOTWORD,
NORMAL,
};
StreamState stream_state_ = StreamState::HOTWORD;
scoped_refptr<base::SequencedTaskRunner> task_runner_;
base::OneShotTimer second_phase_timer_;
AudioInputImpl* input_;
DISALLOW_COPY_AND_ASSIGN(DspHotwordStateManager);
};
} // namespace } // namespace
AudioInputBufferImpl::AudioInputBufferImpl(const void* data, AudioInputBufferImpl::AudioInputBufferImpl(const void* data,
...@@ -116,24 +49,28 @@ int AudioInputBufferImpl::GetFrameCount() const { ...@@ -116,24 +49,28 @@ int AudioInputBufferImpl::GetFrameCount() const {
return frame_count_; return frame_count_;
} }
AudioInputImpl::AudioInputImpl(service_manager::Connector* connector, AudioInputImpl::AudioInputImpl(
bool default_on) std::unique_ptr<service_manager::Connector> connector,
: default_on_(default_on), bool default_on)
: source_(audio::CreateInputDevice(
std::move(connector),
media::AudioDeviceDescription::kDefaultDeviceId)),
default_on_(default_on),
task_runner_(base::ThreadTaskRunnerHandle::Get()), task_runner_(base::ThreadTaskRunnerHandle::Get()),
weak_factory_(this) { weak_factory_(this) {
DETACH_FROM_SEQUENCE(observer_sequence_checker_); DETACH_FROM_SEQUENCE(observer_sequence_checker_);
// AUDIO_PCM_LINEAR and AUDIO_PCM_LOW_LATENCY are the same on CRAS.
if (IsDspHotwordEnabled()) { source_->Initialize(
state_manager_ = media::AudioParameters(
std::make_unique<DspHotwordStateManager>(task_runner_, this); media::AudioParameters::AUDIO_PCM_LOW_LATENCY,
} else { media::CHANNEL_LAYOUT_MONO, kFormat.sample_rate,
state_manager_ = std::make_unique<DefaultHotwordStateManager>(); kFormat.sample_rate / 10 /* buffer size for 100 ms */),
} this);
} }
AudioInputImpl::~AudioInputImpl() { AudioInputImpl::~AudioInputImpl() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
source_.reset(); source_->Stop();
} }
void AudioInputImpl::Capture(const media::AudioBus* audio_source, void AudioInputImpl::Capture(const media::AudioBus* audio_source,
...@@ -141,9 +78,6 @@ void AudioInputImpl::Capture(const media::AudioBus* audio_source, ...@@ -141,9 +78,6 @@ void AudioInputImpl::Capture(const media::AudioBus* audio_source,
double volume, double volume,
bool key_pressed) { bool key_pressed) {
DCHECK_EQ(kFormat.num_channels, audio_source->channels()); DCHECK_EQ(kFormat.num_channels, audio_source->channels());
state_manager_->OnCaptureDataArrived();
std::vector<int32_t> buffer(kFormat.num_channels * audio_source->frames()); std::vector<int32_t> buffer(kFormat.num_channels * audio_source->frames());
audio_source->ToInterleaved<media::SignedInt32SampleTypeTraits>( audio_source->ToInterleaved<media::SignedInt32SampleTypeTraits>(
audio_source->frames(), buffer.data()); audio_source->frames(), buffer.data());
...@@ -216,16 +150,6 @@ void AudioInputImpl::SetMicState(bool mic_open) { ...@@ -216,16 +150,6 @@ void AudioInputImpl::SetMicState(bool mic_open) {
} }
} }
void AudioInputImpl::OnConversationTurnStarted() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
state_manager_->OnConversationTurnStarted();
}
void AudioInputImpl::OnConversationTurnFinished() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
state_manager_->OnConversationTurnFinished();
}
void AudioInputImpl::OnHotwordEnabled(bool enable) { void AudioInputImpl::OnHotwordEnabled(bool enable) {
default_on_ = enable; default_on_ = enable;
if (default_on_) if (default_on_)
...@@ -236,44 +160,22 @@ void AudioInputImpl::OnHotwordEnabled(bool enable) { ...@@ -236,44 +160,22 @@ void AudioInputImpl::OnHotwordEnabled(bool enable) {
void AudioInputImpl::StartRecording() { void AudioInputImpl::StartRecording() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
DCHECK(!source_); source_->Start();
RecreateAudioInputStream(IsDspHotwordEnabled());
} }
void AudioInputImpl::StopRecording() { void AudioInputImpl::StopRecording() {
DCHECK(task_runner_->RunsTasksInCurrentSequence()); DCHECK(task_runner_->RunsTasksInCurrentSequence());
if (source_) { source_->Stop();
source_->Stop();
source_.reset();
}
}
void AudioInputImpl::RecreateAudioInputStream(bool hotword) {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
StopRecording();
source_ = audio::CreateInputDevice(
connector_->Clone(), media::AudioDeviceDescription::kDefaultDeviceId);
// AUDIO_PCM_LINEAR and AUDIO_PCM_LOW_LATENCY are the same on CRAS.
auto param = media::AudioParameters(
media::AudioParameters::AUDIO_PCM_LOW_LATENCY, media::CHANNEL_LAYOUT_MONO,
kFormat.sample_rate,
kFormat.sample_rate / 10 /* buffer size for 100 ms */);
if (hotword) {
param.set_effects(media::AudioParameters::PlatformEffectsMask::HOTWORD);
}
source_->Initialize(param, this);
source_->Start();
} }
AudioInputProviderImpl::AudioInputProviderImpl( AudioInputProviderImpl::AudioInputProviderImpl(
service_manager::Connector* connector, service_manager::Connector* connector,
bool default_on) bool default_on)
: audio_input_(connector, default_on) {} : audio_input_(connector->Clone(), default_on) {}
AudioInputProviderImpl::~AudioInputProviderImpl() = default; AudioInputProviderImpl::~AudioInputProviderImpl() = default;
AudioInputImpl& AudioInputProviderImpl::GetAudioInput() { assistant_client::AudioInput& AudioInputProviderImpl::GetAudioInput() {
return audio_input_; return audio_input_;
} }
......
...@@ -49,17 +49,10 @@ class AudioInputBufferImpl : public assistant_client::AudioBuffer { ...@@ -49,17 +49,10 @@ class AudioInputBufferImpl : public assistant_client::AudioBuffer {
class AudioInputImpl : public assistant_client::AudioInput, class AudioInputImpl : public assistant_client::AudioInput,
public media::AudioCapturerSource::CaptureCallback { public media::AudioCapturerSource::CaptureCallback {
public: public:
AudioInputImpl(service_manager::Connector* connector, bool default_on); AudioInputImpl(std::unique_ptr<service_manager::Connector> connector,
bool default_on);
~AudioInputImpl() override; ~AudioInputImpl() override;
class HotwordStateManager {
public:
virtual ~HotwordStateManager() = default;
virtual void OnConversationTurnStarted() = 0;
virtual void OnConversationTurnFinished() = 0;
virtual void OnCaptureDataArrived() = 0;
};
// media::AudioCapturerSource::CaptureCallback overrides: // media::AudioCapturerSource::CaptureCallback overrides:
void Capture(const media::AudioBus* audio_source, void Capture(const media::AudioBus* audio_source,
int audio_delay_milliseconds, int audio_delay_milliseconds,
...@@ -78,10 +71,6 @@ class AudioInputImpl : public assistant_client::AudioInput, ...@@ -78,10 +71,6 @@ class AudioInputImpl : public assistant_client::AudioInput,
// Called when the mic state associated with the interaction is changed. // Called when the mic state associated with the interaction is changed.
void SetMicState(bool mic_open); void SetMicState(bool mic_open);
void OnConversationTurnStarted();
void OnConversationTurnFinished();
void RecreateAudioInputStream(bool hotword);
// Called when hotword enabled status changed. // Called when hotword enabled status changed.
void OnHotwordEnabled(bool enable); void OnHotwordEnabled(bool enable);
...@@ -104,12 +93,8 @@ class AudioInputImpl : public assistant_client::AudioInput, ...@@ -104,12 +93,8 @@ class AudioInputImpl : public assistant_client::AudioInput,
// sequence. // sequence.
SEQUENCE_CHECKER(observer_sequence_checker_); SEQUENCE_CHECKER(observer_sequence_checker_);
service_manager::Connector* connector_;
scoped_refptr<base::SequencedTaskRunner> task_runner_; scoped_refptr<base::SequencedTaskRunner> task_runner_;
std::unique_ptr<HotwordStateManager> state_manager_;
base::WeakPtrFactory<AudioInputImpl> weak_factory_; base::WeakPtrFactory<AudioInputImpl> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(AudioInputImpl); DISALLOW_COPY_AND_ASSIGN(AudioInputImpl);
}; };
...@@ -121,7 +106,7 @@ class AudioInputProviderImpl : public assistant_client::AudioInputProvider { ...@@ -121,7 +106,7 @@ class AudioInputProviderImpl : public assistant_client::AudioInputProvider {
~AudioInputProviderImpl() override; ~AudioInputProviderImpl() override;
// assistant_client::AudioInputProvider overrides: // assistant_client::AudioInputProvider overrides:
AudioInputImpl& GetAudioInput() override; assistant_client::AudioInput& GetAudioInput() override;
int64_t GetCurrentAudioTime() override; int64_t GetCurrentAudioTime() override;
// Called when the mic state associated with the interaction is changed. // Called when the mic state associated with the interaction is changed.
......
...@@ -81,7 +81,7 @@ PlatformApiImpl::PlatformApiImpl( ...@@ -81,7 +81,7 @@ PlatformApiImpl::PlatformApiImpl(
PlatformApiImpl::~PlatformApiImpl() = default; PlatformApiImpl::~PlatformApiImpl() = default;
AudioInputProviderImpl& PlatformApiImpl::GetAudioInputProvider() { AudioInputProvider& PlatformApiImpl::GetAudioInputProvider() {
return audio_input_provider_; return audio_input_provider_;
} }
......
...@@ -39,7 +39,7 @@ class PlatformApiImpl : public assistant_client::PlatformApi { ...@@ -39,7 +39,7 @@ class PlatformApiImpl : public assistant_client::PlatformApi {
~PlatformApiImpl() override; ~PlatformApiImpl() override;
// assistant_client::PlatformApi overrides // assistant_client::PlatformApi overrides
AudioInputProviderImpl& GetAudioInputProvider() override; assistant_client::AudioInputProvider& GetAudioInputProvider() override;
assistant_client::AudioOutputProvider& GetAudioOutputProvider() override; assistant_client::AudioOutputProvider& GetAudioOutputProvider() override;
assistant_client::AuthProvider& GetAuthProvider() override; assistant_client::AuthProvider& GetAuthProvider() override;
assistant_client::FileProvider& GetFileProvider() override; assistant_client::FileProvider& GetFileProvider() override;
......
# Copyright 2018 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.
# C++ headers and sources that can be used outside ash.
component("cpp") {
sources = [
"features.cc",
"features.h",
]
public_deps = [
"//base",
]
}
// Copyright 2018 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.
#include "chromeos/services/assistant/public/cpp/features.h"
#include "base/feature_list.h"
#include "base/metrics/field_trial_params.h"
namespace chromeos {
namespace assistant {
const base::Feature kEnableDspHotword{"EnableDspHotword",
base::FEATURE_DISABLED_BY_DEFAULT};
bool IsDspHotwordEnabled() {
return base::FeatureList::IsEnabled(kEnableDspHotword);
}
} // namespace assistant
} // namespace chromeos
// Copyright 2018 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_FEATURES_H_
#define CHROMEOS_SERVICES_ASSISTANT_PUBLIC_CPP_FEATURES_H_
namespace base {
struct Feature;
} // namespace base
namespace chromeos {
namespace assistant {
// Enables DSP for hotword detection.
extern const base::Feature kEnableDspHotword;
bool IsDspHotwordEnabled();
} // namespace assistant
} // namespace chromeos
#endif // CHROMEOS_SERVICES_ASSISTANT_PUBLIC_CPP_FEATURES_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