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

Side by Side Diff: media/video/capture/linux/v4l2_capture_delegate_single_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: magjed@ comments 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_single_plane.h"
6
7 #include <sys/mman.h>
8
9 namespace media {
10
11 scoped_refptr<V4L2CaptureDelegate::BufferTracker>
12 V4L2CaptureDelegateSinglePlane::CreateBufferTracker() const {
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) const {
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 const v4l2_format& format) const {
35 const size_t data_length = format.fmt.pix.sizeimage;
36 DCHECK_GE(data_length, capture_format().ImageAllocationSize());
37 client()->OnIncomingCapturedData(
38 buffer_tracker->GetPlaneStart(0),
39 data_length,
40 capture_format(),
41 rotation(),
42 base::TimeTicks::Now());
43 }
44
45 bool V4L2CaptureDelegateSinglePlane::BufferTrackerSPlane::Init(
46 int fd,
47 const v4l2_buffer& buffer) {
48 // Some devices require mmap() to be called with both READ and WRITE.
49 // See http://crbug.com/178582.
50 void* const start = mmap(NULL, buffer.length, PROT_READ | PROT_WRITE,
51 MAP_SHARED, fd, buffer.m.offset);
52 if (start == MAP_FAILED) {
53 DLOG(ERROR) << "Error mmap()ing a V4L2 buffer into userspace";
54 return false;
55 }
56 AddMmapedPlane(static_cast<uint8_t*>(start), buffer.length);
57 return true;
58 }
59
60 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698