| Index: media/remoting/remoting_source_impl.h
|
| diff --git a/media/remoting/remoting_controller.h b/media/remoting/remoting_source_impl.h
|
| similarity index 30%
|
| rename from media/remoting/remoting_controller.h
|
| rename to media/remoting/remoting_source_impl.h
|
| index f565d66d89a5d6b6e8340f9a8a42af296d8e7936..0ad3bf49b187f08238f848deae5e5b53455d7901 100644
|
| --- a/media/remoting/remoting_controller.h
|
| +++ b/media/remoting/remoting_source_impl.h
|
| @@ -2,37 +2,98 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_
|
| -#define MEDIA_REMOTING_REMOTING_CONTROLLER_H_
|
| +#ifndef MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_
|
| +#define MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_
|
|
|
| +#include <vector>
|
| #include "base/callback.h"
|
| #include "base/memory/weak_ptr.h"
|
| -#include "media/base/media_observer.h"
|
| +#include "base/threading/thread_checker.h"
|
| #include "media/mojo/interfaces/remoting.mojom.h"
|
| #include "mojo/public/cpp/bindings/binding.h"
|
|
|
| -namespace base {
|
| -class SingleThreadTaskRunner;
|
| -}
|
| -
|
| -// This class does the following:
|
| -// 1) Sends/Receives messages from/to Remoter;
|
| -// 2) Monitors player events as a MediaObserver;
|
| -// 3) May trigger the switch of the media renderer between local playback
|
| -// and remoting.
|
| -//
|
| namespace media {
|
|
|
| namespace remoting {
|
| class RpcBroker;
|
| }
|
|
|
| -class RemotingController final : public MediaObserver,
|
| - public mojom::RemotingSource {
|
| +// State transition diagram:
|
| +//
|
| +// .--> SESSION_UNAVAILABLE
|
| +// | | ^
|
| +// | V |
|
| +// | SESSION_CAN_START
|
| +// | |
|
| +// | V
|
| +// | .---SESSION_STARTING --.
|
| +// | | | |
|
| +// | | V |
|
| +// | | SESSION_STARTED----|
|
| +// | | | |
|
| +// | | V |
|
| +// | '-> SESSION_STOPPING |
|
| +// '-----' | |
|
| +// V V
|
| +// SESSION_PERMANENTLY_STOPPED
|
| +
|
| +enum RemotingSessionState {
|
| + // Remoting sink is not available. Can't start remoting.
|
| + SESSION_UNAVAILABLE,
|
| + // Remoting sink is available, Can start remoting.
|
| + SESSION_CAN_START,
|
| + // Starting a remoting session.
|
| + SESSION_STARTING,
|
| + // Remoting session is successively started.
|
| + SESSION_STARTED,
|
| + // Stopping the session.
|
| + SESSION_STOPPING,
|
| + // Remoting session is permanently stopped. This state indicates that the
|
| + // video stack cannot continue operation. For example, if a remoting session
|
| + // involving CDM content was stopped, there is no way to continue playback
|
| + // because the CDM is required but is no longer available.
|
| + SESSION_PERMANENTLY_STOPPED,
|
| +};
|
| +
|
| +// Maintains a single remoting session for multiple clients. The session will
|
| +// start remoting when receiving the first request. Once remoting is started,
|
| +// it will be stopped when any of the following happens:
|
| +// 1) Receives the request from any client to stop remoting.
|
| +// 2) Remote sink is gone.
|
| +// 3) Any client requests to permanently terminate the session.
|
| +// 4) All clients are destroyed.
|
| +//
|
| +// This class is ref-counted because, in some cases, an instance will have
|
| +// shared ownership between RemotingRendererController and
|
| +// RemotingCdmController.
|
| +class RemotingSourceImpl final
|
| + : public mojom::RemotingSource,
|
| + public base::RefCountedThreadSafe<RemotingSourceImpl> {
|
| public:
|
| - RemotingController(mojom::RemotingSourceRequest source_request,
|
| + class Client {
|
| + public:
|
| + // Get notified whether the remoting session is successively started.
|
| + virtual void OnStarted(bool success) = 0;
|
| + // Get notified when session state changes.
|
| + virtual void OnSessionStateChanged() = 0;
|
| + };
|
| +
|
| + RemotingSourceImpl(mojom::RemotingSourceRequest source_request,
|
| mojom::RemoterPtr remoter);
|
| - ~RemotingController() override;
|
| +
|
| + // Get the current session state.
|
| + RemotingSessionState state() const {
|
| + DCHECK(thread_checker_.CalledOnValidThread());
|
| + return state_;
|
| + }
|
| +
|
| + // RemotingSource implementations.
|
| + void OnSinkAvailable() override;
|
| + void OnSinkGone() override;
|
| + void OnStarted() override;
|
| + void OnStartFailed(mojom::RemotingStartFailReason reason) override;
|
| + void OnMessageFromSink(const std::vector<uint8_t>& message) override;
|
| + void OnStopped(mojom::RemotingStopReason reason) override;
|
|
|
| using DataPipeStartCallback =
|
| base::Callback<void(mojom::RemotingDataStreamSenderPtrInfo audio,
|
| @@ -43,49 +104,32 @@ class RemotingController final : public MediaObserver,
|
| std::unique_ptr<mojo::DataPipe> video_data_pipe,
|
| const DataPipeStartCallback& done_callback);
|
|
|
| - // RemotingSource implementations.
|
| - void OnSinkAvailable() override;
|
| - void OnSinkGone() override;
|
| - void OnStarted() override;
|
| - void OnStartFailed(mojom::RemotingStartFailReason reason) override;
|
| - void OnMessageFromSink(const std::vector<uint8_t>& message) override;
|
| - void OnStopped(mojom::RemotingStopReason reason) override;
|
| + // Requests to start remoting. Will try start a remoting session if not
|
| + // started yet. |client| will get informed whether the session is
|
| + // successifully started throught OnStarted().
|
| + void StartRemoting(Client* client);
|
|
|
| - // MediaObserver implementations.
|
| - // This is called when the video element or its ancestor enters full screen.
|
| - // We currently use this as an indicator for immersive playback. May add other
|
| - // criteria (e.g. the actual display width/height of the video element) in
|
| - // future.
|
| - void OnEnteredFullscreen() override;
|
| - void OnExitedFullscreen() override;
|
| - void OnSetCdm(CdmContext* cdm_context) override;
|
| - void OnMetadataChanged(const PipelineMetadata& metadata) override;
|
| -
|
| - using SwitchRendererCallback = base::Callback<void()>;
|
| - void SetSwitchRendererCallback(const SwitchRendererCallback& cb);
|
| -
|
| - // Tells which renderer should be used.
|
| - bool is_remoting() const {
|
| - DCHECK(task_runner_->BelongsToCurrentThread());
|
| - return is_remoting_;
|
| - }
|
| + // Requests to stop the current remoting session if started. When the session
|
| + // is stopping, all clients will get notified.
|
| + void StopRemoting(Client* client);
|
|
|
| - base::WeakPtr<RemotingController> GetWeakPtr() {
|
| - return weak_factory_.GetWeakPtr();
|
| - }
|
| + // Permanently terminates the current remoting session.
|
| + void Shutdown();
|
| +
|
| + // Add/remove a client to/from |clients_|.
|
| + // Remoting session will be stopped if all clients are gone.
|
| + void AddClient(Client* client);
|
| + void RemoveClient(Client* client);
|
|
|
| base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const;
|
|
|
| private:
|
| - bool IsVideoCodecSupported();
|
| - bool IsAudioCodecSupported();
|
| -
|
| - // Helper to decide whether to enter or leave Remoting mode.
|
| - bool ShouldBeRemoting();
|
| + friend class base::RefCountedThreadSafe<RemotingSourceImpl>;
|
| + ~RemotingSourceImpl() override;
|
|
|
| - // Determines whether to enter or leave Remoting mode and switches if
|
| - // necessary.
|
| - void UpdateAndMaybeSwitch();
|
| + // Updates the current session state and notifies all the clients if state
|
| + // changes.
|
| + void UpdateAndNotifyState(RemotingSessionState state);
|
|
|
| // Callback from RpcBroker when sending message to remote sink.
|
| void OnSendMessageToSink(std::unique_ptr<std::vector<uint8_t>> message);
|
| @@ -93,39 +137,22 @@ class RemotingController final : public MediaObserver,
|
| // Handle incomging and outgoing RPC message.
|
| std::unique_ptr<remoting::RpcBroker> rpc_broker_;
|
|
|
| - // Indicates if this media element or its ancestor enters full screen.
|
| - bool is_fullscreen_ = false;
|
| -
|
| - // Indicates the remoting sink availablity.
|
| - bool is_sink_available_ = false;
|
| -
|
| - // Indicates if remoting is started.
|
| - bool is_remoting_ = false;
|
| -
|
| - // Indicates whether audio or video is encrypted.
|
| - bool is_encrypted_ = false;
|
| -
|
| - // Current audio/video config.
|
| - VideoDecoderConfig video_decoder_config_;
|
| - AudioDecoderConfig audio_decoder_config_;
|
| - bool has_audio_ = false;
|
| - bool has_video_ = false;
|
| -
|
| - // The callback to switch the media renderer.
|
| - SwitchRendererCallback switch_renderer_cb_;
|
| -
|
| - mojo::Binding<mojom::RemotingSource> binding_;
|
| - mojom::RemoterPtr remoter_;
|
| + const mojo::Binding<mojom::RemotingSource> binding_;
|
| + const mojom::RemoterPtr remoter_;
|
|
|
| - // TODO(xjz): Add a media thread task runner for the received RPC messages for
|
| - // remoting media renderer in the up-coming change.
|
| - const scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
|
| + // The current state.
|
| + RemotingSessionState state_ = RemotingSessionState::SESSION_UNAVAILABLE;
|
|
|
| - base::WeakPtrFactory<RemotingController> weak_factory_;
|
| + // Clients are added/removed to/from this list by calling Add/RemoveClient().
|
| + // All the clients are not belong to this class. They are supposed to call
|
| + // RemoveClient() before they are gone.
|
| + std::vector<Client*> clients_;
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(RemotingController);
|
| + // This is used to check all the methods are called on the current thread in
|
| + // debug builds.
|
| + base::ThreadChecker thread_checker_;
|
| };
|
|
|
| } // namespace media
|
|
|
| -#endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_
|
| +#endif // MEDIA_REMOTING_REMOTING_SOURCE_IMPL_H_
|
|
|