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_source_impl.h" | 11 #include "media/remoting/remoting_source_impl.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.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; |
21 // 2) Monitors player events as a MediaObserver; | 22 // 2) Monitors player events as a MediaObserver; |
22 // 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 |
23 // and remoting. | 24 // and remoting. |
24 class RemotingRendererController final : public RemotingSourceImpl::Client, | 25 class RemotingRendererController final : public RemotingSourceImpl::Client, |
25 public MediaObserver { | 26 public MediaObserver { |
26 public: | 27 public: |
27 explicit RemotingRendererController( | 28 explicit RemotingRendererController( |
28 scoped_refptr<RemotingSourceImpl> remoting_source); | 29 scoped_refptr<RemotingSourceImpl> remoting_source); |
29 ~RemotingRendererController() override; | 30 ~RemotingRendererController() override; |
30 | 31 |
31 // RemotingSourceImpl::Client implemenations. | 32 // RemotingSourceImpl::Client implemenations. |
32 void OnStarted(bool success) override; | 33 void OnStarted(bool success) override; |
33 void OnSessionStateChanged() override; | 34 void OnSessionStateChanged() override; |
34 | 35 |
35 // MediaObserver implementations. | 36 // MediaObserver implementations. |
36 void OnEnteredFullscreen() override; | 37 void OnEnteredFullscreen() override; |
37 void OnExitedFullscreen() override; | 38 void OnExitedFullscreen() override; |
38 void OnSetCdm(CdmContext* cdm_context) override; | 39 void OnSetCdm(CdmContext* cdm_context) override; |
39 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 40 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
| 41 void OnSetPoster(const GURL& poster) override; |
40 | 42 |
41 void SetSwitchRendererCallback(const base::Closure& cb); | 43 void SetSwitchRendererCallback(const base::Closure& cb); |
42 | 44 |
| 45 using DownloadPosterCallback = |
| 46 base::Callback<void(const GURL&, |
| 47 const base::Callback<void(const SkBitmap&)>&)>; |
| 48 // Set the callback to download poster image. Can only be called once. |
| 49 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); |
| 50 |
43 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 51 base::WeakPtr<RemotingRendererController> GetWeakPtr() { |
44 return weak_factory_.GetWeakPtr(); | 52 return weak_factory_.GetWeakPtr(); |
45 } | 53 } |
46 | 54 |
47 // Used by RemotingRendererFactory to query whether to create Media Remoting | 55 // Used by RemotingRendererFactory to query whether to create Media Remoting |
48 // Renderer. | 56 // Renderer. |
49 bool remote_rendering_started() const { | 57 bool remote_rendering_started() const { |
50 DCHECK(thread_checker_.CalledOnValidThread()); | 58 DCHECK(thread_checker_.CalledOnValidThread()); |
51 return remote_rendering_started_; | 59 return remote_rendering_started_; |
52 } | 60 } |
(...skipping 30 matching lines...) Expand all Loading... |
83 bool IsVideoCodecSupported(); | 91 bool IsVideoCodecSupported(); |
84 bool IsAudioCodecSupported(); | 92 bool IsAudioCodecSupported(); |
85 | 93 |
86 // Helper to decide whether to enter or leave Remoting mode. | 94 // Helper to decide whether to enter or leave Remoting mode. |
87 bool ShouldBeRemoting(); | 95 bool ShouldBeRemoting(); |
88 | 96 |
89 // Determines whether to enter or leave Remoting mode and switches if | 97 // Determines whether to enter or leave Remoting mode and switches if |
90 // necessary. | 98 // necessary. |
91 void UpdateAndMaybeSwitch(); | 99 void UpdateAndMaybeSwitch(); |
92 | 100 |
93 // Indicates whether this media element or its ancestor is in full screen. | 101 // Called to download the poster image. Called when: |
| 102 // 1. Poster URL changes. |
| 103 // 2. ShowInterstitialCallback is set. |
| 104 // 3. DownloadPosterCallback is set. |
| 105 void DownloadPosterImage(); |
| 106 |
| 107 // Called when poster image is downloaded. |
| 108 void OnPosterImageDownloaded(const GURL& download_url, const SkBitmap& image); |
| 109 |
| 110 // Update remoting interstitial with |image|. When |image| is empty, |
| 111 // interstitial will be drawn on previously downloaded poster image (in |
| 112 // RemoteRendererImpl) or black background if none was downloaded before. |
| 113 // TODO(xjz): https://codereview.chromium.org/2566223005/ |
| 114 // Call this when: |
| 115 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is created). |
| 116 // 2. The remoting session is shut down (to update the status message in the |
| 117 // interstitial). |
| 118 // 3. The size of the canvas is changed (to update the background image and |
| 119 // the position of the status message). |
| 120 // 4. Poster image is downloaded (to update the background image). |
| 121 void UpdateInterstitial(const SkBitmap& image); |
| 122 |
| 123 // Indicates whether this media element is in full screen. |
94 bool is_fullscreen_ = false; | 124 bool is_fullscreen_ = false; |
95 | 125 |
96 // Indicates whether remoting is started. | 126 // Indicates whether remoting is started. |
97 bool remote_rendering_started_ = false; | 127 bool remote_rendering_started_ = false; |
98 | 128 |
99 // Indicates whether audio or video is encrypted. | 129 // Indicates whether audio or video is encrypted. |
100 bool is_encrypted_ = false; | 130 bool is_encrypted_ = false; |
101 | 131 |
102 // Current audio/video config. | 132 // Current audio/video config. |
103 VideoDecoderConfig video_decoder_config_; | 133 VideoDecoderConfig video_decoder_config_; |
104 AudioDecoderConfig audio_decoder_config_; | 134 AudioDecoderConfig audio_decoder_config_; |
105 | 135 |
106 // The callback to switch the media renderer. | 136 // The callback to switch the media renderer. |
107 base::Closure switch_renderer_cb_; | 137 base::Closure switch_renderer_cb_; |
108 | 138 |
109 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 139 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
110 // replaced with a different instance later if OnSetCdm() is called. | 140 // replaced with a different instance later if OnSetCdm() is called. |
111 scoped_refptr<RemotingSourceImpl> remoting_source_; | 141 scoped_refptr<RemotingSourceImpl> remoting_source_; |
112 | 142 |
113 // This is used to check all the methods are called on the current thread in | 143 // This is used to check all the methods are called on the current thread in |
114 // debug builds. | 144 // debug builds. |
115 base::ThreadChecker thread_checker_; | 145 base::ThreadChecker thread_checker_; |
116 | 146 |
| 147 // Current pipeline metadata. |
117 PipelineMetadata pipeline_metadata_; | 148 PipelineMetadata pipeline_metadata_; |
118 | 149 |
| 150 // Current poster URL, whose image will feed into the local UI. |
| 151 GURL poster_url_; |
| 152 |
| 153 // The callback to download the poster image. Called when |poster_url_| |
| 154 // changes during a remoting session or the show interstial callback is set. |
| 155 // OnPosterImageDownloaded() will be called when download completes. |
| 156 DownloadPosterCallback download_poster_cb_; |
| 157 |
119 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 158 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
120 | 159 |
121 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 160 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
122 }; | 161 }; |
123 | 162 |
124 } // namespace media | 163 } // namespace media |
125 | 164 |
126 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 165 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |