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

Unified Diff: media/remoting/remoting_controller.cc

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Subclass IntersectionObserver. 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_controller.cc
diff --git a/media/remoting/remoting_controller.cc b/media/remoting/remoting_controller.cc
index 73c372f68673518e429677979a24dbd83fd66864..eab034e2a34859aa620566fbf35abe012cd9e389 100644
--- a/media/remoting/remoting_controller.cc
+++ b/media/remoting/remoting_controller.cc
@@ -12,6 +12,26 @@
#include "media/remoting/rpc/proto_utils.h"
#include "media/remoting/rpc/rpc_broker.h"
+namespace {
+
+// Video may be rendered remotely when it covers the viewport with the ratio
+// larger than this threshold.
+constexpr float kViewportRatioVideoRenderingThreshold = 0.85;
+
+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 {
RemotingController::RemotingController(
@@ -142,6 +162,39 @@ void RemotingController::OnExitedFullscreen() {
UpdateAndMaybeSwitch();
}
+void RemotingController::OnVideoViewportIntersectionChanged(
+ const ViewportIntersectionInfo& info) {
+ DCHECK(task_runner_->BelongsToCurrentThread());
+
+ // 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(&RemotingController::OnViewportMostlyFilledAndUnchanging,
+ weak_factory_.GetWeakPtr()));
+ }
+}
+
+void RemotingController::OnViewportMostlyFilledAndUnchanging() {
+ 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
+ UpdateAndMaybeSwitch();
+}
+
void RemotingController::OnSetCdm(CdmContext* cdm_context) {
DCHECK(task_runner_->BelongsToCurrentThread());
@@ -232,13 +285,11 @@ bool RemotingController::ShouldBeRemoting() {
if (!is_sink_available_)
return false;
- if (!is_fullscreen_)
- return false;
if (has_video_ && !IsVideoCodecSupported())
return false;
if (has_audio_ && !IsAudioCodecSupported())
return false;
- return true;
+ return is_fullscreen_ || is_mostly_filling_viewport_;
}
void RemotingController::UpdateAndMaybeSwitch() {
« no previous file with comments | « media/remoting/remoting_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