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_USER_EXPERIENCE_CONTROLLER_H_ |
6 #define MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 6 #define MEDIA_REMOTING_USER_EXPERIENCE_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" | |
12 #include "media/remoting/metrics.h" | 13 #include "media/remoting/metrics.h" |
13 #include "media/remoting/remoting_interstitial_ui.h" | 14 #include "media/remoting/shared_session.h" |
14 #include "media/remoting/remoting_source_impl.h" | |
15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
16 | 16 |
17 namespace media { | 17 namespace media { |
18 namespace remoting { | |
18 | 19 |
19 namespace remoting { | |
20 class RpcBroker; | 20 class RpcBroker; |
21 } | |
22 | 21 |
23 // This class: | 22 // This class: |
24 // 1) Implements the RemotingSourceImpl::Client; | 23 // 1) Implements the SharedSession::Client; |
25 // 2) Monitors player events as a MediaObserver; | 24 // 2) Monitors player events as a MediaObserver; |
26 // 3) May trigger the switch of the media renderer between local playback | 25 // 3) May trigger the switch of the media renderer between local playback |
27 // and remoting. | 26 // and remoting. |
28 class RemotingRendererController final : public RemotingSourceImpl::Client, | 27 class UserExperienceController final : public SharedSession::Client, |
xjz
2017/01/21 06:12:34
naming nit: I still prefer RendererController. The
miu
2017/01/23 20:57:37
Done. Re-thought this one for awhile, and I agree:
| |
29 public MediaObserver { | 28 public MediaObserver { |
30 public: | 29 public: |
31 explicit RemotingRendererController( | 30 explicit UserExperienceController(scoped_refptr<SharedSession> session); |
32 scoped_refptr<RemotingSourceImpl> remoting_source); | 31 ~UserExperienceController() override; |
33 ~RemotingRendererController() override; | |
34 | 32 |
35 // RemotingSourceImpl::Client implemenations. | 33 // SharedSession::Client implemenation. |
36 void OnStarted(bool success) override; | 34 void OnStarted(bool success) override; |
37 void OnSessionStateChanged() override; | 35 void OnSessionStateChanged() override; |
38 | 36 |
39 // MediaObserver implementations. | 37 // MediaObserver implementation. |
40 void OnEnteredFullscreen() override; | 38 void OnEnteredFullscreen() override; |
41 void OnExitedFullscreen() override; | 39 void OnExitedFullscreen() override; |
42 void OnBecameDominantVisibleContent(bool is_dominant) override; | 40 void OnBecameDominantVisibleContent(bool is_dominant) override; |
43 void OnSetCdm(CdmContext* cdm_context) override; | 41 void OnSetCdm(CdmContext* cdm_context) override; |
44 void OnMetadataChanged(const PipelineMetadata& metadata) override; | 42 void OnMetadataChanged(const PipelineMetadata& metadata) override; |
45 void OnRemotePlaybackDisabled(bool disabled) override; | 43 void OnRemotePlaybackDisabled(bool disabled) override; |
46 void OnPlaying() override; | 44 void OnPlaying() override; |
47 void OnPaused() override; | 45 void OnPaused() override; |
48 void OnSetPoster(const GURL& poster) override; | 46 void OnSetPoster(const GURL& poster) override; |
49 | 47 |
50 void SetSwitchRendererCallback(const base::Closure& cb); | 48 void SetSwitchRendererCallback(const base::Closure& cb); |
51 void SetRemoteSinkAvailableChangedCallback( | 49 void SetRemoteSinkAvailableChangedCallback( |
52 const base::Callback<void(bool)>& cb); | 50 const base::Callback<void(bool)>& cb); |
53 | 51 |
54 using ShowInterstitialCallback = | 52 using ShowInterstitialCallback = |
55 base::Callback<void(const base::Optional<SkBitmap>&, | 53 base::Callback<void(const base::Optional<SkBitmap>&, |
56 const gfx::Size&, | 54 const gfx::Size&, |
57 RemotingInterstitialType type)>; | 55 InterstitialType type)>; |
58 // Called by RemoteRendererImpl constructor to set the callback to draw and | 56 // Called by the CourierRenderer constructor to set the callback to draw and |
59 // show remoting interstial. | 57 // show remoting interstial. |
60 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); | 58 void SetShowInterstitialCallback(const ShowInterstitialCallback& cb); |
61 using DownloadPosterCallback = | 59 using DownloadPosterCallback = |
62 base::Callback<void(const GURL&, | 60 base::Callback<void(const GURL&, |
63 const base::Callback<void(const SkBitmap&)>&)>; | 61 const base::Callback<void(const SkBitmap&)>&)>; |
64 // Set the callback to download poster image. | 62 // Set the callback to download poster image. |
65 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); | 63 void SetDownloadPosterCallback(const DownloadPosterCallback& cb); |
66 | 64 |
67 base::WeakPtr<RemotingRendererController> GetWeakPtr() { | 65 base::WeakPtr<UserExperienceController> GetWeakPtr() { |
68 return weak_factory_.GetWeakPtr(); | 66 return weak_factory_.GetWeakPtr(); |
69 } | 67 } |
70 | 68 |
71 // Used by RemotingRendererFactory to query whether to create Media Remoting | 69 // Used by SituationalRendererFactory to query whether to create a Media |
72 // Renderer. | 70 // Remoting Renderer. |
73 bool remote_rendering_started() const { | 71 bool remote_rendering_started() const { |
74 DCHECK(thread_checker_.CalledOnValidThread()); | 72 DCHECK(thread_checker_.CalledOnValidThread()); |
75 return remote_rendering_started_; | 73 return remote_rendering_started_; |
76 } | 74 } |
77 | 75 |
78 void StartDataPipe( | 76 void StartDataPipe(std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
79 std::unique_ptr<mojo::DataPipe> audio_data_pipe, | 77 std::unique_ptr<mojo::DataPipe> video_data_pipe, |
80 std::unique_ptr<mojo::DataPipe> video_data_pipe, | 78 const SharedSession::DataPipeStartCallback& done_callback); |
81 const RemotingSourceImpl::DataPipeStartCallback& done_callback); | |
82 | 79 |
83 // Used by RemotingRendererImpl to query the session state. | 80 // Used by CourierRenderer to query the session state. |
84 RemotingSourceImpl* remoting_source() const { | 81 SharedSession* session() const { return session_.get(); } |
85 DCHECK(thread_checker_.CalledOnValidThread()); | |
86 return remoting_source_.get(); | |
87 } | |
88 | 82 |
89 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; | 83 base::WeakPtr<RpcBroker> GetRpcBroker() const; |
90 | 84 |
91 // Called by RemoteRendererImpl when it encountered a fatal error. This will | 85 // Called by CourierRenderer when it encountered a fatal error. This will |
92 // cause remoting to shut down and never start back up for the lifetime of | 86 // cause remoting to shut down and never start back up for the lifetime of |
93 // this controller. | 87 // this controller. |
94 void OnRendererFatalError(remoting::StopTrigger stop_trigger); | 88 void OnRendererFatalError(StopTrigger stop_trigger); |
95 | 89 |
96 private: | 90 private: |
97 bool has_audio() const { | 91 bool has_audio() const { |
98 return pipeline_metadata_.has_audio && | 92 return pipeline_metadata_.has_audio && |
99 pipeline_metadata_.audio_decoder_config.IsValidConfig(); | 93 pipeline_metadata_.audio_decoder_config.IsValidConfig(); |
100 } | 94 } |
101 | 95 |
102 bool has_video() const { | 96 bool has_video() const { |
103 return pipeline_metadata_.has_video && | 97 return pipeline_metadata_.has_video && |
104 pipeline_metadata_.video_decoder_config.IsValidConfig(); | 98 pipeline_metadata_.video_decoder_config.IsValidConfig(); |
105 } | 99 } |
106 | 100 |
107 // Called when the session availability state may have changed. Each call to | 101 // Called when the session availability state may have changed. Each call to |
108 // this method could cause a remoting session to be started or stopped; and if | 102 // this method could cause a remoting session to be started or stopped; and if |
109 // that happens, the |start_trigger| or |stop_trigger| must be the reason. | 103 // that happens, the |start_trigger| or |stop_trigger| must be the reason. |
110 void UpdateFromSessionState(remoting::StartTrigger start_trigger, | 104 void UpdateFromSessionState(StartTrigger start_trigger, |
111 remoting::StopTrigger stop_trigger); | 105 StopTrigger stop_trigger); |
112 | 106 |
113 bool IsVideoCodecSupported(); | 107 bool IsVideoCodecSupported(); |
114 bool IsAudioCodecSupported(); | 108 bool IsAudioCodecSupported(); |
115 bool IsRemoteSinkAvailable(); | 109 bool IsRemoteSinkAvailable(); |
116 | 110 |
117 // Helper to decide whether to enter or leave Remoting mode. | 111 // Helper to decide whether to enter or leave Remoting mode. |
118 bool ShouldBeRemoting(); | 112 bool ShouldBeRemoting(); |
119 | 113 |
120 // Determines whether to enter or leave Remoting mode and switches if | 114 // Determines whether to enter or leave Remoting mode and switches if |
121 // necessary. Each call to this method could cause a remoting session to be | 115 // necessary. Each call to this method could cause a remoting session to be |
122 // started or stopped; and if that happens, the |start_trigger| or | 116 // started or stopped; and if that happens, the |start_trigger| or |
123 // |stop_trigger| must be the reason. | 117 // |stop_trigger| must be the reason. |
124 void UpdateAndMaybeSwitch(remoting::StartTrigger start_trigger, | 118 void UpdateAndMaybeSwitch(StartTrigger start_trigger, |
125 remoting::StopTrigger stop_trigger); | 119 StopTrigger stop_trigger); |
126 | 120 |
127 // Called to download the poster image. Called when: | 121 // Called to download the poster image. Called when: |
128 // 1. Poster URL changes. | 122 // 1. Poster URL changes. |
129 // 2. ShowInterstitialCallback is set. | 123 // 2. ShowInterstitialCallback is set. |
130 // 3. DownloadPosterCallback is set. | 124 // 3. DownloadPosterCallback is set. |
131 void DownloadPosterImage(); | 125 void DownloadPosterImage(); |
132 | 126 |
133 // Called when poster image is downloaded. | 127 // Called when poster image is downloaded. |
134 void OnPosterImageDownloaded(const GURL& download_url, | 128 void OnPosterImageDownloaded(const GURL& download_url, |
135 base::TimeTicks download_start_time, | 129 base::TimeTicks download_start_time, |
136 const SkBitmap& image); | 130 const SkBitmap& image); |
137 | 131 |
138 // Update remoting interstitial with |image|. When |image| is not set, | 132 // Update remoting interstitial with |image|. When |image| is not set, |
139 // interstitial will be drawn on previously downloaded poster image (in | 133 // interstitial will be drawn on previously downloaded poster image (in |
140 // RemoteRendererImpl) or black background if none was downloaded before. | 134 // CourierRenderer) or black background if none was downloaded before. |
141 // Call this when: | 135 // Call this when: |
142 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is created). | 136 // 1. SetShowInterstitialCallback() is called (CourierRenderer is created). |
143 // 2. The remoting session is shut down (to update the status message in the | 137 // 2. The remoting session is shut down (to update the status message in the |
144 // interstitial). | 138 // interstitial). |
145 // 3. The size of the canvas is changed (to update the background image and | 139 // 3. The size of the canvas is changed (to update the background image and |
146 // the position of the status message). | 140 // the position of the status message). |
147 // 4. Poster image is downloaded (to update the background image). | 141 // 4. Poster image is downloaded (to update the background image). |
148 void UpdateInterstitial(const base::Optional<SkBitmap>& image); | 142 void UpdateInterstitial(const base::Optional<SkBitmap>& image); |
149 | 143 |
150 // Indicates whether this media element is in full screen. | 144 // Indicates whether this media element is in full screen. |
151 bool is_fullscreen_ = false; | 145 bool is_fullscreen_ = false; |
152 | 146 |
(...skipping 26 matching lines...) Expand all Loading... | |
179 // case, once a renderer encounters a fatal error, remoting will be shut down | 173 // case, once a renderer encounters a fatal error, remoting will be shut down |
180 // and never start again for the lifetime of this controller. | 174 // and never start again for the lifetime of this controller. |
181 bool encountered_renderer_fatal_error_ = false; | 175 bool encountered_renderer_fatal_error_ = false; |
182 | 176 |
183 // The callback to switch the media renderer. | 177 // The callback to switch the media renderer. |
184 base::Closure switch_renderer_cb_; | 178 base::Closure switch_renderer_cb_; |
185 | 179 |
186 // Called when remoting sink availability is changed. | 180 // Called when remoting sink availability is changed. |
187 base::Callback<void(bool)> sink_available_changed_cb_; | 181 base::Callback<void(bool)> sink_available_changed_cb_; |
188 | 182 |
189 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 183 // This is initially the SharedSession passed to the ctor, and might be |
190 // replaced with a different instance later if OnSetCdm() is called. | 184 // replaced with a different instance later if OnSetCdm() is called. |
191 scoped_refptr<RemotingSourceImpl> remoting_source_; | 185 scoped_refptr<SharedSession> session_; |
192 | 186 |
193 // This is used to check all the methods are called on the current thread in | 187 // This is used to check all the methods are called on the current thread in |
194 // debug builds. | 188 // debug builds. |
195 base::ThreadChecker thread_checker_; | 189 base::ThreadChecker thread_checker_; |
196 | 190 |
197 // Current pipeline metadata. | 191 // Current pipeline metadata. |
198 PipelineMetadata pipeline_metadata_; | 192 PipelineMetadata pipeline_metadata_; |
199 | 193 |
200 // The callback to show remoting interstitial. It is set when entering the | 194 // The callback to show the remoting interstitial. It is set shortly after |
201 // remoting mode (RemotingRendererImpl is constructed) by calling | 195 // remoting is started (when CourierRenderer is constructed, it calls |
202 // SetShowInterstitialCallback(), and is reset when leaving the remoting mode. | 196 // SetShowInterstitialCallback()), and is reset shortly after remoting has |
197 // ended. | |
203 ShowInterstitialCallback show_interstitial_cb_; | 198 ShowInterstitialCallback show_interstitial_cb_; |
204 | 199 |
205 // Current poster URL, whose image will feed into the local UI. | 200 // Current poster URL, whose image will feed into the local UI. |
206 GURL poster_url_; | 201 GURL poster_url_; |
207 | 202 |
208 // The callback to download the poster image. Called when |poster_url_| | 203 // The callback to download the poster image. Called when |poster_url_| |
209 // changes during a remoting session or the show interstial callback is set. | 204 // changes during a remoting session or the show interstial callback is set. |
210 // OnPosterImageDownloaded() will be called when download completes. | 205 // OnPosterImageDownloaded() will be called when download completes. |
211 DownloadPosterCallback download_poster_cb_; | 206 DownloadPosterCallback download_poster_cb_; |
212 | 207 |
213 // Records session events of interest. | 208 // Records session events of interest. |
214 remoting::SessionMetricsRecorder metrics_recorder_; | 209 SessionMetricsRecorder metrics_recorder_; |
215 | 210 |
216 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 211 base::WeakPtrFactory<UserExperienceController> weak_factory_; |
217 | 212 |
218 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 213 DISALLOW_COPY_AND_ASSIGN(UserExperienceController); |
219 }; | 214 }; |
220 | 215 |
216 } // namespace remoting | |
221 } // namespace media | 217 } // namespace media |
222 | 218 |
223 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 219 #endif // MEDIA_REMOTING_USER_EXPERIENCE_CONTROLLER_H_ |
OLD | NEW |