// Copyright 2016 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ #define CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_ #include <optional> #include <set> #include <vector> #include "base/memory/raw_ptr.h" #include "base/memory/weak_ptr.h" #include "base/supports_user_data.h" #include "components/prefs/pref_change_registrar.h" #include "components/sessions/core/session_id.h" #include "media/mojo/mojom/remoting.mojom.h" #include "media/mojo/mojom/remoting_common.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" namespace content { class RenderFrameHost; class WebContents; } // namespace content class MediaRemotingDialogCoordinator { … }; // 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 a MediaRemoter in the Cast Media // Route Provider that handles the communication with the remote device. The // CastRemotingConnector and the MediaRemoter can communicate with each other // through the media::mojom::Remoter and media::mojom::RemotingSource interfaces // when a sink that is capable of remoting is available. // // Whenever a candidate media source is created in a render frame, // ChromeContentBrowserClient will call CreateMediaRemoter() to instantiate a // media::mojom::Remoter associated with the connector. A corresponding // media::mojom::RemotingSource is provided by the caller for communications // back to the media source in the render frame: The connector uses this to // notify when a sink becomes available for remoting, and to pass binary // messages from the sink back to the source. // // When a mirroring route is created and available for remoting, the Cast MRP // will create a MediaRemoter and notify MediaRouter, which notifies the // CastRemotingConnector registered under the tab ID being remoted. At this // point, the CastRemotingConnector can communicate with the MediaRemoter. When // CastRemotingConnector gets notified 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 Cast MRP 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 MediaRemoter interact to // start/execute/stop remoting sessions. class CastRemotingConnector final : public base::SupportsUserData::Data, public media::mojom::RemotingSource { … }; #endif // CHROME_BROWSER_MEDIA_CAST_REMOTING_CONNECTOR_H_