| 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" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/callback_helpers.h" | 12 #include "base/callback_helpers.h" |
| 13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
| 14 #include "base/time/time.h" | 14 #include "base/time/time.h" |
| 15 #include "media/base/bind_to_current_loop.h" | 15 #include "media/base/bind_to_current_loop.h" |
| 16 #include "media/base/demuxer_stream_provider.h" | 16 #include "media/base/demuxer_stream_provider.h" |
| 17 #include "media/base/media_keys.h" | 17 #include "media/base/media_keys.h" |
| 18 #include "media/remoting/remote_demuxer_stream_adapter.h" | 18 #include "media/remoting/remote_demuxer_stream_adapter.h" |
| 19 #include "media/remoting/remoting_controller.h" | 19 #include "media/remoting/remoting_renderer_controller.h" |
| 20 #include "media/remoting/rpc/proto_enum_utils.h" | 20 #include "media/remoting/rpc/proto_enum_utils.h" |
| 21 #include "media/remoting/rpc/proto_utils.h" | 21 #include "media/remoting/rpc/proto_utils.h" |
| 22 | 22 |
| 23 namespace media { | 23 namespace media { |
| 24 | 24 |
| 25 RemoteRendererImpl::RemoteRendererImpl( | 25 RemoteRendererImpl::RemoteRendererImpl( |
| 26 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, | 26 scoped_refptr<base::SingleThreadTaskRunner> media_task_runner, |
| 27 const base::WeakPtr<RemotingController>& remoting_controller) | 27 const base::WeakPtr<RemotingRendererController>& |
| 28 remoting_renderer_controller) |
| 28 : state_(STATE_UNINITIALIZED), | 29 : state_(STATE_UNINITIALIZED), |
| 29 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 30 main_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 30 media_task_runner_(std::move(media_task_runner)), | 31 media_task_runner_(std::move(media_task_runner)), |
| 31 demuxer_stream_provider_(nullptr), | 32 demuxer_stream_provider_(nullptr), |
| 32 client_(nullptr), | 33 client_(nullptr), |
| 33 remoting_controller_(remoting_controller), | 34 remoting_renderer_controller_(remoting_renderer_controller), |
| 34 rpc_broker_(remoting_controller_->GetRpcBroker()), | 35 rpc_broker_(remoting_renderer_controller_->GetRpcBroker()), |
| 35 rpc_handle_(remoting::RpcBroker::GetUniqueHandle()), | 36 rpc_handle_(remoting::RpcBroker::GetUniqueHandle()), |
| 36 remote_renderer_handle_(remoting::kInvalidHandle), | 37 remote_renderer_handle_(remoting::kInvalidHandle), |
| 37 weak_factory_(this) { | 38 weak_factory_(this) { |
| 38 VLOG(2) << __FUNCTION__; | 39 VLOG(2) << __FUNCTION__; |
| 39 // The constructor is running on the main thread. | 40 // The constructor is running on the main thread. |
| 40 DCHECK(remoting_controller); | 41 DCHECK(remoting_renderer_controller); |
| 41 const remoting::RpcBroker::ReceiveMessageCallback receive_callback = | 42 const remoting::RpcBroker::ReceiveMessageCallback receive_callback = |
| 42 base::Bind(&RemoteRendererImpl::OnMessageReceivedOnMainThread, | 43 base::Bind(&RemoteRendererImpl::OnMessageReceivedOnMainThread, |
| 43 media_task_runner_, weak_factory_.GetWeakPtr()); | 44 media_task_runner_, weak_factory_.GetWeakPtr()); |
| 44 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); | 45 rpc_broker_->RegisterMessageReceiverCallback(rpc_handle_, receive_callback); |
| 45 } | 46 } |
| 46 | 47 |
| 47 RemoteRendererImpl::~RemoteRendererImpl() { | 48 RemoteRendererImpl::~RemoteRendererImpl() { |
| 48 VLOG(2) << __FUNCTION__; | 49 VLOG(2) << __FUNCTION__; |
| 49 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 50 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 50 // Post task on main thread to unregister message receiver. | 51 // Post task on main thread to unregister message receiver. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 79 | 80 |
| 80 // Create video mojo data pipe handles if video is available. | 81 // Create video mojo data pipe handles if video is available. |
| 81 ::media::DemuxerStream* video_demuxer_stream = | 82 ::media::DemuxerStream* video_demuxer_stream = |
| 82 demuxer_stream_provider_->GetStream(::media::DemuxerStream::VIDEO); | 83 demuxer_stream_provider_->GetStream(::media::DemuxerStream::VIDEO); |
| 83 std::unique_ptr<mojo::DataPipe> video_data_pipe; | 84 std::unique_ptr<mojo::DataPipe> video_data_pipe; |
| 84 if (video_demuxer_stream) { | 85 if (video_demuxer_stream) { |
| 85 video_data_pipe = base::WrapUnique(remoting::CreateDataPipe()); | 86 video_data_pipe = base::WrapUnique(remoting::CreateDataPipe()); |
| 86 } | 87 } |
| 87 | 88 |
| 88 // Establish remoting data pipe connection using main thread. | 89 // Establish remoting data pipe connection using main thread. |
| 89 const RemotingController::DataPipeStartCallback data_pipe_callback = | 90 const RemotingSourceImpl::DataPipeStartCallback data_pipe_callback = |
| 90 base::Bind(&RemoteRendererImpl::OnDataPipeCreatedOnMainThread, | 91 base::Bind(&RemoteRendererImpl::OnDataPipeCreatedOnMainThread, |
| 91 media_task_runner_, weak_factory_.GetWeakPtr()); | 92 media_task_runner_, weak_factory_.GetWeakPtr()); |
| 92 main_task_runner_->PostTask( | 93 main_task_runner_->PostTask( |
| 93 FROM_HERE, | 94 FROM_HERE, |
| 94 base::Bind(&RemotingController::StartDataPipe, remoting_controller_, | 95 base::Bind(&RemotingRendererController::StartDataPipe, |
| 95 base::Passed(&audio_data_pipe), base::Passed(&video_data_pipe), | 96 remoting_renderer_controller_, base::Passed(&audio_data_pipe), |
| 96 data_pipe_callback)); | 97 base::Passed(&video_data_pipe), data_pipe_callback)); |
| 97 } | 98 } |
| 98 | 99 |
| 99 void RemoteRendererImpl::SetCdm(CdmContext* cdm_context, | 100 void RemoteRendererImpl::SetCdm(CdmContext* cdm_context, |
| 100 const CdmAttachedCB& cdm_attached_cb) { | 101 const CdmAttachedCB& cdm_attached_cb) { |
| 101 VLOG(2) << __FUNCTION__ << " cdm_id:" << cdm_context->GetCdmId(); | 102 VLOG(2) << __FUNCTION__ << " cdm_id:" << cdm_context->GetCdmId(); |
| 102 DCHECK(media_task_runner_->BelongsToCurrentThread()); | 103 DCHECK(media_task_runner_->BelongsToCurrentThread()); |
| 103 | 104 |
| 104 // TODO(erickung): add implementation once Remote CDM implementation is done. | 105 // TODO(erickung): add implementation once Remote CDM implementation is done. |
| 105 // Right now it returns callback immediately. | 106 // Right now it returns callback immediately. |
| 106 if (!cdm_attached_cb.is_null()) { | 107 if (!cdm_attached_cb.is_null()) { |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 return; | 559 return; |
| 559 } | 560 } |
| 560 | 561 |
| 561 if (!flush_cb_.is_null()) | 562 if (!flush_cb_.is_null()) |
| 562 base::ResetAndReturn(&flush_cb_).Run(); | 563 base::ResetAndReturn(&flush_cb_).Run(); |
| 563 | 564 |
| 564 // After OnError() returns, the pipeline may destroy |this|. | 565 // After OnError() returns, the pipeline may destroy |this|. |
| 565 client_->OnError(error); | 566 client_->OnError(error); |
| 566 } | 567 } |
| 567 } // namespace media | 568 } // namespace media |
| OLD | NEW |