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/renderer_controller.h" | 5 #include "media/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 "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 25 session_->RemoveClient(this); | 25 session_->RemoveClient(this); |
| 26 } | 26 } |
| 27 | 27 |
| 28 void RendererController::OnStarted(bool success) { | 28 void RendererController::OnStarted(bool success) { |
| 29 DCHECK(thread_checker_.CalledOnValidThread()); | 29 DCHECK(thread_checker_.CalledOnValidThread()); |
| 30 | 30 |
| 31 if (success) { | 31 if (success) { |
| 32 VLOG(1) << "Remoting started successively."; | 32 VLOG(1) << "Remoting started successively."; |
| 33 if (remote_rendering_started_) { | 33 if (remote_rendering_started_) { |
| 34 metrics_recorder_.DidStartSession(); | 34 metrics_recorder_.DidStartSession(); |
| 35 DCHECK(!switch_renderer_cb_.is_null()); | 35 DCHECK(client_); |
| 36 switch_renderer_cb_.Run(); | 36 client_->SwitchRenderer(); |
| 37 client_->DisablePipelineAutoSuspend(true); | |
|
miu
2017/02/13 23:36:08
The disable should happen before the SwitchRendere
xjz
2017/02/14 01:46:10
Done.
| |
| 37 } else { | 38 } else { |
| 38 session_->StopRemoting(this); | 39 session_->StopRemoting(this); |
| 39 } | 40 } |
| 40 } else { | 41 } else { |
| 41 VLOG(1) << "Failed to start remoting."; | 42 VLOG(1) << "Failed to start remoting."; |
| 42 remote_rendering_started_ = false; | 43 remote_rendering_started_ = false; |
| 43 metrics_recorder_.WillStopSession(START_RACE); | 44 metrics_recorder_.WillStopSession(START_RACE); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 void RendererController::OnSessionStateChanged() { | 48 void RendererController::OnSessionStateChanged() { |
| 48 DCHECK(thread_checker_.CalledOnValidThread()); | 49 DCHECK(thread_checker_.CalledOnValidThread()); |
| 49 UpdateFromSessionState(SINK_AVAILABLE, ROUTE_TERMINATED); | 50 UpdateFromSessionState(SINK_AVAILABLE, ROUTE_TERMINATED); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void RendererController::UpdateFromSessionState(StartTrigger start_trigger, | 53 void RendererController::UpdateFromSessionState(StartTrigger start_trigger, |
| 53 StopTrigger stop_trigger) { | 54 StopTrigger stop_trigger) { |
| 54 VLOG(1) << "UpdateFromSessionState: " << session_->state(); | 55 VLOG(1) << "UpdateFromSessionState: " << session_->state(); |
| 55 if (!sink_available_changed_cb_.is_null()) | 56 if (client_) |
| 56 sink_available_changed_cb_.Run(IsRemoteSinkAvailable()); | 57 client_->ActivateViewportIntersectionMonitoring(IsRemoteSinkAvailable()); |
| 57 | 58 |
| 58 UpdateInterstitial(base::nullopt); | 59 UpdateInterstitial(base::nullopt); |
| 59 UpdateAndMaybeSwitch(start_trigger, stop_trigger); | 60 UpdateAndMaybeSwitch(start_trigger, stop_trigger); |
| 60 } | 61 } |
| 61 | 62 |
| 62 bool RendererController::IsRemoteSinkAvailable() { | 63 bool RendererController::IsRemoteSinkAvailable() { |
| 63 DCHECK(thread_checker_.CalledOnValidThread()); | 64 DCHECK(thread_checker_.CalledOnValidThread()); |
| 64 | 65 |
| 65 switch (session_->state()) { | 66 switch (session_->state()) { |
| 66 case SharedSession::SESSION_CAN_START: | 67 case SharedSession::SESSION_CAN_START: |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 144 | 145 |
| 145 if (poster_url != poster_url_) { | 146 if (poster_url != poster_url_) { |
| 146 poster_url_ = poster_url; | 147 poster_url_ = poster_url; |
| 147 if (poster_url_.is_empty()) | 148 if (poster_url_.is_empty()) |
| 148 UpdateInterstitial(SkBitmap()); | 149 UpdateInterstitial(SkBitmap()); |
| 149 else | 150 else |
| 150 DownloadPosterImage(); | 151 DownloadPosterImage(); |
| 151 } | 152 } |
| 152 } | 153 } |
| 153 | 154 |
| 154 void RendererController::SetSwitchRendererCallback(const base::Closure& cb) { | |
| 155 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 156 DCHECK(!cb.is_null()); | |
| 157 | |
| 158 switch_renderer_cb_ = cb; | |
| 159 // Note: Not calling UpdateAndMaybeSwitch() here since this method should be | |
| 160 // called during the initialization phase of this RendererController; | |
| 161 // and definitely before a whole lot of other things that are needed to | |
| 162 // trigger a switch. | |
| 163 } | |
| 164 | |
| 165 void RendererController::SetRemoteSinkAvailableChangedCallback( | |
| 166 const base::Callback<void(bool)>& cb) { | |
| 167 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 168 | |
| 169 sink_available_changed_cb_ = cb; | |
| 170 if (!sink_available_changed_cb_.is_null()) | |
| 171 sink_available_changed_cb_.Run(IsRemoteSinkAvailable()); | |
| 172 } | |
| 173 | |
| 174 base::WeakPtr<RpcBroker> RendererController::GetRpcBroker() const { | 155 base::WeakPtr<RpcBroker> RendererController::GetRpcBroker() const { |
| 175 DCHECK(thread_checker_.CalledOnValidThread()); | 156 DCHECK(thread_checker_.CalledOnValidThread()); |
| 176 | 157 |
| 177 return session_->rpc_broker()->GetWeakPtr(); | 158 return session_->rpc_broker()->GetWeakPtr(); |
| 178 } | 159 } |
| 179 | 160 |
| 180 void RendererController::StartDataPipe( | 161 void RendererController::StartDataPipe( |
| 181 std::unique_ptr<mojo::DataPipe> audio_data_pipe, | 162 std::unique_ptr<mojo::DataPipe> audio_data_pipe, |
| 182 std::unique_ptr<mojo::DataPipe> video_data_pipe, | 163 std::unique_ptr<mojo::DataPipe> video_data_pipe, |
| 183 const SharedSession::DataPipeStartCallback& done_callback) { | 164 const SharedSession::DataPipeStartCallback& done_callback) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 279 | 260 |
| 280 void RendererController::OnPaused() { | 261 void RendererController::OnPaused() { |
| 281 DCHECK(thread_checker_.CalledOnValidThread()); | 262 DCHECK(thread_checker_.CalledOnValidThread()); |
| 282 | 263 |
| 283 is_paused_ = true; | 264 is_paused_ = true; |
| 284 } | 265 } |
| 285 | 266 |
| 286 bool RendererController::ShouldBeRemoting() { | 267 bool RendererController::ShouldBeRemoting() { |
| 287 DCHECK(thread_checker_.CalledOnValidThread()); | 268 DCHECK(thread_checker_.CalledOnValidThread()); |
| 288 | 269 |
| 289 if (switch_renderer_cb_.is_null()) { | 270 if (!client_) { |
| 290 DCHECK(!remote_rendering_started_); | 271 DCHECK(!remote_rendering_started_); |
| 291 return false; // No way to switch to the remoting renderer. | 272 return false; // No way to switch to the remoting renderer. |
| 292 } | 273 } |
| 293 | 274 |
| 294 const SharedSession::SessionState state = session_->state(); | 275 const SharedSession::SessionState state = session_->state(); |
| 295 if (is_encrypted_) { | 276 if (is_encrypted_) { |
| 296 // Due to technical limitations when playing encrypted content, once a | 277 // Due to technical limitations when playing encrypted content, once a |
| 297 // remoting session has been started, always return true here to indicate | 278 // remoting session has been started, always return true here to indicate |
| 298 // that the CourierRenderer should continue to be used. In the stopped | 279 // that the CourierRenderer should continue to be used. In the stopped |
| 299 // states, CourierRenderer will display an interstitial to notify the user | 280 // states, CourierRenderer will display an interstitial to notify the user |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 358 // created when video starts loading/playing, receiver will display a black | 339 // created when video starts loading/playing, receiver will display a black |
| 359 // screen before video starts playing if switching to remoting when paused. | 340 // screen before video starts playing if switching to remoting when paused. |
| 360 // Thus, the user experience is improved by not starting remoting until | 341 // Thus, the user experience is improved by not starting remoting until |
| 361 // playback resumes. | 342 // playback resumes. |
| 362 if (should_be_remoting && is_paused_) | 343 if (should_be_remoting && is_paused_) |
| 363 return; | 344 return; |
| 364 | 345 |
| 365 // Switch between local renderer and remoting renderer. | 346 // Switch between local renderer and remoting renderer. |
| 366 remote_rendering_started_ = should_be_remoting; | 347 remote_rendering_started_ = should_be_remoting; |
| 367 | 348 |
| 349 DCHECK(client_); | |
| 368 if (remote_rendering_started_) { | 350 if (remote_rendering_started_) { |
| 369 DCHECK(!switch_renderer_cb_.is_null()); | |
| 370 if (session_->state() == SharedSession::SESSION_PERMANENTLY_STOPPED) { | 351 if (session_->state() == SharedSession::SESSION_PERMANENTLY_STOPPED) { |
| 371 switch_renderer_cb_.Run(); | 352 client_->SwitchRenderer(); |
| 372 return; | 353 return; |
| 373 } | 354 } |
| 374 DCHECK_NE(start_trigger, UNKNOWN_START_TRIGGER); | 355 DCHECK_NE(start_trigger, UNKNOWN_START_TRIGGER); |
| 375 metrics_recorder_.WillStartSession(start_trigger); | 356 metrics_recorder_.WillStartSession(start_trigger); |
| 376 // |switch_renderer_cb_.Run()| will be called after remoting is started | 357 // |MediaObserverClient::SwitchRenderer()| will be called after remoting is |
| 377 // successfully. | 358 // started successfully. |
| 378 session_->StartRemoting(this); | 359 session_->StartRemoting(this); |
| 379 } else { | 360 } else { |
| 380 // For encrypted content, it's only valid to switch to remoting renderer, | 361 // For encrypted content, it's only valid to switch to remoting renderer, |
| 381 // and never back to the local renderer. The RemotingCdmController will | 362 // and never back to the local renderer. The RemotingCdmController will |
| 382 // force-stop the session when remoting has ended; so no need to call | 363 // force-stop the session when remoting has ended; so no need to call |
| 383 // StopRemoting() from here. | 364 // StopRemoting() from here. |
| 384 DCHECK(!is_encrypted_); | 365 DCHECK(!is_encrypted_); |
| 385 DCHECK_NE(stop_trigger, UNKNOWN_STOP_TRIGGER); | 366 DCHECK_NE(stop_trigger, UNKNOWN_STOP_TRIGGER); |
| 386 metrics_recorder_.WillStopSession(stop_trigger); | 367 metrics_recorder_.WillStopSession(stop_trigger); |
| 387 // Update the interstitial one last time before switching back to the local | 368 // Update the interstitial one last time before switching back to the local |
| 388 // Renderer. | 369 // Renderer. |
| 389 UpdateInterstitial(base::nullopt); | 370 UpdateInterstitial(base::nullopt); |
| 390 switch_renderer_cb_.Run(); | 371 client_->SwitchRenderer(); |
| 372 client_->DisablePipelineAutoSuspend(false); | |
| 391 session_->StopRemoting(this); | 373 session_->StopRemoting(this); |
| 392 } | 374 } |
| 393 } | 375 } |
| 394 | 376 |
| 395 void RendererController::SetShowInterstitialCallback( | 377 void RendererController::SetShowInterstitialCallback( |
| 396 const ShowInterstitialCallback& cb) { | 378 const ShowInterstitialCallback& cb) { |
| 397 DCHECK(thread_checker_.CalledOnValidThread()); | 379 DCHECK(thread_checker_.CalledOnValidThread()); |
| 398 show_interstitial_cb_ = cb; | 380 show_interstitial_cb_ = cb; |
| 399 UpdateInterstitial(SkBitmap()); | 381 UpdateInterstitial(SkBitmap()); |
| 400 if (!poster_url_.is_empty()) | 382 if (!poster_url_.is_empty()) |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 | 464 |
| 483 // Do not act on errors caused by things like Mojo pipes being closed during | 465 // Do not act on errors caused by things like Mojo pipes being closed during |
| 484 // shutdown. | 466 // shutdown. |
| 485 if (!remote_rendering_started_) | 467 if (!remote_rendering_started_) |
| 486 return; | 468 return; |
| 487 | 469 |
| 488 encountered_renderer_fatal_error_ = true; | 470 encountered_renderer_fatal_error_ = true; |
| 489 UpdateAndMaybeSwitch(UNKNOWN_START_TRIGGER, stop_trigger); | 471 UpdateAndMaybeSwitch(UNKNOWN_START_TRIGGER, stop_trigger); |
| 490 } | 472 } |
| 491 | 473 |
| 474 void RendererController::SetClient(MediaObserverClient* client) { | |
| 475 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 476 | |
|
miu
2017/02/13 23:36:08
nit: Add: DCHECK(client) and DCHECK(!client_), sin
xjz
2017/02/14 01:46:10
Done.
| |
| 477 client_ = client; | |
| 478 if (client_) | |
|
miu
2017/02/13 23:36:08
nit: And then, no need to null-check here because
xjz
2017/02/14 01:46:10
Done.
| |
| 479 client_->ActivateViewportIntersectionMonitoring(IsRemoteSinkAvailable()); | |
| 480 } | |
| 481 | |
| 492 } // namespace remoting | 482 } // namespace remoting |
| 493 } // namespace media | 483 } // namespace media |
| OLD | NEW |