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

Unified Diff: chrome/browser/media/router/media_remoting_connector.h

Issue 2138013003: media::mojom::Remoter and CastRemotingConnector/Sender (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Split-out some interfaces in prep for landing multi-part changes. Created 4 years, 5 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
« no previous file with comments | « chrome/browser/media/router/BUILD.gn ('k') | chrome/browser/media/router/media_remoting_connector.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/media/router/media_remoting_connector.h
diff --git a/chrome/browser/media/router/media_remoting_connector.h b/chrome/browser/media/router/media_remoting_connector.h
new file mode 100644
index 0000000000000000000000000000000000000000..87b11340df842ec1fb444e12d920e4f1cd570ca1
--- /dev/null
+++ b/chrome/browser/media/router/media_remoting_connector.h
@@ -0,0 +1,113 @@
+// Copyright 2016 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 CHROME_BROWSER_MEDIA_ROUTER_MEDIA_REMOTING_CONNECTOR_H_
+#define CHROME_BROWSER_MEDIA_ROUTER_MEDIA_REMOTING_CONNECTOR_H_
+
+#include <unordered_set>
+
+#include "content/public/browser/web_contents_user_data.h"
+#include "media/mojo/interfaces/remoter.mojom.h"
+
+namespace content {
+class RenderFrameHost;
+}
+
+namespace media_router {
+
+class MediaRemotingProvider;
+
+// MediaRemotingConnector connects a single source (a media player in a render
+// frame) with a single sink (MediaRemotingProvider). There is one instance of a
+// MediaRemotingConnector per source WebContents (representing a collection of
+// render frames), and it is created on-demand.
+//
+// Whenever a RenderFrameHost is created, ChromeContentBrowserClient will call
+// CreateRemoter() to provide a media::mojom::Remoter service to the render
+// frame. This service is how the render frame requests notifications for when
+// remote media services are available, controls the start/stop of remoting, and
+// passes messages to/from the remote.
+//
+// At any time before or after the media::mojom::Remoter services are created,
+// the Media Router extension may create a service that implements the
+// MediaRemotingProvider interface. The implementation, will notify this
+// MediaRemotingConnector when all dependencies for remoting have been
+// satisfied. The connector will then, in turn, notify all the render frames
+// that remoting is available. Finally, it is up to the render frame to decide
+// whether the source media is compatible with what the remote media services
+// provide and, if so, start remoting.
+//
+// Note that only one render frame may be remoting at a time. Therefore,
+// MediaRemotingConnector must mitigate which simultaneous requests for media
+// services are to be rejected. Currently, the policy is "first come, first
+// served."
+class MediaRemotingConnector
+ : protected content::WebContentsUserData<MediaRemotingConnector> {
+ public:
+ // Returns an instance to the MediaRemotingConnector associated with
+ // |source_contents|, creating a new instance if needed.
+ static MediaRemotingConnector* Get(content::WebContents* source_contents);
+
+ // Used by ChromeContentBrowserClient to request a binding to a new media
+ // Remoter mojo service for each new render frame.
+ static void CreateRemoter(
+ content::RenderFrameHost* render_frame_host,
+ mojo::InterfaceRequest<media::mojom::Remoter> request);
+
+ ~MediaRemotingConnector() final;
+
+ // Sets the provider of media remoting services to |provider|. This is called
+ // once a sink is available and is ready to start media remoting. The pointer
+ // must remain valid until after this method is called again with nullptr
+ // (i.e., the provider is no longer available).
+ void SetProvider(MediaRemotingProvider* provider);
+
+ private:
+ // Private implementation of the media::mojom::Remoter service for a single
+ // render frame. A single WebContents may contain more than one render frame,
+ // and so this per-RenderFrameHost object is just a "lightweight shell" that
+ // delegates calls to its MediaRemotingConnector parent class.
+ class FrameMediaRemoter;
+
+ friend class content::WebContentsUserData<MediaRemotingConnector>;
+ explicit MediaRemotingConnector(content::WebContents* source_contents);
+
+ // Returns the MediaRemotingConnector associated with the WebContents
+ // containing |source_render_frame_host|, or nullptr if there is none. This is
+ // used by FrameMediaRemoter.
+ static MediaRemotingConnector* GetIfExists(
+ content::RenderFrameHost* source_render_frame_host);
+
+ // These are called by FrameMediaRemoter to forward media::mojom::Remoter
+ // calls from a render frame through to the MediaRemotingProvider. It is up to
+ // this MediaRemotingConnector to ensure only one FrameMediaRemoter is
+ // actively forwarding to the single MediaRemotingProvider at a time.
+ void RegisterFrameRemoter(FrameMediaRemoter* remoter);
+ void DeregisterFrameRemoter(FrameMediaRemoter* remoter);
+ void StartMediaServices(
+ FrameMediaRemoter* remoter,
+ mojo::ScopedDataPipeConsumerHandle audio_pipe,
+ mojo::ScopedDataPipeConsumerHandle video_pipe,
+ const base::Callback<void(bool, uint32_t, uint32_t)>& callback);
+ void StopMediaServices(FrameMediaRemoter* remoter,
+ const mojo::String& error_reason);
+ void SendMessageToRemote(FrameMediaRemoter* remoter,
+ mojo::Array<uint8_t> message);
+ void SendBufferToRemote(FrameMediaRemoter* remoter, uint32_t pipe_id,
+ media::mojom::DecoderBufferPtr buffer);
+
+ // List of registered FrameMediaRemoters.
+ std::unordered_set<FrameMediaRemoter*> remoters_;
+
+ // When non-null, a sink is available and ready for media remoting.
+ MediaRemotingProvider* provider_;
+
+ // When non-null, remoting is taking place, with this pointing to the
+ // FrameMediaRemoter representing the source.
+ FrameMediaRemoter* active_remoter_;
+};
+
+} // namespace media_router
+
+#endif // CHROME_BROWSER_MEDIA_ROUTER_MEDIA_REMOTING_CONNECTOR_H_
« no previous file with comments | « chrome/browser/media/router/BUILD.gn ('k') | chrome/browser/media/router/media_remoting_connector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698