Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Unified Diff: media/cdm/ppapi/cdm_helpers.cc

Issue 374353004: Encrypted Media: Fix PpbBuffer::Destroy(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/cdm/ppapi/cdm_helpers.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cdm/ppapi/cdm_helpers.cc
diff --git a/media/cdm/ppapi/cdm_helpers.cc b/media/cdm/ppapi/cdm_helpers.cc
index 36b95021f8cc21abb46292be1beac191dbd1f441..62f93a009dd4ef37a1f1e6b6ed9f3e9364f99481 100644
--- a/media/cdm/ppapi/cdm_helpers.cc
+++ b/media/cdm/ppapi/cdm_helpers.cc
@@ -4,6 +4,7 @@
#include "media/cdm/ppapi/cdm_helpers.h"
+#include <algorithm>
#include <utility>
#include "base/basictypes.h"
@@ -20,6 +21,61 @@
namespace media {
+// static
+PpbBuffer* PpbBuffer::Create(const pp::Buffer_Dev& buffer,
+ uint32_t buffer_id,
+ PpbBufferAllocator* allocator) {
+ PP_DCHECK(buffer.data());
+ PP_DCHECK(buffer.size());
+ PP_DCHECK(buffer_id);
+ PP_DCHECK(allocator);
+ return new PpbBuffer(buffer, buffer_id, allocator);
+}
+
+void PpbBuffer::Destroy() {
+ delete this;
+}
+
+uint32_t PpbBuffer::Capacity() const {
+ return buffer_.size();
+}
+
+uint8_t* PpbBuffer::Data() {
+ return static_cast<uint8_t*>(buffer_.data());
+}
+
+void PpbBuffer::SetSize(uint32_t size) {
+ PP_DCHECK(size <= Capacity());
+ if (size > Capacity()) {
+ size_ = 0;
+ return;
+ }
+
+ size_ = size;
+}
+
+pp::Buffer_Dev PpbBuffer::TakeBuffer() {
+ PP_DCHECK(!buffer_.is_null());
+ pp::Buffer_Dev buffer;
+ std::swap(buffer, buffer_);
+ buffer_id_ = 0;
+ size_ = 0;
+ return buffer;
+}
+
+PpbBuffer::PpbBuffer(pp::Buffer_Dev buffer,
+ uint32_t buffer_id,
+ PpbBufferAllocator* allocator)
+ : buffer_(buffer), buffer_id_(buffer_id), size_(0), allocator_(allocator) {
+}
+
+PpbBuffer::~PpbBuffer() {
+ PP_DCHECK(!buffer_id_ == buffer_.is_null());
+ // If still owning the |buffer_|, release it in the |allocator_|.
+ if (buffer_id_)
+ allocator_->Release(buffer_id_);
+}
+
cdm::Buffer* PpbBufferAllocator::Allocate(uint32_t capacity) {
PP_DCHECK(pp::Module::Get()->core()->IsMainThread());
@@ -46,7 +102,7 @@ cdm::Buffer* PpbBufferAllocator::Allocate(uint32_t capacity) {
allocated_buffers_.insert(std::make_pair(buffer_id, buffer));
- return PpbBuffer::Create(buffer, buffer_id);
+ return PpbBuffer::Create(buffer, buffer_id, this);
}
void PpbBufferAllocator::Release(uint32_t buffer_id) {
« no previous file with comments | « media/cdm/ppapi/cdm_helpers.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698