Chromium Code Reviews| 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 "components/video_capture/mojo_video_frame.h" | |
| 6 | |
| 7 #include "ui/gfx/geometry/rect.h" | |
| 8 #include "ui/gfx/geometry/size.h" | |
| 9 | |
| 10 namespace video_capture { | |
| 11 | |
| 12 // static | |
| 13 scoped_refptr<MojoVideoFrame> MojoVideoFrame::CreateMojoVideoFrame( | |
| 14 const gfx::Size& dimensions, | |
| 15 base::TimeDelta timestamp) { | |
| 16 return scoped_refptr<MojoVideoFrame>( | |
| 17 new MojoVideoFrame(dimensions, timestamp)); | |
| 18 } | |
| 19 | |
| 20 MojoVideoFrame::MojoVideoFrame(const gfx::Size& dimensions, | |
| 21 base::TimeDelta timestamp) | |
| 22 : VideoFrame(media::PIXEL_FORMAT_I420, | |
| 23 STORAGE_UNOWNED_MEMORY, | |
| 24 dimensions, | |
| 25 gfx::Rect(dimensions), | |
| 26 dimensions, | |
| 27 timestamp), | |
| 28 shared_buffer_size_( | |
| 29 media::VideoFrame::AllocationSize(media::PIXEL_FORMAT_I420, | |
| 30 dimensions)), | |
| 31 shared_buffer_(shared_buffer_size_) { | |
| 32 DCHECK(shared_buffer_size_ > 0); | |
| 33 DCHECK(shared_buffer_.handle.is_valid()); | |
| 34 | |
| 35 // Map our |shared_buffer_| and plug the pointers into |data_|. | |
| 36 // TODO(mcasas): This step usually needs alignment, e.g. base::AlignedAlloc() | |
| 37 void* memory = nullptr; | |
| 38 const MojoResult rv = | |
| 39 mojo::MapBuffer(shared_buffer_.handle.get(), 0 /* offset */, | |
| 40 shared_buffer_size_, &memory, 0 /* flags */); | |
| 41 DCHECK_EQ(rv, MOJO_RESULT_OK); | |
|
emircan
2016/02/16 17:45:48
We should ideally fail and notify the consumer if
mcasas
2016/02/16 23:17:21
Done.
| |
| 42 DCHECK(memory); | |
| 43 | |
| 44 set_stride(kYPlane, dimensions.width()); | |
| 45 set_stride(kUPlane, dimensions.width() / 2); | |
| 46 set_stride(kVPlane, dimensions.width() / 2); | |
| 47 set_data(kYPlane, static_cast<uint8_t*>(memory)); | |
| 48 set_data(kUPlane, static_cast<uint8_t*>(memory) + dimensions.GetArea()); | |
| 49 set_data(kVPlane, | |
| 50 static_cast<uint8_t*>(memory) + (dimensions.GetArea() * 5 / 4)); | |
|
emircan
2016/02/16 17:45:48
const int num_planes = media::VideoFrame::NumPlane
mcasas
2016/02/16 23:17:21
I don't think is needed since we only support I420
| |
| 51 }; | |
| 52 | |
| 53 MojoVideoFrame::~MojoVideoFrame() {} | |
| 54 | |
| 55 } // namespace video_capture | |
| OLD | NEW |