| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 5 #ifndef MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |
| 6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 6 #define MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |
| 7 | 7 |
| 8 #include "base/callback.h" | 8 #include "base/callback.h" |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/timer/timer.h" |
| 10 #include "media/base/media_observer.h" | 11 #include "media/base/media_observer.h" |
| 11 #include "media/mojo/interfaces/remoting.mojom.h" | 12 #include "media/mojo/interfaces/remoting.mojom.h" |
| 12 #include "mojo/public/cpp/bindings/binding.h" | 13 #include "mojo/public/cpp/bindings/binding.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 class SingleThreadTaskRunner; | 16 class SingleThreadTaskRunner; |
| 16 } | 17 } |
| 17 | 18 |
| 18 // This class does the following: | 19 // This class does the following: |
| 19 // 1) Sends/Receives messages from/to Remoter; | 20 // 1) Sends/Receives messages from/to Remoter; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 45 | 46 |
| 46 // RemotingSource implementations. | 47 // RemotingSource implementations. |
| 47 void OnSinkAvailable() override; | 48 void OnSinkAvailable() override; |
| 48 void OnSinkGone() override; | 49 void OnSinkGone() override; |
| 49 void OnStarted() override; | 50 void OnStarted() override; |
| 50 void OnStartFailed(mojom::RemotingStartFailReason reason) override; | 51 void OnStartFailed(mojom::RemotingStartFailReason reason) override; |
| 51 void OnMessageFromSink(const std::vector<uint8_t>& message) override; | 52 void OnMessageFromSink(const std::vector<uint8_t>& message) override; |
| 52 void OnStopped(mojom::RemotingStopReason reason) override; | 53 void OnStopped(mojom::RemotingStopReason reason) override; |
| 53 | 54 |
| 54 // MediaObserver implementations. | 55 // MediaObserver implementations. |
| 55 // This is called when the video element or its ancestor enters full screen. | |
| 56 // We currently use this as an indicator for immersive playback. May add other | |
| 57 // criteria (e.g. the actual display width/height of the video element) in | |
| 58 // future. | |
| 59 void OnEnteredFullscreen() override; | 56 void OnEnteredFullscreen() override; |
| 60 void OnExitedFullscreen() override; | 57 void OnExitedFullscreen() override; |
| 58 void OnVideoViewportRatioChanged(float ratio) override; |
| 61 void OnSetCdm(CdmContext* cdm_context) override; | 59 void OnSetCdm(CdmContext* cdm_context) override; |
| 62 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 60 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
| 63 | 61 |
| 64 using SwitchRendererCallback = base::Callback<void()>; | 62 using SwitchRendererCallback = base::Callback<void()>; |
| 65 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); | 63 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); |
| 66 | 64 |
| 67 // Tells which renderer should be used. | 65 // Tells which renderer should be used. |
| 68 bool is_remoting() const { | 66 bool is_remoting() const { |
| 69 DCHECK(task_runner_->BelongsToCurrentThread()); | 67 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 70 return is_remoting_; | 68 return is_remoting_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 // Helper to decide whether to enter or leave Remoting mode. | 81 // Helper to decide whether to enter or leave Remoting mode. |
| 84 bool ShouldBeRemoting(); | 82 bool ShouldBeRemoting(); |
| 85 | 83 |
| 86 // Determines whether to enter or leave Remoting mode and switches if | 84 // Determines whether to enter or leave Remoting mode and switches if |
| 87 // necessary. | 85 // necessary. |
| 88 void UpdateAndMaybeSwitch(); | 86 void UpdateAndMaybeSwitch(); |
| 89 | 87 |
| 90 // Callback from RpcBroker when sending message to remote sink. | 88 // Callback from RpcBroker when sending message to remote sink. |
| 91 void OnSendMessageToSink(std::unique_ptr<std::vector<uint8_t>> message); | 89 void OnSendMessageToSink(std::unique_ptr<std::vector<uint8_t>> message); |
| 92 | 90 |
| 91 // Callback from |viewport_fill_debouncer_timer_| when video keeps covering |
| 92 // most of the viewport for a certain time. |
| 93 void OnViewportMostlyFilledAndUnchanging(); |
| 94 |
| 93 // Handle incomging and outgoing RPC message. | 95 // Handle incomging and outgoing RPC message. |
| 94 std::unique_ptr<remoting::RpcBroker> rpc_broker_; | 96 std::unique_ptr<remoting::RpcBroker> rpc_broker_; |
| 95 | 97 |
| 96 // Indicates if this media element or its ancestor enters full screen. | 98 // Indicates if this media element or its ancestor enters full screen. |
| 97 bool is_fullscreen_ = false; | 99 bool is_fullscreen_ = false; |
| 98 | 100 |
| 99 // Indicates the remoting sink availablity. | 101 // Indicates the remoting sink availablity. |
| 100 bool is_sink_available_ = false; | 102 bool is_sink_available_ = false; |
| 101 | 103 |
| 102 // Indicates if remoting is started. | 104 // Indicates if remoting is started. |
| 103 bool is_remoting_ = false; | 105 bool is_remoting_ = false; |
| 104 | 106 |
| 105 // Indicates whether audio or video is encrypted. | 107 // Indicates whether audio or video is encrypted. |
| 106 bool is_encrypted_ = false; | 108 bool is_encrypted_ = false; |
| 107 | 109 |
| 108 // Current audio/video config. | 110 // Current audio/video config. |
| 109 VideoDecoderConfig video_decoder_config_; | 111 VideoDecoderConfig video_decoder_config_; |
| 110 AudioDecoderConfig audio_decoder_config_; | 112 AudioDecoderConfig audio_decoder_config_; |
| 111 bool has_audio_ = false; | 113 bool has_audio_ = false; |
| 112 bool has_video_ = false; | 114 bool has_video_ = false; |
| 113 | 115 |
| 116 // Indicates whether video covers most of the viewport. |
| 117 bool is_mostly_filling_viewport_ = false; |
| 118 // Video/Viewport ratio meeting/exceeding the threshold should hold steady for |
| 119 // a certain time before attempting to start remoting. |
| 120 base::OneShotTimer viewport_fill_debouncer_timer_; |
| 121 |
| 114 // The callback to switch the media renderer. | 122 // The callback to switch the media renderer. |
| 115 SwitchRendererCallback switch_renderer_cb_; | 123 SwitchRendererCallback switch_renderer_cb_; |
| 116 | 124 |
| 117 mojo::Binding<mojom::RemotingSource> binding_; | 125 mojo::Binding<mojom::RemotingSource> binding_; |
| 118 mojom::RemoterPtr remoter_; | 126 mojom::RemoterPtr remoter_; |
| 119 | 127 |
| 120 // TODO(xjz): Add a media thread task runner for the received RPC messages for | 128 // TODO(xjz): Add a media thread task runner for the received RPC messages for |
| 121 // remoting media renderer in the up-coming change. | 129 // remoting media renderer in the up-coming change. |
| 122 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 130 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 123 | 131 |
| 124 base::WeakPtrFactory<RemotingController> weak_factory_; | 132 base::WeakPtrFactory<RemotingController> weak_factory_; |
| 125 | 133 |
| 126 DISALLOW_COPY_AND_ASSIGN(RemotingController); | 134 DISALLOW_COPY_AND_ASSIGN(RemotingController); |
| 127 }; | 135 }; |
| 128 | 136 |
| 129 } // namespace media | 137 } // namespace media |
| 130 | 138 |
| 131 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 139 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |
| OLD | NEW |