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..15b58d5c76851a244f8c00304e6afb260f79f8d9 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> |
xhwang
2014/07/10 16:42:39
This is for std::swap.
|
#include <utility> |
#include "base/basictypes.h" |
@@ -20,6 +21,62 @@ |
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::TakeBufferDev() { |
+ 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() { |
+ // If still owning the |buffer_|, release it in the |allocator_|. |
+ if (buffer_id_) { |
+ PP_DCHECK(!buffer_.is_null()); |
ddorwin
2014/07/10 21:56:14
nit: Move up and make sure !id == !is_null()
xhwang
2014/07/10 22:37:33
Done.
|
+ allocator_->Release(buffer_id_); |
xhwang
2014/07/10 16:42:39
Sorry for moving things around. The changes in thi
|
+ } |
+} |
+ |
cdm::Buffer* PpbBufferAllocator::Allocate(uint32_t capacity) { |
PP_DCHECK(pp::Module::Get()->core()->IsMainThread()); |
@@ -46,7 +103,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) { |