summaryrefslogtreecommitdiffstats
path: root/media/cdm/simple_cdm_allocator.cc
diff options
context:
space:
mode:
authorjrummell <jrummell@chromium.org>2016-02-17 13:37:55 -0800
committerCommit bot <commit-bot@chromium.org>2016-02-17 21:40:15 +0000
commit550e1c056d4456000cb4be88676d6f5f01b9efdb (patch)
tree57c7148baf6f139b71fb56e0dbacd11fde2ad2ac /media/cdm/simple_cdm_allocator.cc
parenta07ac351c9bab9b617d617955e295b59c29941f6 (diff)
downloadchromium_src-550e1c056d4456000cb4be88676d6f5f01b9efdb.zip
chromium_src-550e1c056d4456000cb4be88676d6f5f01b9efdb.tar.gz
chromium_src-550e1c056d4456000cb4be88676d6f5f01b9efdb.tar.bz2
Add allocator interface for use by cdm_adapter
Rather than allocating a buffer directly, add CdmAllocator interface that will allocate buffers as needed. Initial implementation of CdmAllocator (SimpleCdmAllocator) simply creates a new buffer every time one is needed. There is no reuse, since it will only be used for testing purposes. CdmAllocator also has an interface to create a cdm::VideoFrame, which now has the additional ability to create a media::VideoFrame using the data returned by the CDM. BUG=510088 TEST=Updated tests pass Review URL: https://codereview.chromium.org/1673383002 Cr-Commit-Position: refs/heads/master@{#375987}
Diffstat (limited to 'media/cdm/simple_cdm_allocator.cc')
-rw-r--r--media/cdm/simple_cdm_allocator.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/media/cdm/simple_cdm_allocator.cc b/media/cdm/simple_cdm_allocator.cc
new file mode 100644
index 0000000..9c3a46b
--- /dev/null
+++ b/media/cdm/simple_cdm_allocator.cc
@@ -0,0 +1,73 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/cdm/simple_cdm_allocator.h"
+
+#include "media/base/video_frame.h"
+#include "media/cdm/cdm_helpers.h"
+#include "media/cdm/simple_cdm_buffer.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace media {
+
+namespace {
+
+class SimpleCdmVideoFrame : public VideoFrameImpl {
+ public:
+ SimpleCdmVideoFrame() {}
+ ~SimpleCdmVideoFrame() final {}
+
+ // VideoFrameImpl implementation.
+ scoped_refptr<media::VideoFrame> TransformToVideoFrame(
+ gfx::Size natural_size) final {
+ DCHECK(FrameBuffer());
+
+ cdm::Buffer* buffer = FrameBuffer();
+ gfx::Size frame_size(Size().width, Size().height);
+ scoped_refptr<media::VideoFrame> frame =
+ media::VideoFrame::WrapExternalYuvData(
+ PIXEL_FORMAT_YV12, frame_size, gfx::Rect(frame_size), natural_size,
+ Stride(kYPlane), Stride(kUPlane), Stride(kVPlane),
+ buffer->Data() + PlaneOffset(kYPlane),
+ buffer->Data() + PlaneOffset(kUPlane),
+ buffer->Data() + PlaneOffset(kVPlane),
+ base::TimeDelta::FromMicroseconds(Timestamp()));
+
+ // The FrameBuffer needs to remain around until |frame| is destroyed.
+ frame->AddDestructionObserver(
+ base::Bind(&cdm::Buffer::Destroy, base::Unretained(buffer)));
+
+ // Clear FrameBuffer so that SimpleCdmVideoFrame no longer has a reference
+ // to it.
+ SetFrameBuffer(nullptr);
+ return frame;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SimpleCdmVideoFrame);
+};
+
+} // namespace
+
+SimpleCdmAllocator::SimpleCdmAllocator() {}
+
+SimpleCdmAllocator::~SimpleCdmAllocator() {}
+
+// Creates a new SimpleCdmBuffer on every request. It does not keep track of
+// the memory allocated, so the caller is responsible for calling Destroy()
+// on the buffer when it is no longer needed.
+cdm::Buffer* SimpleCdmAllocator::CreateCdmBuffer(uint32_t capacity) {
+ if (!capacity)
+ return nullptr;
+
+ return SimpleCdmBuffer::Create(capacity);
+}
+
+// Creates a new SimpleCdmVideoFrame on every request.
+scoped_ptr<VideoFrameImpl> SimpleCdmAllocator::CreateCdmVideoFrame() {
+ return make_scoped_ptr(new SimpleCdmVideoFrame());
+}
+
+} // namespace media