Chromium Code Reviews| 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> |
| 6 #include <string> | |
| 6 #include <vector> | 7 #include <vector> |
| 7 | 8 |
| 8 #include "base/compiler_specific.h" // For OVERRIDE. | 9 #if defined _MSC_VER |
| 10 #include <memory> | |
| 11 #else | |
| 12 #include <tr1/memory> | |
| 13 #endif | |
| 14 | |
| 15 #include "base/basictypes.h" | |
| 16 #include "base/compiler_specific.h" | |
| 9 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 10 #include "ppapi/c/pp_stdint.h" | 18 #include "ppapi/c/pp_stdint.h" |
| 11 #include "ppapi/c/private/pp_content_decryptor.h" | 19 #include "ppapi/c/private/pp_content_decryptor.h" |
| 12 #include "ppapi/cpp/completion_callback.h" | 20 #include "ppapi/cpp/completion_callback.h" |
| 13 #include "ppapi/cpp/core.h" | 21 #include "ppapi/cpp/core.h" |
| 14 #include "ppapi/cpp/instance.h" | 22 #include "ppapi/cpp/instance.h" |
| 15 #include "ppapi/cpp/logging.h" | 23 #include "ppapi/cpp/logging.h" |
| 16 #include "ppapi/cpp/module.h" | 24 #include "ppapi/cpp/module.h" |
| 17 #include "ppapi/cpp/pass_ref.h" | 25 #include "ppapi/cpp/pass_ref.h" |
| 18 #include "ppapi/cpp/resource.h" | 26 #include "ppapi/cpp/resource.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 48 if (IsMainThread()) | 56 if (IsMainThread()) |
| 49 cb.Run(PP_OK); | 57 cb.Run(PP_OK); |
| 50 else | 58 else |
| 51 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); | 59 pp::Module::Get()->core()->CallOnMainThread(0, cb, PP_OK); |
| 52 } | 60 } |
| 53 | 61 |
| 54 } // namespace | 62 } // namespace |
| 55 | 63 |
| 56 namespace webkit_media { | 64 namespace webkit_media { |
| 57 | 65 |
| 66 // Provides access to memory owned by a pp::Buffer_Dev created by | |
| 67 // PpbBufferAllocator::Allocate(). This class holds a reference to the | |
| 68 // Buffer_Dev throughout its lifetime. | |
| 69 class PpbBuffer : public cdm::Buffer { | |
| 70 public: | |
| 71 // cdm::Buffer methods. | |
| 72 uint8_t* buffer() OVERRIDE { return static_cast<uint8_t*>(buffer_.data()); } | |
| 73 int32_t size() const OVERRIDE { return buffer_.size(); } | |
| 74 | |
| 75 pp::Buffer_Dev buffer_dev() const { return buffer_; } | |
| 76 | |
| 77 private: | |
| 78 explicit PpbBuffer(pp::Buffer_Dev buffer) : buffer_(buffer) {} | |
| 79 virtual ~PpbBuffer() {} | |
| 80 | |
| 81 pp::Buffer_Dev buffer_; | |
| 82 | |
| 83 friend class PpbBufferAllocator; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(PpbBuffer); | |
| 86 }; | |
| 87 | |
| 88 class PpbBufferAllocator : public cdm::Allocator { | |
| 89 public: | |
| 90 explicit PpbBufferAllocator(pp::Instance* instance); | |
| 91 virtual ~PpbBufferAllocator(); | |
| 92 | |
| 93 // cdm::Allocator methods. | |
| 94 // Allocates a pp::Buffer_Dev of the specified size and wraps it in a | |
| 95 // PpbBuffer, which it returns. The caller own the returned buffer and must | |
| 96 // free it by calling ReleaseBuffer(). Returns NULL on failure. | |
| 97 virtual cdm::Buffer* Allocate(int32_t size) OVERRIDE; | |
| 98 | |
| 99 // Deletes the cdm::Buffer*. | |
| 100 virtual void Release(const cdm::Buffer* buffer) OVERRIDE; | |
|
ddorwin
2012/09/17 21:19:23
I don't think the parameter should be const since
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 101 | |
| 102 private: | |
| 103 pp::Instance* const instance_; | |
| 104 | |
| 105 DISALLOW_COPY_AND_ASSIGN(PpbBufferAllocator); | |
| 106 }; | |
| 107 | |
| 108 class KeyMessageImpl : public cdm::KeyMessage { | |
| 109 public: | |
| 110 explicit KeyMessageImpl(PpbBufferAllocator* allocator); | |
| 111 virtual ~KeyMessageImpl(); | |
| 112 | |
| 113 // cdm::KeyMessage methods. | |
| 114 virtual bool set_session_id(const char* session_id, int32_t length) OVERRIDE; | |
| 115 virtual const char* session_id() const OVERRIDE; | |
| 116 virtual int32_t session_id_length() const OVERRIDE; | |
| 117 | |
| 118 virtual bool set_message(cdm::Buffer* message) OVERRIDE; | |
| 119 virtual cdm::Buffer* message() const OVERRIDE; | |
| 120 | |
| 121 virtual bool set_default_url(const char* default_url, | |
| 122 int32_t length) OVERRIDE; | |
| 123 virtual const char* default_url() const OVERRIDE; | |
| 124 virtual int32_t default_url_length() const OVERRIDE; | |
| 125 | |
| 126 private: | |
| 127 PpbBufferAllocator* const allocator_; | |
| 128 PpbBuffer* message_; | |
| 129 std::string session_id_; | |
| 130 std::string default_url_; | |
| 131 | |
| 132 DISALLOW_COPY_AND_ASSIGN(KeyMessageImpl); | |
| 133 }; | |
| 134 | |
| 135 class OutputBufferImpl : public cdm::OutputBuffer { | |
| 136 public: | |
| 137 explicit OutputBufferImpl(PpbBufferAllocator* allocator); | |
| 138 virtual ~OutputBufferImpl(); | |
| 139 | |
| 140 virtual bool set_buffer(cdm::Buffer* buffer) OVERRIDE; | |
| 141 virtual cdm::Buffer* buffer() const OVERRIDE; | |
| 142 | |
| 143 virtual void set_timestamp(int64_t timestamp) OVERRIDE; | |
| 144 virtual int64_t timestamp() const OVERRIDE; | |
| 145 | |
| 146 private: | |
| 147 PpbBufferAllocator* const allocator_; | |
| 148 PpbBuffer* buffer_; | |
| 149 int64_t timestamp_; | |
| 150 | |
| 151 DISALLOW_COPY_AND_ASSIGN(OutputBufferImpl); | |
| 152 }; | |
| 153 | |
| 154 KeyMessageImpl::KeyMessageImpl(PpbBufferAllocator* allocator) | |
| 155 : allocator_(allocator), | |
| 156 message_(NULL) { | |
| 157 PP_DCHECK(allocator_); | |
| 158 } | |
| 159 | |
| 160 KeyMessageImpl::~KeyMessageImpl() { | |
| 161 if (message_) | |
| 162 allocator_->Release(message_); | |
| 163 } | |
| 164 | |
| 165 bool KeyMessageImpl::set_session_id(const char* session_id, int32_t length) { | |
|
ddorwin
2012/09/17 21:19:23
The return type for simple setters, such as set_va
Tom Finegan
2012/09/18 01:08:02
Done, but did not add DCHECKs. If the CDM wants to
| |
| 166 if (!session_id || length < 0) | |
|
ddorwin
2012/09/17 21:19:23
Is 0 okay?
Tom Finegan
2012/09/18 01:08:02
Experience and some quick tests of std::string::as
| |
| 167 return false; | |
| 168 | |
| 169 session_id_.assign(session_id, length); | |
| 170 return true; | |
| 171 } | |
| 172 | |
| 173 const char* KeyMessageImpl::session_id() const { | |
| 174 return session_id_.data(); | |
|
ddorwin
2012/09/17 21:19:23
c_str() would probably be safer (null-terminated).
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 175 } | |
| 176 | |
| 177 int32_t KeyMessageImpl::session_id_length() const { | |
| 178 return session_id_.length(); | |
| 179 } | |
| 180 | |
| 181 bool KeyMessageImpl::set_message(cdm::Buffer* buffer) { | |
| 182 if (!buffer) | |
| 183 return false; | |
| 184 | |
| 185 message_ = static_cast<PpbBuffer*>(buffer); | |
| 186 return true; | |
| 187 } | |
| 188 | |
| 189 cdm::Buffer* KeyMessageImpl::message() const { | |
| 190 return message_; | |
| 191 } | |
| 192 | |
| 193 bool KeyMessageImpl::set_default_url(const char* default_url, int32_t length) { | |
| 194 if (!default_url || length < 0) | |
|
ddorwin
2012/09/17 21:19:23
0 okay?
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 195 return false; | |
| 196 | |
| 197 default_url_.assign(default_url, length); | |
| 198 return true; | |
| 199 } | |
| 200 | |
| 201 const char* KeyMessageImpl::default_url() const { | |
| 202 return default_url_.data(); | |
|
ddorwin
2012/09/17 21:19:23
c_str()
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 203 } | |
| 204 | |
| 205 int32_t KeyMessageImpl::default_url_length() const { | |
| 206 return default_url_.length(); | |
| 207 } | |
| 208 | |
| 209 OutputBufferImpl::OutputBufferImpl(PpbBufferAllocator* allocator) | |
| 210 : allocator_(allocator), | |
| 211 buffer_(NULL), | |
| 212 timestamp_(0) { | |
| 213 PP_DCHECK(allocator_); | |
| 214 } | |
| 215 | |
| 216 OutputBufferImpl::~OutputBufferImpl() { | |
| 217 if (buffer_) | |
| 218 allocator_->Release(buffer_); | |
| 219 } | |
| 220 | |
| 221 bool OutputBufferImpl::set_buffer(cdm::Buffer* buffer) { | |
| 222 if (!buffer) | |
| 223 return false; | |
| 224 | |
| 225 buffer_ = static_cast<PpbBuffer*>(buffer); | |
| 226 return true; | |
| 227 } | |
| 228 | |
| 229 cdm::Buffer* OutputBufferImpl::buffer() const { | |
| 230 return buffer_; | |
| 231 } | |
| 232 | |
| 233 void OutputBufferImpl::set_timestamp(int64_t timestamp) { | |
| 234 timestamp_ = timestamp; | |
| 235 } | |
| 236 | |
| 237 int64_t OutputBufferImpl::timestamp() const { | |
| 238 return timestamp_; | |
| 239 } | |
| 240 | |
| 58 // A wrapper class for abstracting away PPAPI interaction and threading for a | 241 // A wrapper class for abstracting away PPAPI interaction and threading for a |
| 59 // Content Decryption Module (CDM). | 242 // Content Decryption Module (CDM). |
| 60 class CdmWrapper : public pp::Instance, | 243 class CdmWrapper : public pp::Instance, |
| 61 public pp::ContentDecryptor_Private { | 244 public pp::ContentDecryptor_Private { |
| 62 public: | 245 public: |
| 63 CdmWrapper(PP_Instance instance, pp::Module* module); | 246 CdmWrapper(PP_Instance instance, pp::Module* module); |
| 64 virtual ~CdmWrapper(); | 247 virtual ~CdmWrapper(); |
| 65 | |
| 66 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { | 248 virtual bool Init(uint32_t argc, const char* argn[], const char* argv[]) { |
| 67 return true; | 249 return true; |
| 68 } | 250 } |
| 69 | 251 |
| 70 // PPP_ContentDecryptor_Private methods | 252 // PPP_ContentDecryptor_Private methods |
| 71 // Note: As per comments in PPP_ContentDecryptor_Private, these calls should | 253 // 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 | 254 // 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 | 255 // true otherwise. Once the call reaches the CDM, the call result/status |
| 74 // should be reported through the PPB_ContentDecryptor_Private interface. | 256 // should be reported through the PPB_ContentDecryptor_Private interface. |
| 75 virtual void GenerateKeyRequest(const std::string& key_system, | 257 virtual void GenerateKeyRequest(const std::string& key_system, |
| 76 pp::VarArrayBuffer init_data) OVERRIDE; | 258 pp::VarArrayBuffer init_data) OVERRIDE; |
| 77 virtual void AddKey(const std::string& session_id, | 259 virtual void AddKey(const std::string& session_id, |
| 78 pp::VarArrayBuffer key, | 260 pp::VarArrayBuffer key, |
| 79 pp::VarArrayBuffer init_data) OVERRIDE; | 261 pp::VarArrayBuffer init_data) OVERRIDE; |
| 80 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; | 262 virtual void CancelKeyRequest(const std::string& session_id) OVERRIDE; |
| 81 virtual void Decrypt( | 263 virtual void Decrypt( |
| 82 pp::Buffer_Dev encrypted_buffer, | 264 pp::Buffer_Dev encrypted_buffer, |
| 83 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 265 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
| 84 virtual void DecryptAndDecode( | 266 virtual void DecryptAndDecode( |
| 85 pp::Buffer_Dev encrypted_buffer, | 267 pp::Buffer_Dev encrypted_buffer, |
| 86 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; | 268 const PP_EncryptedBlockInfo& encrypted_block_info) OVERRIDE; |
| 87 | 269 |
| 88 private: | 270 private: |
| 89 // Creates a PP_Resource containing a PPB_Buffer_Impl, copies |data| into the | 271 typedef std::tr1::shared_ptr<KeyMessageImpl> SharedKeyMessage; |
| 90 // buffer resource, and returns it. Returns a an invalid PP_Resource with an | 272 typedef std::tr1::shared_ptr<OutputBufferImpl> SharedOutputBuffer; |
| 91 // ID of 0 on failure. Upon success, the returned Buffer resource has a | |
| 92 // reference count of 1. | |
| 93 pp::Buffer_Dev MakeBufferResource(const uint8_t* data, uint32_t data_size); | |
| 94 | 273 |
| 95 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to | 274 // <code>PPB_ContentDecryptor_Private</code> dispatchers. These are passed to |
| 96 // <code>callback_factory_</code> to ensure that calls into | 275 // <code>callback_factory_</code> to ensure that calls into |
| 97 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. | 276 // <code>PPP_ContentDecryptor_Private</code> are asynchronous. |
| 98 void KeyAdded(int32_t result, const std::string& session_id); | 277 void KeyAdded(int32_t result, const std::string& session_id); |
| 99 void KeyMessage(int32_t result, cdm::KeyMessage& key_message); | 278 void KeyMessage(int32_t result, SharedKeyMessage& message); |
| 100 void KeyError(int32_t result, const std::string& session_id); | 279 void KeyError(int32_t result, const std::string& session_id); |
| 101 void DeliverBlock(int32_t result, | 280 void DeliverBlock(int32_t result, |
| 102 const cdm::Status& status, | 281 const cdm::Status& status, |
| 103 cdm::OutputBuffer& output_buffer, | 282 SharedOutputBuffer& output_buffer, |
| 104 const PP_DecryptTrackingInfo& tracking_info); | 283 const PP_DecryptTrackingInfo& tracking_info); |
| 105 | 284 |
| 285 PpbBufferAllocator allocator_; | |
| 106 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; | 286 pp::CompletionCallbackFactory<CdmWrapper> callback_factory_; |
| 107 cdm::ContentDecryptionModule* cdm_; | 287 cdm::ContentDecryptionModule* cdm_; |
| 108 std::string key_system_; | 288 std::string key_system_; |
| 109 }; | 289 }; |
| 110 | 290 |
| 291 PpbBufferAllocator::PpbBufferAllocator(pp::Instance* instance) | |
| 292 : instance_(instance) { | |
| 293 } | |
| 294 | |
| 295 PpbBufferAllocator::~PpbBufferAllocator() { | |
| 296 } | |
| 297 | |
| 298 cdm::Buffer* PpbBufferAllocator::Allocate(int32_t size) { | |
| 299 PP_DCHECK(size > 0); | |
| 300 | |
| 301 pp::Buffer_Dev buffer(instance_, size); | |
| 302 if (buffer.is_null()) | |
| 303 return NULL; | |
| 304 | |
| 305 return new PpbBuffer(buffer); | |
| 306 } | |
| 307 | |
| 308 void PpbBufferAllocator::Release(const cdm::Buffer* buffer) { | |
| 309 delete buffer; | |
| 310 } | |
| 311 | |
| 111 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) | 312 CdmWrapper::CdmWrapper(PP_Instance instance, pp::Module* module) |
| 112 : pp::Instance(instance), | 313 : pp::Instance(instance), |
| 113 pp::ContentDecryptor_Private(this), | 314 pp::ContentDecryptor_Private(this), |
| 315 allocator_(this), | |
| 114 cdm_(NULL) { | 316 cdm_(NULL) { |
| 115 callback_factory_.Initialize(this); | 317 callback_factory_.Initialize(this); |
| 116 } | 318 } |
| 117 | 319 |
| 118 CdmWrapper::~CdmWrapper() { | 320 CdmWrapper::~CdmWrapper() { |
| 119 if (cdm_) | 321 if (cdm_) |
| 120 DestroyCdmInstance(cdm_); | 322 DestroyCdmInstance(cdm_); |
| 121 } | 323 } |
| 122 | 324 |
| 123 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, | 325 void CdmWrapper::GenerateKeyRequest(const std::string& key_system, |
| 124 pp::VarArrayBuffer init_data) { | 326 pp::VarArrayBuffer init_data) { |
| 125 PP_DCHECK(!key_system.empty()); | 327 PP_DCHECK(!key_system.empty()); |
| 126 | 328 |
| 127 if (!cdm_) { | 329 if (!cdm_) { |
| 128 cdm_ = CreateCdmInstance(); | 330 cdm_ = CreateCdmInstance(&allocator_); |
| 129 if (!cdm_) | 331 if (!cdm_) |
| 130 return; | 332 return; |
| 131 } | 333 } |
| 132 | 334 |
| 133 cdm::KeyMessage key_request; | 335 SharedKeyMessage key_request(new KeyMessageImpl(&allocator_)); |
| 134 cdm::Status status = cdm_->GenerateKeyRequest( | 336 cdm::Status status = cdm_->GenerateKeyRequest( |
| 135 reinterpret_cast<const uint8_t*>(init_data.Map()), | 337 reinterpret_cast<const uint8_t*>(init_data.Map()), |
| 136 init_data.ByteLength(), | 338 init_data.ByteLength(), |
| 137 &key_request); | 339 key_request.get()); |
| 138 | 340 |
| 139 if (status != cdm::kSuccess || | 341 if (status != cdm::kSuccess || |
| 140 !key_request.message || | 342 !key_request->message() || |
| 141 key_request.message_size == 0) { | 343 key_request->message()->size() == 0) { |
| 142 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, | 344 CallOnMain(callback_factory_.NewCallback(&CdmWrapper::KeyError, |
| 143 std::string())); | 345 std::string())); |
| 144 return; | 346 return; |
| 145 } | 347 } |
| 146 | 348 |
| 147 // TODO(xhwang): Remove unnecessary CallOnMain calls here and below once we | 349 // TODO(xhwang): Remove unnecessary CallOnMain calls here and below once we |
| 148 // only support out-of-process. | 350 // only support out-of-process. |
| 149 // If running out-of-process, PPB calls will always behave asynchronously | 351 // 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, | 352 // 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, | 353 // we don't need to use CallOnMain to help us call PPB call on main thread, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 subsamples.push_back(cdm::SubsampleEntry( | 419 subsamples.push_back(cdm::SubsampleEntry( |
| 218 encrypted_block_info.subsamples[i].clear_bytes, | 420 encrypted_block_info.subsamples[i].clear_bytes, |
| 219 encrypted_block_info.subsamples[i].cipher_bytes)); | 421 encrypted_block_info.subsamples[i].cipher_bytes)); |
| 220 } | 422 } |
| 221 | 423 |
| 222 input_buffer.subsamples = &subsamples[0]; | 424 input_buffer.subsamples = &subsamples[0]; |
| 223 } | 425 } |
| 224 | 426 |
| 225 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; | 427 input_buffer.timestamp = encrypted_block_info.tracking_info.timestamp; |
| 226 | 428 |
| 227 cdm::OutputBuffer output_buffer; | 429 SharedOutputBuffer output_buffer(new OutputBufferImpl(&allocator_)); |
| 228 cdm::Status status = cdm_->Decrypt(input_buffer, &output_buffer); | 430 cdm::Status status = cdm_->Decrypt(input_buffer, output_buffer.get()); |
| 431 PP_DCHECK(status == cdm::kSuccess); | |
|
ddorwin
2012/09/17 21:19:23
Handle errors including invalid buffer - similar t
Tom Finegan
2012/09/18 01:08:02
I added a PP_DCHECK(output_buffer->buffer()). Shou
ddorwin
2012/09/18 01:26:08
Yes.
| |
| 229 | 432 |
| 230 CallOnMain(callback_factory_.NewCallback( | 433 CallOnMain(callback_factory_.NewCallback( |
| 231 &CdmWrapper::DeliverBlock, | 434 &CdmWrapper::DeliverBlock, |
| 232 status, | 435 status, |
| 233 output_buffer, | 436 output_buffer, |
| 234 encrypted_block_info.tracking_info)); | 437 encrypted_block_info.tracking_info)); |
| 235 } | 438 } |
| 236 | 439 |
| 237 void CdmWrapper::DecryptAndDecode( | 440 void CdmWrapper::DecryptAndDecode( |
| 238 pp::Buffer_Dev encrypted_buffer, | 441 pp::Buffer_Dev encrypted_buffer, |
| 239 const PP_EncryptedBlockInfo& encrypted_block_info) { | 442 const PP_EncryptedBlockInfo& encrypted_block_info) { |
| 240 } | 443 } |
| 241 | 444 |
| 242 pp::Buffer_Dev CdmWrapper::MakeBufferResource(const uint8_t* data, | |
| 243 uint32_t data_size) { | |
| 244 if (!data || !data_size) | |
| 245 return pp::Buffer_Dev(); | |
| 246 | |
| 247 pp::Buffer_Dev buffer(this, data_size); | |
| 248 if (!buffer.data()) | |
| 249 return pp::Buffer_Dev(); | |
| 250 | |
| 251 memcpy(buffer.data(), data, data_size); | |
| 252 return buffer; | |
| 253 } | |
| 254 | |
| 255 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) { | 445 void CdmWrapper::KeyAdded(int32_t result, const std::string& session_id) { |
| 256 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id); | 446 pp::ContentDecryptor_Private::KeyAdded(key_system_, session_id); |
| 257 } | 447 } |
| 258 | 448 |
| 259 void CdmWrapper::KeyMessage(int32_t result, | 449 void CdmWrapper::KeyMessage(int32_t result, |
| 260 cdm::KeyMessage& key_message) { | 450 SharedKeyMessage& key_message) { |
| 261 pp::Buffer_Dev message_buffer(MakeBufferResource(key_message.message, | 451 pp::Buffer_Dev message_buffer = |
| 262 key_message.message_size)); | 452 static_cast<const PpbBuffer*>(key_message->message())->buffer_dev(); |
| 263 pp::ContentDecryptor_Private::KeyMessage( | 453 pp::ContentDecryptor_Private::KeyMessage( |
| 264 key_system_, | 454 key_system_, |
| 265 std::string(key_message.session_id, key_message.session_id_size), | 455 std::string(key_message->session_id(), |
|
ddorwin
2012/09/17 21:19:23
SharedKeyMessage can use the Impl type. In that ca
Tom Finegan
2012/09/18 01:08:02
Done.
| |
| 456 key_message->session_id_length()), | |
| 266 message_buffer, | 457 message_buffer, |
| 267 std::string(key_message.default_url, key_message.default_url_size)); | 458 std::string(key_message->default_url(), |
| 268 | 459 key_message->default_url_length())); |
| 269 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated | |
| 270 // in another shared object. | |
| 271 delete [] key_message.session_id; | |
| 272 key_message.session_id = NULL; | |
| 273 delete [] key_message.message; | |
| 274 key_message.message = NULL; | |
| 275 delete [] key_message.default_url; | |
| 276 key_message.default_url = NULL; | |
| 277 } | 460 } |
| 278 | 461 |
| 279 // TODO(xhwang): Support MediaKeyError (see spec: http://goo.gl/rbdnR) in CDM | 462 // TODO(xhwang): Support MediaKeyError (see spec: http://goo.gl/rbdnR) in CDM |
| 280 // interface and in this function. | 463 // interface and in this function. |
| 281 void CdmWrapper::KeyError(int32_t result, const std::string& session_id) { | 464 void CdmWrapper::KeyError(int32_t result, const std::string& session_id) { |
| 282 pp::ContentDecryptor_Private::KeyError(key_system_, | 465 pp::ContentDecryptor_Private::KeyError(key_system_, |
| 283 session_id, | 466 session_id, |
| 284 kUnknownError, | 467 kUnknownError, |
| 285 0); | 468 0); |
| 286 } | 469 } |
| 287 | 470 |
| 288 void CdmWrapper::DeliverBlock(int32_t result, | 471 void CdmWrapper::DeliverBlock(int32_t result, |
| 289 const cdm::Status& status, | 472 const cdm::Status& status, |
| 290 cdm::OutputBuffer& output_buffer, | 473 SharedOutputBuffer& output_buffer, |
| 291 const PP_DecryptTrackingInfo& tracking_info) { | 474 const PP_DecryptTrackingInfo& tracking_info) { |
| 292 pp::Buffer_Dev decrypted_buffer(MakeBufferResource(output_buffer.data, | |
| 293 output_buffer.data_size)); | |
| 294 PP_DecryptedBlockInfo decrypted_block_info; | 475 PP_DecryptedBlockInfo decrypted_block_info; |
| 295 decrypted_block_info.tracking_info.request_id = tracking_info.request_id; | 476 decrypted_block_info.tracking_info.request_id = tracking_info.request_id; |
| 296 decrypted_block_info.tracking_info.timestamp = output_buffer.timestamp; | 477 decrypted_block_info.tracking_info.timestamp = output_buffer->timestamp(); |
| 297 | 478 |
| 298 switch (status) { | 479 switch (status) { |
| 299 case cdm::kSuccess: | 480 case cdm::kSuccess: |
| 300 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS; | 481 decrypted_block_info.result = PP_DECRYPTRESULT_SUCCESS; |
| 301 break; | 482 break; |
| 302 case cdm::kNoKey: | 483 case cdm::kNoKey: |
| 303 decrypted_block_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY; | 484 decrypted_block_info.result = PP_DECRYPTRESULT_DECRYPT_NOKEY; |
| 304 break; | 485 break; |
| 305 default: | 486 default: |
| 306 decrypted_block_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR; | 487 decrypted_block_info.result = PP_DECRYPTRESULT_DECRYPT_ERROR; |
| 307 } | 488 } |
| 308 | 489 |
| 309 pp::ContentDecryptor_Private::DeliverBlock(decrypted_buffer, | 490 pp::ContentDecryptor_Private::DeliverBlock( |
| 310 decrypted_block_info); | 491 static_cast<PpbBuffer*>(output_buffer->buffer())->buffer_dev(), |
| 311 | 492 decrypted_block_info); |
| 312 // TODO(xhwang): Fix this. This is not always safe as the memory is allocated | |
| 313 // in another shared object. | |
| 314 delete [] output_buffer.data; | |
| 315 output_buffer.data = NULL; | |
| 316 } | 493 } |
| 317 | 494 |
| 318 // This object is the global object representing this plugin library as long | 495 // This object is the global object representing this plugin library as long |
| 319 // as it is loaded. | 496 // as it is loaded. |
| 320 class MyModule : public pp::Module { | 497 class CdmWrapperModule : public pp::Module { |
| 321 public: | 498 public: |
| 322 MyModule() : pp::Module() {} | 499 CdmWrapperModule() : pp::Module() {} |
| 323 virtual ~MyModule() {} | 500 virtual ~CdmWrapperModule() {} |
| 324 | 501 |
| 325 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 502 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
| 326 return new CdmWrapper(instance, this); | 503 return new CdmWrapper(instance, this); |
| 327 } | 504 } |
| 328 }; | 505 }; |
| 329 | 506 |
| 330 } // namespace webkit_media | 507 } // namespace webkit_media |
| 331 | 508 |
| 332 namespace pp { | 509 namespace pp { |
| 333 | 510 |
| 334 // Factory function for your specialization of the Module object. | 511 // Factory function for your specialization of the Module object. |
| 335 Module* CreateModule() { | 512 Module* CreateModule() { |
| 336 return new webkit_media::MyModule(); | 513 return new webkit_media::CdmWrapperModule(); |
| 337 } | 514 } |
| 338 | 515 |
| 339 } // namespace pp | 516 } // namespace pp |
| OLD | NEW |