Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: media/video/capture/linux/v4l2_capture_delegate_multi_plane.cc

Issue 967793002: Linux Video Capture: Add V4L2VideoCaptureDelegate{Single,Multi}Plane. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: posciak@ nits perkj@,magjed@ and dalecurtis@ comments. Rebase. Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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() const {
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) const {
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
53 static const struct v4l2_plane empty_plane = {};
54 std::fill(v4l2_planes_.begin(), v4l2_planes_.end(), empty_plane);
55 buffer->m.planes = v4l2_planes_.data();
56 }
57
58 void V4L2CaptureDelegateMultiPlane::SendBuffer(
59 const scoped_refptr<BufferTracker>& buffer_tracker) const {
60 DCHECK_EQ(capture_format().pixel_format, PIXEL_FORMAT_I420);
61 const size_t y_stride =
62 buffer_tracker->GetPlaneLength(0) / capture_format().frame_size.height();
Pawel Osciak 2015/03/20 00:56:06 If you need stride, then you should use bytesperli
mcasas 2015/03/20 03:01:20 Done.
63 const size_t u_stride = buffer_tracker->GetPlaneLength(1) /
64 ((capture_format().frame_size.height() + 1) / 2);
65 const size_t v_stride = buffer_tracker->GetPlaneLength(2) /
66 ((capture_format().frame_size.height() + 1) / 2);
67 client()->OnIncomingCapturedYuvData(buffer_tracker->GetPlaneStart(0),
68 buffer_tracker->GetPlaneStart(1),
69 buffer_tracker->GetPlaneStart(2),
70 y_stride,
Pawel Osciak 2015/03/20 00:56:06 The prototype of VideoCaptureDevice::Client::OnInc
mcasas 2015/03/20 03:01:20 Done.
71 u_stride,
72 v_stride,
73 capture_format(),
74 rotation(),
75 base::TimeTicks::Now());
76 }
77
78 bool V4L2CaptureDelegateMultiPlane::BufferTrackerMPlane::Init(
79 int fd,
80 const v4l2_buffer& buffer) {
81 for (size_t p = 0; p < buffer.length; ++p) {
82 // Some devices require mmap() to be called with both READ and WRITE.
83 // See http://crbug.com/178582.
84 void* const start =
85 mmap(NULL, buffer.m.planes[p].length, PROT_READ | PROT_WRITE,
86 MAP_SHARED, fd, buffer.m.planes[p].m.mem_offset);
87 if (start == MAP_FAILED) {
88 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
89 return false;
90 }
91 AddMmapedPlane(static_cast<uint8_t*>(start), buffer.m.planes[p].length);
92 DVLOG(3) << "Mmap()ed plane #" << p << " of " << GetPlaneLength(p) << "B";
93 }
94 return true;
95 }
96
97 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698