| Index: chrome/browser/media/router/mojo/media_remoting_session_impl.h
|
| diff --git a/chrome/browser/media/router/mojo/media_remoting_session_impl.h b/chrome/browser/media/router/mojo/media_remoting_session_impl.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..35857342bf865306ec646a92caaed825164bcb59
|
| --- /dev/null
|
| +++ b/chrome/browser/media/router/mojo/media_remoting_session_impl.h
|
| @@ -0,0 +1,141 @@
|
| +// 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_MOJO_MEDIA_REMOTING_SESSION_IMPL_H_
|
| +#define CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_REMOTING_SESSION_IMPL_H_
|
| +
|
| +#include "base/callback.h"
|
| +#include "chrome/browser/media/router/media_remoting_provider.h"
|
| +#include "chrome/browser/media/router/mojo/media_remoter.mojom.h"
|
| +#include "content/public/browser/web_contents_observer.h"
|
| +#include "mojo/public/cpp/bindings/binding.h"
|
| +#include "media/mojo/interfaces/remoter.mojom.h"
|
| +
|
| +namespace media_router {
|
| +
|
| +class MediaRemotingConnector;
|
| +
|
| +// Manages the dependencies and execution of a media remoting session. This is
|
| +// created by a MediaRemotingProvider (mojo) in the Media Router extension after
|
| +// a route is established and the sink is determined to provide remote media
|
| +// services.
|
| +//
|
| +// Once all dependencies are satisfied, this MediaRemotingSessionImpl notifies a
|
| +// MediaRemotingConnector that the session is ready for remoting. It is then up
|
| +// to the connector to delegate requests from a single source to start remoting
|
| +// and pass messages and bitstreams via this MediaRemotingSessionImpl.
|
| +//
|
| +// media_router::MediaRouterMojoImpl owns instances of this class.
|
| +class MediaRemotingSessionImpl : public interfaces::MediaRemotingSession,
|
| + public MediaRemotingProvider {
|
| + public:
|
| + // |connector| is used to register this MediaRemotingProvider once media
|
| + // services become available. It must remain valid until Terminate() is called
|
| + // (or destruction of this instance).
|
| + //
|
| + // |provider| is bound to a mojo instance that provides the implementation for
|
| + // sending/receiving to/from the remote. Also, |this| is bound to the given
|
| + // Mojo interface |request|.
|
| + //
|
| + // If |did_terminate_callback| is not a null Closure, it will be run one time
|
| + // after a call to Terminate(). This is used to notify the owner of this
|
| + // MediaRemotingSessionImpl that this instance can now be destroyed.
|
| + MediaRemotingSessionImpl(
|
| + MediaRemotingConnector* connector,
|
| + interfaces::MediaRemotingProviderPtr provider,
|
| + mojo::InterfaceRequest<interfaces::MediaRemotingSession> request,
|
| + const base::Closure& did_terminate_callback);
|
| +
|
| + ~MediaRemotingSessionImpl() override;
|
| +
|
| + // interfaces::MediaRemotingSession implementation.
|
| + void OnRemoteServicesAvailable(
|
| + media::mojom::RemoteCapabilitiesPtr capabilities) final;
|
| + void OnRemoteServicesGone() final;
|
| + void OnBitstreamTransportAvailable(
|
| + const mojo::String& transport_session_id) final;
|
| + void OnBitstreamTransportGone() final;
|
| + void OnMessageFromRemote(mojo::Array<uint8_t> message) final;
|
| + void Terminate(const mojo::String& error_reason) final;
|
| +
|
| + // MediaRemotingProvider implementation.
|
| + const media::mojom::RemoteCapabilities* GetRemoteCapabilities() const final;
|
| + bool StartMediaServices(mojo::ScopedDataPipeConsumerHandle audio_pipe,
|
| + mojo::ScopedDataPipeConsumerHandle video_pipe,
|
| + const RemoteMessageCallback& message_callback) final;
|
| + void StopMediaServices(const mojo::String& error_reason) final;
|
| + void SendMessageToRemote(mojo::Array<uint8_t> message) final;
|
| + void SendBufferToRemote(uint32_t pipe_id,
|
| + media::mojom::DecoderBufferPtr buffer) final;
|
| +
|
| + private:
|
| + // Called whenever something potentially affecting the availability of remote
|
| + // media services changes. If necessary, the MediaRemotingConnection will be
|
| + // notified, and this could cause active remoting to be stopped.
|
| + void UpdateAvailability();
|
| +
|
| + // A mojo connection error forces termination of this remoting session.
|
| + void OnConnectionError();
|
| +
|
| + // The MediaRemotingConnector to register with when remote media services
|
| + // become available and ready, or are no longer available. The connector will
|
| + // call this implementation's MediaRemotingProvider methods. This is set to
|
| + // nullptr when Terminate() is called.
|
| + MediaRemotingConnector* connector_;
|
| +
|
| + // Mojo bindings. These are closed by a call to Terminate(), which itself is
|
| + // called either by the provider, when the source WebContents goes away, or
|
| + // when a mojo message pipe connection error occurs.
|
| + interfaces::MediaRemotingProviderPtr remoting_provider_;
|
| + mojo::Binding<interfaces::MediaRemotingSession> binding_;
|
| +
|
| + // Run once, at the end of Terminate() to notify the owner that this object
|
| + // can be destroyed.
|
| + base::Closure did_terminate_callback_;
|
| +
|
| + // This is null until OnRemoteServicesAvailable() is called by the
|
| + // provider. It is set to null once OnRemoteServicesGone() is called.
|
| + media::mojom::RemoteCapabilitiesPtr remote_capabilities_;
|
| +
|
| + mojo::String transport_session_id_; // TODO(miu): This is a stub.
|
| +
|
| + // Set to true once all dependencies have been satisfied and the
|
| + // MediaRemotingConnector has been notified that remoting is available.
|
| + bool can_remote_media_;
|
| +
|
| + // During remoting, the content bitstream is read from these pipes (as
|
| + // media::mojom::DecoderBuffers).
|
| + mojo::ScopedDataPipeConsumerHandle audio_pipe_;
|
| + mojo::ScopedDataPipeConsumerHandle video_pipe_;
|
| +
|
| + // During remoting, this callback is run to dispatch messages back to the
|
| + // source.
|
| + RemoteMessageCallback message_callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(MediaRemotingSessionImpl);
|
| +};
|
| +
|
| +// A subclass of MediaRemotingSessionImpl whose lifetime is associated with a
|
| +// specific "content source" WebContents. It observes the WebContents and
|
| +// automatically self-terminates when the WebContents is destroyed.
|
| +class AutoTerminatingRemotingSession : public MediaRemotingSessionImpl,
|
| + protected content::WebContentsObserver {
|
| + public:
|
| + AutoTerminatingRemotingSession(
|
| + content::WebContents* source_contents,
|
| + interfaces::MediaRemotingProviderPtr provider,
|
| + mojo::InterfaceRequest<interfaces::MediaRemotingSession> request,
|
| + const base::Closure& did_terminate_callback);
|
| + ~AutoTerminatingRemotingSession() final;
|
| +
|
| + private:
|
| + // content::WebContentsObserver override.
|
| + void WebContentsDestroyed() final;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(AutoTerminatingRemotingSession);
|
| +};
|
| +
|
| +} // namespace media_router
|
| +
|
| +#endif // CHROME_BROWSER_MEDIA_ROUTER_MOJO_MEDIA_REMOTING_SESSION_IMPL_H_
|
|
|