Commit 31ba7ead authored by Xiaohui Chen's avatar Xiaohui Chen Committed by Commit Bot

assistant: add VLOG to audio input provider

Bug: b/117937718
Test: locally build and see logs on device.
Change-Id: Iea6b72b328c57d3c37e58692e2146f0b71c3218c
Reviewed-on: https://chromium-review.googlesource.com/c/1292549Reviewed-by: default avatarTao Wu <wutao@chromium.org>
Commit-Queue: Xiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#601358}
parent 1da15ee0
......@@ -4,6 +4,8 @@
#include "chromeos/services/assistant/platform/audio_input_provider_impl.h"
#include <utility>
#include "base/logging.h"
#include "base/stl_util.h"
#include "libassistant/shared/public/platform_audio_buffer.h"
......@@ -71,6 +73,7 @@ AudioInputImpl::AudioInputImpl(
AudioInputImpl::~AudioInputImpl() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
source_->Stop();
VLOG(1) << "Ending captured frames: " << captured_frames_count_;
}
void AudioInputImpl::Capture(const media::AudioBus* audio_source,
......@@ -89,10 +92,20 @@ void AudioInputImpl::Capture(const media::AudioBus* audio_source,
for (auto* observer : observers_)
observer->OnBufferAvailable(input_buffer, time);
}
captured_frames_count_ += audio_source->frames();
if (VLOG_IS_ON(1)) {
auto now = base::TimeTicks::Now();
if ((now - last_frame_count_report_time_) >
base::TimeDelta::FromMinutes(2)) {
VLOG(1) << "Captured frames: " << captured_frames_count_;
last_frame_count_report_time_ = now;
}
}
}
void AudioInputImpl::OnCaptureError(const std::string& message) {
DLOG(ERROR) << "Capture error " << message;
LOG(ERROR) << "Capture error " << message;
base::AutoLock lock(lock_);
for (auto* observer : observers_)
observer->OnError(AudioInput::Error::FATAL_ERROR);
......@@ -107,6 +120,7 @@ assistant_client::BufferFormat AudioInputImpl::GetFormat() const {
void AudioInputImpl::AddObserver(
assistant_client::AudioInput::Observer* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(observer_sequence_checker_);
VLOG(1) << "Add observer";
bool should_start = false;
{
base::AutoLock lock(lock_);
......@@ -127,6 +141,7 @@ void AudioInputImpl::AddObserver(
void AudioInputImpl::RemoveObserver(
assistant_client::AudioInput::Observer* observer) {
DCHECK_CALLED_ON_VALID_SEQUENCE(observer_sequence_checker_);
VLOG(1) << "Remove observer";
bool should_stop = false;
{
base::AutoLock lock(lock_);
......@@ -173,11 +188,13 @@ void AudioInputImpl::OnHotwordEnabled(bool enable) {
void AudioInputImpl::StartRecording() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
VLOG(1) << "Start recording";
source_->Start();
}
void AudioInputImpl::StopRecording() {
DCHECK(task_runner_->RunsTasksInCurrentSequence());
VLOG(1) << "Stop recording";
source_->Stop();
}
......
......@@ -6,6 +6,7 @@
#define CHROMEOS_SERVICES_ASSISTANT_PLATFORM_AUDIO_INPUT_PROVIDER_IMPL_H_
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
......@@ -88,6 +89,12 @@ class AudioInputImpl : public assistant_client::AudioInput,
base::Lock lock_;
std::vector<assistant_client::AudioInput::Observer*> observers_;
// This is the total number of frames captured during the life time of this
// object. We don't worry about overflow because this count is only used for
// logging purposes. If in the future this changes, we should re-evaluate.
int captured_frames_count_ = 0;
base::TimeTicks last_frame_count_report_time_;
// To be initialized on assistant thread the first call to AddObserver.
// It ensures that AddObserver / RemoveObserver are called on the same
// sequence.
......
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