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

Side by Side Diff: media/capture/video/linux/v4l2_capture_delegate.h

Issue 2143903003: [WIP] Move media/capture to device/capture (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « media/capture/video/linux/OWNERS ('k') | media/capture/video/linux/v4l2_capture_delegate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_
6 #define MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include "base/files/scoped_file.h"
12 #include "base/macros.h"
13 #include "base/memory/ref_counted.h"
14 #include "build/build_config.h"
15 #include "media/capture/video/video_capture_device.h"
16
17 #if defined(OS_OPENBSD)
18 #include <sys/videoio.h>
19 #else
20 #include <linux/videodev2.h>
21 #endif
22
23 namespace tracked_objects {
24 class Location;
25 } // namespace tracked_objects
26
27 namespace media {
28
29 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE
30 // capture specifics are implemented in derived classes. Created and destroyed
31 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|.
32 // TODO(mcasas): Make this class a non-ref-counted.
33 class V4L2CaptureDelegate final
34 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> {
35 public:
36 // Retrieves the #planes for a given |fourcc|, or 0 if unknown.
37 static size_t GetNumPlanesForFourCc(uint32_t fourcc);
38 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN.
39 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat(
40 uint32_t v4l2_fourcc);
41
42 // Composes a list of usable and supported pixel formats, in order of
43 // preference, with MJPEG prioritised depending on |prefer_mjpeg|.
44 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg);
45
46 V4L2CaptureDelegate(
47 const VideoCaptureDevice::Name& device_name,
48 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner,
49 int power_line_frequency);
50
51 // Forward-to versions of VideoCaptureDevice virtual methods.
52 void AllocateAndStart(int width,
53 int height,
54 float frame_rate,
55 std::unique_ptr<VideoCaptureDevice::Client> client);
56 void StopAndDeAllocate();
57
58 void SetRotation(int rotation);
59
60 private:
61 friend class base::RefCountedThreadSafe<V4L2CaptureDelegate>;
62 ~V4L2CaptureDelegate();
63
64 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and
65 // enqueues it (VIDIOC_QBUF) back into V4L2.
66 bool MapAndQueueBuffer(int index);
67
68 void DoCapture();
69
70 void SetErrorState(const tracked_objects::Location& from_here,
71 const std::string& reason);
72
73 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_;
74 const VideoCaptureDevice::Name device_name_;
75 const int power_line_frequency_;
76
77 // The following members are only known on AllocateAndStart().
78 VideoCaptureFormat capture_format_;
79 v4l2_format video_fmt_;
80 std::unique_ptr<VideoCaptureDevice::Client> client_;
81 base::ScopedFD device_fd_;
82
83 // Vector of BufferTracker to keep track of mmap()ed pointers and their use.
84 class BufferTracker;
85 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_;
86
87 bool is_capturing_;
88 int timeout_count_;
89
90 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270.
91 int rotation_;
92
93 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate);
94 };
95
96 } // namespace media
97
98 #endif // MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_
OLDNEW
« no previous file with comments | « media/capture/video/linux/OWNERS ('k') | media/capture/video/linux/v4l2_capture_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698