| 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_
|
|
|