diff options
author | tomfinegan@chromium.org <tomfinegan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-18 19:53:01 +0000 |
---|---|---|
committer | tomfinegan@chromium.org <tomfinegan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-09-18 19:53:01 +0000 |
commit | 9264e1506e8717104f19dd70f38d084e72816c2b (patch) | |
tree | 818083a975a37a7c119b2d7dc240c4b4718d6170 /webkit/media/crypto/ppapi/clear_key_cdm.cc | |
parent | a769b6cc414cf4c5b49936282939fded59648650 (diff) | |
download | chromium_src-9264e1506e8717104f19dd70f38d084e72816c2b.zip chromium_src-9264e1506e8717104f19dd70f38d084e72816c2b.tar.gz chromium_src-9264e1506e8717104f19dd70f38d084e72816c2b.tar.bz2 |
Add CDM allocator interface.
This allows CDMs to allocate shared memory while hiding the
ppapi implementation details from the CDM. It also removes
one extra memcpy from the Decrypt path.
BUG=138139
TEST=none
Review URL: https://chromiumcodereview.appspot.com/10914028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@157406 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/media/crypto/ppapi/clear_key_cdm.cc')
-rw-r--r-- | webkit/media/crypto/ppapi/clear_key_cdm.cc | 45 |
1 files changed, 29 insertions, 16 deletions
diff --git a/webkit/media/crypto/ppapi/clear_key_cdm.cc b/webkit/media/crypto/ppapi/clear_key_cdm.cc index ad2d739..b04b614 100644 --- a/webkit/media/crypto/ppapi/clear_key_cdm.cc +++ b/webkit/media/crypto/ppapi/clear_key_cdm.cc @@ -15,11 +15,12 @@ static const char kClearKeyCdmVersion[] = "0.1.0.0"; static scoped_refptr<media::DecoderBuffer> CopyDecoderBufferFrom( const cdm::InputBuffer& input_buffer) { + // TODO(tomfinegan): Get rid of this copy. scoped_refptr<media::DecoderBuffer> output_buffer = media::DecoderBuffer::CopyFrom(input_buffer.data, input_buffer.data_size); std::vector<media::SubsampleEntry> subsamples; - for (uint32_t i = 0; i < input_buffer.num_subsamples; ++i) { + for (int32_t i = 0; i < input_buffer.num_subsamples; ++i) { media::SubsampleEntry subsample; subsample.clear_bytes = input_buffer.subsamples[i].clear_bytes; subsample.cypher_bytes = input_buffer.subsamples[i].cipher_bytes; @@ -61,8 +62,8 @@ static Type* AllocateAndCopy(const Type* data, int size) { return copy; } -cdm::ContentDecryptionModule* CreateCdmInstance() { - return new webkit_media::ClearKeyCdm(); +cdm::ContentDecryptionModule* CreateCdmInstance(cdm::Allocator* allocator) { + return new webkit_media::ClearKeyCdm(allocator); } void DestroyCdmInstance(cdm::ContentDecryptionModule* instance) { @@ -122,7 +123,10 @@ void ClearKeyCdm::Client::NeedKey(const std::string& key_system, NOTREACHED(); } -ClearKeyCdm::ClearKeyCdm() : decryptor_(&client_) {} +ClearKeyCdm::ClearKeyCdm(cdm::Allocator* allocator) + : decryptor_(&client_), allocator_(allocator) { + DCHECK(allocator_); +} ClearKeyCdm::~ClearKeyCdm() {} @@ -138,15 +142,20 @@ cdm::Status ClearKeyCdm::GenerateKeyRequest(const uint8_t* init_data, return cdm::kError; DCHECK(key_request); - key_request->session_id = AllocateAndCopy(client_.session_id().data(), - client_.session_id().size()); - key_request->session_id_size = client_.session_id().size(); - key_request->message = AllocateAndCopy(client_.key_message(), - client_.key_message_length()); - key_request->message_size = client_.key_message_length(); - key_request->default_url = AllocateAndCopy(client_.default_url().data(), - client_.default_url().size()); - key_request->default_url_size = client_.default_url().size(); + key_request->set_session_id(client_.session_id().data(), + client_.session_id().size()); + + // TODO(tomfinegan): Get rid of this copy. + key_request->set_message(allocator_->Allocate(client_.key_message_length())); + + DCHECK(key_request->message()); + DCHECK_EQ(key_request->message()->size(), client_.key_message_length()); + memcpy(reinterpret_cast<void*>(key_request->message()->buffer()), + reinterpret_cast<const void*>(client_.key_message()), + client_.key_message_length()); + + key_request->set_default_url(client_.default_url().data(), + client_.default_url().size()); return cdm::kSuccess; } @@ -208,9 +217,13 @@ cdm::Status ClearKeyCdm::Decrypt( DCHECK(buffer); int data_size = buffer->GetDataSize(); - decrypted_buffer->data = AllocateAndCopy(buffer->GetData(), data_size); - decrypted_buffer->data_size = data_size; - decrypted_buffer->timestamp = buffer->GetTimestamp().InMicroseconds(); + + decrypted_buffer->set_buffer(allocator_->Allocate(data_size)); + memcpy(reinterpret_cast<void*>(decrypted_buffer->buffer()->buffer()), + buffer->GetData(), + data_size); + + decrypted_buffer->set_timestamp(buffer->GetTimestamp().InMicroseconds()); return cdm::kSuccess; } |