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 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | |
6 #define MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | |
7 | |
8 #if defined(OS_OPENBSD) | |
9 #include <sys/videoio.h> | |
mcasas
2015/03/14 03:36:12
Let me bring posciak@s comment to the latest patch
Pawel Osciak
2015/03/17 11:05:25
I know. That's what I meant, we won't know if we b
mcasas
2015/03/17 22:01:57
Chromium-dev should do better since the original
C
| |
10 #else | |
11 #include <linux/videodev2.h> | |
12 #endif | |
13 | |
14 #include "base/files/scoped_file.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/scoped_vector.h" | |
17 #include "media/video/capture/video_capture_device.h" | |
18 | |
19 namespace media { | |
20 | |
21 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE | |
22 // capture specifics are implemented in derived classes. Created and destroyed | |
23 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. | |
24 class V4L2VideoCaptureDelegate | |
25 : public base::RefCountedThreadSafe<V4L2VideoCaptureDelegate> { | |
26 public: | |
27 // Creates the appropiate VideoCaptureDelegate according to parameters. | |
28 static scoped_refptr<V4L2VideoCaptureDelegate> CreateV4L2VideoCaptureDelegate( | |
29 const VideoCaptureDevice::Name& device_name, | |
30 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | |
31 int power_line_frequency); | |
32 | |
33 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. | |
34 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat(uint32_t v4l2_fourcc); | |
35 | |
36 // Composes a list of usable and supported pixel formats, in order of | |
37 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. | |
38 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); | |
39 | |
40 // Forward-to versions of VideoCaptureDevice virtual methods. | |
41 void AllocateAndStart(int width, | |
42 int height, | |
43 float frame_rate, | |
44 scoped_ptr<VideoCaptureDevice::Client> client); | |
45 void StopAndDeAllocate(); | |
46 | |
47 void SetRotation(int rotation); | |
48 | |
49 protected: | |
50 // Class for keeping track of SPLANE/MPLANE V4L2 mmap()ed buffers, | |
51 class BufferTracker; | |
52 | |
53 V4L2VideoCaptureDelegate( | |
54 const VideoCaptureDevice::Name& device_name, | |
55 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | |
56 int power_line_frequency); | |
57 virtual ~V4L2VideoCaptureDelegate(); | |
58 | |
59 // Creates the necessary, planarity-specific, internal tracking schemes, | |
60 virtual scoped_refptr<BufferTracker> CreateBufferTracker() = 0; | |
61 | |
62 // Fill in |format| with the given parameters, in a planarity dependent way. | |
63 virtual bool FillV4L2Format(v4l2_format* format, | |
64 uint32_t width, | |
65 uint32_t height, | |
66 uint32_t pixelformat_fourcc) = 0; | |
67 | |
68 // Finish filling |buffer| struct with planarity-dependent data. | |
69 virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer) const = 0; | |
70 | |
71 // Sends the captured |buffer| to the |client_|, synchronously. | |
72 virtual void SendBuffer( | |
73 const scoped_refptr<BufferTracker>& buffer_tracker) = 0; | |
74 | |
75 // A few accessors for SendBuffer()'s to access private member variables. | |
76 VideoCaptureFormat capture_format() const { return capture_format_; } | |
77 VideoCaptureDevice::Client* client() const { return client_.get(); } | |
78 int rotation() const { return rotation_; } | |
79 | |
80 private: | |
81 friend class base::RefCountedThreadSafe<V4L2VideoCaptureDelegate>; | |
82 | |
83 // Request a buffer from V4L2, create and initialize a BufferTracker for it. | |
Pawel Osciak
2015/03/17 11:05:25
We also need to update this documentation.
mcasas
2015/03/17 22:01:57
Done.
| |
84 bool MapAndQueueBuffer(int index); | |
85 // Fills all common parts of |buffer|. Delegates to FinishFillingV4L2Buffer() | |
86 // for filling in the planar-dependent parts. | |
87 void FillV4L2Buffer(v4l2_buffer* buffer, int i) const; | |
88 void DoCapture(); | |
89 void SetErrorState(const std::string& reason); | |
90 | |
91 const v4l2_buf_type capture_type_; | |
92 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; | |
93 const VideoCaptureDevice::Name device_name_; | |
94 const int power_line_frequency_; | |
95 | |
96 // The following members are only known on AllocateAndStart(). | |
97 VideoCaptureFormat capture_format_; | |
98 scoped_ptr<VideoCaptureDevice::Client> client_; | |
99 base::ScopedFD device_fd_; | |
100 | |
101 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. | |
102 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; | |
103 | |
104 bool is_capturing_; | |
105 int timeout_count_; | |
106 | |
107 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | |
108 int rotation_; | |
109 | |
110 DISALLOW_COPY_AND_ASSIGN(V4L2VideoCaptureDelegate); | |
111 }; | |
112 | |
113 } // namespace media | |
114 | |
115 #endif // MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | |
OLD | NEW |