Index: media/video/capture/linux/v4l2_capture_delegate_multi_plane.cc |
diff --git a/media/video/capture/linux/v4l2_capture_delegate_multi_plane.cc b/media/video/capture/linux/v4l2_capture_delegate_multi_plane.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..52522934548a928047fedde59e68990c4bccd2bd |
--- /dev/null |
+++ b/media/video/capture/linux/v4l2_capture_delegate_multi_plane.cc |
@@ -0,0 +1,86 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "media/video/capture/linux/v4l2_capture_delegate_multi_plane.h" |
+ |
+#include <sys/mman.h> |
+ |
+namespace media { |
+ |
+V4L2CaptureDelegateMultiPlane::V4L2CaptureDelegateMultiPlane( |
+ const VideoCaptureDevice::Name& device_name, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
+ int power_line_frequency) |
+ : V4L2VideoCaptureDelegate(device_name, |
+ v4l2_task_runner, |
+ power_line_frequency) { |
+} |
+ |
+V4L2CaptureDelegateMultiPlane::~V4L2CaptureDelegateMultiPlane() { |
+} |
+ |
+scoped_refptr<V4L2VideoCaptureDelegate::BufferTracker> |
+V4L2CaptureDelegateMultiPlane::CreateBufferTracker() { |
+ return make_scoped_refptr(new BufferTrackerMPlane()); |
+} |
+ |
+bool V4L2CaptureDelegateMultiPlane::FillV4L2Format( |
+ v4l2_format* format, |
+ uint32_t width, |
+ uint32_t height, |
+ uint32_t pixelformat_fourcc) { |
+ format->fmt.pix_mp.width = width; |
+ format->fmt.pix_mp.height = height; |
+ format->fmt.pix_mp.pixelformat = pixelformat_fourcc; |
+ |
+ const size_t num_v4l2_planes = |
+ V4L2VideoCaptureDelegate::GetNumPlanesForFourCc(pixelformat_fourcc); |
+ if (num_v4l2_planes == 0u) |
+ return false; |
+ DCHECK_LE(num_v4l2_planes, static_cast<size_t>(VIDEO_MAX_PLANES)); |
+ format->fmt.pix_mp.num_planes = num_v4l2_planes; |
+ |
+ v4l2_planes_.resize(num_v4l2_planes); |
+ return true; |
+} |
+ |
+void V4L2CaptureDelegateMultiPlane::FinishFillingV4L2Buffer( |
+ v4l2_buffer* buffer) const { |
+ buffer->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; |
+ buffer->length = v4l2_planes_.size(); |
+ 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?
|
+} |
+ |
+void V4L2CaptureDelegateMultiPlane::SendBuffer( |
+ const scoped_refptr<BufferTracker>& buffer_tracker) { |
+ DCHECK_EQ(capture_format().pixel_format, PIXEL_FORMAT_I420); |
+ client()->OnIncomingCapturedYuvData(buffer_tracker->GetPlaneStart(0), |
+ 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
|
+ buffer_tracker->GetPlaneStart(2), |
+ 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.
|
+ buffer_tracker->GetPlaneLength(1), |
+ buffer_tracker->GetPlaneLength(2), |
+ capture_format(), |
+ rotation(), |
+ base::TimeTicks::Now()); |
+} |
+ |
+bool V4L2CaptureDelegateMultiPlane::BufferTrackerMPlane::Init( |
+ int fd, |
+ const v4l2_buffer& buffer) { |
+ for (size_t p = 0; p < buffer.length; ++p) { |
+ void* const start = |
+ 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.
|
+ MAP_SHARED, fd, buffer.m.planes[p].m.mem_offset); |
+ if (start == MAP_FAILED) { |
+ DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace"; |
+ return false; |
+ } |
+ AddMmapedPlane(start, buffer.m.planes[p].length); |
+ DVLOG(3) << "Mmap()ed plane #" << p << " of " << GetPlaneLength(p) << "B"; |
+ } |
+ return true; |
+} |
+ |
+} // namespace media |