Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/mojo/services/mojo_cdm.h" | 5 #include "media/mojo/services/mojo_cdm.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "media/base/cdm_key_information.h" | 9 #include "media/base/cdm_key_information.h" |
| 10 #include "media/base/cdm_promise.h" | 10 #include "media/base/cdm_promise.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 26 } | 26 } |
| 27 | 27 |
| 28 template <typename PromiseType> | 28 template <typename PromiseType> |
| 29 static void RejectPromise(scoped_ptr<PromiseType> promise, | 29 static void RejectPromise(scoped_ptr<PromiseType> promise, |
| 30 mojo::CdmPromiseResultPtr result) { | 30 mojo::CdmPromiseResultPtr result) { |
| 31 promise->reject(static_cast<MediaKeys::Exception>(result->exception), | 31 promise->reject(static_cast<MediaKeys::Exception>(result->exception), |
| 32 result->system_code, result->error_message); | 32 result->system_code, result->error_message); |
| 33 } | 33 } |
| 34 | 34 |
| 35 MojoCdm::MojoCdm(mojo::ContentDecryptionModulePtr remote_cdm, | 35 MojoCdm::MojoCdm(mojo::ContentDecryptionModulePtr remote_cdm, |
| 36 int32_t cdm_id, | |
| 36 const SessionMessageCB& session_message_cb, | 37 const SessionMessageCB& session_message_cb, |
| 37 const SessionClosedCB& session_closed_cb, | 38 const SessionClosedCB& session_closed_cb, |
| 38 const SessionErrorCB& session_error_cb, | 39 const SessionErrorCB& session_error_cb, |
| 39 const SessionKeysChangeCB& session_keys_change_cb, | 40 const SessionKeysChangeCB& session_keys_change_cb, |
| 40 const SessionExpirationUpdateCB& session_expiration_update_cb) | 41 const SessionExpirationUpdateCB& session_expiration_update_cb) |
| 41 : remote_cdm_(remote_cdm.Pass()), | 42 : remote_cdm_(remote_cdm.Pass()), |
| 42 binding_(this), | 43 binding_(this), |
| 44 cdm_id_(cdm_id), | |
| 43 session_message_cb_(session_message_cb), | 45 session_message_cb_(session_message_cb), |
| 44 session_closed_cb_(session_closed_cb), | 46 session_closed_cb_(session_closed_cb), |
| 45 session_error_cb_(session_error_cb), | 47 session_error_cb_(session_error_cb), |
| 46 session_keys_change_cb_(session_keys_change_cb), | 48 session_keys_change_cb_(session_keys_change_cb), |
| 47 session_expiration_update_cb_(session_expiration_update_cb), | 49 session_expiration_update_cb_(session_expiration_update_cb), |
| 48 weak_factory_(this) { | 50 weak_factory_(this) { |
| 49 DVLOG(1) << __FUNCTION__; | 51 DVLOG(1) << __FUNCTION__; |
| 50 DCHECK(!session_message_cb_.is_null()); | 52 DCHECK(!session_message_cb_.is_null()); |
| 51 DCHECK(!session_closed_cb_.is_null()); | 53 DCHECK(!session_closed_cb_.is_null()); |
| 52 DCHECK(!session_error_cb_.is_null()); | 54 DCHECK(!session_error_cb_.is_null()); |
| 53 DCHECK(!session_keys_change_cb_.is_null()); | 55 DCHECK(!session_keys_change_cb_.is_null()); |
| 54 DCHECK(!session_expiration_update_cb_.is_null()); | 56 DCHECK(!session_expiration_update_cb_.is_null()); |
| 55 | 57 |
| 56 mojo::ContentDecryptionModuleClientPtr client_ptr; | 58 mojo::ContentDecryptionModuleClientPtr client_ptr; |
| 57 binding_.Bind(GetProxy(&client_ptr)); | 59 binding_.Bind(GetProxy(&client_ptr)); |
| 58 remote_cdm_->SetClient(client_ptr.Pass()); | 60 remote_cdm_->SetClient(client_ptr.Pass()); |
| 59 } | 61 } |
| 60 | 62 |
| 61 MojoCdm::~MojoCdm() { | 63 MojoCdm::~MojoCdm() { |
| 62 DVLOG(1) << __FUNCTION__; | 64 DVLOG(1) << __FUNCTION__; |
| 63 } | 65 } |
| 64 | 66 |
| 65 void MojoCdm::SetServerCertificate(const uint8_t* certificate_data, | 67 void MojoCdm::SetServerCertificate(const uint8_t* certificate_data, |
| 66 int certificate_data_length, | 68 int certificate_data_length, |
| 67 scoped_ptr<SimpleCdmPromise> promise) { | 69 scoped_ptr<SimpleCdmPromise> promise) { |
| 70 DVLOG(2) << __FUNCTION__; | |
| 68 remote_cdm_->SetServerCertificate( | 71 remote_cdm_->SetServerCertificate( |
| 69 CreateMojoArray(certificate_data, certificate_data_length), | 72 CreateMojoArray(certificate_data, certificate_data_length), |
| 70 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), | 73 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), |
| 71 base::Passed(&promise))); | 74 base::Passed(&promise))); |
| 72 } | 75 } |
| 73 | 76 |
| 74 void MojoCdm::CreateSessionAndGenerateRequest( | 77 void MojoCdm::CreateSessionAndGenerateRequest( |
| 75 SessionType session_type, | 78 SessionType session_type, |
| 76 const std::string& init_data_type, | 79 const std::string& init_data_type, |
| 77 const uint8_t* init_data, | 80 const uint8_t* init_data, |
| 78 int init_data_length, | 81 int init_data_length, |
| 79 scoped_ptr<NewSessionCdmPromise> promise) { | 82 scoped_ptr<NewSessionCdmPromise> promise) { |
| 83 DVLOG(2) << __FUNCTION__; | |
| 80 remote_cdm_->CreateSessionAndGenerateRequest( | 84 remote_cdm_->CreateSessionAndGenerateRequest( |
| 81 static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), | 85 static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), |
| 82 init_data_type, CreateMojoArray(init_data, init_data_length), | 86 init_data_type, CreateMojoArray(init_data, init_data_length), |
| 83 base::Bind(&MojoCdm::OnPromiseResult<std::string>, | 87 base::Bind(&MojoCdm::OnPromiseResult<std::string>, |
| 84 weak_factory_.GetWeakPtr(), base::Passed(&promise))); | 88 weak_factory_.GetWeakPtr(), base::Passed(&promise))); |
| 85 } | 89 } |
| 86 | 90 |
| 87 void MojoCdm::LoadSession(SessionType session_type, | 91 void MojoCdm::LoadSession(SessionType session_type, |
| 88 const std::string& session_id, | 92 const std::string& session_id, |
| 89 scoped_ptr<NewSessionCdmPromise> promise) { | 93 scoped_ptr<NewSessionCdmPromise> promise) { |
| 94 DVLOG(2) << __FUNCTION__; | |
| 90 remote_cdm_->LoadSession( | 95 remote_cdm_->LoadSession( |
| 91 static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), | 96 static_cast<mojo::ContentDecryptionModule::SessionType>(session_type), |
| 92 session_id, | 97 session_id, |
| 93 base::Bind(&MojoCdm::OnPromiseResult<std::string>, | 98 base::Bind(&MojoCdm::OnPromiseResult<std::string>, |
| 94 weak_factory_.GetWeakPtr(), base::Passed(&promise))); | 99 weak_factory_.GetWeakPtr(), base::Passed(&promise))); |
| 95 } | 100 } |
| 96 | 101 |
| 97 void MojoCdm::UpdateSession(const std::string& session_id, | 102 void MojoCdm::UpdateSession(const std::string& session_id, |
| 98 const uint8_t* response, | 103 const uint8_t* response, |
| 99 int response_length, | 104 int response_length, |
| 100 scoped_ptr<SimpleCdmPromise> promise) { | 105 scoped_ptr<SimpleCdmPromise> promise) { |
| 106 DVLOG(2) << __FUNCTION__; | |
| 101 remote_cdm_->UpdateSession( | 107 remote_cdm_->UpdateSession( |
| 102 session_id, CreateMojoArray(response, response_length), | 108 session_id, CreateMojoArray(response, response_length), |
| 103 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), | 109 base::Bind(&MojoCdm::OnPromiseResult<>, weak_factory_.GetWeakPtr(), |
| 104 base::Passed(&promise))); | 110 base::Passed(&promise))); |
| 105 } | 111 } |
| 106 | 112 |
| 107 void MojoCdm::CloseSession(const std::string& session_id, | 113 void MojoCdm::CloseSession(const std::string& session_id, |
| 108 scoped_ptr<SimpleCdmPromise> promise) { | 114 scoped_ptr<SimpleCdmPromise> promise) { |
| 115 DVLOG(2) << __FUNCTION__; | |
| 109 remote_cdm_->CloseSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, | 116 remote_cdm_->CloseSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, |
| 110 weak_factory_.GetWeakPtr(), | 117 weak_factory_.GetWeakPtr(), |
| 111 base::Passed(&promise))); | 118 base::Passed(&promise))); |
| 112 } | 119 } |
| 113 | 120 |
| 114 void MojoCdm::RemoveSession(const std::string& session_id, | 121 void MojoCdm::RemoveSession(const std::string& session_id, |
| 115 scoped_ptr<SimpleCdmPromise> promise) { | 122 scoped_ptr<SimpleCdmPromise> promise) { |
| 123 DVLOG(2) << __FUNCTION__; | |
| 116 remote_cdm_->RemoveSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, | 124 remote_cdm_->RemoveSession(session_id, base::Bind(&MojoCdm::OnPromiseResult<>, |
| 117 weak_factory_.GetWeakPtr(), | 125 weak_factory_.GetWeakPtr(), |
| 118 base::Passed(&promise))); | 126 base::Passed(&promise))); |
| 119 } | 127 } |
| 120 | 128 |
| 121 CdmContext* MojoCdm::GetCdmContext() { | 129 CdmContext* MojoCdm::GetCdmContext() { |
| 130 DVLOG(2) << __FUNCTION__; | |
| 131 return this; | |
| 132 } | |
| 133 | |
| 134 media::Decryptor* MojoCdm::GetDecryptor() { | |
| 122 NOTIMPLEMENTED(); | 135 NOTIMPLEMENTED(); |
|
ddorwin
2015/05/15 19:10:07
Will this be implemented? Should there be a TODO?
| |
| 123 return nullptr; | 136 return nullptr; |
| 124 } | 137 } |
| 125 | 138 |
| 139 int MojoCdm::GetCdmId() const { | |
| 140 DVLOG(2) << __FUNCTION__ << cdm_id_; | |
| 141 return cdm_id_; | |
| 142 } | |
| 143 | |
| 126 void MojoCdm::OnSessionMessage(const mojo::String& session_id, | 144 void MojoCdm::OnSessionMessage(const mojo::String& session_id, |
| 127 mojo::CdmMessageType message_type, | 145 mojo::CdmMessageType message_type, |
| 128 mojo::Array<uint8_t> message, | 146 mojo::Array<uint8_t> message, |
| 129 const mojo::String& legacy_destination_url) { | 147 const mojo::String& legacy_destination_url) { |
| 148 DVLOG(2) << __FUNCTION__; | |
| 130 GURL verified_gurl = GURL(legacy_destination_url); | 149 GURL verified_gurl = GURL(legacy_destination_url); |
| 131 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { | 150 if (!verified_gurl.is_valid() && !verified_gurl.is_empty()) { |
| 132 DLOG(WARNING) << "SessionMessage destination_url is invalid : " | 151 DLOG(WARNING) << "SessionMessage destination_url is invalid : " |
| 133 << verified_gurl.possibly_invalid_spec(); | 152 << verified_gurl.possibly_invalid_spec(); |
| 134 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. | 153 verified_gurl = GURL::EmptyGURL(); // Replace invalid destination_url. |
| 135 } | 154 } |
| 136 | 155 |
| 137 session_message_cb_.Run(session_id, | 156 session_message_cb_.Run(session_id, |
| 138 static_cast<MediaKeys::MessageType>(message_type), | 157 static_cast<MediaKeys::MessageType>(message_type), |
| 139 message.storage(), verified_gurl); | 158 message.storage(), verified_gurl); |
| 140 } | 159 } |
| 141 | 160 |
| 142 void MojoCdm::OnSessionClosed(const mojo::String& session_id) { | 161 void MojoCdm::OnSessionClosed(const mojo::String& session_id) { |
| 162 DVLOG(2) << __FUNCTION__; | |
| 143 session_closed_cb_.Run(session_id); | 163 session_closed_cb_.Run(session_id); |
| 144 } | 164 } |
| 145 | 165 |
| 146 void MojoCdm::OnSessionError(const mojo::String& session_id, | 166 void MojoCdm::OnSessionError(const mojo::String& session_id, |
| 147 mojo::CdmException exception, | 167 mojo::CdmException exception, |
| 148 uint32_t system_code, | 168 uint32_t system_code, |
| 149 const mojo::String& error_message) { | 169 const mojo::String& error_message) { |
| 170 DVLOG(2) << __FUNCTION__; | |
| 150 session_error_cb_.Run(session_id, | 171 session_error_cb_.Run(session_id, |
| 151 static_cast<MediaKeys::Exception>(exception), | 172 static_cast<MediaKeys::Exception>(exception), |
| 152 system_code, error_message); | 173 system_code, error_message); |
| 153 } | 174 } |
| 154 | 175 |
| 155 void MojoCdm::OnSessionKeysChange( | 176 void MojoCdm::OnSessionKeysChange( |
| 156 const mojo::String& session_id, | 177 const mojo::String& session_id, |
| 157 bool has_additional_usable_key, | 178 bool has_additional_usable_key, |
| 158 mojo::Array<mojo::CdmKeyInformationPtr> keys_info) { | 179 mojo::Array<mojo::CdmKeyInformationPtr> keys_info) { |
| 180 DVLOG(2) << __FUNCTION__; | |
| 159 media::CdmKeysInfo key_data; | 181 media::CdmKeysInfo key_data; |
| 160 key_data.reserve(keys_info.size()); | 182 key_data.reserve(keys_info.size()); |
| 161 for (size_t i = 0; i < keys_info.size(); ++i) { | 183 for (size_t i = 0; i < keys_info.size(); ++i) { |
| 162 key_data.push_back( | 184 key_data.push_back( |
| 163 keys_info[i].To<scoped_ptr<media::CdmKeyInformation>>().release()); | 185 keys_info[i].To<scoped_ptr<media::CdmKeyInformation>>().release()); |
| 164 } | 186 } |
| 165 session_keys_change_cb_.Run(session_id, has_additional_usable_key, | 187 session_keys_change_cb_.Run(session_id, has_additional_usable_key, |
| 166 key_data.Pass()); | 188 key_data.Pass()); |
| 167 } | 189 } |
| 168 | 190 |
| 169 void MojoCdm::OnSessionExpirationUpdate(const mojo::String& session_id, | 191 void MojoCdm::OnSessionExpirationUpdate(const mojo::String& session_id, |
| 170 int64_t new_expiry_time_usec) { | 192 int64_t new_expiry_time_usec) { |
| 193 DVLOG(2) << __FUNCTION__; | |
| 171 session_expiration_update_cb_.Run( | 194 session_expiration_update_cb_.Run( |
| 172 session_id, base::Time::FromInternalValue(new_expiry_time_usec)); | 195 session_id, base::Time::FromInternalValue(new_expiry_time_usec)); |
| 173 } | 196 } |
| 174 | 197 |
| 175 } // namespace media | 198 } // namespace media |
| OLD | NEW |