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

Unified Diff: media/cdm/simple_cdm_buffer_allocator.cc

Issue 1673383002: Add allocator interface for use by cdm_adapter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Simple classes Created 4 years, 10 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
Index: media/cdm/simple_cdm_buffer_allocator.cc
diff --git a/media/cdm/simple_cdm_buffer_allocator.cc b/media/cdm/simple_cdm_buffer_allocator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9653f93d0355ac5e4b9080dfc68c1483efd8705
--- /dev/null
+++ b/media/cdm/simple_cdm_buffer_allocator.cc
@@ -0,0 +1,66 @@
+// 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_buffer_allocator.h"
+
+#include "media/base/video_frame.h"
+#include "media/cdm/cdm_video_frame.h"
+#include "media/cdm/simple_cdm_buffer.h"
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace media {
+
+class SimpleCdmVideoFrame : public CdmVideoFrame {
+ public:
+ SimpleCdmVideoFrame() {}
+ ~SimpleCdmVideoFrame() final {}
+
+ // CdmVideoFrame implementation.
+ scoped_refptr<media::VideoFrame> CreateVideoFrame(
+ gfx::Size natural_size) override {
+ SimpleCdmBuffer* buffer = static_cast<SimpleCdmBuffer*>(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(CdmVideoFrame::kYPlane), Stride(CdmVideoFrame::kUPlane),
+ Stride(CdmVideoFrame::kVPlane),
+ buffer->Data() + PlaneOffset(CdmVideoFrame::kYPlane),
+ buffer->Data() + PlaneOffset(CdmVideoFrame::kUPlane),
+ buffer->Data() + PlaneOffset(CdmVideoFrame::kVPlane),
+ base::TimeDelta::FromMicroseconds(Timestamp()));
+
+ // The FrameBuffer needs to remain around until |frame| is destroyed.
+ frame->AddDestructionObserver(
+ base::Bind(&SimpleCdmBuffer::Destroy, base::Unretained(buffer)));
+ return frame;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SimpleCdmVideoFrame);
+};
+
+SimpleCdmBufferAllocator::SimpleCdmBufferAllocator() {}
+
+SimpleCdmBufferAllocator::~SimpleCdmBufferAllocator() {}
+
+scoped_refptr<CdmBuffer> SimpleCdmBufferAllocator::Allocate(uint32_t capacity) {
+ if (!capacity)
+ return nullptr;
+
+ return SimpleCdmBuffer::Create(this, capacity);
+}
+
+void SimpleCdmBufferAllocator::Release(scoped_refptr<CdmBuffer> buffer) {
+ // No caching of memory in this simple implementation, so |buffer| is
+ // simply released.
+}
+
+scoped_ptr<CdmVideoFrame> SimpleCdmBufferAllocator::CreateCdmVideoFrame() {
+ scoped_ptr<CdmVideoFrame> frame(new SimpleCdmVideoFrame());
+ return frame;
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698