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