| 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_RENDERER_CONTROLLER_H_ | 5 #ifndef MEDIA_REMOTING_RENDERER_CONTROLLER_H_ |
| 6 #define MEDIA_REMOTING_RENDERER_CONTROLLER_H_ | 6 #define MEDIA_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 "base/optional.h" | 10 #include "base/optional.h" |
| 11 #include "media/base/media_observer.h" | 11 #include "media/base/media_observer.h" |
| 12 #include "media/remoting/interstitial.h" | |
| 13 #include "media/remoting/metrics.h" | 12 #include "media/remoting/metrics.h" |
| 14 #include "media/remoting/shared_session.h" | 13 #include "media/remoting/shared_session.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | |
| 16 | 14 |
| 17 namespace media { | 15 namespace media { |
| 18 namespace remoting { | 16 namespace remoting { |
| 19 | 17 |
| 20 class RpcBroker; | 18 class RpcBroker; |
| 21 | 19 |
| 22 // This class: | 20 // This class: |
| 23 // 1) Implements the SharedSession::Client; | 21 // 1) Implements the SharedSession::Client; |
| 24 // 2) Monitors player events as a MediaObserver; | 22 // 2) Monitors player events as a MediaObserver; |
| 25 // 3) May trigger the switch of the media renderer between local playback | 23 // 3) May trigger the switch of the media renderer between local playback |
| (...skipping 10 matching lines...) Expand all Loading... |
| 36 | 34 |
| 37 // MediaObserver implementation. | 35 // MediaObserver implementation. |
| 38 void OnEnteredFullscreen() override; | 36 void OnEnteredFullscreen() override; |
| 39 void OnExitedFullscreen() override; | 37 void OnExitedFullscreen() override; |
| 40 void OnBecameDominantVisibleContent(bool is_dominant) override; | 38 void OnBecameDominantVisibleContent(bool is_dominant) override; |
| 41 void OnSetCdm(CdmContext* cdm_context) override; | 39 void OnSetCdm(CdmContext* cdm_context) override; |
| 42 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 40 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
| 43 void OnRemotePlaybackDisabled(bool disabled) override; | 41 void OnRemotePlaybackDisabled(bool disabled) override; |
| 44 void OnPlaying() override; | 42 void OnPlaying() override; |
| 45 void OnPaused() override; | 43 void OnPaused() override; |
| 46 void OnSetPoster(const GURL& poster) override; | |
| 47 void SetClient(MediaObserverClient* client) override; | 44 void SetClient(MediaObserverClient* client) override; |
| 48 | 45 |
| 49 using ShowInterstitialCallback = base::Callback< | |
| 50 void(const SkBitmap&, const gfx::Size&, InterstitialType type)>; | |
| 51 // Called by the CourierRenderer constructor to set the callback to draw and | |
| 52 // show remoting interstial. | |
| 53 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); | |
| 54 using DownloadPosterCallback = | |
| 55 base::Callback<void(const GURL&, | |
| 56 const base::Callback<void(const SkBitmap&)>&)>; | |
| 57 // Set the callback to download poster image. | |
| 58 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); | |
| 59 | |
| 60 base::WeakPtr<RendererController> GetWeakPtr() { | 46 base::WeakPtr<RendererController> GetWeakPtr() { |
| 61 return weak_factory_.GetWeakPtr(); | 47 return weak_factory_.GetWeakPtr(); |
| 62 } | 48 } |
| 63 | 49 |
| 64 // Used by AdaptiveRendererFactory to query whether to create a Media | 50 // Used by AdaptiveRendererFactory to query whether to create a Media |
| 65 // Remoting Renderer. | 51 // Remoting Renderer. |
| 66 bool remote_rendering_started() const { | 52 bool remote_rendering_started() const { |
| 67 DCHECK(thread_checker_.CalledOnValidThread()); | 53 DCHECK(thread_checker_.CalledOnValidThread()); |
| 68 return remote_rendering_started_; | 54 return remote_rendering_started_; |
| 69 } | 55 } |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 // Helper to decide whether to enter or leave Remoting mode. | 92 // Helper to decide whether to enter or leave Remoting mode. |
| 107 bool ShouldBeRemoting(); | 93 bool ShouldBeRemoting(); |
| 108 | 94 |
| 109 // Determines whether to enter or leave Remoting mode and switches if | 95 // Determines whether to enter or leave Remoting mode and switches if |
| 110 // necessary. Each call to this method could cause a remoting session to be | 96 // necessary. Each call to this method could cause a remoting session to be |
| 111 // started or stopped; and if that happens, the |start_trigger| or | 97 // started or stopped; and if that happens, the |start_trigger| or |
| 112 // |stop_trigger| must be the reason. | 98 // |stop_trigger| must be the reason. |
| 113 void UpdateAndMaybeSwitch(StartTrigger start_trigger, | 99 void UpdateAndMaybeSwitch(StartTrigger start_trigger, |
| 114 StopTrigger stop_trigger); | 100 StopTrigger stop_trigger); |
| 115 | 101 |
| 116 // Called to download the poster image. Called when: | |
| 117 // 1. Poster URL changes. | |
| 118 // 2. ShowInterstitialCallback is set. | |
| 119 // 3. DownloadPosterCallback is set. | |
| 120 void DownloadPosterImage(); | |
| 121 | |
| 122 // Called when poster image is downloaded. | |
| 123 void OnPosterImageDownloaded(const GURL& download_url, | |
| 124 base::TimeTicks download_start_time, | |
| 125 const SkBitmap& image); | |
| 126 | |
| 127 // Update remoting interstitial with |image|. When |image| is not set, | |
| 128 // interstitial will be drawn on previously downloaded poster image (in | |
| 129 // CourierRenderer) or black background if none was downloaded before. | |
| 130 // Call this when: | |
| 131 // 1. SetShowInterstitialCallback() is called (CourierRenderer is created). | |
| 132 // 2. The remoting session is shut down (to update the status message in the | |
| 133 // interstitial). | |
| 134 // 3. The size of the canvas is changed (to update the background image and | |
| 135 // the position of the status message). | |
| 136 // 4. Poster image is downloaded (to update the background image). | |
| 137 void UpdateInterstitial(const base::Optional<SkBitmap>& image); | |
| 138 | |
| 139 // Indicates whether this media element is in full screen. | 102 // Indicates whether this media element is in full screen. |
| 140 bool is_fullscreen_ = false; | 103 bool is_fullscreen_ = false; |
| 141 | 104 |
| 142 // Indicates whether remoting is started. | 105 // Indicates whether remoting is started. |
| 143 bool remote_rendering_started_ = false; | 106 bool remote_rendering_started_ = false; |
| 144 | 107 |
| 145 // Indicates whether audio or video is encrypted. | 108 // Indicates whether audio or video is encrypted. |
| 146 bool is_encrypted_ = false; | 109 bool is_encrypted_ = false; |
| 147 | 110 |
| 148 // Indicates whether remote playback is currently disabled. This starts out as | 111 // Indicates whether remote playback is currently disabled. This starts out as |
| (...skipping 24 matching lines...) Expand all Loading... |
| 173 // replaced with a different instance later if OnSetCdm() is called. | 136 // replaced with a different instance later if OnSetCdm() is called. |
| 174 scoped_refptr<SharedSession> session_; | 137 scoped_refptr<SharedSession> session_; |
| 175 | 138 |
| 176 // This is used to check all the methods are called on the current thread in | 139 // This is used to check all the methods are called on the current thread in |
| 177 // debug builds. | 140 // debug builds. |
| 178 base::ThreadChecker thread_checker_; | 141 base::ThreadChecker thread_checker_; |
| 179 | 142 |
| 180 // Current pipeline metadata. | 143 // Current pipeline metadata. |
| 181 PipelineMetadata pipeline_metadata_; | 144 PipelineMetadata pipeline_metadata_; |
| 182 | 145 |
| 183 // The callback to show the remoting interstitial. It is set shortly after | |
| 184 // remoting is started (when CourierRenderer is constructed, it calls | |
| 185 // SetShowInterstitialCallback()), and is reset shortly after remoting has | |
| 186 // ended. | |
| 187 ShowInterstitialCallback show_interstitial_cb_; | |
| 188 | |
| 189 // The arguments passed in the last call to the interstitial callback. On each | |
| 190 // call to UpdateInterstitial(), one or more of these may be changed. If any | |
| 191 // change, the callback will be run. | |
| 192 SkBitmap interstitial_background_; | |
| 193 gfx::Size interstitial_natural_size_; | |
| 194 InterstitialType interstitial_type_ = InterstitialType::BETWEEN_SESSIONS; | |
| 195 | |
| 196 // Current poster URL, whose image will feed into the local UI. | |
| 197 GURL poster_url_; | |
| 198 | |
| 199 // The callback to download the poster image. Called when |poster_url_| | |
| 200 // changes during a remoting session or the show interstial callback is set. | |
| 201 // OnPosterImageDownloaded() will be called when download completes. | |
| 202 DownloadPosterCallback download_poster_cb_; | |
| 203 | |
| 204 // Records session events of interest. | 146 // Records session events of interest. |
| 205 SessionMetricsRecorder metrics_recorder_; | 147 SessionMetricsRecorder metrics_recorder_; |
| 206 | 148 |
| 207 // Not own by this class. Can only be set once by calling SetClient(). | 149 // Not own by this class. Can only be set once by calling SetClient(). |
| 208 MediaObserverClient* client_ = nullptr; | 150 MediaObserverClient* client_ = nullptr; |
| 209 | 151 |
| 210 base::WeakPtrFactory<RendererController> weak_factory_; | 152 base::WeakPtrFactory<RendererController> weak_factory_; |
| 211 | 153 |
| 212 DISALLOW_COPY_AND_ASSIGN(RendererController); | 154 DISALLOW_COPY_AND_ASSIGN(RendererController); |
| 213 }; | 155 }; |
| 214 | 156 |
| 215 } // namespace remoting | 157 } // namespace remoting |
| 216 } // namespace media | 158 } // namespace media |
| 217 | 159 |
| 218 #endif // MEDIA_REMOTING_RENDERER_CONTROLLER_H_ | 160 #endif // MEDIA_REMOTING_RENDERER_CONTROLLER_H_ |
| OLD | NEW |