Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: chrome/browser/media/cast_remoting_connector.h

Issue 2951523002: Media Remoting: Add mojo interfaces between browser and extension. (Closed)
Patch Set: Fix compile failure on Android bots. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media/cast_remoting_connector.h
diff --git a/chrome/browser/media/cast_remoting_connector.h b/chrome/browser/media/cast_remoting_connector.h
index 9fb6d8278aaf2b091c61504ba7ef76f1dcb4c1b6..a332fe4631db6145fab4a410a2514edd96ceb149 100644
--- a/chrome/browser/media/cast_remoting_connector.h
+++ b/chrome/browser/media/cast_remoting_connector.h
@@ -9,21 +9,30 @@
#include "base/memory/weak_ptr.h"
#include "base/supports_user_data.h"
-#include "chrome/browser/media/router/media_routes_observer.h"
-#include "chrome/common/media_router/route_message.h"
+#include "media/mojo/interfaces/mirror_service_remoting.mojom.h"
#include "media/mojo/interfaces/remoting.mojom.h"
+#include "mojo/public/cpp/bindings/strong_binding.h"
namespace content {
class RenderFrameHost;
class WebContents;
}
+namespace media_router {
+class MediaRouter;
+}
+
// CastRemotingConnector connects a single source (a media element in a render
// frame) with a single sink (a media player in a remote device). There is one
// instance of a CastRemotingConnector per source WebContents (representing a
// collection of render frames), and it is created on-demand. The source in the
// render process represents itself by providing a media::mojom::RemotingSource
-// service instance. The sink is represented by the Media Router Cast Provider.
+// service instance. The sink is represented by a MediaRemoter in Media Route
imcheng 2017/06/22 01:13:27 The MR extension is desktop-specific. How about "
xjz 2017/06/23 19:02:41 Done.
+// extension, which handles the communication with the remote device. The
+// CastRemotingConnector and the MediaRemoter are connected when a sink that is
+// capable of remoting is available. Once connected, they can communicate with
+// each other through the media::mojom::MirrorServiceRemoter and
+// media::mojom::MirrorServiceRemotingSource interfaces.
//
// Whenever a candidate media source is created in a render frame,
// ChromeContentBrowserClient will call CreateMediaRemoter() to instantiate a
@@ -33,38 +42,35 @@ class WebContents;
// notify when a sink becomes available for remoting, and to pass binary
// messages from the sink back to the source.
//
-// At any time before or after the CastRemotingConnector is created, the
-// Media Router Cast Provider may create a tab remoting media route. This
-// indicates that the provider has found a sink that is capable of remoting and
-// is available for use. At this point, CastRemotingConnector notifies all
-// RemotingSources that a sink is available, and some time later a
-// RemotingSource can request the start of a remoting session. Once the sink is
-// no longer available, the provider terminates the route and
-// CastRemotingConnector notifies all RemotingSources that the sink is gone.
+// When the CastRemotingConnector is created, it will register itself in the
+// media_router::MediaRouterMojoImpl with the tab ID. When a mirroring route is
imcheng 2017/06/22 01:13:27 s/MojoImpl//
xjz 2017/06/23 19:02:41 Done.
+// created and avilable for remoting, a MediaRemoter is created and started in
+// the extension, and it notifies the media_router::MediaRouterMojoImpl through
imcheng 2017/06/22 01:13:27 ditto for "extension". How about something along t
xjz 2017/06/23 19:02:41 Done.
+// the MediaRouter mojo interface, and connects to the CastRemotingConnector
+// with the same source tab Id. At this point, the CastRemotingConnector can
+// compunicate with the MediaRemoter. When CastRemotingConnector gets notified
imcheng 2017/06/22 01:13:27 typo in "communicate"
xjz 2017/06/23 19:02:41 Done.
+// that a sink is available, it notifies all RemotingSources, and some time
+// later a RemotingSource can request the start of a remoting session.
//
// Note that only one RemotingSource can remote media at a time. Therefore,
// CastRemotingConnector must mediate among simultaneous requests for media
// remoting, and only allow one at a time. Currently, the policy is "first come,
// first served."
//
-// When starting a remoting session, the CastRemotingConnector sends control
-// messages to the Cast Provider. These control messages direct the provider to
-// start/stop remoting with the remote device (e.g., launching apps or services
-// on the remote device). Among its other duties, the provider will also set up
-// a Cast Streaming session to provide a bitstream transport for the media. Once
-// this is done, the provider sends notification messages back to
-// CastRemotingConnector to acknowledge this. Then, CastRemotingConnector knows
-// it can look-up and pass the mojo data pipe handles to CastRemotingSenders,
-// and the remoting session will be fully active. The CastRemotingConnector is
-// responsible for passing small binary messages between the source and sink,
-// while the CastRemotingSender handles the high-volume media data transfer.
+// When starting a remoting session, the MediaRemoter will also set up a Cast
+// Streaming session to provide a bitstream transport for the media. Once this
+// is done, the MediaRemoter notifies the CastRemotingConnector. Then,
+// CastRemotingConnector knows it can look-up and pass the mojo data pipe
+// handles to CastRemotingSenders, and the remoting session will be fully active
+// The CastRemotingConnector is responsible for passing small binary messages
+// between the source and sink, while the CastRemotingSender handles the
+// high-volume media data transfer.
//
// Please see the unit tests in cast_remoting_connector_unittest.cc as a
-// reference for how CastRemotingConnector and a Cast Provider interact to
+// reference for how CastRemotingConnector and a MediaRemoter interact to
// start/execute/stop remoting sessions.
-class CastRemotingConnector
- : public base::SupportsUserData::Data,
- public media_router::MediaRoutesObserver {
+class CastRemotingConnector : public base::SupportsUserData::Data,
imcheng 2017/06/22 01:13:27 Was it a deliberate decision to not put this class
xjz 2017/06/23 19:02:41 It sgtm to put this class under the cast namespace
+ public media::mojom::MirrorServiceRemotingSource {
public:
~CastRemotingConnector() final;
@@ -78,6 +84,13 @@ class CastRemotingConnector
media::mojom::RemotingSourcePtr source,
media::mojom::RemoterRequest request);
+ // Called when a MediaRemoter is created and started in extension. This call
+ // connects the CastRemotingConnector with the MediaRemoter in extension.
+ // Remoting sessions can only be started after this is called.
+ void ConnectToService(
+ media::mojom::MirrorServiceRemotingSourceRequest source_request,
+ media::mojom::MirrorServiceRemoterPtr remoter);
+
private:
// Allow unit tests access to the private constructor and CreateBridge()
// method, since unit tests don't have a complete browser (i.e., with a
@@ -91,15 +104,9 @@ class CastRemotingConnector
// mojo message pipe.
class RemotingBridge;
- // A RouteMessageObserver for the remoting route that passes messages from the
- // Cast Provider back to this connector. An instance of this class only exists
- // while a remoting route is available, and is owned by CastRemotingConnector.
- class MessageObserver;
-
- // Main constructor. |media_source_id| refers to any remoted content managed
+ // Main constructor. |tab_id| refers to any remoted content managed
// by this instance (i.e., any remoted content from one tab/WebContents).
- CastRemotingConnector(media_router::MediaRouter* router,
- const media_router::MediaSource::Id& media_source_id);
+ CastRemotingConnector(media_router::MediaRouter* router, int32_t tab_id);
// Creates a RemotingBridge that implements the requested Remoter service, and
// binds it to the interface |request|.
@@ -113,6 +120,17 @@ class CastRemotingConnector
void DeregisterBridge(RemotingBridge* bridge,
media::mojom::RemotingStopReason reason);
+ // media::mojom::MirrorServiceRemotingSource implementations.
+ void OnSinkAvailable(
+ media::mojom::RemotingSinkCapabilities capabilities) override;
+ void OnStarted() override;
+ void OnStartFailed(media::mojom::RemotingStartFailReason reason) override;
+ void OnMessageFromSink(const std::vector<uint8_t>& message) override;
+ void OnStopped(media::mojom::RemotingStopReason reason) override;
+ void OnDataStreamsStarted(int32_t audio_stream_id,
+ int32_t video_stream_id) override;
+ void OnError() override;
+
// These methods are called by RemotingBridge to forward media::mojom::Remoter
// calls from a source through to this connector. They ensure that only one
// source is allowed to be in a remoting session at a time, and that no source
@@ -129,35 +147,16 @@ class CastRemotingConnector
void SendMessageToSink(RemotingBridge* bridge,
const std::vector<uint8_t>& message);
- // Send a control message to the Cast Provider. This may or may not succeed,
- // with the success status reported later via HandleSendMessageResult().
- void SendMessageToProvider(const std::string& message);
-
- // Called by the current MessageObserver to process messages observed on the
- // remoting route. There are two types of messages: 1) TEXT notification
- // messages from the Cast Provider, to report on the current state of a
- // remoting session between Chrome and the remote device, and 2) BINARY
- // messages, to be passed directly to the active remoting source during a
- // remoting session.
- void ProcessMessagesFromRoute(
- const std::vector<media_router::RouteMessage>& messages);
-
- // Error handlers for message/data sending during an active remoting
- // session. When a failure occurs, these immediately force-stop remoting.
- void HandleSendMessageResult(bool success);
+ // Error handlers for message sending during an active remoting session. When
+ // a failure occurs, these immediately force-stop remoting.
void OnDataSendFailed();
- // MediaRoutesObserver implementation: Scans |routes| to check whether the
- // existing remoting route has gone away and/or there is a new remoting route
- // established, and take the necessary actions to notify sources and/or
- // shutdown an active remoting session.
- void OnRoutesUpdated(
- const std::vector<media_router::MediaRoute>& routes,
- const std::vector<media_router::MediaRoute::Id>& ignored) final;
+ // Called when any connection error/lost occurs with the MediaRemoter.
+ void OnMirrorServiceStopped();
- // The MediaSource ID referring to any remoted content managed by this
- // CastRemotingConnector.
- const media_router::MediaSource::Id media_source_id_;
+ media_router::MediaRouter* const media_router_;
+
+ const int32_t tab_id_;
// Describes the sink's capabilities according to what has been enabled via
// |features::kMediaRemoting|. These are controlled manually via
@@ -169,18 +168,6 @@ class CastRemotingConnector
// set.
std::set<RemotingBridge*> bridges_;
- // Created when the Media Router Cast Provider has created a media remoting
- // route to a sink that supports remoting and is available for use. This
- // observer simply dispatches messages from the Cast Provider and sink back to
- // this connector. Once the route is gone, this is reset to null.
- std::unique_ptr<MessageObserver> message_observer_;
-
- // Incremented each time StartRemoting() is called, and used as a "current
- // session ID" to ensure that control messaging between this connector and the
- // Cast Provider are referring to the same remoting session. This allows both
- // this connector and the provider to ignore stale messages.
- unsigned int session_counter_;
-
// When non-null, an active remoting session is taking place, with this
// pointing to the RemotingBridge being used to communicate with the source.
RemotingBridge* active_bridge_;
@@ -192,6 +179,9 @@ class CastRemotingConnector
media::mojom::RemotingDataStreamSenderRequest pending_audio_sender_request_;
media::mojom::RemotingDataStreamSenderRequest pending_video_sender_request_;
+ mojo::Binding<media::mojom::MirrorServiceRemotingSource> binding_;
+ media::mojom::MirrorServiceRemoterPtr remoter_;
+
// Produces weak pointers that are only valid for the current remoting
// session. This is used to cancel any outstanding callbacks when a remoting
// session is stopped.

Powered by Google App Engine
This is Rietveld 408576698