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

Side by Side Diff: media/remoting/remoting_controller.cc

Issue 2475643004: Monitor the intersection of video and viewport. (Closed)
Patch Set: Moved the calculation of intersection ratio to RemotingController. 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 unified diff | Download patch
OLDNEW
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 float GetVideoViewportRatio(const gfx::Rect& root_rect,
18 const gfx::Rect& intersect_rect) {
19 if (root_rect.IsEmpty() || intersect_rect.IsEmpty())
20 return 0;
21
22 float intersect_area = static_cast<float>(intersect_rect.width()) *
23 static_cast<float>(intersect_rect.height());
24 float root_area = static_cast<float>(root_rect.width()) *
25 static_cast<float>(root_rect.height());
26 return intersect_area / root_area;
27 }
28
29 } // namespace
30
15 namespace media { 31 namespace media {
16 32
17 RemotingController::RemotingController( 33 RemotingController::RemotingController(
18 mojom::RemotingSourceRequest source_request, 34 mojom::RemotingSourceRequest source_request,
19 mojom::RemoterPtr remoter) 35 mojom::RemoterPtr remoter)
20 : binding_(this, std::move(source_request)), 36 : binding_(this, std::move(source_request)),
21 remoter_(std::move(remoter)), 37 remoter_(std::move(remoter)),
22 task_runner_(base::ThreadTaskRunnerHandle::Get()), 38 task_runner_(base::ThreadTaskRunnerHandle::Get()),
23 weak_factory_(this) { 39 weak_factory_(this) {
24 DCHECK(remoter_); 40 DCHECK(remoter_);
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 UpdateAndMaybeSwitch(); 151 UpdateAndMaybeSwitch();
136 } 152 }
137 153
138 void RemotingController::OnExitedFullscreen() { 154 void RemotingController::OnExitedFullscreen() {
139 DCHECK(task_runner_->BelongsToCurrentThread()); 155 DCHECK(task_runner_->BelongsToCurrentThread());
140 156
141 is_fullscreen_ = false; 157 is_fullscreen_ = false;
142 UpdateAndMaybeSwitch(); 158 UpdateAndMaybeSwitch();
143 } 159 }
144 160
161 void RemotingController::OnVideoViewportIntersectionChanged(
162 const ViewportIntersectionInfo& info) {
163 DCHECK(task_runner_->BelongsToCurrentThread());
164
165 // Reset on any notification, since this indicates the user is scrolling
166 // around in the document, the document is changing layout, etc.
167 viewport_fill_debouncer_timer_.Stop();
168
169 float ratio = GetVideoViewportRatio(info.root_rect, info.intersect_rect);
170 // Dropping below the threshold should instantly stop remote rendering.
171 if (ratio < 0.85) {
172 if (is_mostly_filling_viewport_) {
173 is_mostly_filling_viewport_ = false;
174 UpdateAndMaybeSwitch();
175 }
176 return;
177 }
178
179 // Meeting/Exceeding the threshold should hold steady for 5 seconds before
180 // starting remote rendering.
181 if (!is_mostly_filling_viewport_) {
182 viewport_fill_debouncer_timer_.Start(
183 FROM_HERE, base::TimeDelta::FromSeconds(5),
184 base::Bind(&RemotingController::OnViewportMostlyFilledAndUnchanging,
185 weak_factory_.GetWeakPtr()));
186 }
187 }
188
189 void RemotingController::OnViewportMostlyFilledAndUnchanging() {
190 is_mostly_filling_viewport_ = true;
191 UpdateAndMaybeSwitch();
192 }
193
145 void RemotingController::OnSetCdm(CdmContext* cdm_context) { 194 void RemotingController::OnSetCdm(CdmContext* cdm_context) {
146 DCHECK(task_runner_->BelongsToCurrentThread()); 195 DCHECK(task_runner_->BelongsToCurrentThread());
147 196
148 // TODO(xjz): Not implemented. Will add in up-coming change. 197 // TODO(xjz): Not implemented. Will add in up-coming change.
149 NOTIMPLEMENTED(); 198 NOTIMPLEMENTED();
150 } 199 }
151 200
152 void RemotingController::SetSwitchRendererCallback( 201 void RemotingController::SetSwitchRendererCallback(
153 const SwitchRendererCallback& cb) { 202 const SwitchRendererCallback& cb) {
154 DCHECK(task_runner_->BelongsToCurrentThread()); 203 DCHECK(task_runner_->BelongsToCurrentThread());
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 274
226 bool RemotingController::ShouldBeRemoting() { 275 bool RemotingController::ShouldBeRemoting() {
227 DCHECK(task_runner_->BelongsToCurrentThread()); 276 DCHECK(task_runner_->BelongsToCurrentThread());
228 277
229 // TODO(xjz): The control logic for EME will be added in a later CL. 278 // TODO(xjz): The control logic for EME will be added in a later CL.
230 if (is_encrypted_) 279 if (is_encrypted_)
231 return false; 280 return false;
232 281
233 if (!is_sink_available_) 282 if (!is_sink_available_)
234 return false; 283 return false;
235 if (!is_fullscreen_)
236 return false;
237 if (has_video_ && !IsVideoCodecSupported()) 284 if (has_video_ && !IsVideoCodecSupported())
238 return false; 285 return false;
239 if (has_audio_ && !IsAudioCodecSupported()) 286 if (has_audio_ && !IsAudioCodecSupported())
240 return false; 287 return false;
241 return true; 288 return is_fullscreen_ || is_mostly_filling_viewport_;
242 } 289 }
243 290
244 void RemotingController::UpdateAndMaybeSwitch() { 291 void RemotingController::UpdateAndMaybeSwitch() {
245 DCHECK(task_runner_->BelongsToCurrentThread()); 292 DCHECK(task_runner_->BelongsToCurrentThread());
246 293
247 // TODO(xjz): The switching logic for encrypted content will be added in a 294 // TODO(xjz): The switching logic for encrypted content will be added in a
248 // later CL. 295 // later CL.
249 296
250 // Demuxer is not initialized yet. 297 // Demuxer is not initialized yet.
251 if (!has_audio_ && !has_video_) 298 if (!has_audio_ && !has_video_)
(...skipping 11 matching lines...) Expand all
263 // |swithc_renderer_cb_.Run()| will be called after remoting is started 310 // |swithc_renderer_cb_.Run()| will be called after remoting is started
264 // successfully. 311 // successfully.
265 remoter_->Start(); 312 remoter_->Start();
266 } else { 313 } else {
267 switch_renderer_cb_.Run(); 314 switch_renderer_cb_.Run();
268 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK); 315 remoter_->Stop(mojom::RemotingStopReason::LOCAL_PLAYBACK);
269 } 316 }
270 } 317 }
271 318
272 } // namespace media 319 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698