| 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/remote_renderer_impl.h" | 5 #include "media/remoting/remote_renderer_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 VideoRendererSink* video_renderer_sink) | 29 VideoRendererSink* video_renderer_sink) |
| 30 : state_(STATE_UNINITIALIZED), | 30 : state_(STATE_UNINITIALIZED), |
| 31 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 31 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 32 media_task_runner_(std::move(media_task_runner)), | 32 media_task_runner_(std::move(media_task_runner)), |
| 33 demuxer_stream_provider_(nullptr), | 33 demuxer_stream_provider_(nullptr), |
| 34 client_(nullptr), | 34 client_(nullptr), |
| 35 remoting_renderer_controller_(remoting_renderer_controller), | 35 remoting_renderer_controller_(remoting_renderer_controller), |
| 36 rpc_broker_(remoting_renderer_controller_->GetRpcBroker()), | 36 rpc_broker_(remoting_renderer_controller_->GetRpcBroker()), |
| 37 rpc_handle_(remoting::RpcBroker::GetUniqueHandle()), | 37 rpc_handle_(remoting::RpcBroker::GetUniqueHandle()), |
| 38 remote_renderer_handle_(remoting::kInvalidHandle), | 38 remote_renderer_handle_(remoting::kInvalidHandle), |
| 39 interstitial_ui_(video_renderer_sink, | 39 video_renderer_sink_(video_renderer_sink), |
| 40 remoting_renderer_controller->pipeline_metadata()), | |
| 41 weak_factory_(this) { | 40 weak_factory_(this) { |
| 42 VLOG(2) << __FUNCTION__; | 41 VLOG(2) << __FUNCTION__; |
| 43 // The constructor is running on the main thread. | 42 // The constructor is running on the main thread. |
| 44 DCHECK(remoting_renderer_controller); | 43 DCHECK(remoting_renderer_controller_); |
| 45 | 44 remoting_renderer_controller_->SetShowInterstitialCallback( |
| 46 UpdateInterstitial(); | 45 base::Bind(&RemoteRendererImpl::RequestUpdateInterstitialOnMainThread, |
| 46 media_task_runner_, weak_factory_.GetWeakPtr())); |
| 47 | 47 |
| 48 const remoting::RpcBroker::ReceiveMessageCallback receive_callback = | 48 const remoting::RpcBroker::ReceiveMessageCallback receive_callback = |
| 49 base::Bind(&RemoteRendererImpl::OnMessageReceivedOnMainThread, | 49 base::Bind(&RemoteRendererImpl::OnMessageReceivedOnMainThread, |
| 50 media_task_runner_, weak_factory_.GetWeakPtr()); | 50 media_task_runner_, weak_factory_.GetWeakPtr()); |
| 51 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); | 51 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); |
| 52 } | 52 } |
| 53 | 53 |
| 54 RemoteRendererImpl::~RemoteRendererImpl() { | 54 RemoteRendererImpl::~RemoteRendererImpl() { |
| 55 VLOG(2) << __FUNCTION__; | 55 VLOG(2) << __FUNCTION__; |
| 56 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 56 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 57 |
| 58 UpdateInterstitial(interstitial_background_, canvas_size_, |
| 59 RemotingInterstitialType::BETWEEN_SESSIONS); |
| 60 |
| 61 // Post task on main thread to unset the interstial callback. |
| 62 main_task_runner_->PostTask( |
| 63 FROM_HERE, |
| 64 base::Bind(&RemotingRendererController::SetShowInterstitialCallback, |
| 65 remoting_renderer_controller_, |
| 66 RemotingRendererController::ShowInterstitialCallback())); |
| 67 |
| 57 // Post task on main thread to unregister message receiver. | 68 // Post task on main thread to unregister message receiver. |
| 58 main_task_runner_->PostTask( | 69 main_task_runner_->PostTask( |
| 59 FROM_HERE, | 70 FROM_HERE, |
| 60 base::Bind(&remoting::RpcBroker::UnregisterMessageReceiverCallback, | 71 base::Bind(&remoting::RpcBroker::UnregisterMessageReceiverCallback, |
| 61 rpc_broker_, rpc_handle_)); | 72 rpc_broker_, rpc_handle_)); |
| 62 } | 73 } |
| 63 | 74 |
| 64 void RemoteRendererImpl::Initialize( | 75 void RemoteRendererImpl::Initialize( |
| 65 DemuxerStreamProvider* demuxer_stream_provider, | 76 DemuxerStreamProvider* demuxer_stream_provider, |
| 66 media::RendererClient* client, | 77 media::RendererClient* client, |
| (...skipping 481 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 } | 559 } |
| 549 | 560 |
| 550 void RemoteRendererImpl::OnFatalError(PipelineStatus error) { | 561 void RemoteRendererImpl::OnFatalError(PipelineStatus error) { |
| 551 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 562 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 552 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; | 563 DCHECK_NE(PIPELINE_OK, error) << "PIPELINE_OK isn't an error!"; |
| 553 | 564 |
| 554 // An error has already been delivered. | 565 // An error has already been delivered. |
| 555 if (state_ == STATE_ERROR) | 566 if (state_ == STATE_ERROR) |
| 556 return; | 567 return; |
| 557 | 568 |
| 558 main_task_runner_->PostTask( | |
| 559 FROM_HERE, base::Bind(&RemoteRendererImpl::UpdateInterstitial, | |
| 560 weak_factory_.GetWeakPtr())); | |
| 561 | |
| 562 const State old_state = state_; | 569 const State old_state = state_; |
| 563 state_ = STATE_ERROR; | 570 state_ = STATE_ERROR; |
| 564 | 571 |
| 565 if (!init_workflow_done_callback_.is_null()) { | 572 if (!init_workflow_done_callback_.is_null()) { |
| 566 DCHECK(old_state == STATE_CREATE_PIPE || old_state == STATE_ACQUIRING || | 573 DCHECK(old_state == STATE_CREATE_PIPE || old_state == STATE_ACQUIRING || |
| 567 old_state == STATE_INITIALIZING); | 574 old_state == STATE_INITIALIZING); |
| 568 base::ResetAndReturn(&init_workflow_done_callback_).Run(error); | 575 base::ResetAndReturn(&init_workflow_done_callback_).Run(error); |
| 569 return; | 576 return; |
| 570 } | 577 } |
| 571 | 578 |
| 572 if (!flush_cb_.is_null()) | 579 if (!flush_cb_.is_null()) |
| 573 base::ResetAndReturn(&flush_cb_).Run(); | 580 base::ResetAndReturn(&flush_cb_).Run(); |
| 574 | 581 |
| 575 // After OnError() returns, the pipeline may destroy |this|. | 582 // After OnError() returns, the pipeline may destroy |this|. |
| 576 client_->OnError(error); | 583 client_->OnError(error); |
| 577 } | 584 } |
| 578 | 585 |
| 579 void RemoteRendererImpl::UpdateInterstitial() { | 586 // static |
| 580 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 587 void RemoteRendererImpl::RequestUpdateInterstitialOnMainThread( |
| 588 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, |
| 589 base::WeakPtr<RemoteRendererImpl> remote_renderer_impl, |
| 590 const SkBitmap& background_image, |
| 591 const gfx::Size& canvas_size, |
| 592 RemotingInterstitialType interstitial_type) { |
| 593 media_task_runner->PostTask( |
| 594 FROM_HERE, |
| 595 base::Bind(&RemoteRendererImpl::UpdateInterstitial, remote_renderer_impl, |
| 596 background_image, canvas_size, interstitial_type)); |
| 597 } |
| 581 | 598 |
| 582 interstitial_ui_.ShowInterstitial( | 599 void RemoteRendererImpl::UpdateInterstitial( |
| 583 remoting_renderer_controller_->remoting_source()->state() == | 600 const SkBitmap& background_image, |
| 584 RemotingSessionState::SESSION_STARTED); | 601 const gfx::Size& canvas_size, |
| 602 RemotingInterstitialType interstitial_type) { |
| 603 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 604 if (!background_image.drawsNothing()) |
| 605 interstitial_background_ = background_image; |
| 606 canvas_size_ = canvas_size; |
| 607 PaintRemotingInterstitial(interstitial_background_, canvas_size_, |
| 608 interstitial_type, video_renderer_sink_); |
| 585 } | 609 } |
| 586 | 610 |
| 587 } // namespace media | 611 } // namespace media |
| OLD | NEW |