Commit 494a6807 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

Convert RemotingDataStreamSender to new Mojo types

This CL converts RemotingDataStreamSender to new Mojo types using
PendingRemote, PendingReceiever, Receiver, and Remote.

Bug: 955171
Change-Id: I6e19b01ee378d1996e1bed31dea0fed7bc8baefc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1923972
Commit-Queue: Julie Kim <jkim@igalia.com>
Reviewed-by: default avatarmark a. foltz <mfoltz@chromium.org>
Reviewed-by: default avatarYuri Wiitala <miu@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#718420}
parent 44ef83fe
...@@ -26,7 +26,6 @@ ...@@ -26,7 +26,6 @@
#include "content/public/browser/render_frame_host.h" #include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h" #include "content/public/browser/render_process_host.h"
#include "content/public/browser/web_contents.h" #include "content/public/browser/web_contents.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h" #include "mojo/public/cpp/bindings/self_owned_receiver.h"
#if defined(TOOLKIT_VIEWS) #if defined(TOOLKIT_VIEWS)
...@@ -91,13 +90,13 @@ class CastRemotingConnector::RemotingBridge : public media::mojom::Remoter { ...@@ -91,13 +90,13 @@ class CastRemotingConnector::RemotingBridge : public media::mojom::Remoter {
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
audio_sender_receiver, audio_sender,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
video_sender_receiver) final { video_sender) final {
if (connector_) { if (connector_) {
connector_->StartRemotingDataStreams( connector_->StartRemotingDataStreams(
this, std::move(audio_pipe), std::move(video_pipe), this, std::move(audio_pipe), std::move(video_pipe),
std::move(audio_sender_receiver), std::move(video_sender_receiver)); std::move(audio_sender), std::move(video_sender));
} }
} }
void Stop(RemotingStopReason reason) final { void Stop(RemotingStopReason reason) final {
...@@ -382,48 +381,47 @@ void CastRemotingConnector::StartRemotingDataStreams( ...@@ -382,48 +381,47 @@ void CastRemotingConnector::StartRemotingDataStreams(
RemotingBridge* bridge, RemotingBridge* bridge,
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> audio_sender,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
audio_sender_receiver, video_sender) {
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
video_sender_receiver) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
// Refuse to start if there is no remoting route available, or if remoting is // Refuse to start if there is no remoting route available, or if remoting is
// not active for this |bridge|. // not active for this |bridge|.
if ((!deprecated_remoter_ && !remoter_) || active_bridge_ != bridge) if ((!deprecated_remoter_ && !remoter_) || active_bridge_ != bridge)
return; return;
// Also, if neither audio nor video pipe was provided, or if a request for a // Also, if neither audio nor video pipe was provided, or if a receiver for a
// RemotingDataStreamSender was not provided for a data pipe, error-out early. // RemotingDataStreamSender was not provided for a data pipe, error-out early.
if ((!audio_pipe.is_valid() && !video_pipe.is_valid()) || if ((!audio_pipe.is_valid() && !video_pipe.is_valid()) ||
(audio_pipe.is_valid() && !audio_sender_receiver.is_valid()) || (audio_pipe.is_valid() && !audio_sender.is_valid()) ||
(video_pipe.is_valid() && !video_sender_receiver.is_valid())) { (video_pipe.is_valid() && !video_sender.is_valid())) {
StopRemoting(active_bridge_, RemotingStopReason::DATA_SEND_FAILED, false); StopRemoting(active_bridge_, RemotingStopReason::DATA_SEND_FAILED, false);
return; return;
} }
if (deprecated_remoter_) { if (deprecated_remoter_) {
DCHECK(!remoter_); DCHECK(!remoter_);
const bool want_audio = audio_sender_receiver.is_valid(); const bool want_audio = audio_sender.is_valid();
const bool want_video = video_sender_receiver.is_valid(); const bool want_video = video_sender.is_valid();
deprecated_remoter_->StartDataStreams( deprecated_remoter_->StartDataStreams(
want_audio, want_video, want_audio, want_video,
base::BindOnce(&CastRemotingConnector::OnDataStreamsStarted, base::BindOnce(&CastRemotingConnector::OnDataStreamsStarted,
weak_factory_.GetWeakPtr(), std::move(audio_pipe), weak_factory_.GetWeakPtr(), std::move(audio_pipe),
std::move(video_pipe), std::move(audio_sender_receiver), std::move(video_pipe), std::move(audio_sender),
std::move(video_sender_receiver))); std::move(video_sender)));
} else { } else {
DCHECK(remoter_); DCHECK(remoter_);
remoter_->StartDataStreams(std::move(audio_pipe), std::move(video_pipe), remoter_->StartDataStreams(std::move(audio_pipe), std::move(video_pipe),
std::move(audio_sender_receiver), std::move(audio_sender),
std::move(video_sender_receiver)); std::move(video_sender));
} }
} }
void CastRemotingConnector::OnDataStreamsStarted( void CastRemotingConnector::OnDataStreamsStarted(
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
media::mojom::RemotingDataStreamSenderRequest audio_sender_request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> audio_sender,
media::mojom::RemotingDataStreamSenderRequest video_sender_request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> video_sender,
int32_t audio_stream_id, int32_t audio_stream_id,
int32_t video_stream_id) { int32_t video_stream_id) {
DCHECK_CURRENTLY_ON(BrowserThread::UI); DCHECK_CURRENTLY_ON(BrowserThread::UI);
...@@ -435,15 +433,15 @@ void CastRemotingConnector::OnDataStreamsStarted( ...@@ -435,15 +433,15 @@ void CastRemotingConnector::OnDataStreamsStarted(
return; return;
} }
if (audio_sender_request.is_pending() && audio_stream_id > -1) { if (audio_sender && audio_stream_id > -1) {
mirroring::CastRemotingSender::FindAndBind( mirroring::CastRemotingSender::FindAndBind(
audio_stream_id, std::move(audio_pipe), std::move(audio_sender_request), audio_stream_id, std::move(audio_pipe), std::move(audio_sender),
base::BindOnce(&CastRemotingConnector::OnDataSendFailed, base::BindOnce(&CastRemotingConnector::OnDataSendFailed,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
if (video_sender_request.is_pending() && video_stream_id > -1) { if (video_sender && video_stream_id > -1) {
mirroring::CastRemotingSender::FindAndBind( mirroring::CastRemotingSender::FindAndBind(
video_stream_id, std::move(video_pipe), std::move(video_sender_request), video_stream_id, std::move(video_pipe), std::move(video_sender),
base::BindOnce(&CastRemotingConnector::OnDataSendFailed, base::BindOnce(&CastRemotingConnector::OnDataSendFailed,
weak_factory_.GetWeakPtr())); weak_factory_.GetWeakPtr()));
} }
......
...@@ -176,9 +176,9 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -176,9 +176,9 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
audio_sender_receiver, audio_sender,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
video_sender_receiver); video_sender);
void StopRemoting(RemotingBridge* bridge, void StopRemoting(RemotingBridge* bridge,
media::mojom::RemotingStopReason reason, media::mojom::RemotingStopReason reason,
bool is_initiated_by_source); bool is_initiated_by_source);
...@@ -195,8 +195,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data, ...@@ -195,8 +195,10 @@ class CastRemotingConnector : public base::SupportsUserData::Data,
void OnDataStreamsStarted( void OnDataStreamsStarted(
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
media::mojom::RemotingDataStreamSenderRequest audio_sender_request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
media::mojom::RemotingDataStreamSenderRequest video_sender_request, audio_sender,
mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
video_sender,
int32_t audio_stream_id, int32_t audio_stream_id,
int32_t video_stream_id); int32_t video_stream_id);
......
...@@ -91,7 +91,6 @@ CastRemotingSender::CastRemotingSender( ...@@ -91,7 +91,6 @@ CastRemotingSender::CastRemotingSender(
logging_flush_interval_(logging_flush_interval), logging_flush_interval_(logging_flush_interval),
frame_event_cb_(cb), frame_event_cb_(cb),
clock_(base::DefaultTickClock::GetInstance()), clock_(base::DefaultTickClock::GetInstance()),
binding_(this),
max_ack_delay_(kMaxAckDelay), max_ack_delay_(kMaxAckDelay),
last_sent_frame_id_(media::cast::FrameId::first() - 1), last_sent_frame_id_(media::cast::FrameId::first() - 1),
latest_acked_frame_id_(media::cast::FrameId::first() - 1), latest_acked_frame_id_(media::cast::FrameId::first() - 1),
...@@ -130,7 +129,7 @@ CastRemotingSender::~CastRemotingSender() { ...@@ -130,7 +129,7 @@ CastRemotingSender::~CastRemotingSender() {
void CastRemotingSender::FindAndBind( void CastRemotingSender::FindAndBind(
int32_t rtp_stream_id, int32_t rtp_stream_id,
mojo::ScopedDataPipeConsumerHandle pipe, mojo::ScopedDataPipeConsumerHandle pipe,
media::mojom::RemotingDataStreamSenderRequest request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> stream_sender,
base::OnceClosure error_callback) { base::OnceClosure error_callback) {
// CastRemotingSender lives entirely on the IO thread, so trampoline if // CastRemotingSender lives entirely on the IO thread, so trampoline if
// necessary. // necessary.
...@@ -139,7 +138,7 @@ void CastRemotingSender::FindAndBind( ...@@ -139,7 +138,7 @@ void CastRemotingSender::FindAndBind(
FROM_HERE, {BrowserThread::IO}, FROM_HERE, {BrowserThread::IO},
base::BindOnce( base::BindOnce(
&CastRemotingSender::FindAndBind, rtp_stream_id, std::move(pipe), &CastRemotingSender::FindAndBind, rtp_stream_id, std::move(pipe),
std::move(request), std::move(stream_sender),
// Using media::BindToCurrentLoop() so the |error_callback| // Using media::BindToCurrentLoop() so the |error_callback|
// is trampolined back to the original thread. // is trampolined back to the original thread.
media::BindToCurrentLoop(std::move(error_callback)))); media::BindToCurrentLoop(std::move(error_callback))));
...@@ -159,7 +158,7 @@ void CastRemotingSender::FindAndBind( ...@@ -159,7 +158,7 @@ void CastRemotingSender::FindAndBind(
CastRemotingSender* const sender = it->second; CastRemotingSender* const sender = it->second;
// Confirm that the CastRemotingSender isn't already bound to a message pipe. // Confirm that the CastRemotingSender isn't already bound to a message pipe.
if (sender->binding_.is_bound()) { if (sender->receiver_.is_bound()) {
DLOG(ERROR) << "Attempt to bind to CastRemotingSender a second time (id=" DLOG(ERROR) << "Attempt to bind to CastRemotingSender a second time (id="
<< rtp_stream_id << ")!"; << rtp_stream_id << ")!";
std::move(error_callback).Run(); std::move(error_callback).Run();
...@@ -171,8 +170,8 @@ void CastRemotingSender::FindAndBind( ...@@ -171,8 +170,8 @@ void CastRemotingSender::FindAndBind(
sender->data_pipe_reader_ = sender->data_pipe_reader_ =
std::make_unique<media::MojoDataPipeReader>(std::move(pipe)); std::make_unique<media::MojoDataPipeReader>(std::move(pipe));
sender->binding_.Bind(std::move(request)); sender->receiver_.Bind(std::move(stream_sender));
sender->binding_.set_connection_error_handler(base::BindOnce( sender->receiver_.set_disconnect_handler(base::BindOnce(
[](CastRemotingSender* sender) { [](CastRemotingSender* sender) {
if (!sender->error_callback_.is_null()) if (!sender->error_callback_.is_null())
std::move(sender->error_callback_).Run(); std::move(sender->error_callback_).Run();
...@@ -403,7 +402,7 @@ void CastRemotingSender::OnFrameRead(bool success) { ...@@ -403,7 +402,7 @@ void CastRemotingSender::OnFrameRead(bool success) {
void CastRemotingSender::OnPipeError() { void CastRemotingSender::OnPipeError() {
data_pipe_reader_.reset(); data_pipe_reader_.reset();
binding_.Close(); receiver_.reset();
if (!error_callback_.is_null()) if (!error_callback_.is_null())
std::move(error_callback_).Run(); std::move(error_callback_).Run();
} }
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "media/cast/net/cast_transport.h" #include "media/cast/net/cast_transport.h"
#include "media/cast/net/rtcp/rtcp_defines.h" #include "media/cast/net/rtcp/rtcp_defines.h"
#include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace media { namespace media {
class MojoDataPipeReader; class MojoDataPipeReader;
...@@ -53,19 +54,21 @@ class CastRemotingSender : public media::mojom::RemotingDataStreamSender { ...@@ -53,19 +54,21 @@ class CastRemotingSender : public media::mojom::RemotingDataStreamSender {
~CastRemotingSender() final; ~CastRemotingSender() final;
// Look-up a CastRemotingSender instance by its |rtp_stream_id| and then bind // Look-up a CastRemotingSender instance by its |rtp_stream_id| and then bind
// to the given |request|. The client of the RemotingDataStreamSender will // to the given |stream_sender|. The client of the RemotingDataStreamSender
// then instruct this CastRemotingSender when to read from the data |pipe| and // will then instruct this CastRemotingSender when to read from the data
// send the data to the Cast Receiver. If the bind fails, or an error occurs // |pipe| and send the data to the Cast Receiver. If the bind fails, or an
// reading from the data pipe during later operation, the |error_callback| is // error occurs reading from the data pipe during later operation, the
// run. // |error_callback| is run.
// //
// Threading note: This function is thread-safe, but its internal // Threading note: This function is thread-safe, but its internal
// implementation runs on the IO BrowserThread. If |error_callback| is run, it // implementation runs on the IO BrowserThread. If |error_callback| is run, it
// will execute on the thread that called this function. // will execute on the thread that called this function.
static void FindAndBind(int32_t rtp_stream_id, static void FindAndBind(
mojo::ScopedDataPipeConsumerHandle pipe, int32_t rtp_stream_id,
media::mojom::RemotingDataStreamSenderRequest request, mojo::ScopedDataPipeConsumerHandle pipe,
base::OnceClosure error_callback); mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
stream_sender,
base::OnceClosure error_callback);
private: private:
// Friend class for unit tests. // Friend class for unit tests.
...@@ -159,10 +162,10 @@ class CastRemotingSender : public media::mojom::RemotingDataStreamSender { ...@@ -159,10 +162,10 @@ class CastRemotingSender : public media::mojom::RemotingDataStreamSender {
std::unique_ptr<media::MojoDataPipeReader> data_pipe_reader_; std::unique_ptr<media::MojoDataPipeReader> data_pipe_reader_;
// Mojo binding for this instance. Implementation at the other end of the // Mojo receiver for this instance. Implementation at the other end of the
// message pipe uses the RemotingDataStreamSender interface to control when // message pipe uses the RemotingDataStreamSender remote to control when
// this CastRemotingSender consumes from |pipe_|. // this CastRemotingSender consumes from |pipe_|.
mojo::Binding<RemotingDataStreamSender> binding_; mojo::Receiver<RemotingDataStreamSender> receiver_{this};
// This is the maximum delay that the sender should get ack from receiver. // This is the maximum delay that the sender should get ack from receiver.
// Otherwise, sender will call ResendForKickstart(). // Otherwise, sender will call ResendForKickstart().
......
...@@ -21,7 +21,7 @@ RemotingSender::RemotingSender( ...@@ -21,7 +21,7 @@ RemotingSender::RemotingSender(
media::cast::CastTransport* transport, media::cast::CastTransport* transport,
const media::cast::FrameSenderConfig& config, const media::cast::FrameSenderConfig& config,
mojo::ScopedDataPipeConsumerHandle pipe, mojo::ScopedDataPipeConsumerHandle pipe,
media::mojom::RemotingDataStreamSenderRequest request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender> stream_sender,
base::OnceClosure error_callback) base::OnceClosure error_callback)
: FrameSender(cast_environment, : FrameSender(cast_environment,
transport, transport,
...@@ -30,11 +30,11 @@ RemotingSender::RemotingSender( ...@@ -30,11 +30,11 @@ RemotingSender::RemotingSender(
clock_(cast_environment->Clock()), clock_(cast_environment->Clock()),
error_callback_(std::move(error_callback)), error_callback_(std::move(error_callback)),
data_pipe_reader_(new media::MojoDataPipeReader(std::move(pipe))), data_pipe_reader_(new media::MojoDataPipeReader(std::move(pipe))),
binding_(this, std::move(request)), stream_sender_(this, std::move(stream_sender)),
input_queue_discards_remaining_(0), input_queue_discards_remaining_(0),
is_reading_(false), is_reading_(false),
flow_restart_pending_(true) { flow_restart_pending_(true) {
binding_.set_connection_error_handler(base::BindOnce( stream_sender_.set_disconnect_handler(base::BindOnce(
&RemotingSender::OnRemotingDataStreamError, base::Unretained(this))); &RemotingSender::OnRemotingDataStreamError, base::Unretained(this)));
} }
...@@ -207,7 +207,7 @@ void RemotingSender::OnInputTaskComplete() { ...@@ -207,7 +207,7 @@ void RemotingSender::OnInputTaskComplete() {
void RemotingSender::OnRemotingDataStreamError() { void RemotingSender::OnRemotingDataStreamError() {
data_pipe_reader_.reset(); data_pipe_reader_.reset();
binding_.Close(); stream_sender_.reset();
if (!error_callback_.is_null()) if (!error_callback_.is_null())
std::move(error_callback_).Run(); std::move(error_callback_).Run();
} }
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "media/cast/sender/frame_sender.h" #include "media/cast/sender/frame_sender.h"
#include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting.mojom.h"
#include "mojo/public/cpp/bindings/binding.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/receiver.h"
namespace base { namespace base {
class TickClock; class TickClock;
...@@ -39,7 +40,8 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) RemotingSender final ...@@ -39,7 +40,8 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) RemotingSender final
media::cast::CastTransport* transport, media::cast::CastTransport* transport,
const media::cast::FrameSenderConfig& config, const media::cast::FrameSenderConfig& config,
mojo::ScopedDataPipeConsumerHandle pipe, mojo::ScopedDataPipeConsumerHandle pipe,
media::mojom::RemotingDataStreamSenderRequest request, mojo::PendingReceiver<media::mojom::RemotingDataStreamSender>
stream_sender,
base::OnceClosure error_callback); base::OnceClosure error_callback);
~RemotingSender() override; ~RemotingSender() override;
...@@ -88,10 +90,10 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) RemotingSender final ...@@ -88,10 +90,10 @@ class COMPONENT_EXPORT(MIRRORING_SERVICE) RemotingSender final
std::unique_ptr<media::MojoDataPipeReader> data_pipe_reader_; std::unique_ptr<media::MojoDataPipeReader> data_pipe_reader_;
// Mojo binding for this instance. Implementation at the other end of the // Mojo receiver for this instance. Implementation at the other end of the
// message pipe uses the RemotingDataStreamSender interface to control when // message pipe uses the RemotingDataStreamSender remote to control when
// this RemotingSender consumes from |pipe_|. // this RemotingSender consumes from |pipe_|.
mojo::Binding<media::mojom::RemotingDataStreamSender> binding_; mojo::Receiver<media::mojom::RemotingDataStreamSender> stream_sender_;
// The next frame's payload data. Populated by call to OnFrameRead() when // The next frame's payload data. Populated by call to OnFrameRead() when
// reading succeeded. // reading succeeded.
......
...@@ -292,8 +292,8 @@ void CourierRenderer::OnDataPipeCreatedOnMainThread( ...@@ -292,8 +292,8 @@ void CourierRenderer::OnDataPipeCreatedOnMainThread(
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
base::WeakPtr<CourierRenderer> self, base::WeakPtr<CourierRenderer> self,
base::WeakPtr<RpcBroker> rpc_broker, base::WeakPtr<RpcBroker> rpc_broker,
mojom::RemotingDataStreamSenderPtrInfo audio, mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojom::RemotingDataStreamSenderPtrInfo video, mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle, mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle) { mojo::ScopedDataPipeProducerHandle video_handle) {
media_task_runner->PostTask( media_task_runner->PostTask(
...@@ -308,8 +308,8 @@ void CourierRenderer::OnDataPipeCreatedOnMainThread( ...@@ -308,8 +308,8 @@ void CourierRenderer::OnDataPipeCreatedOnMainThread(
} }
void CourierRenderer::OnDataPipeCreated( void CourierRenderer::OnDataPipeCreated(
mojom::RemotingDataStreamSenderPtrInfo audio, mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojom::RemotingDataStreamSenderPtrInfo video, mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle, mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle, mojo::ScopedDataPipeProducerHandle video_handle,
int audio_rpc_handle, int audio_rpc_handle,
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting.mojom.h"
#include "media/remoting/metrics.h" #include "media/remoting/metrics.h"
#include "media/remoting/rpc_broker.h" #include "media/remoting/rpc_broker.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
namespace media { namespace media {
...@@ -55,8 +56,8 @@ class CourierRenderer : public Renderer { ...@@ -55,8 +56,8 @@ class CourierRenderer : public Renderer {
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
base::WeakPtr<CourierRenderer> self, base::WeakPtr<CourierRenderer> self,
base::WeakPtr<RpcBroker> rpc_broker, base::WeakPtr<RpcBroker> rpc_broker,
mojom::RemotingDataStreamSenderPtrInfo audio, mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojom::RemotingDataStreamSenderPtrInfo video, mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle, mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle); mojo::ScopedDataPipeProducerHandle video_handle);
...@@ -95,12 +96,13 @@ class CourierRenderer : public Renderer { ...@@ -95,12 +96,13 @@ class CourierRenderer : public Renderer {
}; };
// Callback when attempting to establish data pipe. Runs on media thread only. // Callback when attempting to establish data pipe. Runs on media thread only.
void OnDataPipeCreated(mojom::RemotingDataStreamSenderPtrInfo audio, void OnDataPipeCreated(
mojom::RemotingDataStreamSenderPtrInfo video, mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojo::ScopedDataPipeProducerHandle audio_handle, mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle video_handle, mojo::ScopedDataPipeProducerHandle audio_handle,
int audio_rpc_handle, mojo::ScopedDataPipeProducerHandle video_handle,
int video_rpc_handle); int audio_rpc_handle,
int video_rpc_handle);
// Callback function when RPC message is received. Runs on media thread only. // Callback function when RPC message is received. Runs on media thread only.
void OnReceivedRpc(std::unique_ptr<pb::RpcMessage> message); void OnReceivedRpc(std::unique_ptr<pb::RpcMessage> message);
......
...@@ -34,7 +34,7 @@ DemuxerStreamAdapter::DemuxerStreamAdapter( ...@@ -34,7 +34,7 @@ DemuxerStreamAdapter::DemuxerStreamAdapter(
DemuxerStream* demuxer_stream, DemuxerStream* demuxer_stream,
const base::WeakPtr<RpcBroker>& rpc_broker, const base::WeakPtr<RpcBroker>& rpc_broker,
int rpc_handle, int rpc_handle,
mojom::RemotingDataStreamSenderPtrInfo stream_sender_info, mojo::PendingRemote<mojom::RemotingDataStreamSender> stream_sender_remote,
mojo::ScopedDataPipeProducerHandle producer_handle, mojo::ScopedDataPipeProducerHandle producer_handle,
ErrorCallback error_callback) ErrorCallback error_callback)
: main_task_runner_(std::move(main_task_runner)), : main_task_runner_(std::move(main_task_runner)),
...@@ -66,8 +66,8 @@ DemuxerStreamAdapter::DemuxerStreamAdapter( ...@@ -66,8 +66,8 @@ DemuxerStreamAdapter::DemuxerStreamAdapter(
FROM_HERE, base::BindOnce(&RpcBroker::RegisterMessageReceiverCallback, FROM_HERE, base::BindOnce(&RpcBroker::RegisterMessageReceiverCallback,
rpc_broker_, rpc_handle_, receive_callback)); rpc_broker_, rpc_handle_, receive_callback));
stream_sender_.Bind(std::move(stream_sender_info)); stream_sender_.Bind(std::move(stream_sender_remote));
stream_sender_.set_connection_error_handler( stream_sender_.set_disconnect_handler(
base::BindOnce(&DemuxerStreamAdapter::OnFatalError, base::BindOnce(&DemuxerStreamAdapter::OnFatalError,
weak_factory_.GetWeakPtr(), MOJO_PIPE_ERROR)); weak_factory_.GetWeakPtr(), MOJO_PIPE_ERROR));
} }
......
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
#include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting.mojom.h"
#include "media/remoting/rpc_broker.h" #include "media/remoting/rpc_broker.h"
#include "media/remoting/triggers.h" #include "media/remoting/triggers.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "mojo/public/cpp/system/data_pipe.h" #include "mojo/public/cpp/system/data_pipe.h"
#include "mojo/public/cpp/system/simple_watcher.h" #include "mojo/public/cpp/system/simple_watcher.h"
...@@ -49,8 +51,8 @@ class DemuxerStreamAdapter { ...@@ -49,8 +51,8 @@ class DemuxerStreamAdapter {
// |rpc_broker|: Broker class to handle incoming and outgoing RPC message. It // |rpc_broker|: Broker class to handle incoming and outgoing RPC message. It
// is used only on the main thread. // is used only on the main thread.
// |rpc_handle|: Unique value that references this DemuxerStreamAdapter. // |rpc_handle|: Unique value that references this DemuxerStreamAdapter.
// |stream_sender_info|: Transfer of pipe binding on the media thread. It is // |stream_sender_remote|: Transfer of pipe binding on the media thread. It is
// to access mojo interface for sending data stream. // to access mojo remote for sending data stream.
// |producer_handle|: handle to send data using mojo data pipe. // |producer_handle|: handle to send data using mojo data pipe.
// |error_callback|: Run if a fatal runtime error occurs and remoting should // |error_callback|: Run if a fatal runtime error occurs and remoting should
// be shut down. // be shut down.
...@@ -61,7 +63,7 @@ class DemuxerStreamAdapter { ...@@ -61,7 +63,7 @@ class DemuxerStreamAdapter {
DemuxerStream* demuxer_stream, DemuxerStream* demuxer_stream,
const base::WeakPtr<RpcBroker>& rpc_broker, const base::WeakPtr<RpcBroker>& rpc_broker,
int rpc_handle, int rpc_handle,
mojom::RemotingDataStreamSenderPtrInfo stream_sender_info, mojo::PendingRemote<mojom::RemotingDataStreamSender> stream_sender_remote,
mojo::ScopedDataPipeProducerHandle producer_handle, mojo::ScopedDataPipeProducerHandle producer_handle,
ErrorCallback error_callback); ErrorCallback error_callback);
~DemuxerStreamAdapter(); ~DemuxerStreamAdapter();
...@@ -180,7 +182,7 @@ class DemuxerStreamAdapter { ...@@ -180,7 +182,7 @@ class DemuxerStreamAdapter {
AudioDecoderConfig audio_config_; AudioDecoderConfig audio_config_;
VideoDecoderConfig video_config_; VideoDecoderConfig video_config_;
mojom::RemotingDataStreamSenderPtr stream_sender_; mojo::Remote<mojom::RemotingDataStreamSender> stream_sender_;
MojoDataPipeWriter data_pipe_writer_; MojoDataPipeWriter data_pipe_writer_;
// Tracks the number of bytes written to the pipe. // Tracks the number of bytes written to the pipe.
......
...@@ -34,7 +34,7 @@ class MockDemuxerStreamAdapter { ...@@ -34,7 +34,7 @@ class MockDemuxerStreamAdapter {
scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, scoped_refptr<base::SingleThreadTaskRunner> media_task_runner,
const std::string& name, const std::string& name,
DemuxerStream* demuxer_stream, DemuxerStream* demuxer_stream,
mojom::RemotingDataStreamSenderPtrInfo stream_sender_info, mojo::PendingRemote<mojom::RemotingDataStreamSender> stream_sender_remote,
mojo::ScopedDataPipeProducerHandle producer_handle) { mojo::ScopedDataPipeProducerHandle producer_handle) {
rpc_broker_.reset(new RpcBroker( rpc_broker_.reset(new RpcBroker(
base::BindRepeating(&MockDemuxerStreamAdapter::OnSendMessageToSink, base::BindRepeating(&MockDemuxerStreamAdapter::OnSendMessageToSink,
...@@ -42,7 +42,7 @@ class MockDemuxerStreamAdapter { ...@@ -42,7 +42,7 @@ class MockDemuxerStreamAdapter {
demuxer_stream_adapter_.reset(new DemuxerStreamAdapter( demuxer_stream_adapter_.reset(new DemuxerStreamAdapter(
std::move(main_task_runner), std::move(media_task_runner), name, std::move(main_task_runner), std::move(media_task_runner), name,
demuxer_stream, rpc_broker_->GetWeakPtr(), demuxer_stream, rpc_broker_->GetWeakPtr(),
rpc_broker_->GetUniqueHandle(), std::move(stream_sender_info), rpc_broker_->GetUniqueHandle(), std::move(stream_sender_remote),
std::move(producer_handle), std::move(producer_handle),
base::BindOnce(&MockDemuxerStreamAdapter::OnError, base::BindOnce(&MockDemuxerStreamAdapter::OnError,
weak_factory_.GetWeakPtr()))); weak_factory_.GetWeakPtr())));
...@@ -119,7 +119,7 @@ class DemuxerStreamAdapterTest : public ::testing::Test { ...@@ -119,7 +119,7 @@ class DemuxerStreamAdapterTest : public ::testing::Test {
const MojoCreateDataPipeOptions data_pipe_options{ const MojoCreateDataPipeOptions data_pipe_options{
sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1, sizeof(MojoCreateDataPipeOptions), MOJO_CREATE_DATA_PIPE_FLAG_NONE, 1,
kDataPipeCapacity}; kDataPipeCapacity};
mojom::RemotingDataStreamSenderPtr stream_sender; mojo::PendingRemote<mojom::RemotingDataStreamSender> stream_sender;
mojo::ScopedDataPipeProducerHandle producer_end; mojo::ScopedDataPipeProducerHandle producer_end;
mojo::ScopedDataPipeConsumerHandle consumer_end; mojo::ScopedDataPipeConsumerHandle consumer_end;
CHECK_EQ( CHECK_EQ(
...@@ -127,10 +127,11 @@ class DemuxerStreamAdapterTest : public ::testing::Test { ...@@ -127,10 +127,11 @@ class DemuxerStreamAdapterTest : public ::testing::Test {
mojo::CreateDataPipe(&data_pipe_options, &producer_end, &consumer_end)); mojo::CreateDataPipe(&data_pipe_options, &producer_end, &consumer_end));
data_stream_sender_.reset(new FakeRemotingDataStreamSender( data_stream_sender_.reset(new FakeRemotingDataStreamSender(
MakeRequest(&stream_sender), std::move(consumer_end))); stream_sender.InitWithNewPipeAndPassReceiver(),
std::move(consumer_end)));
demuxer_stream_adapter_.reset(new MockDemuxerStreamAdapter( demuxer_stream_adapter_.reset(new MockDemuxerStreamAdapter(
message_loop_.task_runner(), message_loop_.task_runner(), "test", message_loop_.task_runner(), message_loop_.task_runner(), "test",
demuxer_stream_.get(), stream_sender.PassInterface(), demuxer_stream_.get(), std::move(stream_sender),
std::move(producer_end))); std::move(producer_end)));
// DemuxerStreamAdapter constructor posts task to main thread to // DemuxerStreamAdapter constructor posts task to main thread to
// register MessageReceiverCallback. Therefore it should call // register MessageReceiverCallback. Therefore it should call
......
...@@ -24,9 +24,9 @@ namespace media { ...@@ -24,9 +24,9 @@ namespace media {
namespace remoting { namespace remoting {
FakeRemotingDataStreamSender::FakeRemotingDataStreamSender( FakeRemotingDataStreamSender::FakeRemotingDataStreamSender(
mojo::PendingReceiver<mojom::RemotingDataStreamSender> receiver, mojo::PendingReceiver<mojom::RemotingDataStreamSender> stream_sender,
mojo::ScopedDataPipeConsumerHandle consumer_handle) mojo::ScopedDataPipeConsumerHandle consumer_handle)
: receiver_(this, std::move(receiver)), : receiver_(this, std::move(stream_sender)),
data_pipe_reader_(std::move(consumer_handle)), data_pipe_reader_(std::move(consumer_handle)),
send_frame_count_(0), send_frame_count_(0),
cancel_in_flight_count_(0) {} cancel_in_flight_count_(0) {}
...@@ -134,20 +134,18 @@ void FakeRemoter::Start() { ...@@ -134,20 +134,18 @@ void FakeRemoter::Start() {
void FakeRemoter::StartDataStreams( void FakeRemoter::StartDataStreams(
mojo::ScopedDataPipeConsumerHandle audio_pipe, mojo::ScopedDataPipeConsumerHandle audio_pipe,
mojo::ScopedDataPipeConsumerHandle video_pipe, mojo::ScopedDataPipeConsumerHandle video_pipe,
mojo::PendingReceiver<mojom::RemotingDataStreamSender> mojo::PendingReceiver<mojom::RemotingDataStreamSender> audio_sender,
audio_sender_receiver, mojo::PendingReceiver<mojom::RemotingDataStreamSender> video_sender) {
mojo::PendingReceiver<mojom::RemotingDataStreamSender>
video_sender_receiver) {
if (audio_pipe.is_valid()) { if (audio_pipe.is_valid()) {
VLOG(2) << "Has audio"; VLOG(2) << "Has audio";
audio_stream_sender_.reset(new FakeRemotingDataStreamSender( audio_stream_sender_.reset(new FakeRemotingDataStreamSender(
std::move(audio_sender_receiver), std::move(audio_pipe))); std::move(audio_sender), std::move(audio_pipe)));
} }
if (video_pipe.is_valid()) { if (video_pipe.is_valid()) {
VLOG(2) << "Has video"; VLOG(2) << "Has video";
video_stream_sender_.reset(new FakeRemotingDataStreamSender( video_stream_sender_.reset(new FakeRemotingDataStreamSender(
std::move(video_sender_receiver), std::move(video_pipe))); std::move(video_sender), std::move(video_pipe)));
} }
} }
......
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
#include "media/base/decoder_buffer.h" #include "media/base/decoder_buffer.h"
#include "media/mojo/common/mojo_data_pipe_read_write.h" #include "media/mojo/common/mojo_data_pipe_read_write.h"
#include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting.mojom.h"
#include "mojo/public/cpp/bindings/binding.h"
#include "mojo/public/cpp/bindings/pending_receiver.h" #include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/pending_remote.h" #include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/receiver.h"
#include "mojo/public/cpp/bindings/remote.h" #include "mojo/public/cpp/bindings/remote.h"
namespace media { namespace media {
...@@ -40,7 +40,7 @@ class FakeRemotingDataStreamSender : public mojom::RemotingDataStreamSender { ...@@ -40,7 +40,7 @@ class FakeRemotingDataStreamSender : public mojom::RemotingDataStreamSender {
void OnFrameRead(bool success); void OnFrameRead(bool success);
mojo::Binding<RemotingDataStreamSender> receiver_; mojo::Receiver<RemotingDataStreamSender> receiver_;
MojoDataPipeReader data_pipe_reader_; MojoDataPipeReader data_pipe_reader_;
std::vector<uint8_t> next_frame_data_; std::vector<uint8_t> next_frame_data_;
......
...@@ -226,25 +226,24 @@ void RendererController::StartDataPipe( ...@@ -226,25 +226,24 @@ void RendererController::StartDataPipe(
if (!audio && !video) { if (!audio && !video) {
LOG(ERROR) << "No audio nor video to establish data pipe"; LOG(ERROR) << "No audio nor video to establish data pipe";
std::move(done_callback) std::move(done_callback)
.Run(mojom::RemotingDataStreamSenderPtrInfo(), .Run(mojo::NullRemote(), mojo::NullRemote(),
mojom::RemotingDataStreamSenderPtrInfo(),
mojo::ScopedDataPipeProducerHandle(), mojo::ScopedDataPipeProducerHandle(),
mojo::ScopedDataPipeProducerHandle()); mojo::ScopedDataPipeProducerHandle());
return; return;
} }
mojom::RemotingDataStreamSenderPtr audio_stream_sender; mojo::PendingRemote<mojom::RemotingDataStreamSender> audio_stream_sender;
mojom::RemotingDataStreamSenderPtr video_stream_sender; mojo::PendingRemote<mojom::RemotingDataStreamSender> video_stream_sender;
remoter_->StartDataStreams(audio ? std::move(audio_data_pipe->consumer_handle) remoter_->StartDataStreams(
: mojo::ScopedDataPipeConsumerHandle(), audio ? std::move(audio_data_pipe->consumer_handle)
video ? std::move(video_data_pipe->consumer_handle) : mojo::ScopedDataPipeConsumerHandle(),
: mojo::ScopedDataPipeConsumerHandle(), video ? std::move(video_data_pipe->consumer_handle)
audio ? mojo::MakeRequest(&audio_stream_sender) : mojo::ScopedDataPipeConsumerHandle(),
: mojom::RemotingDataStreamSenderRequest(), audio ? audio_stream_sender.InitWithNewPipeAndPassReceiver()
video ? mojo::MakeRequest(&video_stream_sender) : mojo::NullReceiver(),
: mojom::RemotingDataStreamSenderRequest()); video ? video_stream_sender.InitWithNewPipeAndPassReceiver()
: mojo::NullReceiver());
std::move(done_callback) std::move(done_callback)
.Run(audio_stream_sender.PassInterface(), .Run(std::move(audio_stream_sender), std::move(video_stream_sender),
video_stream_sender.PassInterface(),
audio ? std::move(audio_data_pipe->producer_handle) audio ? std::move(audio_data_pipe->producer_handle)
: mojo::ScopedDataPipeProducerHandle(), : mojo::ScopedDataPipeProducerHandle(),
video ? std::move(video_data_pipe->producer_handle) video ? std::move(video_data_pipe->producer_handle)
......
...@@ -74,11 +74,11 @@ class RendererController final : public mojom::RemotingSource, ...@@ -74,11 +74,11 @@ class RendererController final : public mojom::RemotingSource,
return remote_rendering_started_; return remote_rendering_started_;
} }
using DataPipeStartCallback = using DataPipeStartCallback = base::OnceCallback<void(
base::OnceCallback<void(mojom::RemotingDataStreamSenderPtrInfo audio, mojo::PendingRemote<mojom::RemotingDataStreamSender> audio,
mojom::RemotingDataStreamSenderPtrInfo video, mojo::PendingRemote<mojom::RemotingDataStreamSender> video,
mojo::ScopedDataPipeProducerHandle audio_handle, mojo::ScopedDataPipeProducerHandle audio_handle,
mojo::ScopedDataPipeProducerHandle video_handle)>; mojo::ScopedDataPipeProducerHandle video_handle)>;
void StartDataPipe(std::unique_ptr<mojo::DataPipe> audio_data_pipe, void StartDataPipe(std::unique_ptr<mojo::DataPipe> audio_data_pipe,
std::unique_ptr<mojo::DataPipe> video_data_pipe, std::unique_ptr<mojo::DataPipe> video_data_pipe,
DataPipeStartCallback done_callback); DataPipeStartCallback done_callback);
......
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