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 "base/optional.h" |
10 #include "media/base/media_observer.h" | 11 #include "media/base/media_observer.h" |
11 #include "media/remoting/remoting_interstitial_ui.h" | 12 #include "media/remoting/remoting_interstitial_ui.h" |
12 #include "media/remoting/remoting_source_impl.h" | 13 #include "media/remoting/remoting_source_impl.h" |
| 14 #include "third_party/skia/include/core/SkBitmap.h" |
13 | 15 |
14 namespace media { | 16 namespace media { |
15 | 17 |
16 namespace remoting { | 18 namespace remoting { |
17 class RpcBroker; | 19 class RpcBroker; |
18 } | 20 } |
19 | 21 |
20 // This class: | 22 // This class: |
21 // 1) Implements the RemotingSourceImpl::Client; | 23 // 1) Implements the RemotingSourceImpl::Client; |
22 // 2) Monitors player events as a MediaObserver; | 24 // 2) Monitors player events as a MediaObserver; |
(...skipping 12 matching lines...) Expand all Loading... |
35 | 37 |
36 // MediaObserver implementations. | 38 // MediaObserver implementations. |
37 void OnEnteredFullscreen() override; | 39 void OnEnteredFullscreen() override; |
38 void OnExitedFullscreen() override; | 40 void OnExitedFullscreen() override; |
39 void OnBecameDominantVisibleContent(bool is_dominant) override; | 41 void OnBecameDominantVisibleContent(bool is_dominant) override; |
40 void OnSetCdm(CdmContext* cdm_context) override; | 42 void OnSetCdm(CdmContext* cdm_context) override; |
41 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 43 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
42 void OnRemotePlaybackDisabled(bool disabled) override; | 44 void OnRemotePlaybackDisabled(bool disabled) override; |
43 void OnPlaying() override; | 45 void OnPlaying() override; |
44 void OnPaused() override; | 46 void OnPaused() override; |
| 47 void OnSetPoster(const GURL& poster) override; |
45 | 48 |
46 void SetSwitchRendererCallback(const base::Closure& cb); | 49 void SetSwitchRendererCallback(const base::Closure& cb); |
47 void SetRemoteSinkAvailableChangedCallback( | 50 void SetRemoteSinkAvailableChangedCallback( |
48 const base::Callback<void(bool)>& cb); | 51 const base::Callback<void(bool)>& cb); |
49 | 52 |
50 using ShowInterstitialCallback = base::Callback< | 53 using ShowInterstitialCallback = |
51 void(const SkBitmap&, const gfx::Size&, RemotingInterstitialType type)>; | 54 base::Callback<void(const base::Optional<SkBitmap>&, |
| 55 const gfx::Size&, |
| 56 RemotingInterstitialType type)>; |
52 // Called by RemoteRendererImpl constructor to set the callback to draw and | 57 // Called by RemoteRendererImpl constructor to set the callback to draw and |
53 // show remoting interstial. | 58 // show remoting interstial. |
54 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); | 59 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); |
| 60 using DownloadPosterCallback = |
| 61 base::Callback<void(const GURL&, |
| 62 const base::Callback<void(const SkBitmap&)>&)>; |
| 63 // Set the callback to download poster image. |
| 64 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); |
55 | 65 |
56 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 66 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
57 return weak_factory_.GetWeakPtr(); | 67 return weak_factory_.GetWeakPtr(); |
58 } | 68 } |
59 | 69 |
60 // Used by RemotingRendererFactory to query whether to create Media Remoting | 70 // Used by RemotingRendererFactory to query whether to create Media Remoting |
61 // Renderer. | 71 // Renderer. |
62 bool remote_rendering_started() const { | 72 bool remote_rendering_started() const { |
63 DCHECK(thread_checker_.CalledOnValidThread()); | 73 DCHECK(thread_checker_.CalledOnValidThread()); |
64 return remote_rendering_started_; | 74 return remote_rendering_started_; |
(...skipping 27 matching lines...) Expand all Loading... |
92 bool IsAudioCodecSupported(); | 102 bool IsAudioCodecSupported(); |
93 bool IsRemoteSinkAvailable(); | 103 bool IsRemoteSinkAvailable(); |
94 | 104 |
95 // Helper to decide whether to enter or leave Remoting mode. | 105 // Helper to decide whether to enter or leave Remoting mode. |
96 bool ShouldBeRemoting(); | 106 bool ShouldBeRemoting(); |
97 | 107 |
98 // Determines whether to enter or leave Remoting mode and switches if | 108 // Determines whether to enter or leave Remoting mode and switches if |
99 // necessary. | 109 // necessary. |
100 void UpdateAndMaybeSwitch(); | 110 void UpdateAndMaybeSwitch(); |
101 | 111 |
102 // Called when any of the following happens: | 112 // Called to download the poster image. Called when: |
103 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is | 113 // 1. Poster URL changes. |
104 // constructed); | 114 // 2. ShowInterstitialCallback is set. |
| 115 // 3. DownloadPosterCallback is set. |
| 116 void DownloadPosterImage(); |
| 117 |
| 118 // Called when poster image is downloaded. |
| 119 void OnPosterImageDownloaded(const GURL& download_url, const SkBitmap& image); |
| 120 |
| 121 // Update remoting interstitial with |image|. When |image| is not set, |
| 122 // interstitial will be drawn on previously downloaded poster image (in |
| 123 // RemoteRendererImpl) or black background if none was downloaded before. |
| 124 // Call this when: |
| 125 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is created). |
105 // 2. The remoting session is shut down (to update the status message in the | 126 // 2. The remoting session is shut down (to update the status message in the |
106 // interstitial). | 127 // interstitial). |
107 // 3. The size of the canvas is changed (to update the background image and | 128 // 3. The size of the canvas is changed (to update the background image and |
108 // the position of the status message). | 129 // the position of the status message). |
109 // TODO(xjz): Call this when poster url is set/changed. Download poster image | 130 // 4. Poster image is downloaded (to update the background image). |
110 // when available, and draw interstitial on it. | 131 void UpdateInterstitial(const base::Optional<SkBitmap>& image); |
111 void UpdateInterstitial(); | |
112 | 132 |
113 // Indicates whether this media element or its ancestor is in full screen. | 133 // Indicates whether this media element is in full screen. |
114 bool is_fullscreen_ = false; | 134 bool is_fullscreen_ = false; |
115 | 135 |
116 // Indicates whether remoting is started. | 136 // Indicates whether remoting is started. |
117 bool remote_rendering_started_ = false; | 137 bool remote_rendering_started_ = false; |
118 | 138 |
119 // Indicates whether audio or video is encrypted. | 139 // Indicates whether audio or video is encrypted. |
120 bool is_encrypted_ = false; | 140 bool is_encrypted_ = false; |
121 | 141 |
122 // Indicates whether remote playback is currently disabled. This starts out as | 142 // Indicates whether remote playback is currently disabled. This starts out as |
123 // true, and should be updated at least once via a call to | 143 // true, and should be updated at least once via a call to |
(...skipping 17 matching lines...) Expand all Loading... |
141 base::Callback<void(bool)> sink_available_changed_cb_; | 161 base::Callback<void(bool)> sink_available_changed_cb_; |
142 | 162 |
143 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 163 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
144 // replaced with a different instance later if OnSetCdm() is called. | 164 // replaced with a different instance later if OnSetCdm() is called. |
145 scoped_refptr<RemotingSourceImpl> remoting_source_; | 165 scoped_refptr<RemotingSourceImpl> remoting_source_; |
146 | 166 |
147 // This is used to check all the methods are called on the current thread in | 167 // This is used to check all the methods are called on the current thread in |
148 // debug builds. | 168 // debug builds. |
149 base::ThreadChecker thread_checker_; | 169 base::ThreadChecker thread_checker_; |
150 | 170 |
| 171 // Current pipeline metadata. |
151 PipelineMetadata pipeline_metadata_; | 172 PipelineMetadata pipeline_metadata_; |
152 | 173 |
153 // The callback to show remoting interstitial. It is set when entering the | 174 // The callback to show remoting interstitial. It is set when entering the |
154 // remoting mode (RemotingRendererImpl is constructed) by calling | 175 // remoting mode (RemotingRendererImpl is constructed) by calling |
155 // SetShowInterstitialCallback(), and is reset when leaving the remoting mode. | 176 // SetShowInterstitialCallback(), and is reset when leaving the remoting mode. |
156 ShowInterstitialCallback show_interstitial_cb_; | 177 ShowInterstitialCallback show_interstitial_cb_; |
157 | 178 |
| 179 // Current poster URL, whose image will feed into the local UI. |
| 180 GURL poster_url_; |
| 181 |
| 182 // The callback to download the poster image. Called when |poster_url_| |
| 183 // changes during a remoting session or the show interstial callback is set. |
| 184 // OnPosterImageDownloaded() will be called when download completes. |
| 185 DownloadPosterCallback download_poster_cb_; |
| 186 |
158 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 187 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
159 | 188 |
160 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 189 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
161 }; | 190 }; |
162 | 191 |
163 } // namespace media | 192 } // namespace media |
164 | 193 |
165 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 194 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |