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

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

Issue 2511143006: Detect change on the intersection of video and viewport. (Closed)
Patch Set: Addressed miu's comments. 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_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 constexpr int64_t kOneHundredPercent = 100;
15
16 // The threshold of the percentage of the viewport filled by the media to
17 // start remoting.
18 constexpr int64_t kFillActivationThresholdPercent = 85;
19
20 } // namespace
21
12 namespace media { 22 namespace media {
13 23
14 RemotingRendererController::RemotingRendererController( 24 RemotingRendererController::RemotingRendererController(
15 scoped_refptr<RemotingSourceImpl> remoting_source) 25 scoped_refptr<RemotingSourceImpl> remoting_source)
16 : remoting_source_(remoting_source), weak_factory_(this) { 26 : remoting_source_(remoting_source), weak_factory_(this) {
17 remoting_source_->AddClient(this); 27 remoting_source_->AddClient(this);
18 } 28 }
19 29
20 RemotingRendererController::~RemotingRendererController() { 30 RemotingRendererController::~RemotingRendererController() {
21 DCHECK(thread_checker_.CalledOnValidThread()); 31 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 UpdateAndMaybeSwitch(); 63 UpdateAndMaybeSwitch();
54 } 64 }
55 65
56 void RemotingRendererController::OnExitedFullscreen() { 66 void RemotingRendererController::OnExitedFullscreen() {
57 DCHECK(thread_checker_.CalledOnValidThread()); 67 DCHECK(thread_checker_.CalledOnValidThread());
58 68
59 is_fullscreen_ = false; 69 is_fullscreen_ = false;
60 UpdateAndMaybeSwitch(); 70 UpdateAndMaybeSwitch();
61 } 71 }
62 72
73 void RemotingRendererController::OnViewportIntersectionChanged(
74 const ViewportIntersectionInfo& info) {
75 DCHECK(thread_checker_.CalledOnValidThread());
76
77 // Reset on any notification, since this indicates the user is scrolling
78 // around in the document, the document is changing layout, etc.
79 viewport_fill_debouncer_timer_.Stop();
80
81 if (kOneHundredPercent * info.intersect_rect.size().GetArea() <=
82 kFillActivationThresholdPercent * info.root_rect.size().GetArea()) {
83 if (is_mostly_filling_viewport_) {
84 is_mostly_filling_viewport_ = false;
85 UpdateAndMaybeSwitch();
86 }
87 return;
88 }
89
90 // Meeting/Exceeding the threshold should hold steady for 5 seconds before
91 // starting remote rendering.
92 if (!is_mostly_filling_viewport_) {
93 viewport_fill_debouncer_timer_.Start(
94 FROM_HERE, base::TimeDelta::FromSeconds(5),
95 base::Bind(
96 &RemotingRendererController::OnViewportMostlyFilledAndUnchanging,
97 weak_factory_.GetWeakPtr()));
98 }
99 }
100
101 void RemotingRendererController::OnViewportMostlyFilledAndUnchanging() {
102 is_mostly_filling_viewport_ = true;
103 UpdateAndMaybeSwitch();
104 }
105
63 void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) { 106 void RemotingRendererController::OnSetCdm(CdmContext* cdm_context) {
64 DCHECK(thread_checker_.CalledOnValidThread()); 107 DCHECK(thread_checker_.CalledOnValidThread());
65 108
66 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context); 109 auto* remoting_cdm_context = RemotingCdmContext::From(cdm_context);
67 if (!remoting_cdm_context) 110 if (!remoting_cdm_context)
68 return; 111 return;
69 112
70 remoting_source_->RemoveClient(this); 113 remoting_source_->RemoveClient(this);
71 remoting_source_ = remoting_cdm_context->GetRemotingSource(); 114 remoting_source_ = remoting_cdm_context->GetRemotingSource();
72 remoting_source_->AddClient(this); // Calls OnSessionStateChanged(). 115 remoting_source_->AddClient(this); // Calls OnSessionStateChanged().
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 break; // Media remoting is possible, assuming other requirments are met. 231 break; // Media remoting is possible, assuming other requirments are met.
189 case SESSION_STOPPING: 232 case SESSION_STOPPING:
190 case SESSION_PERMANENTLY_STOPPED: 233 case SESSION_PERMANENTLY_STOPPED:
191 return false; // Use local rendering after stopping remoting. 234 return false; // Use local rendering after stopping remoting.
192 } 235 }
193 if ((!has_audio() && !has_video()) || 236 if ((!has_audio() && !has_video()) ||
194 (has_video() && !IsVideoCodecSupported()) || 237 (has_video() && !IsVideoCodecSupported()) ||
195 (has_audio() && !IsAudioCodecSupported())) 238 (has_audio() && !IsAudioCodecSupported()))
196 return false; 239 return false;
197 240
198 // Normally, entering fullscreen is the signal that starts remote rendering. 241 // Normally, entering fullscreen or filling most of the viewport is the signal
199 // However, current technical limitations require encrypted content be remoted 242 // that starts remote rendering. However, current technical limitations
200 // without waiting for a user signal. 243 // require encrypted content be remoted without waiting for a user signal.
201 return is_fullscreen_; 244 return is_fullscreen_ || is_mostly_filling_viewport_;
202 } 245 }
203 246
204 void RemotingRendererController::UpdateAndMaybeSwitch() { 247 void RemotingRendererController::UpdateAndMaybeSwitch() {
205 DCHECK(thread_checker_.CalledOnValidThread()); 248 DCHECK(thread_checker_.CalledOnValidThread());
206 249
207 bool should_be_remoting = ShouldBeRemoting(); 250 bool should_be_remoting = ShouldBeRemoting();
208 251
209 if (remote_rendering_started_ == should_be_remoting) 252 if (remote_rendering_started_ == should_be_remoting)
210 return; 253 return;
211 254
(...skipping 15 matching lines...) Expand all
227 // and never back to the local renderer. The RemotingCdmController will 270 // and never back to the local renderer. The RemotingCdmController will
228 // force-stop the session when remoting has ended; so no need to call 271 // force-stop the session when remoting has ended; so no need to call
229 // StopRemoting() from here. 272 // StopRemoting() from here.
230 DCHECK(!is_encrypted_); 273 DCHECK(!is_encrypted_);
231 switch_renderer_cb_.Run(); 274 switch_renderer_cb_.Run();
232 remoting_source_->StopRemoting(this); 275 remoting_source_->StopRemoting(this);
233 } 276 }
234 } 277 }
235 278
236 } // namespace media 279 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698