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_multi_plane.h" | |
6 | |
7 #include <sys/mman.h> | |
8 | |
9 namespace media { | |
10 | |
11 V4L2CaptureDelegateMultiPlane::V4L2CaptureDelegateMultiPlane( | |
12 const VideoCaptureDevice::Name& device_name, | |
13 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | |
14 int power_line_frequency) | |
15 : V4L2VideoCaptureDelegate(device_name, | |
16 v4l2_task_runner, | |
17 power_line_frequency) { | |
18 } | |
19 | |
20 V4L2CaptureDelegateMultiPlane::~V4L2CaptureDelegateMultiPlane() { | |
21 } | |
22 | |
23 scoped_refptr<V4L2VideoCaptureDelegate::BufferTracker> | |
24 V4L2CaptureDelegateMultiPlane::CreateBufferTracker() { | |
25 return make_scoped_refptr(new BufferTrackerMPlane()); | |
26 } | |
27 | |
28 bool V4L2CaptureDelegateMultiPlane::FillV4L2Format( | |
29 v4l2_format* format, | |
30 uint32_t width, | |
31 uint32_t height, | |
32 uint32_t pixelformat_fourcc) { | |
33 format->fmt.pix_mp.width = width; | |
34 format->fmt.pix_mp.height = height; | |
35 format->fmt.pix_mp.pixelformat = pixelformat_fourcc; | |
36 | |
37 const size_t num_v4l2_planes = | |
38 V4L2VideoCaptureDelegate::GetNumPlanesForFourCc(pixelformat_fourcc); | |
39 if (num_v4l2_planes == 0u) | |
40 return false; | |
41 DCHECK_LE(num_v4l2_planes, static_cast<size_t>(VIDEO_MAX_PLANES)); | |
42 format->fmt.pix_mp.num_planes = num_v4l2_planes; | |
43 | |
44 v4l2_planes_.resize(num_v4l2_planes); | |
45 return true; | |
46 } | |
47 | |
48 void V4L2CaptureDelegateMultiPlane::FinishFillingV4L2Buffer( | |
49 v4l2_buffer* buffer) const { | |
50 buffer->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; | |
51 buffer->length = v4l2_planes_.size(); | |
52 buffer->m.planes = const_cast<struct v4l2_plane*>(v4l2_planes_.data()); | |
Pawel Osciak
2015/03/19 07:52:43
memset to 0 please
Also, why do we need this cast?
mcasas
2015/03/19 22:57:00
Done.
Pawel Osciak
2015/03/20 00:56:06
The method should not be const?
| |
53 } | |
54 | |
55 void V4L2CaptureDelegateMultiPlane::SendBuffer( | |
56 const scoped_refptr<BufferTracker>& buffer_tracker) { | |
57 DCHECK_EQ(capture_format().pixel_format, PIXEL_FORMAT_I420); | |
58 client()->OnIncomingCapturedYuvData(buffer_tracker->GetPlaneStart(0), | |
59 buffer_tracker->GetPlaneStart(1), | |
Pawel Osciak
2015/03/19 07:52:43
This makes me nervous. I'd like to have a check in
mcasas
2015/03/19 22:57:00
Done. DCHECK is good for me, but please speak up
o
Pawel Osciak
2015/03/20 00:56:06
I'd prefer something stronger please, better than
| |
60 buffer_tracker->GetPlaneStart(2), | |
61 buffer_tracker->GetPlaneLength(0), | |
perkj_chrome
2015/03/19 20:38:17
I think this should be the stride instead of the p
mcasas
2015/03/19 22:57:00
Done.
| |
62 buffer_tracker->GetPlaneLength(1), | |
63 buffer_tracker->GetPlaneLength(2), | |
64 capture_format(), | |
65 rotation(), | |
66 base::TimeTicks::Now()); | |
67 } | |
68 | |
69 bool V4L2CaptureDelegateMultiPlane::BufferTrackerMPlane::Init( | |
70 int fd, | |
71 const v4l2_buffer& buffer) { | |
72 for (size_t p = 0; p < buffer.length; ++p) { | |
73 void* const start = | |
74 mmap(NULL, buffer.m.planes[p].length, PROT_READ | PROT_WRITE, | |
Pawel Osciak
2015/03/19 07:52:43
// Some devices require mmap() to be called with b
mcasas
2015/03/19 22:57:00
Done.
| |
75 MAP_SHARED, fd, buffer.m.planes[p].m.mem_offset); | |
76 if (start == MAP_FAILED) { | |
77 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; | |
78 return false; | |
79 } | |
80 AddMmapedPlane(start, buffer.m.planes[p].length); | |
81 DVLOG(3) << "Mmap()ed plane #" << p << " of " << GetPlaneLength(p) << "B"; | |
82 } | |
83 return true; | |
84 } | |
85 | |
86 } // namespace media | |
OLD | NEW |