OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "media/capture/service/mojo_video_frame.h" |
| 6 |
| 7 #include "ui/gfx/geometry/rect.h" |
| 8 #include "ui/gfx/geometry/size.h" |
| 9 |
| 10 namespace media { |
| 11 |
| 12 // static |
| 13 scoped_refptr<MojoVideoFrame> MojoVideoFrame::CreateMojoVideoFrame( |
| 14 const gfx::Size& dimensions, |
| 15 base::TimeDelta timestamp) { |
| 16 scoped_refptr<MojoVideoFrame> frame = |
| 17 new MojoVideoFrame(dimensions, timestamp); |
| 18 return frame->Init() ? frame : nullptr; |
| 19 } |
| 20 |
| 21 MojoVideoFrame::MojoVideoFrame(const gfx::Size& dimensions, |
| 22 base::TimeDelta timestamp) |
| 23 : VideoFrame(media::PIXEL_FORMAT_I420, |
| 24 STORAGE_UNOWNED_MEMORY, |
| 25 dimensions, |
| 26 gfx::Rect(dimensions), |
| 27 dimensions, |
| 28 timestamp), |
| 29 shared_buffer_size_( |
| 30 media::VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, |
| 31 dimensions)), |
| 32 shared_buffer_(shared_buffer_size_) { |
| 33 DCHECK(shared_buffer_size_ > 0); |
| 34 DCHECK(shared_buffer_.handle.is_valid()); |
| 35 } |
| 36 |
| 37 bool MojoVideoFrame::Init() { |
| 38 CHECK_EQ(format(), media::PIXEL_FORMAT_I420); |
| 39 // Map our |shared_buffer_| and plug the pointers into |data_|. |
| 40 // TODO(mcasas): This step usually needs alignment, e.g. base::AlignedAlloc() |
| 41 void* memory = nullptr; |
| 42 const MojoResult rv = |
| 43 mojo::MapBuffer(shared_buffer_.handle.get(), 0 /* offset */, |
| 44 shared_buffer_size_, &memory, 0 /* flags */); |
| 45 if (rv != MOJO_RESULT_OK || !memory) |
| 46 return false; |
| 47 |
| 48 const auto dimensions = coded_size(); |
| 49 |
| 50 set_stride(kYPlane, dimensions.width()); |
| 51 set_stride(kUPlane, dimensions.width() / 2); |
| 52 set_stride(kVPlane, dimensions.width() / 2); |
| 53 set_data(kYPlane, static_cast<uint8_t*>(memory)); |
| 54 set_data(kUPlane, static_cast<uint8_t*>(memory) + dimensions.GetArea()); |
| 55 set_data(kVPlane, |
| 56 static_cast<uint8_t*>(memory) + (dimensions.GetArea() * 5 / 4)); |
| 57 |
| 58 return true; |
| 59 }; |
| 60 |
| 61 MojoVideoFrame::~MojoVideoFrame() {} |
| 62 |
| 63 } // namespace media |
OLD | NEW |