| 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 OnVideoViewportIntersectionChanged( |
| 59 const ViewportIntersectionInfo& info) override; |
| 61 void OnSetCdm(CdmContext* cdm_context) override; | 60 void OnSetCdm(CdmContext* cdm_context) override; |
| 62 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 61 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
| 63 | 62 |
| 64 using SwitchRendererCallback = base::Callback<void()>; | 63 using SwitchRendererCallback = base::Callback<void()>; |
| 65 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); | 64 void SetSwitchRendererCallback(const SwitchRendererCallback& cb); |
| 66 | 65 |
| 67 // Tells which renderer should be used. | 66 // Tells which renderer should be used. |
| 68 bool is_remoting() const { | 67 bool is_remoting() const { |
| 69 DCHECK(task_runner_->BelongsToCurrentThread()); | 68 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 70 return is_remoting_; | 69 return is_remoting_; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 83 // Helper to decide whether to enter or leave Remoting mode. | 82 // Helper to decide whether to enter or leave Remoting mode. |
| 84 bool ShouldBeRemoting(); | 83 bool ShouldBeRemoting(); |
| 85 | 84 |
| 86 // Determines whether to enter or leave Remoting mode and switches if | 85 // Determines whether to enter or leave Remoting mode and switches if |
| 87 // necessary. | 86 // necessary. |
| 88 void UpdateAndMaybeSwitch(); | 87 void UpdateAndMaybeSwitch(); |
| 89 | 88 |
| 90 // Callback from RpcBroker when sending message to remote sink. | 89 // Callback from RpcBroker when sending message to remote sink. |
| 91 void OnSendMessageToSink(std::unique_ptr<std::vector<uint8_t>> message); | 90 void OnSendMessageToSink(std::unique_ptr<std::vector<uint8_t>> message); |
| 92 | 91 |
| 92 // Callback from |viewport_fill_debouncer_timer_| when video keeps covering |
| 93 // most of the viewport for a certain time. |
| 94 void OnViewportMostlyFilledAndUnchanging(); |
| 95 |
| 93 // Handle incomging and outgoing RPC message. | 96 // Handle incomging and outgoing RPC message. |
| 94 std::unique_ptr<remoting::RpcBroker> rpc_broker_; | 97 std::unique_ptr<remoting::RpcBroker> rpc_broker_; |
| 95 | 98 |
| 96 // Indicates if this media element or its ancestor enters full screen. | 99 // Indicates if this media element or its ancestor enters full screen. |
| 97 bool is_fullscreen_ = false; | 100 bool is_fullscreen_ = false; |
| 98 | 101 |
| 99 // Indicates the remoting sink availablity. | 102 // Indicates the remoting sink availablity. |
| 100 bool is_sink_available_ = false; | 103 bool is_sink_available_ = false; |
| 101 | 104 |
| 102 // Indicates if remoting is started. | 105 // Indicates if remoting is started. |
| 103 bool is_remoting_ = false; | 106 bool is_remoting_ = false; |
| 104 | 107 |
| 105 // Indicates whether audio or video is encrypted. | 108 // Indicates whether audio or video is encrypted. |
| 106 bool is_encrypted_ = false; | 109 bool is_encrypted_ = false; |
| 107 | 110 |
| 108 // Current audio/video config. | 111 // Current audio/video config. |
| 109 VideoDecoderConfig video_decoder_config_; | 112 VideoDecoderConfig video_decoder_config_; |
| 110 AudioDecoderConfig audio_decoder_config_; | 113 AudioDecoderConfig audio_decoder_config_; |
| 111 bool has_audio_ = false; | 114 bool has_audio_ = false; |
| 112 bool has_video_ = false; | 115 bool has_video_ = false; |
| 113 | 116 |
| 117 // Indicates whether video covers most of the viewport. |
| 118 bool is_mostly_filling_viewport_ = false; |
| 119 // Video/Viewport ratio meeting/exceeding the threshold should hold steady for |
| 120 // a certain time before attempting to start remoting. |
| 121 base::OneShotTimer viewport_fill_debouncer_timer_; |
| 122 |
| 114 // The callback to switch the media renderer. | 123 // The callback to switch the media renderer. |
| 115 SwitchRendererCallback switch_renderer_cb_; | 124 SwitchRendererCallback switch_renderer_cb_; |
| 116 | 125 |
| 117 mojo::Binding<mojom::RemotingSource> binding_; | 126 mojo::Binding<mojom::RemotingSource> binding_; |
| 118 mojom::RemoterPtr remoter_; | 127 mojom::RemoterPtr remoter_; |
| 119 | 128 |
| 120 // TODO(xjz): Add a media thread task runner for the received RPC messages for | 129 // TODO(xjz): Add a media thread task runner for the received RPC messages for |
| 121 // remoting media renderer in the up-coming change. | 130 // remoting media renderer in the up-coming change. |
| 122 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; | 131 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; |
| 123 | 132 |
| 124 base::WeakPtrFactory<RemotingController> weak_factory_; | 133 base::WeakPtrFactory<RemotingController> weak_factory_; |
| 125 | 134 |
| 126 DISALLOW_COPY_AND_ASSIGN(RemotingController); | 135 DISALLOW_COPY_AND_ASSIGN(RemotingController); |
| 127 }; | 136 }; |
| 128 | 137 |
| 129 } // namespace media | 138 } // namespace media |
| 130 | 139 |
| 131 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ | 140 #endif // MEDIA_REMOTING_REMOTING_CONTROLLER_H_ |
| OLD | NEW |