Chromium Code Reviews| 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 #include "media/remoting/remoting_controller.h" | 5 #include "media/remoting/remoting_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/single_thread_task_runner.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "media/remoting/rpc/proto_utils.h" | 12 #include "media/remoting/rpc/proto_utils.h" |
| 13 #include "media/remoting/rpc/rpc_broker.h" | 13 #include "media/remoting/rpc/rpc_broker.h" |
| 14 | 14 |
| 15 namespace { | |
| 16 | |
| 17 // Video may be rendered remotely when it covers the viewport with the ratio | |
| 18 // larger than this threshold. | |
| 19 constexpr float kViewportRatioVideoRenderingThreshold = 0.85; | |
| 20 | |
| 21 float GetVideoViewportRatio(const gfx::Rect& root_rect, | |
| 22 const gfx::Rect& intersect_rect) { | |
| 23 if (root_rect.IsEmpty() || intersect_rect.IsEmpty()) | |
| 24 return 0; | |
| 25 | |
| 26 float intersect_area = static_cast<float>(intersect_rect.width()) * | |
| 27 static_cast<float>(intersect_rect.height()); | |
| 28 float root_area = static_cast<float>(root_rect.width()) * | |
| 29 static_cast<float>(root_rect.height()); | |
| 30 return intersect_area / root_area; | |
| 31 } | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 15 namespace media { | 35 namespace media { |
| 16 | 36 |
| 17 RemotingController::RemotingController( | 37 RemotingController::RemotingController( |
| 18 mojom::RemotingSourceRequest source_request, | 38 mojom::RemotingSourceRequest source_request, |
| 19 mojom::RemoterPtr remoter) | 39 mojom::RemoterPtr remoter) |
| 20 : binding_(this, std::move(source_request)), | 40 : binding_(this, std::move(source_request)), |
| 21 remoter_(std::move(remoter)), | 41 remoter_(std::move(remoter)), |
| 22 task_runner_(base::ThreadTaskRunnerHandle::Get()), | 42 task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 23 weak_factory_(this) { | 43 weak_factory_(this) { |
| 24 DCHECK(remoter_); | 44 DCHECK(remoter_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 UpdateAndMaybeSwitch(); | 155 UpdateAndMaybeSwitch(); |
| 136 } | 156 } |
| 137 | 157 |
| 138 void RemotingController::OnExitedFullscreen() { | 158 void RemotingController::OnExitedFullscreen() { |
| 139 DCHECK(task_runner_->BelongsToCurrentThread()); | 159 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 140 | 160 |
| 141 is_fullscreen_ = false; | 161 is_fullscreen_ = false; |
| 142 UpdateAndMaybeSwitch(); | 162 UpdateAndMaybeSwitch(); |
| 143 } | 163 } |
| 144 | 164 |
| 165 void RemotingController::OnVideoViewportIntersectionChanged( | |
| 166 const ViewportIntersectionInfo& info) { | |
| 167 DCHECK(task_runner_->BelongsToCurrentThread()); | |
| 168 | |
| 169 // Reset on any notification, since this indicates the user is scrolling | |
| 170 // around in the document, the document is changing layout, etc. | |
| 171 viewport_fill_debouncer_timer_.Stop(); | |
| 172 | |
| 173 float ratio = GetVideoViewportRatio(info.root_rect, info.intersect_rect); | |
| 174 // Dropping below the threshold should instantly stop remote rendering. | |
| 175 if (ratio < kViewportRatioVideoRenderingThreshold) { | |
| 176 if (is_mostly_filling_viewport_) { | |
| 177 is_mostly_filling_viewport_ = false; | |
| 178 UpdateAndMaybeSwitch(); | |
| 179 } | |
| 180 return; | |
| 181 } | |
| 182 | |
| 183 // Meeting/Exceeding the threshold should hold steady for 5 seconds before | |
| 184 // starting remote rendering. | |
| 185 if (!is_mostly_filling_viewport_) { | |
| 186 viewport_fill_debouncer_timer_.Start( | |
| 187 FROM_HERE, base::TimeDelta::FromSeconds(5), | |
| 188 base::Bind(&RemotingController::OnViewportMostlyFilledAndUnchanging, | |
| 189 weak_factory_.GetWeakPtr())); | |
| 190 } | |
| 191 } | |
| 192 | |
| 193 void RemotingController::OnViewportMostlyFilledAndUnchanging() { | |
| 194 is_mostly_filling_viewport_ = true; | |
|
Z_DONOTUSE
2016/11/17 06:19:05
If the video is mostly filling the viewport, then
xjz
2016/11/17 07:15:18
Before setting |is_mostly_filling_viewport_| to fa
| |
| 195 UpdateAndMaybeSwitch(); | |
| 196 } | |
| 197 | |
| 145 void RemotingController::OnSetCdm(CdmContext* cdm_context) { | 198 void RemotingController::OnSetCdm(CdmContext* cdm_context) { |
| 146 DCHECK(task_runner_->BelongsToCurrentThread()); | 199 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 147 | 200 |
| 148 // TODO(xjz): Not implemented. Will add in up-coming change. | 201 // TODO(xjz): Not implemented. Will add in up-coming change. |
| 149 NOTIMPLEMENTED(); | 202 NOTIMPLEMENTED(); |
| 150 } | 203 } |
| 151 | 204 |
| 152 void RemotingController::SetSwitchRendererCallback( | 205 void RemotingController::SetSwitchRendererCallback( |
| 153 const SwitchRendererCallback& cb) { | 206 const SwitchRendererCallback& cb) { |
| 154 DCHECK(task_runner_->BelongsToCurrentThread()); | 207 DCHECK(task_runner_->BelongsToCurrentThread()); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 225 | 278 |
| 226 bool RemotingController::ShouldBeRemoting() { | 279 bool RemotingController::ShouldBeRemoting() { |
| 227 DCHECK(task_runner_->BelongsToCurrentThread()); | 280 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 228 | 281 |
| 229 // TODO(xjz): The control logic for EME will be added in a later CL. | 282 // TODO(xjz): The control logic for EME will be added in a later CL. |
| 230 if (is_encrypted_) | 283 if (is_encrypted_) |
| 231 return false; | 284 return false; |
| 232 | 285 |
| 233 if (!is_sink_available_) | 286 if (!is_sink_available_) |
| 234 return false; | 287 return false; |
| 235 if (!is_fullscreen_) | |
| 236 return false; | |
| 237 if (has_video_ && !IsVideoCodecSupported()) | 288 if (has_video_ && !IsVideoCodecSupported()) |
| 238 return false; | 289 return false; |
| 239 if (has_audio_ && !IsAudioCodecSupported()) | 290 if (has_audio_ && !IsAudioCodecSupported()) |
| 240 return false; | 291 return false; |
| 241 return true; | 292 return is_fullscreen_ || is_mostly_filling_viewport_; |
| 242 } | 293 } |
| 243 | 294 |
| 244 void RemotingController::UpdateAndMaybeSwitch() { | 295 void RemotingController::UpdateAndMaybeSwitch() { |
| 245 DCHECK(task_runner_->BelongsToCurrentThread()); | 296 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 246 | 297 |
| 247 // TODO(xjz): The switching logic for encrypted content will be added in a | 298 // TODO(xjz): The switching logic for encrypted content will be added in a |
| 248 // later CL. | 299 // later CL. |
| 249 | 300 |
| 250 // Demuxer is not initialized yet. | 301 // Demuxer is not initialized yet. |
| 251 if (!has_audio_ && !has_video_) | 302 if (!has_audio_ && !has_video_) |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 263 // |swithc_renderer_cb_.Run()| will be called after remoting is started | 314 // |swithc_renderer_cb_.Run()| will be called after remoting is started |
| 264 // successfully. | 315 // successfully. |
| 265 remoter_->Start(); | 316 remoter_->Start(); |
| 266 } else { | 317 } else { |
| 267 switch_renderer_cb_.Run(); | 318 switch_renderer_cb_.Run(); |
| 268 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); | 319 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); |
| 269 } | 320 } |
| 270 } | 321 } |
| 271 | 322 |
| 272 } // namespace media | 323 } // namespace media |
| OLD | NEW |