OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/remoting/remoting_cdm_factory.h" |
| 6 |
| 7 #include "base/bind.h" |
| 8 #include "base/single_thread_task_runner.h" |
| 9 #include "media/base/cdm_config.h" |
| 10 #include "media/remoting/remoting_cdm.h" |
| 11 |
| 12 namespace media { |
| 13 |
| 14 RemotingCdmFactory::RemotingCdmFactory( |
| 15 std::unique_ptr<CdmFactory> default_cdm_factory, |
| 16 mojom::RemoterFactory* remoter_factory, |
| 17 std::unique_ptr<RemotingSinkObserver> sink_observer) |
| 18 : default_cdm_factory_(std::move(default_cdm_factory)), |
| 19 remoter_factory_(remoter_factory), |
| 20 sink_observer_(std::move(sink_observer)), |
| 21 weak_factory_(this) { |
| 22 DCHECK(default_cdm_factory_); |
| 23 DCHECK(remoter_factory_); |
| 24 DCHECK(sink_observer_); |
| 25 } |
| 26 |
| 27 RemotingCdmFactory::~RemotingCdmFactory() {} |
| 28 |
| 29 std::unique_ptr<RemotingCdmController> |
| 30 RemotingCdmFactory::CreateRemotingCdmController() { |
| 31 mojom::RemotingSourcePtr remoting_source; |
| 32 mojom::RemotingSourceRequest remoting_source_request = |
| 33 mojo::GetProxy(&remoting_source); |
| 34 mojom::RemoterPtr remoter; |
| 35 remoter_factory_->Create(std::move(remoting_source), |
| 36 mojo::GetProxy(&remoter)); |
| 37 scoped_refptr<RemotingSourceImpl> remoting_source_impl = |
| 38 new RemotingSourceImpl(std::move(remoting_source_request), |
| 39 std::move(remoter)); |
| 40 // HACK: Copy-over the sink availability status from |sink_observer_| before |
| 41 // the RemotingCdmController would naturally get the notification. This is to |
| 42 // avoid the possible delay on OnSinkAvailable() call from browser. |
| 43 if (sink_observer_->is_sink_available()) |
| 44 remoting_source_impl->OnSinkAvailable(); |
| 45 return base::MakeUnique<RemotingCdmController>(remoting_source_impl); |
| 46 } |
| 47 |
| 48 // TODO(xjz): Replace the callbacks with an interface. http://crbug.com/657940. |
| 49 void RemotingCdmFactory::Create( |
| 50 const std::string& key_system, |
| 51 const GURL& security_origin, |
| 52 const CdmConfig& cdm_config, |
| 53 const SessionMessageCB& session_message_cb, |
| 54 const SessionClosedCB& session_closed_cb, |
| 55 const SessionKeysChangeCB& session_keys_change_cb, |
| 56 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 57 const CdmCreatedCB& cdm_created_cb) { |
| 58 if (!sink_observer_->is_sink_available()) { |
| 59 CreateCdm(key_system, security_origin, cdm_config, session_message_cb, |
| 60 session_closed_cb, session_keys_change_cb, |
| 61 session_expiration_update_cb, cdm_created_cb, nullptr, false); |
| 62 return; |
| 63 } |
| 64 |
| 65 std::unique_ptr<RemotingCdmController> remoting_cdm_controller = |
| 66 CreateRemotingCdmController(); |
| 67 // Get the raw pointer of |remoting_cdm_controller| as it will be invalidated |
| 68 // before calling |ShouldCreateRemotingCdm()| by base::Passed(). |
| 69 RemotingCdmController* remoting_cdm_controller_ptr = |
| 70 remoting_cdm_controller.get(); |
| 71 remoting_cdm_controller_ptr->ShouldCreateRemotingCdm(base::Bind( |
| 72 &RemotingCdmFactory::CreateCdm, weak_factory_.GetWeakPtr(), key_system, |
| 73 security_origin, cdm_config, session_message_cb, session_closed_cb, |
| 74 session_keys_change_cb, session_expiration_update_cb, cdm_created_cb, |
| 75 base::Passed(&remoting_cdm_controller))); |
| 76 } |
| 77 |
| 78 void RemotingCdmFactory::CreateCdm( |
| 79 const std::string& key_system, |
| 80 const GURL& security_origin, |
| 81 const CdmConfig& cdm_config, |
| 82 const SessionMessageCB& session_message_cb, |
| 83 const SessionClosedCB& session_closed_cb, |
| 84 const SessionKeysChangeCB& session_keys_change_cb, |
| 85 const SessionExpirationUpdateCB& session_expiration_update_cb, |
| 86 const CdmCreatedCB& cdm_created_cb, |
| 87 std::unique_ptr<RemotingCdmController> remoting_cdm_controller, |
| 88 bool is_remoting) { |
| 89 if (is_remoting) { |
| 90 VLOG(1) << "Create remoting CDM."; |
| 91 // TODO(xjz): Merge this with erickung's implementation to create remoting |
| 92 // CDM. |
| 93 NOTIMPLEMENTED(); |
| 94 } else { |
| 95 VLOG(1) << "Create default CDM."; |
| 96 default_cdm_factory_->Create(key_system, security_origin, cdm_config, |
| 97 session_message_cb, session_closed_cb, |
| 98 session_keys_change_cb, |
| 99 session_expiration_update_cb, cdm_created_cb); |
| 100 } |
| 101 } |
| 102 |
| 103 } // namespace media |
OLD | NEW |