Chromium Code Reviews| Index: media/remoting/remoting_controller.h | 
| diff --git a/media/remoting/remoting_controller.h b/media/remoting/remoting_controller.h | 
| new file mode 100644 | 
| index 0000000000000000000000000000000000000000..514d6124f283b582096c1f3efe0124572aa07efd | 
| --- /dev/null | 
| +++ b/media/remoting/remoting_controller.h | 
| @@ -0,0 +1,110 @@ | 
| +// 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 MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 
| +#define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 
| + | 
| +#include "base/callback.h" | 
| +#include "base/memory/weak_ptr.h" | 
| +#include "media/base/media_observer.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 { | 
| + | 
| +class RemotingController final : public MediaObserver, | 
| + public mojom::RemotingSource { | 
| + public: | 
| + RemotingController(mojom::RemotingSourceRequest source_request, | 
| + mojom::RemoterPtr remoter); | 
| + ~RemotingController() override; | 
| + | 
| + // RemotingSource implementations. | 
| + void OnSinkAvailable() override; | 
| + void OnSinkGone() override; | 
| + // This is called when remoting is started successfully. Note: Only one video | 
| + // element can start remoting successfully at one time. The current | 
| + // logic is the first come first serve. This logic might be changed in future. | 
| 
 
xhwang
2016/10/05 05:27:53
Usually for overrides, we don't have extra comment
 
xjz
2016/10/05 17:24:24
Removed this comment here. This is controled by br
 
 | 
| + void OnStarted() override; | 
| + void OnStartFailed(mojom::RemotingStartFailReason reason) override; | 
| + void OnMessageFromSink(const std::vector<uint8_t>& message) override; | 
| + void OnStopped(mojom::RemotingStopReason reason) override; | 
| + | 
| + // 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 OnMetadata(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_; | 
| + } | 
| + | 
| + base::WeakPtr<RemotingController> GetWeakPtr() { | 
| + return weak_factory_.GetWeakPtr(); | 
| + } | 
| + | 
| + private: | 
| + bool IsVideoConfigSupported(); | 
| + bool IsAudioConfigSupported(); | 
| + | 
| + // Helper to decide whether to enter or leave Remoting mode. | 
| + bool ShouldBeRemoting(); | 
| + | 
| + // Determines whether to enter or leave Remoting mode and switches if | 
| + // necessary. | 
| + void UpdateAndMaybeSwitch(); | 
| + | 
| + // 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; | 
| + | 
| + // 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_; | 
| + | 
| + // 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_; | 
| + | 
| + base::WeakPtrFactory<RemotingController> weak_factory_; | 
| + | 
| + DISALLOW_COPY_AND_ASSIGN(RemotingController); | 
| +}; | 
| + | 
| +} // namespace media | 
| + | 
| +#endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |