Index: media/video/capture/linux/v4l2_video_capture_delegate.h |
diff --git a/media/video/capture/linux/v4l2_video_capture_delegate.h b/media/video/capture/linux/v4l2_video_capture_delegate.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5a11fd622e0bfae4b82010d5d07dc47c0afb1455 |
--- /dev/null |
+++ b/media/video/capture/linux/v4l2_video_capture_delegate.h |
@@ -0,0 +1,139 @@ |
+// 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. |
+ |
+#ifndef MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |
+#define MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |
+ |
+#if defined(OS_OPENBSD) |
+#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
|
+#else |
+#include <linux/videodev2.h> |
+#endif |
+ |
+#include "base/files/scoped_file.h" |
+#include "base/memory/ref_counted.h" |
+#include "base/memory/scoped_vector.h" |
+#include "media/video/capture/video_capture_device.h" |
+ |
+namespace media { |
+ |
+// Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE |
+// capture specifics are implemented in derived classes. Created and destroyed |
+// on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. |
+class V4L2VideoCaptureDelegate |
+ : public base::RefCountedThreadSafe<V4L2VideoCaptureDelegate> { |
+ public: |
+ // Creates the appropiate VideoCaptureDelegate according to parameters. |
+ static scoped_refptr<V4L2VideoCaptureDelegate> CreateV4L2VideoCaptureDelegate( |
+ const VideoCaptureDevice::Name& device_name, |
+ const VideoPixelFormat pixel_format, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
+ int power_line_frequency); |
+ |
+ // 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.
|
+ static VideoPixelFormat V4l2FourCcToChromiumPixelFormat(uint32_t v4l2_fourcc); |
+ |
+ // Composes a list of usable and supported pixel formats, in order of |
+ // preference, with MJPEG prioritised depending on |prefer_mjpeg|. |
+ 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.
|
+ |
+ // Forward-to versions of VideoCaptureDevice virtual methods. |
+ void AllocateAndStart(int width, |
+ int height, |
+ float frame_rate, |
+ scoped_ptr<VideoCaptureDevice::Client> client); |
+ void StopAndDeAllocate(); |
+ |
+ void SetRotation(int rotation); |
+ |
+ protected: |
+ // Class keeping track of SPLANE/MPLANE V4L2 buffers, mmap()ed on construction |
+ // 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.
|
+ // S/MPLANE but not construction, so this is implemented in derived classes. |
+ // Internally it has a ScopedVector of planes, which for SPLANE will contain |
+ // only one element. |
+ 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.
|
+ public: |
+ struct Plane { |
+ void* start; |
+ size_t length; |
+ }; |
+ |
+ BufferTracker(int fd, const v4l2_buffer& buffer); |
+ |
+ 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
|
+ const ScopedVector<Plane>& planes() const { return planes_; } |
+ |
+ protected: |
+ friend class base::RefCounted<BufferTracker>; |
+ virtual ~BufferTracker(); |
+ |
+ private: |
+ 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.
|
+ }; |
+ |
+ V4L2VideoCaptureDelegate( |
+ const VideoCaptureDevice::Name& device_name, |
+ const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
+ int power_line_frequency); |
+ virtual ~V4L2VideoCaptureDelegate(); |
+ |
+ // 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.
|
+ virtual scoped_refptr<BufferTracker> CreateBufferTracker( |
+ int fd, |
+ const v4l2_buffer& buffer) = 0; |
+ |
+ // Fill in |format| with the given parameters, in a planarity dependent way. |
+ virtual void FillV4L2Format(v4l2_format* format, |
+ uint32_t width, |
+ uint32_t height, |
+ uint32_t pixelformat_fourcc) = 0; |
+ |
+ // 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.
|
+ virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer) = 0; |
+ |
+ // 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.
|
+ virtual void SendBuffer(const v4l2_buffer& buffer) = 0; |
+ |
+ // A few accessors for SendBuffer()'s to access private member variables. |
+ VideoCaptureFormat capture_format() const { return capture_format_; } |
+ VideoCaptureDevice::Client* client() const { return client_.get(); } |
+ int rotation() const { return rotation_; } |
+ const std::vector<scoped_refptr<BufferTracker>>& buffer_tracker_pool() const { |
+ return buffer_tracker_pool_; |
+ } |
+ |
+ private: |
+ friend class base::RefCountedThreadSafe<V4L2VideoCaptureDelegate>; |
+ |
+ // Request buffers from V4L2 and create BufferTrackers for them. |
+ bool AllocateVideoBuffers(); |
+ void DoCapture(); |
+ void SetErrorState(const std::string& reason); |
+ |
+ const v4l2_buf_type capture_type_; |
+ const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; |
+ const VideoCaptureDevice::Name device_name_; |
+ const int power_line_frequency_; |
+ |
+ // The following members are only known on AllocateAndStart(). |
+ VideoCaptureFormat capture_format_; |
+ scoped_ptr<VideoCaptureDevice::Client> client_; |
+ base::ScopedFD device_fd_; |
+ |
+ // Vector of BufferTracker to keep track of mmap()ed pointers and their use. |
+ std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; |
+ |
+ bool is_capturing_; |
+ int timeout_count_; |
+ |
+ // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. |
+ int rotation_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(V4L2VideoCaptureDelegate); |
+}; |
+ |
+} // namespace media |
+ |
+#endif // MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |