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

Unified Diff: media/capture/service/mojo_video_frame.cc

Issue 1699553002: Mojo Video Capture service in media/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: perkj@s and magjed@s comments 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/capture/service/mojo_video_frame.cc
diff --git a/media/capture/service/mojo_video_frame.cc b/media/capture/service/mojo_video_frame.cc
new file mode 100644
index 0000000000000000000000000000000000000000..4af89639b97d7e3dead566061476456c660cbee3
--- /dev/null
+++ b/media/capture/service/mojo_video_frame.cc
@@ -0,0 +1,63 @@
+// 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/capture/service/mojo_video_frame.h"
+
+#include "ui/gfx/geometry/rect.h"
+#include "ui/gfx/geometry/size.h"
+
+namespace media {
+
+// static
+scoped_refptr<MojoVideoFrame> MojoVideoFrame::CreateMojoVideoFrame(
+ const gfx::Size& dimensions,
+ base::TimeDelta timestamp) {
+ scoped_refptr<MojoVideoFrame> frame =
+ new MojoVideoFrame(dimensions, timestamp);
+ return frame->Init() ? frame : nullptr;
+}
+
+MojoVideoFrame::MojoVideoFrame(const gfx::Size& dimensions,
+ base::TimeDelta timestamp)
+ : VideoFrame(media::PIXEL_FORMAT_I420,
+ STORAGE_UNOWNED_MEMORY,
+ dimensions,
+ gfx::Rect(dimensions),
+ dimensions,
+ timestamp),
+ shared_buffer_size_(
+ media::VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420,
+ dimensions)),
+ shared_buffer_(shared_buffer_size_) {
+ DCHECK(shared_buffer_size_ > 0);
+ DCHECK(shared_buffer_.handle.is_valid());
+}
+
+bool MojoVideoFrame::Init() {
+ CHECK_EQ(format(), media::PIXEL_FORMAT_I420);
+ // Map our |shared_buffer_| and plug the pointers into |data_|.
+ // TODO(mcasas): This step usually needs alignment, e.g. base::AlignedAlloc()
+ void* memory = nullptr;
+ const MojoResult rv =
+ mojo::MapBuffer(shared_buffer_.handle.get(), 0 /* offset */,
+ shared_buffer_size_, &memory, 0 /* flags */);
+ if (rv != MOJO_RESULT_OK || !memory)
+ return false;
+
+ const auto dimensions = coded_size();
+
+ set_stride(kYPlane, dimensions.width());
+ set_stride(kUPlane, dimensions.width() / 2);
+ set_stride(kVPlane, dimensions.width() / 2);
+ set_data(kYPlane, static_cast<uint8_t*>(memory));
+ set_data(kUPlane, static_cast<uint8_t*>(memory) + dimensions.GetArea());
+ set_data(kVPlane,
+ static_cast<uint8_t*>(memory) + (dimensions.GetArea() * 5 / 4));
+
+ return true;
+};
+
+MojoVideoFrame::~MojoVideoFrame() {}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698