Chromium Code Reviews| 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..02d182c9882882ffc6c6f21b8119515584d3a75f |
| --- /dev/null |
| +++ b/media/video/capture/linux/v4l2_video_capture_delegate.h |
| @@ -0,0 +1,115 @@ |
| +// 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> |
|
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
|
| +#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 scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| + int power_line_frequency); |
| + |
| + // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. |
| + 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> GetListOfUsableFourCcs(bool prefer_mjpeg); |
| + |
| + // 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 for keeping track of SPLANE/MPLANE V4L2 mmap()ed buffers, |
| + class BufferTracker; |
| + |
| + 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, |
| + virtual scoped_refptr<BufferTracker> CreateBufferTracker() = 0; |
| + |
| + // Fill in |format| with the given parameters, in a planarity dependent way. |
| + virtual bool FillV4L2Format(v4l2_format* format, |
| + uint32_t width, |
| + uint32_t height, |
| + uint32_t pixelformat_fourcc) = 0; |
| + |
| + // Finish filling |buffer| struct with planarity-dependent data. |
| + virtual void FinishFillingV4L2Buffer(v4l2_buffer* buffer) const = 0; |
| + |
| + // Sends the captured |buffer| to the |client_|, synchronously. |
| + virtual void SendBuffer( |
| + const scoped_refptr<BufferTracker>& buffer_tracker) = 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_; } |
| + |
| + private: |
| + friend class base::RefCountedThreadSafe<V4L2VideoCaptureDelegate>; |
| + |
| + // 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.
|
| + bool MapAndQueueBuffer(int index); |
| + // Fills all common parts of |buffer|. Delegates to FinishFillingV4L2Buffer() |
| + // for filling in the planar-dependent parts. |
| + void FillV4L2Buffer(v4l2_buffer* buffer, int i) const; |
| + 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_ |