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 |