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

Unified Diff: media/mojo/services/mojo_video_frame.cc

Issue 1704273002: Add MojoVideoFrame (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« media/mojo/services/BUILD.gn ('K') | « media/mojo/services/mojo_video_frame.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/mojo/services/mojo_video_frame.cc
diff --git a/media/mojo/services/mojo_video_frame.cc b/media/mojo/services/mojo_video_frame.cc
new file mode 100644
index 0000000000000000000000000000000000000000..05902b9bf06f4fc6b08cbad14aa586f91b43f065
--- /dev/null
+++ b/media/mojo/services/mojo_video_frame.cc
@@ -0,0 +1,96 @@
+// 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/mojo/services/mojo_video_frame.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "build/build_config.h"
+
+namespace media {
+
+// static
+scoped_refptr<VideoFrame> MojoVideoFrame::Create(
+ VideoPixelFormat format,
+ const gfx::Size& coded_size,
+ const gfx::Rect& visible_rect,
+ const gfx::Size& natural_size,
+ int32_t y_stride,
+ int32_t u_stride,
+ int32_t v_stride,
+ mojo::ScopedSharedBufferHandle handle,
+ size_t data_size,
+ size_t y_offset,
+ size_t u_offset,
+ size_t v_offset,
+ base::TimeDelta timestamp) {
+ const StorageType storage = STORAGE_MOJO_SHARED_MEMORY;
+ if (!IsValidConfig(format, storage, coded_size, visible_rect, natural_size)) {
+ LOG(DFATAL) << __FUNCTION__ << " Invalid config."
+ << ConfigToString(format, storage, coded_size, visible_rect,
+ natural_size);
+ return nullptr;
+ }
+
+ scoped_refptr<MojoVideoFrame> frame(new MojoVideoFrame(
+ format, storage, coded_size, visible_rect, natural_size, timestamp));
+
+ MojoResult result = mojo::DuplicateBuffer(handle.get(), nullptr,
+ &frame->mojo_shared_memory_handle_);
+ if (result != MOJO_RESULT_OK)
+ return nullptr;
+
+ uint8_t* frame_data;
+ result = mojo::MapBuffer(frame->mojo_shared_memory_handle_.get(), 0,
+ data_size, reinterpret_cast<void**>(&frame_data),
+ MOJO_MAP_BUFFER_FLAG_NONE);
+ if (result != MOJO_RESULT_OK)
+ return nullptr;
+
+ frame->mojo_shared_memory_size_ = data_size;
+ frame->strides_[kYPlane] = y_stride;
+ frame->strides_[kUPlane] = u_stride;
+ frame->strides_[kVPlane] = v_stride;
+ frame->offsets_[kYPlane] = y_offset;
+ frame->offsets_[kUPlane] = u_offset;
+ frame->offsets_[kVPlane] = v_offset;
+ frame->data_[kYPlane] = frame_data + y_offset;
+ frame->data_[kUPlane] = frame_data + u_offset;
+ frame->data_[kVPlane] = frame_data + v_offset;
+ return frame;
+}
+
+MojoVideoFrame::MojoVideoFrame(VideoPixelFormat format,
+ StorageType storage_type,
+ const gfx::Size& coded_size,
+ const gfx::Rect& visible_rect,
+ const gfx::Size& natural_size,
+ base::TimeDelta timestamp)
+ : VideoFrame(format,
+ storage_type,
+ coded_size,
+ visible_rect,
+ natural_size,
+ timestamp) {}
+
+MojoVideoFrame::~MojoVideoFrame() {}
+
+mojo::SharedBufferHandle MojoVideoFrame::mojo_shared_memory_handle() const {
+ DCHECK_EQ(storage_type_, STORAGE_MOJO_SHARED_MEMORY);
+ DCHECK(mojo_shared_memory_handle_.is_valid());
+ return mojo_shared_memory_handle_.get();
+}
+
+size_t MojoVideoFrame::mojo_shared_memory_size() const {
+ DCHECK_EQ(storage_type_, STORAGE_MOJO_SHARED_MEMORY);
+ DCHECK(mojo_shared_memory_handle_.is_valid());
+ return mojo_shared_memory_size_;
+}
+
+size_t MojoVideoFrame::plane_offset(size_t plane) const {
+ DCHECK(IsValidPlane(plane, format_));
+ return offsets_[plane];
+}
+
+} // namespace media
« media/mojo/services/BUILD.gn ('K') | « media/mojo/services/mojo_video_frame.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698