| 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_RENDERER_CONTROLLER_H_ | 5 #ifndef MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
| 6 #define MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 6 #define MEDIA_REMOTING_REMOTING_RENDERER_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 "media/base/media_observer.h" | 10 #include "media/base/media_observer.h" |
| 11 #include "media/remoting/remoting_interstitial_ui.h" |
| 11 #include "media/remoting/remoting_source_impl.h" | 12 #include "media/remoting/remoting_source_impl.h" |
| 12 | 13 |
| 13 namespace media { | 14 namespace media { |
| 14 | 15 |
| 15 namespace remoting { | 16 namespace remoting { |
| 16 class RpcBroker; | 17 class RpcBroker; |
| 17 } | 18 } |
| 18 | 19 |
| 19 // This class: | 20 // This class: |
| 20 // 1) Implements the RemotingSourceImpl::Client; | 21 // 1) Implements the RemotingSourceImpl::Client; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 39 void OnSetCdm(CdmContext* cdm_context) override; | 40 void OnSetCdm(CdmContext* cdm_context) override; |
| 40 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 41 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
| 41 void OnRemotePlaybackDisabled(bool disabled) override; | 42 void OnRemotePlaybackDisabled(bool disabled) override; |
| 42 void OnPlaying() override; | 43 void OnPlaying() override; |
| 43 void OnPaused() override; | 44 void OnPaused() override; |
| 44 | 45 |
| 45 void SetSwitchRendererCallback(const base::Closure& cb); | 46 void SetSwitchRendererCallback(const base::Closure& cb); |
| 46 void SetRemoteSinkAvailableChangedCallback( | 47 void SetRemoteSinkAvailableChangedCallback( |
| 47 const base::Callback<void(bool)>& cb); | 48 const base::Callback<void(bool)>& cb); |
| 48 | 49 |
| 50 using ShowInterstitialCallback = base::Callback< |
| 51 void(const SkBitmap&, const gfx::Size&, RemotingInterstitialType type)>; |
| 52 // Called by RemoteRendererImpl constructor to set the callback to draw and |
| 53 // show remoting interstial. |
| 54 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); |
| 55 |
| 49 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 56 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
| 50 return weak_factory_.GetWeakPtr(); | 57 return weak_factory_.GetWeakPtr(); |
| 51 } | 58 } |
| 52 | 59 |
| 53 // Used by RemotingRendererFactory to query whether to create Media Remoting | 60 // Used by RemotingRendererFactory to query whether to create Media Remoting |
| 54 // Renderer. | 61 // Renderer. |
| 55 bool remote_rendering_started() const { | 62 bool remote_rendering_started() const { |
| 56 DCHECK(thread_checker_.CalledOnValidThread()); | 63 DCHECK(thread_checker_.CalledOnValidThread()); |
| 57 return remote_rendering_started_; | 64 return remote_rendering_started_; |
| 58 } | 65 } |
| 59 | 66 |
| 60 void StartDataPipe( | 67 void StartDataPipe( |
| 61 std::unique_ptr<mojo::DataPipe> audio_data_pipe, | 68 std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
| 62 std::unique_ptr<mojo::DataPipe> video_data_pipe, | 69 std::unique_ptr<mojo::DataPipe> video_data_pipe, |
| 63 const RemotingSourceImpl::DataPipeStartCallback& done_callback); | 70 const RemotingSourceImpl::DataPipeStartCallback& done_callback); |
| 64 | 71 |
| 65 // Used by RemotingRendererImpl to query the session state. | 72 // Used by RemotingRendererImpl to query the session state. |
| 66 RemotingSourceImpl* remoting_source() const { | 73 RemotingSourceImpl* remoting_source() const { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 74 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 return remoting_source_.get(); | 75 return remoting_source_.get(); |
| 69 } | 76 } |
| 70 | 77 |
| 71 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; | 78 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; |
| 72 | 79 |
| 73 PipelineMetadata pipeline_metadata() const { | |
| 74 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 75 return pipeline_metadata_; | |
| 76 } | |
| 77 | |
| 78 private: | 80 private: |
| 79 bool has_audio() const { | 81 bool has_audio() const { |
| 80 return pipeline_metadata_.has_audio && | 82 return pipeline_metadata_.has_audio && |
| 81 pipeline_metadata_.audio_decoder_config.IsValidConfig(); | 83 pipeline_metadata_.audio_decoder_config.IsValidConfig(); |
| 82 } | 84 } |
| 83 | 85 |
| 84 bool has_video() const { | 86 bool has_video() const { |
| 85 return pipeline_metadata_.has_video && | 87 return pipeline_metadata_.has_video && |
| 86 pipeline_metadata_.video_decoder_config.IsValidConfig(); | 88 pipeline_metadata_.video_decoder_config.IsValidConfig(); |
| 87 } | 89 } |
| 88 | 90 |
| 89 bool IsVideoCodecSupported(); | 91 bool IsVideoCodecSupported(); |
| 90 bool IsAudioCodecSupported(); | 92 bool IsAudioCodecSupported(); |
| 91 bool IsRemoteSinkAvailable(); | 93 bool IsRemoteSinkAvailable(); |
| 92 | 94 |
| 93 // Helper to decide whether to enter or leave Remoting mode. | 95 // Helper to decide whether to enter or leave Remoting mode. |
| 94 bool ShouldBeRemoting(); | 96 bool ShouldBeRemoting(); |
| 95 | 97 |
| 96 // Determines whether to enter or leave Remoting mode and switches if | 98 // Determines whether to enter or leave Remoting mode and switches if |
| 97 // necessary. | 99 // necessary. |
| 98 void UpdateAndMaybeSwitch(); | 100 void UpdateAndMaybeSwitch(); |
| 99 | 101 |
| 102 // Called when any of the following happens: |
| 103 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is |
| 104 // constructed); |
| 105 // 2. The remoting session is shut down (to update the status message in the |
| 106 // interstitial). |
| 107 // 3. The size of the canvas is changed (to update the background image and |
| 108 // the position of the status message). |
| 109 // TODO(xjz): Call this when poster url is set/changed. Download poster image |
| 110 // when available, and draw interstitial on it. |
| 111 void UpdateInterstitial(); |
| 112 |
| 100 // Indicates whether this media element or its ancestor is in full screen. | 113 // Indicates whether this media element or its ancestor is in full screen. |
| 101 bool is_fullscreen_ = false; | 114 bool is_fullscreen_ = false; |
| 102 | 115 |
| 103 // Indicates whether remoting is started. | 116 // Indicates whether remoting is started. |
| 104 bool remote_rendering_started_ = false; | 117 bool remote_rendering_started_ = false; |
| 105 | 118 |
| 106 // Indicates whether audio or video is encrypted. | 119 // Indicates whether audio or video is encrypted. |
| 107 bool is_encrypted_ = false; | 120 bool is_encrypted_ = false; |
| 108 | 121 |
| 109 // Current audio/video config. | |
| 110 VideoDecoderConfig video_decoder_config_; | |
| 111 AudioDecoderConfig audio_decoder_config_; | |
| 112 | |
| 113 // Indicates whether remote playback is currently disabled. This starts out as | 122 // Indicates whether remote playback is currently disabled. This starts out as |
| 114 // true, and should be updated at least once via a call to | 123 // true, and should be updated at least once via a call to |
| 115 // OnRemotePlaybackDisabled() at some point in the future. A web page | 124 // OnRemotePlaybackDisabled() at some point in the future. A web page |
| 116 // typically sets/removes the disableRemotePlayback attribute on a | 125 // typically sets/removes the disableRemotePlayback attribute on a |
| 117 // HTMLMediaElement to disable/enable remoting of its content. Please see the | 126 // HTMLMediaElement to disable/enable remoting of its content. Please see the |
| 118 // Remote Playback API spec for more details: | 127 // Remote Playback API spec for more details: |
| 119 // https://w3c.github.io/remote-playback | 128 // https://w3c.github.io/remote-playback |
| 120 bool is_remote_playback_disabled_ = true; | 129 bool is_remote_playback_disabled_ = true; |
| 121 | 130 |
| 122 // Indicates whether video is the dominant visible content in the tab. | 131 // Indicates whether video is the dominant visible content in the tab. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 143 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
| 135 // replaced with a different instance later if OnSetCdm() is called. | 144 // replaced with a different instance later if OnSetCdm() is called. |
| 136 scoped_refptr<RemotingSourceImpl> remoting_source_; | 145 scoped_refptr<RemotingSourceImpl> remoting_source_; |
| 137 | 146 |
| 138 // This is used to check all the methods are called on the current thread in | 147 // This is used to check all the methods are called on the current thread in |
| 139 // debug builds. | 148 // debug builds. |
| 140 base::ThreadChecker thread_checker_; | 149 base::ThreadChecker thread_checker_; |
| 141 | 150 |
| 142 PipelineMetadata pipeline_metadata_; | 151 PipelineMetadata pipeline_metadata_; |
| 143 | 152 |
| 153 // The callback to show remoting interstitial. It is set when entering the |
| 154 // remoting mode (RemotingRendererImpl is constructed) by calling |
| 155 // SetShowInterstitialCallback(), and is reset when leaving the remoting mode. |
| 156 ShowInterstitialCallback show_interstitial_cb_; |
| 157 |
| 144 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 158 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
| 145 | 159 |
| 146 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 160 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
| 147 }; | 161 }; |
| 148 | 162 |
| 149 } // namespace media | 163 } // namespace media |
| 150 | 164 |
| 151 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 165 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
| OLD | NEW |