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

Unified Diff: media/cdm/simple_cdm_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: add MEDIA_CDM_EXPORT for Windows 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
« no previous file with comments | « media/cdm/simple_cdm_allocator.h ('k') | media/cdm/simple_cdm_allocator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/cdm/simple_cdm_allocator.cc
diff --git a/media/cdm/simple_cdm_allocator.cc b/media/cdm/simple_cdm_allocator.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9c3a46b8c1f4ea352111538622171c101d79eeda
--- /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
« no previous file with comments | « media/cdm/simple_cdm_allocator.h ('k') | media/cdm/simple_cdm_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698