Chromium Code Reviews| 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> | |
|
Pawel Osciak
2015/03/06 10:43:55
As mentioned in previous PS, this is does not appe
mcasas
2015/03/09 21:23:57
There are no OpenBSD bots.
My guess is that Chro
Pawel Osciak
2015/03/13 09:52:52
This CL may breaking these platforms (may not even
| |
| 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 VideoPixelFormat pixel_format, | |
| 31 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | |
| 32 int power_line_frequency); | |
| 33 | |
| 34 // Returns the Cr pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. | |
|
Pawel Osciak
2015/03/06 10:43:55
s/Cr/Chromium/
mcasas
2015/03/09 21:23:57
Done.
| |
| 35 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat(uint32_t v4l2_fourcc); | |
| 36 | |
| 37 // Composes a list of usable and supported pixel formats, in order of | |
| 38 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. | |
| 39 static std::list<uint32_t> GetListOfUsableFourCss(bool prefer_mjpeg); | |
|
emircan
2015/03/04 02:47:47
/s/FourCss/FourCcs/
mcasas
2015/03/09 21:23:57
Done.
| |
| 40 | |
| 41 // Forward-to versions of VideoCaptureDevice virtual methods. | |
| 42 void AllocateAndStart(int width, | |
| 43 int height, | |
| 44 float frame_rate, | |
| 45 scoped_ptr<VideoCaptureDevice::Client> client); | |
| 46 void StopAndDeAllocate(); | |
| 47 | |
| 48 void SetRotation(int rotation); | |
| 49 | |
| 50 protected: | |
| 51 // Class keeping track of SPLANE/MPLANE V4L2 buffers, mmap()ed on construction | |
| 52 // and munmap()ed on destruction. Destruction is syntactically equalfor | |
|
Pawel Osciak
2015/03/06 10:43:55
s/equalfor/equal for/
mcasas
2015/03/09 21:23:57
Done.
| |
| 53 // S/MPLANE but not construction, so this is implemented in derived classes. | |
| 54 // Internally it has a ScopedVector of planes, which for SPLANE will contain | |
| 55 // only one element. | |
| 56 class BufferTracker : public base::RefCounted<BufferTracker> { | |
|
Pawel Osciak
2015/03/06 10:43:55
You should need to only declare this class here in
mcasas
2015/03/09 21:23:57
Done.
| |
| 57 public: | |
| 58 struct Plane { | |
| 59 void* start; | |
| 60 size_t length; | |
| 61 }; | |
| 62 | |
| 63 BufferTracker(int fd, const v4l2_buffer& buffer); | |
| 64 | |
| 65 ScopedVector<Plane>& planes() { return planes_; } | |
|
Pawel Osciak
2015/03/06 10:43:55
In what case would you like to use a non-const acc
mcasas
2015/03/09 21:23:57
It's needed in the ctor of derived classes, f.i. f
Pawel Osciak
2015/03/13 09:52:52
Right, the point is we don't want the users of thi
mcasas
2015/03/14 03:36:10
I propose adding a protected AddMmapedPlane() meth
| |
| 66 const ScopedVector<Plane>& planes() const { return planes_; } | |
| 67 | |
| 68 protected: | |
| 69 friend class base::RefCounted<BufferTracker>; | |
| 70 virtual ~BufferTracker(); | |
| 71 | |
| 72 private: | |
| 73 ScopedVector<Plane> planes_; | |
|
Pawel Osciak
2015/03/06 10:43:55
Plane does not have a specialized destructor and d
mcasas
2015/03/09 21:23:56
Done.
| |
| 74 }; | |
| 75 | |
| 76 V4L2VideoCaptureDelegate( | |
| 77 const VideoCaptureDevice::Name& device_name, | |
| 78 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | |
| 79 int power_line_frequency); | |
| 80 virtual ~V4L2VideoCaptureDelegate(); | |
| 81 | |
| 82 // Creates the necessary, planarity-specific, internal tracking schemes. | |
|
Pawel Osciak
2015/03/06 10:43:55
Please document arguments.
mcasas
2015/03/09 21:23:57
Done.
| |
| 83 virtual scoped_refptr<BufferTracker> CreateBufferTracker( | |
| 84 int fd, | |
| 85 const v4l2_buffer& buffer) = 0; | |
| 86 | |
| 87 // Fill in |format| with the given parameters, in a planarity dependent way. | |
| 88 virtual void FillV4L2Format(v4l2_format* format, | |
| 89 uint32_t width, | |
| 90 uint32_t height, | |
| 91 uint32_t pixelformat_fourcc) = 0; | |
| 92 | |
| 93 // Finish filling |buffer| struct with planarity-dependent data. | |
|
Pawel Osciak
2015/03/06 10:43:55
"Finish" doesn't really explain what this does and
mcasas
2015/03/09 21:23:57
Done.
| |
| 94 virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer) = 0; | |
| 95 | |
| 96 // Sends the captured |buffer| to the |client|, synchronously. | |
|
Pawel Osciak
2015/03/06 10:43:55
s/|client|/client_/
Also, please just take scoped
mcasas
2015/03/09 21:23:57
Done.
| |
| 97 virtual void SendBuffer(const v4l2_buffer& buffer) = 0; | |
| 98 | |
| 99 // A few accessors for SendBuffer()'s to access private member variables. | |
| 100 VideoCaptureFormat capture_format() const { return capture_format_; } | |
| 101 VideoCaptureDevice::Client* client() const { return client_.get(); } | |
| 102 int rotation() const { return rotation_; } | |
| 103 const std::vector<scoped_refptr<BufferTracker>>& buffer_tracker_pool() const { | |
| 104 return buffer_tracker_pool_; | |
| 105 } | |
| 106 | |
| 107 private: | |
| 108 friend class base::RefCountedThreadSafe<V4L2VideoCaptureDelegate>; | |
| 109 | |
| 110 // Request buffers from V4L2 and create BufferTrackers for them. | |
| 111 bool AllocateVideoBuffers(); | |
| 112 void DoCapture(); | |
| 113 void SetErrorState(const std::string& reason); | |
| 114 | |
| 115 const v4l2_buf_type capture_type_; | |
| 116 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; | |
| 117 const VideoCaptureDevice::Name device_name_; | |
| 118 const int power_line_frequency_; | |
| 119 | |
| 120 // The following members are only known on AllocateAndStart(). | |
| 121 VideoCaptureFormat capture_format_; | |
| 122 scoped_ptr<VideoCaptureDevice::Client> client_; | |
| 123 base::ScopedFD device_fd_; | |
| 124 | |
| 125 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. | |
| 126 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; | |
| 127 | |
| 128 bool is_capturing_; | |
| 129 int timeout_count_; | |
| 130 | |
| 131 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | |
| 132 int rotation_; | |
| 133 | |
| 134 DISALLOW_COPY_AND_ASSIGN(V4L2VideoCaptureDelegate); | |
| 135 }; | |
| 136 | |
| 137 } // namespace media | |
| 138 | |
| 139 #endif // MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | |
| OLD | NEW |