Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ | 5 #ifndef MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ |
| 6 #define MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ | 6 #define MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include "base/files/scoped_file.h" | 11 #include "base/files/scoped_file.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "media/capture/video/video_capture_device.h" | 15 #include "media/capture/video/video_capture_device.h" |
| 16 | 16 |
| 17 #if defined(OS_OPENBSD) | 17 #if defined(OS_OPENBSD) |
| 18 #include <sys/videoio.h> | 18 #include <sys/videoio.h> |
| 19 #else | 19 #else |
| 20 #include <linux/videodev2.h> | 20 #include <linux/videodev2.h> |
| 21 #endif | 21 #endif |
| 22 | 22 |
| 23 namespace tracked_objects { | 23 namespace tracked_objects { |
| 24 class Location; | 24 class Location; |
| 25 } // namespace tracked_objects | 25 } // namespace tracked_objects |
| 26 | 26 |
| 27 namespace media { | 27 namespace media { |
| 28 | 28 |
| 29 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE | 29 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE |
|
emircan
2016/07/25 22:56:40
There is no derived classes; this is marked final.
| |
| 30 // capture specifics are implemented in derived classes. Created and destroyed | 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_|. | 31 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. |
| 32 // TODO(mcasas): Make this class a non-ref-counted. | 32 // TODO(mcasas): Make this class a non-ref-counted. |
| 33 class V4L2CaptureDelegate final | 33 class V4L2CaptureDelegate final |
| 34 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { | 34 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { |
| 35 public: | 35 public: |
| 36 // Retrieves the #planes for a given |fourcc|, or 0 if unknown. | 36 // Retrieves the #planes for a given |fourcc|, or 0 if unknown. |
| 37 static size_t GetNumPlanesForFourCc(uint32_t fourcc); | 37 static size_t GetNumPlanesForFourCc(uint32_t fourcc); |
| 38 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. | 38 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. |
| 39 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat( | 39 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat( |
| 40 uint32_t v4l2_fourcc); | 40 uint32_t v4l2_fourcc); |
| 41 | 41 |
| 42 // Composes a list of usable and supported pixel formats, in order of | 42 // Composes a list of usable and supported pixel formats, in order of |
| 43 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. | 43 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. |
| 44 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); | 44 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); |
| 45 | 45 |
| 46 V4L2CaptureDelegate( | 46 V4L2CaptureDelegate( |
| 47 const VideoCaptureDevice::Name& device_name, | 47 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 48 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | 48 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| 49 int power_line_frequency); | 49 int power_line_frequency); |
| 50 | 50 |
| 51 // Forward-to versions of VideoCaptureDevice virtual methods. | 51 // Forward-to versions of VideoCaptureDevice virtual methods. |
| 52 void AllocateAndStart(int width, | 52 void AllocateAndStart(int width, |
| 53 int height, | 53 int height, |
| 54 float frame_rate, | 54 float frame_rate, |
| 55 std::unique_ptr<VideoCaptureDevice::Client> client); | 55 std::unique_ptr<VideoCaptureDevice::Client> client); |
| 56 void StopAndDeAllocate(); | 56 void StopAndDeAllocate(); |
| 57 | 57 |
| 58 void SetRotation(int rotation); | 58 void SetRotation(int rotation); |
| 59 | 59 |
| 60 private: | 60 private: |
| 61 friend class base::RefCountedThreadSafe<V4L2CaptureDelegate>; | 61 friend class base::RefCountedThreadSafe<V4L2CaptureDelegate>; |
| 62 ~V4L2CaptureDelegate(); | 62 ~V4L2CaptureDelegate(); |
| 63 | 63 |
| 64 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and | 64 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and |
| 65 // enqueues it (VIDIOC_QBUF) back into V4L2. | 65 // enqueues it (VIDIOC_QBUF) back into V4L2. |
| 66 bool MapAndQueueBuffer(int index); | 66 bool MapAndQueueBuffer(int index); |
| 67 | 67 |
| 68 void DoCapture(); | 68 void DoCapture(); |
| 69 | 69 |
| 70 void SetErrorState(const tracked_objects::Location& from_here, | 70 void SetErrorState(const tracked_objects::Location& from_here, |
| 71 const std::string& reason); | 71 const std::string& reason); |
| 72 | 72 |
| 73 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; | 73 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; |
| 74 const VideoCaptureDevice::Name device_name_; | 74 const VideoCaptureDeviceDescriptor device_descriptor_; |
| 75 const int power_line_frequency_; | 75 const int power_line_frequency_; |
| 76 | 76 |
| 77 // The following members are only known on AllocateAndStart(). | 77 // The following members are only known on AllocateAndStart(). |
| 78 VideoCaptureFormat capture_format_; | 78 VideoCaptureFormat capture_format_; |
| 79 v4l2_format video_fmt_; | 79 v4l2_format video_fmt_; |
| 80 std::unique_ptr<VideoCaptureDevice::Client> client_; | 80 std::unique_ptr<VideoCaptureDevice::Client> client_; |
| 81 base::ScopedFD device_fd_; | 81 base::ScopedFD device_fd_; |
| 82 | 82 |
| 83 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. | 83 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. |
| 84 class BufferTracker; | 84 class BufferTracker; |
| 85 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; | 85 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; |
| 86 | 86 |
| 87 bool is_capturing_; | 87 bool is_capturing_; |
| 88 int timeout_count_; | 88 int timeout_count_; |
| 89 | 89 |
| 90 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | 90 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. |
| 91 int rotation_; | 91 int rotation_; |
| 92 | 92 |
| 93 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); | 93 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); |
| 94 }; | 94 }; |
| 95 | 95 |
| 96 } // namespace media | 96 } // namespace media |
| 97 | 97 |
| 98 #endif // MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ | 98 #endif // MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ |
| OLD | NEW |