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