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 "base/optional.h" |
11 #include "media/base/media_observer.h" | 11 #include "media/base/media_observer.h" |
| 12 #include "media/remoting/metrics.h" |
12 #include "media/remoting/remoting_interstitial_ui.h" | 13 #include "media/remoting/remoting_interstitial_ui.h" |
13 #include "media/remoting/remoting_source_impl.h" | 14 #include "media/remoting/remoting_source_impl.h" |
14 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
15 | 16 |
16 namespace media { | 17 namespace media { |
17 | 18 |
18 namespace remoting { | 19 namespace remoting { |
19 class RpcBroker; | 20 class RpcBroker; |
20 } | 21 } |
21 | 22 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 const RemotingSourceImpl::DataPipeStartCallback& done_callback); | 81 const RemotingSourceImpl::DataPipeStartCallback& done_callback); |
81 | 82 |
82 // Used by RemotingRendererImpl to query the session state. | 83 // Used by RemotingRendererImpl to query the session state. |
83 RemotingSourceImpl* remoting_source() const { | 84 RemotingSourceImpl* remoting_source() const { |
84 DCHECK(thread_checker_.CalledOnValidThread()); | 85 DCHECK(thread_checker_.CalledOnValidThread()); |
85 return remoting_source_.get(); | 86 return remoting_source_.get(); |
86 } | 87 } |
87 | 88 |
88 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; | 89 base::WeakPtr<remoting::RpcBroker> GetRpcBroker() const; |
89 | 90 |
90 // Called by RemoteRendererImpl when irregular playback is detected, which | 91 // Called by RemoteRendererImpl when it encountered a fatal error. This will |
91 // indicates either insufficient network bandwidth or the receiver cannot | 92 // cause remoting to shut down and never start back up for the lifetime of |
92 // handle the data volume of the content (e.g., too high resolution and/or | 93 // this controller. |
93 // frame rate). | 94 void OnRendererFatalError(remoting::StopTrigger stop_trigger); |
94 void OnIrregularPlaybackDetected(); | |
95 | 95 |
96 private: | 96 private: |
97 bool has_audio() const { | 97 bool has_audio() const { |
98 return pipeline_metadata_.has_audio && | 98 return pipeline_metadata_.has_audio && |
99 pipeline_metadata_.audio_decoder_config.IsValidConfig(); | 99 pipeline_metadata_.audio_decoder_config.IsValidConfig(); |
100 } | 100 } |
101 | 101 |
102 bool has_video() const { | 102 bool has_video() const { |
103 return pipeline_metadata_.has_video && | 103 return pipeline_metadata_.has_video && |
104 pipeline_metadata_.video_decoder_config.IsValidConfig(); | 104 pipeline_metadata_.video_decoder_config.IsValidConfig(); |
105 } | 105 } |
106 | 106 |
| 107 // 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 |
| 109 // that happens, the |start_trigger| or |stop_trigger| must be the reason. |
| 110 void UpdateFromSessionState(remoting::StartTrigger start_trigger, |
| 111 remoting::StopTrigger stop_trigger); |
| 112 |
107 bool IsVideoCodecSupported(); | 113 bool IsVideoCodecSupported(); |
108 bool IsAudioCodecSupported(); | 114 bool IsAudioCodecSupported(); |
109 bool IsRemoteSinkAvailable(); | 115 bool IsRemoteSinkAvailable(); |
110 | 116 |
111 // Helper to decide whether to enter or leave Remoting mode. | 117 // Helper to decide whether to enter or leave Remoting mode. |
112 bool ShouldBeRemoting(); | 118 bool ShouldBeRemoting(); |
113 | 119 |
114 // Determines whether to enter or leave Remoting mode and switches if | 120 // Determines whether to enter or leave Remoting mode and switches if |
115 // necessary. | 121 // necessary. Each call to this method could cause a remoting session to be |
116 void UpdateAndMaybeSwitch(); | 122 // started or stopped; and if that happens, the |start_trigger| or |
| 123 // |stop_trigger| must be the reason. |
| 124 void UpdateAndMaybeSwitch(remoting::StartTrigger start_trigger, |
| 125 remoting::StopTrigger stop_trigger); |
117 | 126 |
118 // Called to download the poster image. Called when: | 127 // Called to download the poster image. Called when: |
119 // 1. Poster URL changes. | 128 // 1. Poster URL changes. |
120 // 2. ShowInterstitialCallback is set. | 129 // 2. ShowInterstitialCallback is set. |
121 // 3. DownloadPosterCallback is set. | 130 // 3. DownloadPosterCallback is set. |
122 void DownloadPosterImage(); | 131 void DownloadPosterImage(); |
123 | 132 |
124 // Called when poster image is downloaded. | 133 // Called when poster image is downloaded. |
125 void OnPosterImageDownloaded(const GURL& download_url, const SkBitmap& image); | 134 void OnPosterImageDownloaded(const GURL& download_url, |
| 135 base::TimeTicks download_start_time, |
| 136 const SkBitmap& image); |
126 | 137 |
127 // Update remoting interstitial with |image|. When |image| is not set, | 138 // Update remoting interstitial with |image|. When |image| is not set, |
128 // interstitial will be drawn on previously downloaded poster image (in | 139 // interstitial will be drawn on previously downloaded poster image (in |
129 // RemoteRendererImpl) or black background if none was downloaded before. | 140 // RemoteRendererImpl) or black background if none was downloaded before. |
130 // Call this when: | 141 // Call this when: |
131 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is created). | 142 // 1. SetShowInterstitialCallback() is called (RemoteRendererImpl is created). |
132 // 2. The remoting session is shut down (to update the status message in the | 143 // 2. The remoting session is shut down (to update the status message in the |
133 // interstitial). | 144 // interstitial). |
134 // 3. The size of the canvas is changed (to update the background image and | 145 // 3. The size of the canvas is changed (to update the background image and |
135 // the position of the status message). | 146 // the position of the status message). |
(...skipping 17 matching lines...) Expand all Loading... |
153 // Remote Playback API spec for more details: | 164 // Remote Playback API spec for more details: |
154 // https://w3c.github.io/remote-playback | 165 // https://w3c.github.io/remote-playback |
155 bool is_remote_playback_disabled_ = true; | 166 bool is_remote_playback_disabled_ = true; |
156 | 167 |
157 // Indicates whether video is the dominant visible content in the tab. | 168 // Indicates whether video is the dominant visible content in the tab. |
158 bool is_dominant_content_ = false; | 169 bool is_dominant_content_ = false; |
159 | 170 |
160 // Indicates whether video is paused. | 171 // Indicates whether video is paused. |
161 bool is_paused_ = true; | 172 bool is_paused_ = true; |
162 | 173 |
163 // Indicates whether OnIrregularPlaybackDetected() has been called. | 174 // Indicates whether OnRendererFatalError() has been called. This indicates |
164 bool irregular_playback_detected_ = false; | 175 // one of several possible problems: 1) An environmental problem such as |
| 176 // out-of-memory, insufficient network bandwidth, etc. 2) The receiver may |
| 177 // have been unable to play-out the content correctly (e.g., not capable of a |
| 178 // high frame rate at a high resolution). 3) An implementation bug. In any |
| 179 // case, once a renderer encounters a fatal error, remoting will be shut down |
| 180 // and never start again for the lifetime of this controller. |
| 181 bool encountered_renderer_fatal_error_ = false; |
165 | 182 |
166 // The callback to switch the media renderer. | 183 // The callback to switch the media renderer. |
167 base::Closure switch_renderer_cb_; | 184 base::Closure switch_renderer_cb_; |
168 | 185 |
169 // Called when remoting sink availability is changed. | 186 // Called when remoting sink availability is changed. |
170 base::Callback<void(bool)> sink_available_changed_cb_; | 187 base::Callback<void(bool)> sink_available_changed_cb_; |
171 | 188 |
172 // This is initially the RemotingSourceImpl passed to the ctor, and might be | 189 // This is initially the RemotingSourceImpl passed to the ctor, and might be |
173 // replaced with a different instance later if OnSetCdm() is called. | 190 // replaced with a different instance later if OnSetCdm() is called. |
174 scoped_refptr<RemotingSourceImpl> remoting_source_; | 191 scoped_refptr<RemotingSourceImpl> remoting_source_; |
(...skipping 11 matching lines...) Expand all Loading... |
186 ShowInterstitialCallback show_interstitial_cb_; | 203 ShowInterstitialCallback show_interstitial_cb_; |
187 | 204 |
188 // Current poster URL, whose image will feed into the local UI. | 205 // Current poster URL, whose image will feed into the local UI. |
189 GURL poster_url_; | 206 GURL poster_url_; |
190 | 207 |
191 // The callback to download the poster image. Called when |poster_url_| | 208 // The callback to download the poster image. Called when |poster_url_| |
192 // changes during a remoting session or the show interstial callback is set. | 209 // changes during a remoting session or the show interstial callback is set. |
193 // OnPosterImageDownloaded() will be called when download completes. | 210 // OnPosterImageDownloaded() will be called when download completes. |
194 DownloadPosterCallback download_poster_cb_; | 211 DownloadPosterCallback download_poster_cb_; |
195 | 212 |
| 213 // Records session events of interest. |
| 214 remoting::SessionMetricsRecorder metrics_recorder_; |
| 215 |
196 base::WeakPtrFactory<RemotingRendererController> weak_factory_; | 216 base::WeakPtrFactory<RemotingRendererController> weak_factory_; |
197 | 217 |
198 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); | 218 DISALLOW_COPY_AND_ASSIGN(RemotingRendererController); |
199 }; | 219 }; |
200 | 220 |
201 } // namespace media | 221 } // namespace media |
202 | 222 |
203 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ | 223 #endif // MEDIA_REMOTING_REMOTING_RENDERER_CONTROLLER_H_ |
OLD | NEW |