| 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_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | 5 #ifndef MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |
| 6 #define MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | 6 #define MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |
| 7 | 7 |
| 8 #if defined(OS_OPENBSD) | 8 #if defined(OS_OPENBSD) |
| 9 #include <sys/videoio.h> | 9 #include <sys/videoio.h> |
| 10 #else | 10 #else |
| 11 #include <linux/videodev2.h> | 11 #include <linux/videodev2.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/files/scoped_file.h" | 14 #include "base/files/scoped_file.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "media/capture/video/video_capture_device.h" | 16 #include "media/capture/video/video_capture_device.h" |
| 17 | 17 |
| 18 namespace tracked_objects { |
| 19 class Location; |
| 20 } // namespace tracked_objects |
| 21 |
| 18 namespace media { | 22 namespace media { |
| 19 | 23 |
| 20 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE | 24 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE |
| 21 // capture specifics are implemented in derived classes. Created and destroyed | 25 // capture specifics are implemented in derived classes. Created and destroyed |
| 22 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. | 26 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. |
| 23 class V4L2CaptureDelegate | 27 class V4L2CaptureDelegate |
| 24 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { | 28 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { |
| 25 public: | 29 public: |
| 26 // Creates the appropiate VideoCaptureDelegate according to parameters. | 30 // Creates the appropiate VideoCaptureDelegate according to parameters. |
| 27 static scoped_refptr<V4L2CaptureDelegate> CreateV4L2CaptureDelegate( | 31 static scoped_refptr<V4L2CaptureDelegate> CreateV4L2CaptureDelegate( |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 134 |
| 131 // Returns the input |fourcc| as a std::string four char representation. | 135 // Returns the input |fourcc| as a std::string four char representation. |
| 132 static std::string FourccToString(uint32_t fourcc); | 136 static std::string FourccToString(uint32_t fourcc); |
| 133 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and | 137 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and |
| 134 // enqueues it (VIDIOC_QBUF) back into V4L2. | 138 // enqueues it (VIDIOC_QBUF) back into V4L2. |
| 135 bool MapAndQueueBuffer(int index); | 139 bool MapAndQueueBuffer(int index); |
| 136 // Fills all common parts of |buffer|. Delegates to FinishFillingV4L2Buffer() | 140 // Fills all common parts of |buffer|. Delegates to FinishFillingV4L2Buffer() |
| 137 // for filling in the planar-dependent parts. | 141 // for filling in the planar-dependent parts. |
| 138 void FillV4L2Buffer(v4l2_buffer* buffer, int i) const; | 142 void FillV4L2Buffer(v4l2_buffer* buffer, int i) const; |
| 139 void DoCapture(); | 143 void DoCapture(); |
| 140 void SetErrorState(const std::string& reason); | 144 void SetErrorState(const tracked_objects::Location& from_here, |
| 145 const std::string& reason); |
| 141 | 146 |
| 142 const v4l2_buf_type capture_type_; | 147 const v4l2_buf_type capture_type_; |
| 143 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; | 148 const scoped_refptr<base::SingleThreadTaskRunner> v4l2_task_runner_; |
| 144 const VideoCaptureDevice::Name device_name_; | 149 const VideoCaptureDevice::Name device_name_; |
| 145 const int power_line_frequency_; | 150 const int power_line_frequency_; |
| 146 | 151 |
| 147 // The following members are only known on AllocateAndStart(). | 152 // The following members are only known on AllocateAndStart(). |
| 148 VideoCaptureFormat capture_format_; | 153 VideoCaptureFormat capture_format_; |
| 149 v4l2_format video_fmt_; | 154 v4l2_format video_fmt_; |
| 150 scoped_ptr<VideoCaptureDevice::Client> client_; | 155 scoped_ptr<VideoCaptureDevice::Client> client_; |
| 151 base::ScopedFD device_fd_; | 156 base::ScopedFD device_fd_; |
| 152 | 157 |
| 153 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. | 158 // Vector of BufferTracker to keep track of mmap()ed pointers and their use. |
| 154 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; | 159 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; |
| 155 | 160 |
| 156 bool is_capturing_; | 161 bool is_capturing_; |
| 157 int timeout_count_; | 162 int timeout_count_; |
| 158 | 163 |
| 159 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | 164 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. |
| 160 int rotation_; | 165 int rotation_; |
| 161 | 166 |
| 162 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); | 167 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); |
| 163 }; | 168 }; |
| 164 | 169 |
| 165 } // namespace media | 170 } // namespace media |
| 166 | 171 |
| 167 #endif // MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ | 172 #endif // MEDIA_VIDEO_CAPTURE_LINUX_V4L2_VIDEO_CAPTURE_DELEGATE_H_ |
| OLD | NEW |