Commit 46876cce authored by Oskar Sundbom's avatar Oskar Sundbom Committed by Commit Bot

APM move: Add AudioSourceParameters to AudioDeviceFactory et al

Putting parameters in a struct like this will make it easier to change
parameters going forward, as it should be less necessary to update
implementations that don't care about certain parameters.

This CL also adds processing configuration as a new, optional
audio source parameter to this struct. It is used to configure audio
processing when it's supported directly in the source, as will be the
case in the audio service.

For an outline of the project this CL is part of, see: https://docs.google.com/document/d/1u4POff_ts_1LE3WDLA_wDDFnUswdlsuHL5DsiTE0a3U/edit?usp=sharing
It's accessible to everyone @chromium.org.

Bug: 851959

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: Ibdcddf1bfc741467dcab68776872c6fcda0f43ad
Reviewed-on: https://chromium-review.googlesource.com/1167849
Commit-Queue: Oskar Sundbom <ossu@chromium.org>
Reviewed-by: default avatarNasko Oskov <nasko@chromium.org>
Reviewed-by: default avatarDale Curtis <dalecurtis@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#584025}
parent 439d3bfd
...@@ -158,19 +158,19 @@ AudioDeviceFactory::NewSwitchableAudioRendererSink( ...@@ -158,19 +158,19 @@ AudioDeviceFactory::NewSwitchableAudioRendererSink(
// static // static
scoped_refptr<media::AudioCapturerSource> scoped_refptr<media::AudioCapturerSource>
AudioDeviceFactory::NewAudioCapturerSource(int render_frame_id, AudioDeviceFactory::NewAudioCapturerSource(
int session_id) { int render_frame_id,
const media::AudioSourceParameters& params) {
if (factory_) { if (factory_) {
// We don't pass on |session_id|, as this branch is only used for tests. // We don't pass on |session_id|, as this branch is only used for tests.
scoped_refptr<media::AudioCapturerSource> source = scoped_refptr<media::AudioCapturerSource> source =
factory_->CreateAudioCapturerSource(render_frame_id); factory_->CreateAudioCapturerSource(render_frame_id, params);
if (source) if (source)
return source; return source;
} }
return base::MakeRefCounted<media::AudioInputDevice>( return base::MakeRefCounted<media::AudioInputDevice>(
AudioInputIPCFactory::get()->CreateAudioInputIPC(render_frame_id, AudioInputIPCFactory::get()->CreateAudioInputIPC(render_frame_id, params),
session_id),
base::ThreadPriority::REALTIME_AUDIO); base::ThreadPriority::REALTIME_AUDIO);
} }
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "media/audio/audio_sink_parameters.h" #include "media/audio/audio_sink_parameters.h"
#include "media/audio/audio_source_parameters.h"
#include "media/base/audio_latency.h" #include "media/base/audio_latency.h"
#include "media/base/output_device_info.h" #include "media/base/output_device_info.h"
...@@ -86,7 +87,7 @@ class CONTENT_EXPORT AudioDeviceFactory { ...@@ -86,7 +87,7 @@ class CONTENT_EXPORT AudioDeviceFactory {
// consuming the audio. // consuming the audio.
static scoped_refptr<media::AudioCapturerSource> NewAudioCapturerSource( static scoped_refptr<media::AudioCapturerSource> NewAudioCapturerSource(
int render_frame_id, int render_frame_id,
int session_id); const media::AudioSourceParameters& params);
protected: protected:
AudioDeviceFactory(); AudioDeviceFactory();
...@@ -115,7 +116,8 @@ class CONTENT_EXPORT AudioDeviceFactory { ...@@ -115,7 +116,8 @@ class CONTENT_EXPORT AudioDeviceFactory {
const media::AudioSinkParameters& params) = 0; const media::AudioSinkParameters& params) = 0;
virtual scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource( virtual scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource(
int render_frame_id) = 0; int render_frame_id,
const media::AudioSourceParameters& params) = 0;
private: private:
// The current globally registered factory. This is NULL when we should // The current globally registered factory. This is NULL when we should
......
...@@ -20,31 +20,33 @@ namespace { ...@@ -20,31 +20,33 @@ namespace {
void CreateMojoAudioInputStreamOnMainThread( void CreateMojoAudioInputStreamOnMainThread(
int frame_id, int frame_id,
int32_t session_id, const media::AudioSourceParameters& source_params,
mojom::RendererAudioInputStreamFactoryClientPtr client, mojom::RendererAudioInputStreamFactoryClientPtr client,
const media::AudioParameters& params, const media::AudioParameters& params,
bool automatic_gain_control, bool automatic_gain_control,
uint32_t total_segments) { uint32_t total_segments) {
// TODO(ossu): Make an AudioProcessingConfig from params and send that along.
RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_id); RenderFrameImpl* frame = RenderFrameImpl::FromRoutingID(frame_id);
if (frame) { if (frame) {
frame->GetAudioInputStreamFactory()->CreateStream( frame->GetAudioInputStreamFactory()->CreateStream(
std::move(client), session_id, params, automatic_gain_control, std::move(client), source_params.session_id, params,
total_segments); automatic_gain_control, total_segments);
} }
} }
void CreateMojoAudioInputStream( void CreateMojoAudioInputStream(
scoped_refptr<base::SequencedTaskRunner> main_task_runner, scoped_refptr<base::SequencedTaskRunner> main_task_runner,
int frame_id, int frame_id,
int32_t session_id, const media::AudioSourceParameters& source_params,
mojom::RendererAudioInputStreamFactoryClientPtr client, mojom::RendererAudioInputStreamFactoryClientPtr client,
const media::AudioParameters& params, const media::AudioParameters& params,
bool automatic_gain_control, bool automatic_gain_control,
uint32_t total_segments) { uint32_t total_segments) {
main_task_runner->PostTask( main_task_runner->PostTask(
FROM_HERE, base::BindOnce(&CreateMojoAudioInputStreamOnMainThread, FROM_HERE,
frame_id, session_id, std::move(client), params, base::BindOnce(&CreateMojoAudioInputStreamOnMainThread, frame_id,
automatic_gain_control, total_segments)); source_params, std::move(client), params,
automatic_gain_control, total_segments));
} }
void AssociateInputAndOutputForAec( void AssociateInputAndOutputForAec(
...@@ -86,11 +88,11 @@ AudioInputIPCFactory::~AudioInputIPCFactory() { ...@@ -86,11 +88,11 @@ AudioInputIPCFactory::~AudioInputIPCFactory() {
std::unique_ptr<media::AudioInputIPC> AudioInputIPCFactory::CreateAudioInputIPC( std::unique_ptr<media::AudioInputIPC> AudioInputIPCFactory::CreateAudioInputIPC(
int frame_id, int frame_id,
int session_id) const { const media::AudioSourceParameters& source_params) const {
DCHECK_NE(0, session_id); DCHECK_NE(0, source_params.session_id);
return std::make_unique<MojoAudioInputIPC>( return std::make_unique<MojoAudioInputIPC>(
base::BindRepeating(&CreateMojoAudioInputStream, main_task_runner_, base::BindRepeating(&CreateMojoAudioInputStream, main_task_runner_,
frame_id, session_id), frame_id, source_params),
base::BindRepeating(&AssociateInputAndOutputForAec, main_task_runner_, base::BindRepeating(&AssociateInputAndOutputForAec, main_task_runner_,
frame_id)); frame_id));
} }
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include "base/containers/flat_map.h" #include "base/containers/flat_map.h"
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "content/common/content_export.h" #include "content/common/content_export.h"
#include "media/audio/audio_source_parameters.h"
namespace base { namespace base {
class SequencedTaskRunner; class SequencedTaskRunner;
...@@ -43,7 +44,7 @@ class CONTENT_EXPORT AudioInputIPCFactory { ...@@ -43,7 +44,7 @@ class CONTENT_EXPORT AudioInputIPCFactory {
// The returned object may only be used on io_task_runner(). // The returned object may only be used on io_task_runner().
std::unique_ptr<media::AudioInputIPC> CreateAudioInputIPC( std::unique_ptr<media::AudioInputIPC> CreateAudioInputIPC(
int frame_id, int frame_id,
int session_id) const; const media::AudioSourceParameters& source_params) const;
private: private:
const scoped_refptr<base::SequencedTaskRunner> main_task_runner_; const scoped_refptr<base::SequencedTaskRunner> main_task_runner_;
......
...@@ -22,7 +22,9 @@ MockAudioDeviceFactory::MockAudioDeviceFactory() ...@@ -22,7 +22,9 @@ MockAudioDeviceFactory::MockAudioDeviceFactory()
MockAudioDeviceFactory::~MockAudioDeviceFactory() {} MockAudioDeviceFactory::~MockAudioDeviceFactory() {}
scoped_refptr<media::AudioCapturerSource> scoped_refptr<media::AudioCapturerSource>
MockAudioDeviceFactory::CreateAudioCapturerSource(int render_frame_id) { MockAudioDeviceFactory::CreateAudioCapturerSource(
int render_frame_id,
const media::AudioSourceParameters& params) {
CHECK(!did_create_once_); CHECK(!did_create_once_);
did_create_once_ = true; did_create_once_ = true;
return scoped_refptr<media::AudioCapturerSource>(mock_capturer_source_); return scoped_refptr<media::AudioCapturerSource>(mock_capturer_source_);
......
...@@ -64,7 +64,8 @@ class MockAudioDeviceFactory : public AudioDeviceFactory { ...@@ -64,7 +64,8 @@ class MockAudioDeviceFactory : public AudioDeviceFactory {
// Returns mock_capturer_source_ once. If called a second time, the process // Returns mock_capturer_source_ once. If called a second time, the process
// will crash. // will crash.
scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource( scoped_refptr<media::AudioCapturerSource> CreateAudioCapturerSource(
int render_frame_id) override; int render_frame_id,
const media::AudioSourceParameters& params) override;
private: private:
scoped_refptr<MockCapturerSource> mock_capturer_source_; scoped_refptr<MockCapturerSource> mock_capturer_source_;
......
...@@ -80,8 +80,10 @@ class RendererWebAudioDeviceImplTest ...@@ -80,8 +80,10 @@ class RendererWebAudioDeviceImplTest
webaudio_device_->SetMediaTaskRunnerForTesting(message_loop_.task_runner()); webaudio_device_->SetMediaTaskRunnerForTesting(message_loop_.task_runner());
} }
MOCK_METHOD1(CreateAudioCapturerSource, MOCK_METHOD2(CreateAudioCapturerSource,
scoped_refptr<media::AudioCapturerSource>(int)); scoped_refptr<media::AudioCapturerSource>(
int,
const media::AudioSourceParameters&));
MOCK_METHOD2(CreateFinalAudioRendererSink, MOCK_METHOD2(CreateFinalAudioRendererSink,
scoped_refptr<media::AudioRendererSink>( scoped_refptr<media::AudioRendererSink>(
int, int,
......
...@@ -66,7 +66,8 @@ bool LocalMediaStreamAudioSource::EnsureSourceIsStarted() { ...@@ -66,7 +66,8 @@ bool LocalMediaStreamAudioSource::EnsureSourceIsStarted() {
<< GetAudioParameters().AsHumanReadableString() << "}."; << GetAudioParameters().AsHumanReadableString() << "}.";
source_ = AudioDeviceFactory::NewAudioCapturerSource( source_ = AudioDeviceFactory::NewAudioCapturerSource(
consumer_render_frame_id_, device().session_id); consumer_render_frame_id_,
media::AudioSourceParameters(device().session_id));
source_->Initialize(GetAudioParameters(), this); source_->Initialize(GetAudioParameters(), this);
source_->Start(); source_->Start();
return true; return true;
......
...@@ -203,8 +203,9 @@ bool ProcessedLocalAudioSource::EnsureSourceIsStarted() { ...@@ -203,8 +203,9 @@ bool ProcessedLocalAudioSource::EnsureSourceIsStarted() {
<< params.AsHumanReadableString() << "} and output parameters={" << params.AsHumanReadableString() << "} and output parameters={"
<< GetAudioParameters().AsHumanReadableString() << '}'; << GetAudioParameters().AsHumanReadableString() << '}';
scoped_refptr<media::AudioCapturerSource> new_source = scoped_refptr<media::AudioCapturerSource> new_source =
AudioDeviceFactory::NewAudioCapturerSource(consumer_render_frame_id_, AudioDeviceFactory::NewAudioCapturerSource(
device().session_id); consumer_render_frame_id_,
media::AudioSourceParameters(device().session_id));
new_source->Initialize(params, this); new_source->Initialize(params, this);
// We need to set the AGC control before starting the stream. // We need to set the AGC control before starting the stream.
new_source->SetAutomaticGainControl(true); new_source->SetAutomaticGainControl(true);
......
...@@ -83,8 +83,10 @@ class WebRtcAudioRendererTest : public testing::Test, ...@@ -83,8 +83,10 @@ class WebRtcAudioRendererTest : public testing::Test,
renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_); renderer_proxy_ = renderer_->CreateSharedAudioRendererProxy(stream_);
} }
MOCK_METHOD1(CreateAudioCapturerSource, MOCK_METHOD2(CreateAudioCapturerSource,
scoped_refptr<media::AudioCapturerSource>(int)); scoped_refptr<media::AudioCapturerSource>(
int,
const media::AudioSourceParameters&));
MOCK_METHOD2(CreateFinalAudioRendererSink, MOCK_METHOD2(CreateFinalAudioRendererSink,
scoped_refptr<media::AudioRendererSink>( scoped_refptr<media::AudioRendererSink>(
int, int,
......
...@@ -176,8 +176,8 @@ void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) { ...@@ -176,8 +176,8 @@ void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) {
DCHECK(io_task_runner_->BelongsToCurrentThread()); DCHECK(io_task_runner_->BelongsToCurrentThread());
if (ipc_startup_state_ != kStopped) if (ipc_startup_state_ != kStopped)
ipc_ = AudioInputIPCFactory::get()->CreateAudioInputIPC(render_frame_id_, ipc_ = AudioInputIPCFactory::get()->CreateAudioInputIPC(
session_id); render_frame_id_, media::AudioSourceParameters(session_id));
if (!ipc_) if (!ipc_)
return; return;
......
...@@ -127,6 +127,8 @@ source_set("audio") { ...@@ -127,6 +127,8 @@ source_set("audio") {
"audio_sink_parameters.cc", "audio_sink_parameters.cc",
"audio_sink_parameters.h", "audio_sink_parameters.h",
"audio_source_diverter.h", "audio_source_diverter.h",
"audio_source_parameters.cc",
"audio_source_parameters.h",
"audio_sync_reader.cc", "audio_sync_reader.cc",
"audio_sync_reader.h", "audio_sync_reader.h",
"audio_system.cc", "audio_system.cc",
......
...@@ -218,6 +218,9 @@ void AudioInputDevice::OnStreamCreated( ...@@ -218,6 +218,9 @@ void AudioInputDevice::OnStreamCreated(
if (initially_muted) if (initially_muted)
callback_->OnCaptureMuted(true); callback_->OnCaptureMuted(true);
if (auto* controls = ipc_->GetProcessorControls())
callback_->OnCaptureProcessorCreated(controls);
if (output_device_id_for_aec_) if (output_device_id_for_aec_)
ipc_->SetOutputDeviceForAec(*output_device_id_for_aec_); ipc_->SetOutputDeviceForAec(*output_device_id_for_aec_);
......
...@@ -10,4 +10,8 @@ AudioInputIPCDelegate::~AudioInputIPCDelegate() = default; ...@@ -10,4 +10,8 @@ AudioInputIPCDelegate::~AudioInputIPCDelegate() = default;
AudioInputIPC::~AudioInputIPC() = default; AudioInputIPC::~AudioInputIPC() = default;
AudioProcessorControls* AudioInputIPC::GetProcessorControls() {
return nullptr;
}
} // namespace media } // namespace media
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace media { namespace media {
class AudioProcessorControls;
// Contains IPC notifications for the state of the server side // Contains IPC notifications for the state of the server side
// (AudioInputController) audio state changes and when an AudioInputController // (AudioInputController) audio state changes and when an AudioInputController
// has been created. Implemented by AudioInputDevice. // has been created. Implemented by AudioInputDevice.
...@@ -72,6 +74,10 @@ class MEDIA_EXPORT AudioInputIPC { ...@@ -72,6 +74,10 @@ class MEDIA_EXPORT AudioInputIPC {
// called before the stream has been successfully created. // called before the stream has been successfully created.
virtual void SetOutputDeviceForAec(const std::string& output_device_id) = 0; virtual void SetOutputDeviceForAec(const std::string& output_device_id) = 0;
// If the input has built-in processing, returns a pointer to processing
// controls. Valid after the stream has been created.
virtual AudioProcessorControls* GetProcessorControls();
// Closes the audio stream, which should shut down the corresponding // Closes the audio stream, which should shut down the corresponding
// AudioInputController in the peer process. // AudioInputController in the peer process.
virtual void CloseStream() = 0; virtual void CloseStream() = 0;
......
// 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 "media/audio/audio_source_parameters.h"
namespace media {
AudioSourceParameters::AudioSourceParameters() = default;
AudioSourceParameters::AudioSourceParameters(int session_id)
: session_id(session_id) {}
AudioSourceParameters::AudioSourceParameters(
const AudioSourceParameters& params) = default;
AudioSourceParameters::~AudioSourceParameters() = default;
AudioSourceParameters::ProcessingConfig::ProcessingConfig(
base::UnguessableToken id,
AudioProcessingSettings settings)
: id(id), settings(settings) {
DCHECK(!id.is_empty());
}
} // namespace media
// 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 MEDIA_AUDIO_AUDIO_SOURCE_PARAMETERS_H_
#define MEDIA_AUDIO_AUDIO_SOURCE_PARAMETERS_H_
#include <string>
#include "base/optional.h"
#include "base/unguessable_token.h"
#include "media/audio/audio_processing.h"
#include "media/base/media_export.h"
namespace media {
// The set of parameters used to create an AudioInputDevice.
// If |session_id| is nonzero, it is used by the browser
// to select the correct input device ID. If |session_id| is zero, the default
// input device will be selected. This is the state when default constructed.
struct MEDIA_EXPORT AudioSourceParameters final {
AudioSourceParameters();
explicit AudioSourceParameters(int session_id);
AudioSourceParameters(const AudioSourceParameters& params);
~AudioSourceParameters();
int session_id = 0;
struct ProcessingConfig {
ProcessingConfig(base::UnguessableToken id,
AudioProcessingSettings settings);
base::UnguessableToken id;
AudioProcessingSettings settings;
};
base::Optional<ProcessingConfig> processing;
};
} // namespace media
#endif // MEDIA_AUDIO_AUDIO_SOURCE_PARAMETERS_H_
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
namespace media { namespace media {
class AudioProcessorControls;
// AudioCapturerSource is an interface representing the source for // AudioCapturerSource is an interface representing the source for
// captured audio. An implementation will periodically call Capture() on a // captured audio. An implementation will periodically call Capture() on a
// callback object. // callback object.
...@@ -45,6 +47,10 @@ class AudioCapturerSource ...@@ -45,6 +47,10 @@ class AudioCapturerSource
// OnCaptureStarted. // OnCaptureStarted.
virtual void OnCaptureMuted(bool is_muted) = 0; virtual void OnCaptureMuted(bool is_muted) = 0;
// For streams created with audio processing, signals that a controllable
// audio processor has been created.
virtual void OnCaptureProcessorCreated(AudioProcessorControls* controls) {}
protected: protected:
virtual ~CaptureCallback() {} virtual ~CaptureCallback() {}
}; };
......
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