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.
5 #include "media/capture/video/linux/v4l2_capture_delegate_single_plane.h"
11 scoped_refptr
<V4L2CaptureDelegate::BufferTracker
>
12 V4L2CaptureDelegateSinglePlane::CreateBufferTracker() const {
13 return make_scoped_refptr(new BufferTrackerSPlane());
16 bool V4L2CaptureDelegateSinglePlane::FillV4L2Format(
20 uint32_t pixelformat_fourcc
) const {
21 format
->fmt
.pix
.width
= width
;
22 format
->fmt
.pix
.height
= height
;
23 format
->fmt
.pix
.pixelformat
= pixelformat_fourcc
;
27 void V4L2CaptureDelegateSinglePlane::FinishFillingV4L2Buffer(
28 v4l2_buffer
* buffer
) const {
29 buffer
->type
= V4L2_BUF_TYPE_VIDEO_CAPTURE
;
32 void V4L2CaptureDelegateSinglePlane::SetPayloadSize(
33 const scoped_refptr
<BufferTracker
>& buffer_tracker
,
34 const v4l2_buffer
& buffer
) const {
35 buffer_tracker
->SetPlanePayloadSize(0, buffer
.bytesused
);
38 void V4L2CaptureDelegateSinglePlane::SendBuffer(
39 const scoped_refptr
<BufferTracker
>& buffer_tracker
,
40 const v4l2_format
& format
) const {
41 client()->OnIncomingCapturedData(
42 buffer_tracker
->GetPlaneStart(0), buffer_tracker
->GetPlanePayloadSize(0),
43 capture_format(), rotation(), base::TimeTicks::Now());
46 bool V4L2CaptureDelegateSinglePlane::BufferTrackerSPlane::Init(
48 const v4l2_buffer
& buffer
) {
49 // Some devices require mmap() to be called with both READ and WRITE.
50 // See http://crbug.com/178582.
51 void* const start
= mmap(NULL
, buffer
.length
, PROT_READ
| PROT_WRITE
,
52 MAP_SHARED
, fd
, buffer
.m
.offset
);
53 if (start
== MAP_FAILED
) {
54 DLOG(ERROR
) << "Error mmap()ing a V4L2 buffer into userspace";
57 AddMmapedPlane(static_cast<uint8_t*>(start
), buffer
.length
);