OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <cstring> // For memcpy. | 5 #include <cstring> // For memcpy. |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/compiler_specific.h" // For OVERRIDE. | 8 #include "base/compiler_specific.h" // For OVERRIDE. |
9 #include "ppapi/c/pp_errors.h" | 9 #include "ppapi/c/pp_errors.h" |
10 #include "ppapi/c/pp_stdint.h" | 10 #include "ppapi/c/pp_stdint.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
65 | 65 |
66 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 66 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
67 return true; | 67 return true; |
68 } | 68 } |
69 | 69 |
70 // PPP_ContentDecryptor_Private methods | 70 // PPP_ContentDecryptor_Private methods |
71 // Note: As per comments in PPP_ContentDecryptor_Private, these calls should | 71 // Note: As per comments in PPP_ContentDecryptor_Private, these calls should |
72 // return false if the call was not forwarded to the CDM and should return | 72 // return false if the call was not forwarded to the CDM and should return |
73 // true otherwise. Once the call reaches the CDM, the call result/status | 73 // true otherwise. Once the call reaches the CDM, the call result/status |
74 // should be reported through the PPB_ContentDecryptor_Private interface. | 74 // should be reported through the PPB_ContentDecryptor_Private interface. |
75 virtual bool GenerateKeyRequest(const std::string& key_system, | 75 virtual void GenerateKeyRequest(const std::string& key_system, |
76 pp::VarArrayBuffer init_data) OVERRIDE; | 76 pp::VarArrayBuffer init_data) OVERRIDE; |
77 virtual bool AddKey(const std::string& session_id, | 77 virtual void AddKey(const std::string& session_id, |
78 pp::VarArrayBuffer key, | 78 pp::VarArrayBuffer key, |
79 pp::VarArrayBuffer init_data) OVERRIDE; | 79 pp::VarArrayBuffer init_data) OVERRIDE; |
80 virtual bool CancelKeyRequest(const std::string& session_id) OVERRIDE; | 80 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; |
81 virtual bool Decrypt( | 81 virtual void Decrypt( |
82 pp::Buffer_Dev encrypted_buffer, | 82 pp::Buffer_Dev encrypted_buffer, |
83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
84 virtual bool DecryptAndDecode( | 84 virtual void DecryptAndDecode( |
85 pp::Buffer_Dev encrypted_buffer, | 85 pp::Buffer_Dev encrypted_buffer, |
86 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 86 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
87 | 87 |
88 private: | 88 private: |
89 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the | 89 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the |
90 // buffer resource, and returns it. Returns a an invalid PP_Resource with an | 90 // buffer resource, and returns it. Returns a an invalid PP_Resource with an |
91 // ID of 0 on failure. Upon success, the returned Buffer resource has a | 91 // ID of 0 on failure. Upon success, the returned Buffer resource has a |
92 // reference count of 1. | 92 // reference count of 1. |
93 pp::Buffer_Dev MakeBufferResource(const uint8_t* data, uint32_t data_size); | 93 pp::Buffer_Dev MakeBufferResource(const uint8_t* data, uint32_t data_size); |
94 | 94 |
(...skipping 18 matching lines...) Expand all Loading... | |
113 pp::ContentDecryptor_Private(this), | 113 pp::ContentDecryptor_Private(this), |
114 cdm_(NULL) { | 114 cdm_(NULL) { |
115 callback_factory_.Initialize(this); | 115 callback_factory_.Initialize(this); |
116 } | 116 } |
117 | 117 |
118 CdmWrapper::~CdmWrapper() { | 118 CdmWrapper::~CdmWrapper() { |
119 if (cdm_) | 119 if (cdm_) |
120 DestroyCdmInstance(cdm_); | 120 DestroyCdmInstance(cdm_); |
121 } | 121 } |
122 | 122 |
123 bool CdmWrapper::GenerateKeyRequest(const std::string& key_system, | 123 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, |
124 pp::VarArrayBuffer init_data) { | 124 pp::VarArrayBuffer init_data) { |
125 PP_DCHECK(!key_system.empty()); | 125 PP_DCHECK(!key_system.empty()); |
126 | 126 |
127 if (!cdm_) { | 127 if (!cdm_) { |
128 cdm_ = CreateCdmInstance(); | 128 cdm_ = CreateCdmInstance(); |
129 if (!cdm_) | 129 if (!cdm_) |
130 return false; | 130 return; |
xhwang
2012/09/13 12:24:59
Should we return a keyerror here? Based on the spe
Tom Finegan
2012/09/14 00:08:37
Makes sense. I agree.
| |
131 } | 131 } |
132 | 132 |
133 cdm::KeyMessage key_request; | 133 cdm::KeyMessage key_request; |
134 cdm::Status status = cdm_->GenerateKeyRequest( | 134 cdm::Status status = cdm_->GenerateKeyRequest( |
135 reinterpret_cast<const uint8_t*>(init_data.Map()), | 135 reinterpret_cast<const uint8_t*>(init_data.Map()), |
136 init_data.ByteLength(), | 136 init_data.ByteLength(), |
137 &key_request); | 137 &key_request); |
138 | 138 |
139 if (status != cdm::kSuccess || | 139 if (status != cdm::kSuccess || |
140 !key_request.message || | 140 !key_request.message || |
141 key_request.message_size == 0) { | 141 key_request.message_size == 0) { |
142 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, | 142 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, |
143 std::string())); | 143 std::string())); |
144 return true; | 144 return; |
145 } | 145 } |
146 | 146 |
147 // TODO(xhwang): Remove unnecessary CallOnMain calls here and below once we | 147 // TODO(xhwang): Remove unnecessary CallOnMain calls here and below once we |
148 // only support out-of-process. | 148 // only support out-of-process. |
149 // If running out-of-process, PPB calls will always behave asynchronously | 149 // If running out-of-process, PPB calls will always behave asynchronously |
150 // since IPC is involved. In that case, if we are already on main thread, | 150 // since IPC is involved. In that case, if we are already on main thread, |
151 // we don't need to use CallOnMain to help us call PPB call on main thread, | 151 // we don't need to use CallOnMain to help us call PPB call on main thread, |
152 // or to help call PPB asynchronously. | 152 // or to help call PPB asynchronously. |
153 key_system_ = key_system; | 153 key_system_ = key_system; |
154 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyMessage, | 154 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyMessage, |
155 key_request)); | 155 key_request)); |
156 | |
157 return true; | |
158 } | 156 } |
159 | 157 |
160 bool CdmWrapper::AddKey(const std::string& session_id, | 158 void CdmWrapper::AddKey(const std::string& session_id, |
161 pp::VarArrayBuffer key, | 159 pp::VarArrayBuffer key, |
162 pp::VarArrayBuffer init_data) { | 160 pp::VarArrayBuffer init_data) { |
163 const uint8_t* key_ptr = reinterpret_cast<const uint8_t*>(key.Map()); | 161 const uint8_t* key_ptr = reinterpret_cast<const uint8_t*>(key.Map()); |
164 int key_size = key.ByteLength(); | 162 int key_size = key.ByteLength(); |
165 const uint8_t* init_data_ptr = | 163 const uint8_t* init_data_ptr = |
166 reinterpret_cast<const uint8_t*>(init_data.Map()); | 164 reinterpret_cast<const uint8_t*>(init_data.Map()); |
167 int init_data_size = init_data.ByteLength(); | 165 int init_data_size = init_data.ByteLength(); |
168 | 166 |
169 if (!key_ptr || key_size <= 0 || !init_data_ptr || init_data_size <= 0) | 167 if (!key_ptr || key_size <= 0 || !init_data_ptr || init_data_size <= 0) |
170 return false; | 168 return; |
xhwang
2012/09/13 12:24:59
ditto, a keyerror here?
Tom Finegan
2012/09/14 00:08:37
Same, agreed.
| |
171 | 169 |
172 PP_DCHECK(cdm_); | 170 PP_DCHECK(cdm_); |
173 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), | 171 cdm::Status status = cdm_->AddKey(session_id.data(), session_id.size(), |
174 key_ptr, key_size, | 172 key_ptr, key_size, |
175 init_data_ptr, init_data_size); | 173 init_data_ptr, init_data_size); |
176 | 174 |
177 if (status != cdm::kSuccess) { | 175 if (status != cdm::kSuccess) { |
178 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, | 176 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, |
179 session_id)); | 177 session_id)); |
180 return true; | 178 return; |
181 } | 179 } |
182 | 180 |
183 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyAdded, session_id)); | 181 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyAdded, session_id)); |
184 return true; | |
185 } | 182 } |
186 | 183 |
187 bool CdmWrapper::CancelKeyRequest(const std::string& session_id) { | 184 void CdmWrapper::CancelKeyRequest(const std::string& session_id) { |
188 PP_DCHECK(cdm_); | 185 PP_DCHECK(cdm_); |
189 | |
190 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), | 186 cdm::Status status = cdm_->CancelKeyRequest(session_id.data(), |
191 session_id.size()); | 187 session_id.size()); |
192 | |
193 if (status != cdm::kSuccess) { | 188 if (status != cdm::kSuccess) { |
194 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, | 189 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, |
195 session_id)); | 190 session_id)); |
196 return true; | |
197 } | 191 } |
198 | |
199 return true; | |
200 } | 192 } |
201 | 193 |
202 bool CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, | 194 void CdmWrapper::Decrypt(pp::Buffer_Dev encrypted_buffer, |
203 const PP_EncryptedBlockInfo& encrypted_block_info) { | 195 const PP_EncryptedBlockInfo& encrypted_block_info) { |
204 PP_DCHECK(!encrypted_buffer.is_null()); | 196 PP_DCHECK(!encrypted_buffer.is_null()); |
205 PP_DCHECK(cdm_); | 197 PP_DCHECK(cdm_); |
206 | 198 |
207 // TODO(xhwang): Simplify the following data conversion. | 199 // TODO(xhwang): Simplify the following data conversion. |
208 cdm::InputBuffer input_buffer; | 200 cdm::InputBuffer input_buffer; |
209 input_buffer.data = reinterpret_cast<uint8_t*>(encrypted_buffer.data()); | 201 input_buffer.data = reinterpret_cast<uint8_t*>(encrypted_buffer.data()); |
210 input_buffer.data_size = encrypted_buffer.size(); | 202 input_buffer.data_size = encrypted_buffer.size(); |
211 input_buffer.data_offset = encrypted_block_info.data_offset; | 203 input_buffer.data_offset = encrypted_block_info.data_offset; |
212 input_buffer.key_id = encrypted_block_info.key_id; | 204 input_buffer.key_id = encrypted_block_info.key_id; |
(...skipping 13 matching lines...) Expand all Loading... | |
226 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; | 218 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; |
227 | 219 |
228 cdm::OutputBuffer output_buffer; | 220 cdm::OutputBuffer output_buffer; |
229 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer); | 221 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer); |
230 | 222 |
231 CallOnMain(callback_factory_.NewCallback( | 223 CallOnMain(callback_factory_.NewCallback( |
232 &CdmWrapper::DeliverBlock, | 224 &CdmWrapper::DeliverBlock, |
233 status, | 225 status, |
234 output_buffer, | 226 output_buffer, |
235 encrypted_block_info.tracking_info)); | 227 encrypted_block_info.tracking_info)); |
236 return true; | |
237 } | 228 } |
238 | 229 |
239 bool CdmWrapper::DecryptAndDecode( | 230 void CdmWrapper::DecryptAndDecode( |
240 pp::Buffer_Dev encrypted_buffer, | 231 pp::Buffer_Dev encrypted_buffer, |
241 const PP_EncryptedBlockInfo& encrypted_block_info) { | 232 const PP_EncryptedBlockInfo& encrypted_block_info) { |
242 return false; | |
243 } | 233 } |
244 | 234 |
245 pp::Buffer_Dev CdmWrapper::MakeBufferResource(const uint8_t* data, | 235 pp::Buffer_Dev CdmWrapper::MakeBufferResource(const uint8_t* data, |
246 uint32_t data_size) { | 236 uint32_t data_size) { |
247 if (!data || !data_size) | 237 if (!data || !data_size) |
248 return pp::Buffer_Dev(); | 238 return pp::Buffer_Dev(); |
249 | 239 |
250 pp::Buffer_Dev buffer(this, data_size); | 240 pp::Buffer_Dev buffer(this, data_size); |
251 if (!buffer.data()) | 241 if (!buffer.data()) |
252 return pp::Buffer_Dev(); | 242 return pp::Buffer_Dev(); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 } // namespace webkit_media | 323 } // namespace webkit_media |
334 | 324 |
335 namespace pp { | 325 namespace pp { |
336 | 326 |
337 // Factory function for your specialization of the Module object. | 327 // Factory function for your specialization of the Module object. |
338 Module* CreateModule() { | 328 Module* CreateModule() { |
339 return new webkit_media::MyModule(); | 329 return new webkit_media::MyModule(); |
340 } | 330 } |
341 | 331 |
342 } // namespace pp | 332 } // namespace pp |
OLD | NEW |