Skip to content

Commit

Permalink
Migrate references of content::mojom::RendererAudioInputStreamFactory…
Browse files Browse the repository at this point in the history
…Client

Convert both the implementation and clients in the browser and renderer
processes for the content.mojom.RendererAudioInputStreamFactoryClient
interface, and adapt unit tests.

Bug: 955171
Change-Id: Ifee40a10fb7957b4ce606f46ed9183d93498ba94
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1800765
Reviewed-by: Tommi <tommi@chromium.org>
Reviewed-by: Oksana Zhuravlova <oksamyt@chromium.org>
Reviewed-by: Ken Buchanan <kenrb@chromium.org>
Reviewed-by: Yuri Wiitala <miu@chromium.org>
Commit-Queue: Mario Sanchez Prada <mario@igalia.com>
Cr-Commit-Position: refs/heads/master@{#696798}
  • Loading branch information
mariospr authored and Commit Bot committed Sep 16, 2019
1 parent 4f12a99 commit 8d5bfb8
Show file tree
Hide file tree
Showing 25 changed files with 196 additions and 151 deletions.
6 changes: 3 additions & 3 deletions content/browser/media/audio_input_stream_broker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#include "media/audio/audio_logging.h"
#include "media/base/media_switches.h"
#include "media/base/user_input_monitor.h"
#include "mojo/public/cpp/bindings/interface_request.h"
#include "mojo/public/cpp/system/platform_handle.h"

#if defined(OS_CHROMEOS)
Expand Down Expand Up @@ -70,7 +69,8 @@ AudioInputStreamBroker::AudioInputStreamBroker(
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client)
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client)
: AudioStreamBroker(render_process_id, render_frame_id),
device_id_(device_id),
params_(params),
Expand All @@ -79,7 +79,7 @@ AudioInputStreamBroker::AudioInputStreamBroker(
enable_agc_(enable_agc),
deleter_(std::move(deleter)),
processing_config_(std::move(processing_config)),
renderer_factory_client_(renderer_factory_client.PassInterface()) {
renderer_factory_client_(std::move(renderer_factory_client)) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(renderer_factory_client_);
DCHECK(deleter_);
Expand Down
4 changes: 3 additions & 1 deletion content/browser/media/audio_input_stream_broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "media/mojo/mojom/audio_data_pipe.mojom.h"
#include "media/mojo/mojom/audio_input_stream.mojom.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/audio/public/mojom/audio_processing.mojom.h"
Expand Down Expand Up @@ -43,7 +44,8 @@ class CONTENT_EXPORT AudioInputStreamBroker final
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client);
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client);

~AudioInputStreamBroker() final;

Expand Down
19 changes: 9 additions & 10 deletions content/browser/media/audio_input_stream_broker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "base/test/mock_callback.h"
#include "content/public/test/browser_task_environment.h"
#include "media/mojo/mojom/audio_input_stream.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/audio/public/cpp/fake_stream_factory.h"
Expand Down Expand Up @@ -47,10 +47,9 @@ class MockRendererAudioInputStreamFactoryClient
MockRendererAudioInputStreamFactoryClient() = default;
~MockRendererAudioInputStreamFactoryClient() override = default;

mojom::RendererAudioInputStreamFactoryClientPtr MakePtr() {
mojom::RendererAudioInputStreamFactoryClientPtr ret;
binding_.Bind(mojo::MakeRequest(&ret));
return ret;
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
MakeRemote() {
return receiver_.BindNewPipeAndPassRemote();
}

MOCK_METHOD0(OnStreamCreated, void());
Expand All @@ -67,10 +66,10 @@ class MockRendererAudioInputStreamFactoryClient
OnStreamCreated();
}

void CloseBinding() { binding_.Close(); }
void CloseReceiver() { receiver_.reset(); }

private:
mojo::Binding<mojom::RendererAudioInputStreamFactoryClient> binding_{this};
mojo::Receiver<mojom::RendererAudioInputStreamFactoryClient> receiver_{this};
media::mojom::AudioInputStreamPtr input_stream_;
media::mojom::AudioInputStreamClientRequest client_request_;
DISALLOW_COPY_AND_ASSIGN(MockRendererAudioInputStreamFactoryClient);
Expand Down Expand Up @@ -151,7 +150,7 @@ struct TestEnvironment {
kEnableAgc,
nullptr,
deleter.Get(),
renderer_factory_client.MakePtr())) {}
renderer_factory_client.MakeRemote())) {}

void RunUntilIdle() { task_environment.RunUntilIdle(); }

Expand All @@ -174,7 +173,7 @@ TEST(AudioInputStreamBrokerTest, StoresProcessAndFrameId) {
AudioInputStreamBroker broker(
kRenderProcessId, kRenderFrameId, kDeviceId, TestParams(), kShMemCount,
nullptr /*user_input_monitor*/, kEnableAgc, nullptr, deleter.Get(),
renderer_factory_client.MakePtr());
renderer_factory_client.MakeRemote());

EXPECT_EQ(kRenderProcessId, broker.render_process_id());
EXPECT_EQ(kRenderFrameId, broker.render_frame_id());
Expand Down Expand Up @@ -242,7 +241,7 @@ TEST(AudioInputStreamBrokerTest, RendererFactoryClientDisconnect_CallsDeleter) {

EXPECT_CALL(env.deleter, Run(env.broker.release()))
.WillOnce(testing::DeleteArg<0>());
env.renderer_factory_client.CloseBinding();
env.renderer_factory_client.CloseReceiver();
env.RunUntilIdle();
Mock::VerifyAndClear(&env.deleter);

Expand Down
5 changes: 3 additions & 2 deletions content/browser/media/audio_loopback_stream_broker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ AudioLoopbackStreamBroker::AudioLoopbackStreamBroker(
uint32_t shared_memory_count,
bool mute_source,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client)
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client)
: AudioStreamBroker(render_process_id, render_frame_id),
source_(source),
params_(params),
Expand All @@ -43,7 +44,7 @@ AudioLoopbackStreamBroker::AudioLoopbackStreamBroker(
}

// Unretained is safe because |this| owns |renderer_factory_client_|.
renderer_factory_client_.set_connection_error_handler(base::BindOnce(
renderer_factory_client_.set_disconnect_handler(base::BindOnce(
&AudioLoopbackStreamBroker::Cleanup, base::Unretained(this)));

// Notify the source that we are capturing from it.
Expand Down
8 changes: 6 additions & 2 deletions content/browser/media/audio_loopback_stream_broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "media/mojo/mojom/audio_data_pipe.mojom.h"
#include "media/mojo/mojom/audio_input_stream.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"

namespace audio {
namespace mojom {
Expand All @@ -42,7 +44,8 @@ class CONTENT_EXPORT AudioLoopbackStreamBroker final
uint32_t shared_memory_count,
bool mute_source,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client);
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client);

~AudioLoopbackStreamBroker() final;

Expand Down Expand Up @@ -72,7 +75,8 @@ class CONTENT_EXPORT AudioLoopbackStreamBroker final
// loopback stream is running.
base::Optional<AudioMutingSession> muter_;

mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client_;
mojo::Remote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client_;
mojo::Binding<AudioInputStreamObserver> observer_binding_;
media::mojom::AudioInputStreamClientRequest client_request_;

Expand Down
20 changes: 10 additions & 10 deletions content/browser/media/audio_loopback_stream_broker_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "content/public/test/browser_task_environment.h"
#include "media/mojo/mojom/audio_input_stream.mojom.h"
#include "mojo/public/cpp/bindings/pending_associated_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "services/audio/public/cpp/fake_stream_factory.h"
Expand Down Expand Up @@ -58,13 +59,12 @@ using MockDeleterCallback = StrictMock<
class MockRendererAudioInputStreamFactoryClient
: public mojom::RendererAudioInputStreamFactoryClient {
public:
MockRendererAudioInputStreamFactoryClient() : binding_(this) {}
MockRendererAudioInputStreamFactoryClient() = default;
~MockRendererAudioInputStreamFactoryClient() override {}

mojom::RendererAudioInputStreamFactoryClientPtr MakePtr() {
mojom::RendererAudioInputStreamFactoryClientPtr ret;
binding_.Bind(mojo::MakeRequest(&ret));
return ret;
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
MakeRemote() {
return receiver_.BindNewPipeAndPassRemote();
}

MOCK_METHOD0(OnStreamCreated, void());
Expand All @@ -82,10 +82,10 @@ class MockRendererAudioInputStreamFactoryClient
OnStreamCreated();
}

void CloseBinding() { binding_.Close(); }
void CloseReceiver() { receiver_.reset(); }

private:
mojo::Binding<mojom::RendererAudioInputStreamFactoryClient> binding_;
mojo::Receiver<mojom::RendererAudioInputStreamFactoryClient> receiver_{this};
media::mojom::AudioInputStreamPtr input_stream_;
media::mojom::AudioInputStreamClientRequest client_request_;
};
Expand Down Expand Up @@ -163,7 +163,7 @@ struct TestEnvironment {
EXPECT_CALL(source, AddLoopbackSink(_));
broker = std::make_unique<AudioLoopbackStreamBroker>(
kRenderProcessId, kRenderFrameId, &source, TestParams(), kShMemCount,
mute_source, deleter.Get(), renderer_factory_client.MakePtr());
mute_source, deleter.Get(), renderer_factory_client.MakeRemote());
}

void RunUntilIdle() { task_environment.RunUntilIdle(); }
Expand Down Expand Up @@ -191,7 +191,7 @@ TEST(AudioLoopbackStreamBrokerTest, StoresProcessAndFrameId) {

AudioLoopbackStreamBroker broker(
kRenderProcessId, kRenderFrameId, &source, TestParams(), kShMemCount,
!kMuteSource, deleter.Get(), renderer_factory_client.MakePtr());
!kMuteSource, deleter.Get(), renderer_factory_client.MakeRemote());

EXPECT_EQ(kRenderProcessId, broker.render_process_id());
EXPECT_EQ(kRenderFrameId, broker.render_frame_id());
Expand Down Expand Up @@ -332,7 +332,7 @@ TEST(AudioLoopbackStreamBrokerTest,

EXPECT_CALL(env.deleter, Run(env.broker.release()))
.WillOnce(testing::DeleteArg<0>());
env.renderer_factory_client.CloseBinding();
env.renderer_factory_client.CloseReceiver();
env.RunUntilIdle();
Mock::VerifyAndClear(&env.deleter);

Expand Down
8 changes: 4 additions & 4 deletions content/browser/media/audio_stream_broker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ class AudioStreamBrokerFactoryImpl final : public AudioStreamBrokerFactory {
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client)
final {
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) final {
return std::make_unique<AudioInputStreamBroker>(
render_process_id, render_frame_id, device_id, params,
shared_memory_count, user_input_monitor, enable_agc,
Expand All @@ -52,8 +52,8 @@ class AudioStreamBrokerFactoryImpl final : public AudioStreamBrokerFactory {
uint32_t shared_memory_count,
bool mute_source,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client)
final {
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) final {
return std::make_unique<AudioLoopbackStreamBroker>(
render_process_id, render_frame_id, source, params, shared_memory_count,
mute_source, std::move(deleter), std::move(renderer_factory_client));
Expand Down
5 changes: 3 additions & 2 deletions content/browser/media/audio_stream_broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "content/common/media/renderer_audio_input_stream_factory.mojom.h"
#include "media/mojo/mojom/audio_input_stream.mojom.h"
#include "media/mojo/mojom/audio_output_stream.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "services/audio/public/mojom/audio_processing.mojom.h"

namespace audio {
Expand Down Expand Up @@ -107,7 +108,7 @@ class CONTENT_EXPORT AudioStreamBrokerFactory {
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) = 0;

virtual std::unique_ptr<AudioStreamBroker> CreateAudioLoopbackStreamBroker(
Expand All @@ -118,7 +119,7 @@ class CONTENT_EXPORT AudioStreamBrokerFactory {
uint32_t shared_memory_count,
bool mute_source,
AudioStreamBroker::DeleterCallback deleter,
mojom::RendererAudioInputStreamFactoryClientPtr
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) = 0;

virtual std::unique_ptr<AudioStreamBroker> CreateAudioOutputStreamBroker(
Expand Down
6 changes: 4 additions & 2 deletions content/browser/media/forwarding_audio_stream_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ void ForwardingAudioStreamFactory::Core::CreateInputStream(
uint32_t shared_memory_count,
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client) {
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);

// |this| owns |inputs_|, so Unretained is safe.
Expand Down Expand Up @@ -117,7 +118,8 @@ void ForwardingAudioStreamFactory::Core::CreateLoopbackStream(
const media::AudioParameters& params,
uint32_t shared_memory_count,
bool mute_source,
mojom::RendererAudioInputStreamFactoryClientPtr renderer_factory_client) {
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client) {
DCHECK_CURRENTLY_ON(BrowserThread::IO);
DCHECK(loopback_source);

Expand Down
5 changes: 3 additions & 2 deletions content/browser/media/forwarding_audio_stream_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "content/common/media/renderer_audio_input_stream_factory.mojom.h"
#include "content/public/browser/web_contents_observer.h"
#include "media/mojo/mojom/audio_output_stream.mojom.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "services/audio/public/mojom/audio_processing.mojom.h"
#include "services/audio/public/mojom/stream_factory.mojom.h"
Expand Down Expand Up @@ -84,7 +85,7 @@ class CONTENT_EXPORT ForwardingAudioStreamFactory final
uint32_t shared_memory_count,
bool enable_agc,
audio::mojom::AudioProcessingConfigPtr processing_config,
mojom::RendererAudioInputStreamFactoryClientPtr
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client);

void AssociateInputAndOutputForAec(
Expand All @@ -106,7 +107,7 @@ class CONTENT_EXPORT ForwardingAudioStreamFactory final
const media::AudioParameters& params,
uint32_t shared_memory_count,
bool mute_source,
mojom::RendererAudioInputStreamFactoryClientPtr
mojo::PendingRemote<mojom::RendererAudioInputStreamFactoryClient>
renderer_factory_client);

// Sets the muting state for all output streams created through this
Expand Down
Loading

0 comments on commit 8d5bfb8

Please sign in to comment.