OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 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/video/capture/linux/v4l2_capture_delegate_single_plane.h" |
| 6 |
| 7 #include <sys/mman.h> |
| 8 |
| 9 namespace media { |
| 10 |
| 11 scoped_refptr<V4L2VideoCaptureDelegate::BufferTracker> |
| 12 V4L2CaptureDelegateSinglePlane::CreateBufferTracker() { |
| 13 return make_scoped_refptr(new BufferTrackerSPlane()); |
| 14 } |
| 15 |
| 16 bool V4L2CaptureDelegateSinglePlane::FillV4L2Format( |
| 17 v4l2_format* format, |
| 18 uint32_t width, |
| 19 uint32_t height, |
| 20 uint32_t pixelformat_fourcc) { |
| 21 format->fmt.pix.width = width; |
| 22 format->fmt.pix.height = height; |
| 23 format->fmt.pix.pixelformat = pixelformat_fourcc; |
| 24 return true; |
| 25 } |
| 26 |
| 27 void V4L2CaptureDelegateSinglePlane::FinishFillingV4L2Buffer( |
| 28 v4l2_buffer* buffer) const { |
| 29 buffer->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 30 } |
| 31 |
| 32 void V4L2CaptureDelegateSinglePlane::SendBuffer( |
| 33 const scoped_refptr<BufferTracker>& buffer_tracker) { |
| 34 client()->OnIncomingCapturedData( |
| 35 buffer_tracker->GetPlaneStart(0), |
| 36 buffer_tracker->GetPlaneLength(0), |
| 37 capture_format(), |
| 38 rotation(), |
| 39 base::TimeTicks::Now()); |
| 40 } |
| 41 |
| 42 bool V4L2CaptureDelegateSinglePlane::BufferTrackerSPlane::Init( |
| 43 int fd, |
| 44 const v4l2_buffer& buffer) { |
| 45 // Some devices require mmap() to be called with both READ and WRITE. |
| 46 // See http://crbug.com/178582. |
| 47 void* const start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE, |
| 48 MAP_SHARED, fd, buffer.m.offset); |
| 49 if (start == MAP_FAILED) { |
| 50 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
| 51 return false; |
| 52 } |
| 53 AddMmapedPlane(start, buffer.length); |
| 54 return true; |
| 55 } |
| 56 |
| 57 } // namespace media |
OLD | NEW |