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