Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1199)

Unified Diff: media/remoting/remoting_renderer_controller.cc

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Fix trybots failure. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/remoting/remoting_renderer_controller.cc
diff --git a/media/remoting/remoting_renderer_controller.cc b/media/remoting/remoting_renderer_controller.cc
index c9cb743cc1e27004115b9bddcdbd55fee64f70e7..a087520e40ea11d767898e7f72505b651fce506a 100644
--- a/media/remoting/remoting_renderer_controller.cc
+++ b/media/remoting/remoting_renderer_controller.cc
@@ -9,6 +9,26 @@
#include "base/threading/thread_checker.h"
#include "media/remoting/remoting_cdm_context.h"
+namespace {
+
+// Video may be rendered remotely when it covers the viewport with the ratio
+// larger than this threshold.
+constexpr float kViewportRatioVideoRenderingThreshold = 0.85f;
+
+float GetVideoViewportRatio(const gfx::Rect& root_rect,
+ const gfx::Rect& intersect_rect) {
+ if (root_rect.IsEmpty() || intersect_rect.IsEmpty())
+ return 0;
+
+ float intersect_area = static_cast<float>(intersect_rect.width()) *
+ static_cast<float>(intersect_rect.height());
+ float root_area = static_cast<float>(root_rect.width()) *
+ static_cast<float>(root_rect.height());
+ return intersect_area / root_area;
+}
+
+} // namespace
+
namespace media {
RemotingRendererController::RemotingRendererController(
@@ -60,6 +80,40 @@ void RemotingRendererController::OnExitedFullscreen() {
UpdateAndMaybeSwitch();
}
+void RemotingRendererController::OnVideoViewportIntersectionChanged(
+ const ViewportIntersectionInfo& info) {
+ DCHECK(thread_checker_.CalledOnValidThread());
+
+ // Reset on any notification, since this indicates the user is scrolling
+ // around in the document, the document is changing layout, etc.
+ viewport_fill_debouncer_timer_.Stop();
+
+ float ratio = GetVideoViewportRatio(info.root_rect, info.intersect_rect);
+ // Dropping below the threshold should instantly stop remote rendering.
+ if (ratio < kViewportRatioVideoRenderingThreshold) {
+ if (is_mostly_filling_viewport_) {
+ is_mostly_filling_viewport_ = false;
+ UpdateAndMaybeSwitch();
+ }
+ return;
+ }
+
+ // Meeting/Exceeding the threshold should hold steady for 5 seconds before
+ // starting remote rendering.
+ if (!is_mostly_filling_viewport_) {
+ viewport_fill_debouncer_timer_.Start(
+ FROM_HERE, base::TimeDelta::FromSeconds(5),
+ base::Bind(
+ &RemotingRendererController::OnViewportMostlyFilledAndUnchanging,
+ weak_factory_.GetWeakPtr()));
+ }
+}
+
+void RemotingRendererController::OnViewportMostlyFilledAndUnchanging() {
+ is_mostly_filling_viewport_ = true;
+ UpdateAndMaybeSwitch();
+}
+
void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) {
DCHECK(thread_checker_.CalledOnValidThread());
@@ -195,10 +249,10 @@ bool RemotingRendererController::ShouldBeRemoting() {
(has_audio() && !IsAudioCodecSupported()))
return false;
- // Normally, entering fullscreen is the signal that starts remote rendering.
- // However, current technical limitations require encrypted content be remoted
- // without waiting for a user signal.
- return is_fullscreen_;
+ // Normally, entering fullscreen or filling most of the viewport is the signal
+ // that starts remote rendering. However, current technical limitations
+ // require encrypted content be remoted without waiting for a user signal.
+ return is_fullscreen_ || is_mostly_filling_viewport_;
}
void RemotingRendererController::UpdateAndMaybeSwitch() {
« no previous file with comments | « media/remoting/remoting_renderer_controller.h ('k') | third_party/WebKit/Source/core/dom/ElementVisibilityObserver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698