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_renderer_controller.h" | 5 #include "media/remoting/remoting_renderer_controller.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
| 10 #include "media/remoting/remoting_cdm_context.h" | 10 #include "media/remoting/remoting_cdm_context.h" |
| 11 | 11 |
| 12 namespace { | |
| 13 | |
| 14 // Video may be rendered remotely when it covers the viewport with the ratio | |
| 15 // larger than this threshold. | |
| 16 constexpr float kViewportRatioVideoRenderingThreshold = 0.85f; | |
|
miu
2016/11/21 21:07:03
naming accuracy: How about kViewportFillActivation
xjz
2016/11/21 23:58:42
Done.
| |
| 17 | |
| 18 float GetVideoViewportRatio(const gfx::Rect& root_rect, | |
| 19 const gfx::Rect& intersect_rect) { | |
| 20 if (root_rect.IsEmpty() || intersect_rect.IsEmpty()) | |
| 21 return 0; | |
| 22 | |
| 23 float intersect_area = static_cast<float>(intersect_rect.width()) * | |
|
miu
2016/11/21 21:07:03
To simplify: Instead of width*height, you can call
xjz
2016/11/21 23:58:42
Removed this helper as suggested in the below comm
| |
| 24 static_cast<float>(intersect_rect.height()); | |
| 25 float root_area = static_cast<float>(root_rect.width()) * | |
| 26 static_cast<float>(root_rect.height()); | |
| 27 return intersect_area / root_area; | |
| 28 } | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 12 namespace media { | 32 namespace media { |
| 13 | 33 |
| 14 RemotingRendererController::RemotingRendererController( | 34 RemotingRendererController::RemotingRendererController( |
| 15 scoped_refptr<RemotingSourceImpl> remoting_source) | 35 scoped_refptr<RemotingSourceImpl> remoting_source) |
| 16 : remoting_source_(remoting_source), weak_factory_(this) { | 36 : remoting_source_(remoting_source), weak_factory_(this) { |
| 17 remoting_source_->AddClient(this); | 37 remoting_source_->AddClient(this); |
| 18 } | 38 } |
| 19 | 39 |
| 20 RemotingRendererController::~RemotingRendererController() { | 40 RemotingRendererController::~RemotingRendererController() { |
| 21 DCHECK(thread_checker_.CalledOnValidThread()); | 41 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 UpdateAndMaybeSwitch(); | 73 UpdateAndMaybeSwitch(); |
| 54 } | 74 } |
| 55 | 75 |
| 56 void RemotingRendererController::OnExitedFullscreen() { | 76 void RemotingRendererController::OnExitedFullscreen() { |
| 57 DCHECK(thread_checker_.CalledOnValidThread()); | 77 DCHECK(thread_checker_.CalledOnValidThread()); |
| 58 | 78 |
| 59 is_fullscreen_ = false; | 79 is_fullscreen_ = false; |
| 60 UpdateAndMaybeSwitch(); | 80 UpdateAndMaybeSwitch(); |
| 61 } | 81 } |
| 62 | 82 |
| 83 void RemotingRendererController::OnVideoViewportIntersectionChanged( | |
| 84 const ViewportIntersectionInfo& info) { | |
| 85 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 86 | |
| 87 // Reset on any notification, since this indicates the user is scrolling | |
| 88 // around in the document, the document is changing layout, etc. | |
| 89 viewport_fill_debouncer_timer_.Stop(); | |
| 90 | |
| 91 float ratio = GetVideoViewportRatio(info.root_rect, info.intersect_rect); | |
| 92 // Dropping below the threshold should instantly stop remote rendering. | |
| 93 if (ratio < kViewportRatioVideoRenderingThreshold) { | |
|
miu
2016/11/21 21:07:03
To simplify: You can avoid both the floating-point
xjz
2016/11/21 23:58:42
Done.
| |
| 94 if (is_mostly_filling_viewport_) { | |
| 95 is_mostly_filling_viewport_ = false; | |
| 96 UpdateAndMaybeSwitch(); | |
| 97 } | |
| 98 return; | |
| 99 } | |
| 100 | |
| 101 // Meeting/Exceeding the threshold should hold steady for 5 seconds before | |
| 102 // starting remote rendering. | |
| 103 if (!is_mostly_filling_viewport_) { | |
| 104 viewport_fill_debouncer_timer_.Start( | |
| 105 FROM_HERE, base::TimeDelta::FromSeconds(5), | |
| 106 base::Bind( | |
| 107 &RemotingRendererController::OnViewportMostlyFilledAndUnchanging, | |
| 108 weak_factory_.GetWeakPtr())); | |
| 109 } | |
| 110 } | |
| 111 | |
| 112 void RemotingRendererController::OnViewportMostlyFilledAndUnchanging() { | |
| 113 is_mostly_filling_viewport_ = true; | |
| 114 UpdateAndMaybeSwitch(); | |
| 115 } | |
| 116 | |
| 63 void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) { | 117 void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) { |
| 64 DCHECK(thread_checker_.CalledOnValidThread()); | 118 DCHECK(thread_checker_.CalledOnValidThread()); |
| 65 | 119 |
| 66 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context); | 120 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context); |
| 67 if (!remoting_cdm_context) | 121 if (!remoting_cdm_context) |
| 68 return; | 122 return; |
| 69 | 123 |
| 70 remoting_source_->RemoveClient(this); | 124 remoting_source_->RemoveClient(this); |
| 71 remoting_source_ = remoting_cdm_context->GetRemotingSource(); | 125 remoting_source_ = remoting_cdm_context->GetRemotingSource(); |
| 72 remoting_source_->AddClient(this); // Calls OnSessionStateChanged(). | 126 remoting_source_->AddClient(this); // Calls OnSessionStateChanged(). |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 188 break; // Media remoting is possible, assuming other requirments are met. | 242 break; // Media remoting is possible, assuming other requirments are met. |
| 189 case SESSION_STOPPING: | 243 case SESSION_STOPPING: |
| 190 case SESSION_PERMANENTLY_STOPPED: | 244 case SESSION_PERMANENTLY_STOPPED: |
| 191 return false; // Use local rendering after stopping remoting. | 245 return false; // Use local rendering after stopping remoting. |
| 192 } | 246 } |
| 193 if ((!has_audio() && !has_video()) || | 247 if ((!has_audio() && !has_video()) || |
| 194 (has_video() && !IsVideoCodecSupported()) || | 248 (has_video() && !IsVideoCodecSupported()) || |
| 195 (has_audio() && !IsAudioCodecSupported())) | 249 (has_audio() && !IsAudioCodecSupported())) |
| 196 return false; | 250 return false; |
| 197 | 251 |
| 198 // Normally, entering fullscreen is the signal that starts remote rendering. | 252 // Normally, entering fullscreen or filling most of the viewport is the signal |
| 199 // However, current technical limitations require encrypted content be remoted | 253 // that starts remote rendering. However, current technical limitations |
| 200 // without waiting for a user signal. | 254 // require encrypted content be remoted without waiting for a user signal. |
| 201 return is_fullscreen_; | 255 return is_fullscreen_ || is_mostly_filling_viewport_; |
| 202 } | 256 } |
| 203 | 257 |
| 204 void RemotingRendererController::UpdateAndMaybeSwitch() { | 258 void RemotingRendererController::UpdateAndMaybeSwitch() { |
| 205 DCHECK(thread_checker_.CalledOnValidThread()); | 259 DCHECK(thread_checker_.CalledOnValidThread()); |
| 206 | 260 |
| 207 bool should_be_remoting = ShouldBeRemoting(); | 261 bool should_be_remoting = ShouldBeRemoting(); |
| 208 | 262 |
| 209 if (remote_rendering_started_ == should_be_remoting) | 263 if (remote_rendering_started_ == should_be_remoting) |
| 210 return; | 264 return; |
| 211 | 265 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 227 // and never back to the local renderer. The RemotingCdmController will | 281 // and never back to the local renderer. The RemotingCdmController will |
| 228 // force-stop the session when remoting has ended; so no need to call | 282 // force-stop the session when remoting has ended; so no need to call |
| 229 // StopRemoting() from here. | 283 // StopRemoting() from here. |
| 230 DCHECK(!is_encrypted_); | 284 DCHECK(!is_encrypted_); |
| 231 switch_renderer_cb_.Run(); | 285 switch_renderer_cb_.Run(); |
| 232 remoting_source_->StopRemoting(this); | 286 remoting_source_->StopRemoting(this); |
| 233 } | 287 } |
| 234 } | 288 } |
| 235 | 289 |
| 236 } // namespace media | 290 } // namespace media |
| OLD | NEW |