OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "content/renderer/media/cdm/proxy_media_keys.h" | |
6 | |
7 #include <utility> | |
8 #include <vector> | |
9 | |
10 #include "base/logging.h" | |
11 #include "base/stl_util.h" | |
12 #include "content/renderer/media/cdm/renderer_cdm_manager.h" | |
13 #include "media/base/cdm_initialized_promise.h" | |
14 #include "media/base/cdm_key_information.h" | |
15 #include "media/base/cdm_promise.h" | |
16 | |
17 namespace content { | |
18 | |
19 void ProxyMediaKeys::Create( | |
20 const std::string& key_system, | |
21 const GURL& security_origin, | |
22 bool use_hw_secure_codecs, | |
23 RendererCdmManager* manager, | |
24 const media::SessionMessageCB& session_message_cb, | |
25 const media::SessionClosedCB& session_closed_cb, | |
26 const media::SessionKeysChangeCB& session_keys_change_cb, | |
27 const media::SessionExpirationUpdateCB& session_expiration_update_cb, | |
28 const media::CdmCreatedCB& cdm_created_cb) { | |
29 DCHECK(manager); | |
30 scoped_refptr<ProxyMediaKeys> proxy_media_keys( | |
31 new ProxyMediaKeys(manager, session_message_cb, session_closed_cb, | |
32 session_keys_change_cb, session_expiration_update_cb)); | |
33 | |
34 // ProxyMediaKeys ownership passed to the promise. | |
35 std::unique_ptr<media::CdmInitializedPromise> promise( | |
36 new media::CdmInitializedPromise(cdm_created_cb, proxy_media_keys)); | |
37 | |
38 proxy_media_keys->InitializeCdm(key_system, security_origin, | |
39 use_hw_secure_codecs, std::move(promise)); | |
40 } | |
41 | |
42 void ProxyMediaKeys::SetServerCertificate( | |
43 const std::vector<uint8_t>& certificate, | |
44 std::unique_ptr<media::SimpleCdmPromise> promise) { | |
45 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
46 manager_->SetServerCertificate(cdm_id_, promise_id, certificate); | |
47 } | |
48 | |
49 void ProxyMediaKeys::CreateSessionAndGenerateRequest( | |
50 SessionType session_type, | |
51 media::EmeInitDataType init_data_type, | |
52 const std::vector<uint8_t>& init_data, | |
53 std::unique_ptr<media::NewSessionCdmPromise> promise) { | |
54 CdmHostMsg_CreateSession_InitDataType create_session_init_data_type = | |
55 INIT_DATA_TYPE_WEBM; | |
56 switch (init_data_type) { | |
57 case media::EmeInitDataType::CENC: | |
58 create_session_init_data_type = INIT_DATA_TYPE_CENC; | |
59 break; | |
60 case media::EmeInitDataType::WEBM: | |
61 create_session_init_data_type = INIT_DATA_TYPE_WEBM; | |
62 break; | |
63 case media::EmeInitDataType::KEYIDS: | |
64 case media::EmeInitDataType::UNKNOWN: | |
65 DLOG(ERROR) << "Unsupported EME CreateSession init data type"; | |
66 promise->reject(NOT_SUPPORTED_ERROR, 0, | |
67 "Unsupported EME CreateSession init data type"); | |
68 return; | |
69 } | |
70 | |
71 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
72 manager_->CreateSessionAndGenerateRequest(cdm_id_, promise_id, session_type, | |
73 create_session_init_data_type, | |
74 init_data); | |
75 } | |
76 | |
77 void ProxyMediaKeys::LoadSession( | |
78 SessionType session_type, | |
79 const std::string& session_id, | |
80 std::unique_ptr<media::NewSessionCdmPromise> promise) { | |
81 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
82 manager_->LoadSession(cdm_id_, promise_id, session_type, session_id); | |
83 } | |
84 | |
85 void ProxyMediaKeys::UpdateSession( | |
86 const std::string& session_id, | |
87 const std::vector<uint8_t>& response, | |
88 std::unique_ptr<media::SimpleCdmPromise> promise) { | |
89 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
90 manager_->UpdateSession(cdm_id_, promise_id, session_id, response); | |
91 } | |
92 | |
93 void ProxyMediaKeys::CloseSession( | |
94 const std::string& session_id, | |
95 std::unique_ptr<media::SimpleCdmPromise> promise) { | |
96 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
97 manager_->CloseSession(cdm_id_, promise_id, session_id); | |
98 } | |
99 | |
100 void ProxyMediaKeys::RemoveSession( | |
101 const std::string& session_id, | |
102 std::unique_ptr<media::SimpleCdmPromise> promise) { | |
103 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
104 manager_->RemoveSession(cdm_id_, promise_id, session_id); | |
105 } | |
106 | |
107 media::CdmContext* ProxyMediaKeys::GetCdmContext() { | |
108 return this; | |
109 } | |
110 | |
111 media::Decryptor* ProxyMediaKeys::GetDecryptor() { | |
112 return nullptr; | |
113 } | |
114 | |
115 int ProxyMediaKeys::GetCdmId() const { | |
116 return cdm_id_; | |
117 } | |
118 | |
119 void ProxyMediaKeys::OnSessionMessage( | |
120 const std::string& session_id, | |
121 media::MediaKeys::MessageType message_type, | |
122 const std::vector<uint8_t>& message) { | |
123 session_message_cb_.Run(session_id, message_type, message); | |
124 } | |
125 | |
126 void ProxyMediaKeys::OnSessionClosed(const std::string& session_id) { | |
127 session_closed_cb_.Run(session_id); | |
128 } | |
129 | |
130 void ProxyMediaKeys::OnSessionKeysChange(const std::string& session_id, | |
131 bool has_additional_usable_key, | |
132 media::CdmKeysInfo keys_info) { | |
133 session_keys_change_cb_.Run(session_id, has_additional_usable_key, | |
134 std::move(keys_info)); | |
135 } | |
136 | |
137 void ProxyMediaKeys::OnSessionExpirationUpdate( | |
138 const std::string& session_id, | |
139 const base::Time& new_expiry_time) { | |
140 session_expiration_update_cb_.Run(session_id, new_expiry_time); | |
141 } | |
142 | |
143 void ProxyMediaKeys::OnPromiseResolved(uint32_t promise_id) { | |
144 cdm_promise_adapter_.ResolvePromise(promise_id); | |
145 } | |
146 | |
147 void ProxyMediaKeys::OnPromiseResolvedWithSession( | |
148 uint32_t promise_id, | |
149 const std::string& session_id) { | |
150 cdm_promise_adapter_.ResolvePromise(promise_id, session_id); | |
151 } | |
152 | |
153 void ProxyMediaKeys::OnPromiseRejected(uint32_t promise_id, | |
154 media::MediaKeys::Exception exception, | |
155 uint32_t system_code, | |
156 const std::string& error_message) { | |
157 cdm_promise_adapter_.RejectPromise(promise_id, exception, system_code, | |
158 error_message); | |
159 } | |
160 | |
161 ProxyMediaKeys::ProxyMediaKeys( | |
162 RendererCdmManager* manager, | |
163 const media::SessionMessageCB& session_message_cb, | |
164 const media::SessionClosedCB& session_closed_cb, | |
165 const media::SessionKeysChangeCB& session_keys_change_cb, | |
166 const media::SessionExpirationUpdateCB& session_expiration_update_cb) | |
167 : manager_(manager), | |
168 session_message_cb_(session_message_cb), | |
169 session_closed_cb_(session_closed_cb), | |
170 session_keys_change_cb_(session_keys_change_cb), | |
171 session_expiration_update_cb_(session_expiration_update_cb) { | |
172 cdm_id_ = manager->RegisterMediaKeys(this); | |
173 } | |
174 | |
175 ProxyMediaKeys::~ProxyMediaKeys() { | |
176 manager_->DestroyCdm(cdm_id_); | |
177 manager_->UnregisterMediaKeys(cdm_id_); | |
178 cdm_promise_adapter_.Clear(); | |
179 } | |
180 | |
181 void ProxyMediaKeys::InitializeCdm( | |
182 const std::string& key_system, | |
183 const GURL& security_origin, | |
184 bool use_hw_secure_codecs, | |
185 std::unique_ptr<media::SimpleCdmPromise> promise) { | |
186 uint32_t promise_id = cdm_promise_adapter_.SavePromise(std::move(promise)); | |
187 manager_->InitializeCdm(cdm_id_, promise_id, this, key_system, | |
188 security_origin, use_hw_secure_codecs); | |
189 } | |
190 | |
191 } // namespace content | |
OLD | NEW |