| 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" | |
| 14 #include "build/build_config.h" | 13 #include "build/build_config.h" |
| 15 #include "media/capture/video/video_capture_device.h" | 14 #include "media/capture/video/video_capture_device.h" |
| 16 | 15 |
| 17 #if defined(OS_OPENBSD) | 16 #if defined(OS_OPENBSD) |
| 18 #include <sys/videoio.h> | 17 #include <sys/videoio.h> |
| 19 #else | 18 #else |
| 20 #include <linux/videodev2.h> | 19 #include <linux/videodev2.h> |
| 21 #endif | 20 #endif |
| 22 | 21 |
| 23 namespace tracked_objects { | 22 namespace tracked_objects { |
| 24 class Location; | 23 class Location; |
| 25 } // namespace tracked_objects | 24 } // namespace tracked_objects |
| 26 | 25 |
| 27 namespace media { | 26 namespace media { |
| 28 | 27 |
| 29 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE | 28 // Class doing the actual Linux capture using V4L2 API. V4L2 SPLANE/MPLANE |
| 30 // capture specifics are implemented in derived classes. Created and destroyed | 29 // capture specifics are implemented in derived classes. Created on the owner's |
| 31 // on the owner's thread, otherwise living and operating on |v4l2_task_runner_|. | 30 // thread, otherwise living, operating and destroyed on |v4l2_task_runner_|. |
| 32 // TODO(mcasas): Make this class a non-ref-counted. | 31 class CAPTURE_EXPORT V4L2CaptureDelegate final { |
| 33 class CAPTURE_EXPORT V4L2CaptureDelegate final | |
| 34 : public base::RefCountedThreadSafe<V4L2CaptureDelegate> { | |
| 35 public: | 32 public: |
| 36 // Retrieves the #planes for a given |fourcc|, or 0 if unknown. | 33 // Retrieves the #planes for a given |fourcc|, or 0 if unknown. |
| 37 static size_t GetNumPlanesForFourCc(uint32_t fourcc); | 34 static size_t GetNumPlanesForFourCc(uint32_t fourcc); |
| 38 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. | 35 // Returns the Chrome pixel format for |v4l2_fourcc| or PIXEL_FORMAT_UNKNOWN. |
| 39 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat( | 36 static VideoPixelFormat V4l2FourCcToChromiumPixelFormat( |
| 40 uint32_t v4l2_fourcc); | 37 uint32_t v4l2_fourcc); |
| 41 | 38 |
| 42 // Composes a list of usable and supported pixel formats, in order of | 39 // Composes a list of usable and supported pixel formats, in order of |
| 43 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. | 40 // preference, with MJPEG prioritised depending on |prefer_mjpeg|. |
| 44 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); | 41 static std::list<uint32_t> GetListOfUsableFourCcs(bool prefer_mjpeg); |
| 45 | 42 |
| 46 V4L2CaptureDelegate( | 43 V4L2CaptureDelegate( |
| 47 const VideoCaptureDeviceDescriptor& device_descriptor, | 44 const VideoCaptureDeviceDescriptor& device_descriptor, |
| 48 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, | 45 const scoped_refptr<base::SingleThreadTaskRunner>& v4l2_task_runner, |
| 49 int power_line_frequency); | 46 int power_line_frequency); |
| 47 ~V4L2CaptureDelegate(); |
| 50 | 48 |
| 51 // Forward-to versions of VideoCaptureDevice virtual methods. | 49 // Forward-to versions of VideoCaptureDevice virtual methods. |
| 52 void AllocateAndStart(int width, | 50 void AllocateAndStart(int width, |
| 53 int height, | 51 int height, |
| 54 float frame_rate, | 52 float frame_rate, |
| 55 std::unique_ptr<VideoCaptureDevice::Client> client); | 53 std::unique_ptr<VideoCaptureDevice::Client> client); |
| 56 void StopAndDeAllocate(); | 54 void StopAndDeAllocate(); |
| 57 | 55 |
| 58 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback); | 56 void TakePhoto(VideoCaptureDevice::TakePhotoCallback callback); |
| 59 | 57 |
| 60 void GetPhotoCapabilities( | 58 void GetPhotoCapabilities( |
| 61 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback); | 59 VideoCaptureDevice::GetPhotoCapabilitiesCallback callback); |
| 62 void SetPhotoOptions(mojom::PhotoSettingsPtr settings, | 60 void SetPhotoOptions(mojom::PhotoSettingsPtr settings, |
| 63 VideoCaptureDevice::SetPhotoOptionsCallback callback); | 61 VideoCaptureDevice::SetPhotoOptionsCallback callback); |
| 64 | 62 |
| 65 void SetRotation(int rotation); | 63 void SetRotation(int rotation); |
| 66 | 64 |
| 65 base::WeakPtr<V4L2CaptureDelegate> GetWeakPtr(); |
| 66 |
| 67 private: | 67 private: |
| 68 friend class V4L2CaptureDelegateTest; | 68 friend class V4L2CaptureDelegateTest; |
| 69 | 69 |
| 70 friend class base::RefCountedThreadSafe<V4L2CaptureDelegate>; | |
| 71 ~V4L2CaptureDelegate(); | |
| 72 | |
| 73 class BufferTracker; | 70 class BufferTracker; |
| 74 | 71 |
| 75 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and | 72 // VIDIOC_QUERYBUFs a buffer from V4L2, creates a BufferTracker for it and |
| 76 // enqueues it (VIDIOC_QBUF) back into V4L2. | 73 // enqueues it (VIDIOC_QBUF) back into V4L2. |
| 77 bool MapAndQueueBuffer(int index); | 74 bool MapAndQueueBuffer(int index); |
| 78 | 75 |
| 79 void DoCapture(); | 76 void DoCapture(); |
| 80 | 77 |
| 81 void SetErrorState(const tracked_objects::Location& from_here, | 78 void SetErrorState(const tracked_objects::Location& from_here, |
| 82 const std::string& reason); | 79 const std::string& reason); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 97 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; | 94 std::vector<scoped_refptr<BufferTracker>> buffer_tracker_pool_; |
| 98 | 95 |
| 99 bool is_capturing_; | 96 bool is_capturing_; |
| 100 int timeout_count_; | 97 int timeout_count_; |
| 101 | 98 |
| 102 base::TimeTicks first_ref_time_; | 99 base::TimeTicks first_ref_time_; |
| 103 | 100 |
| 104 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. | 101 // Clockwise rotation in degrees. This value should be 0, 90, 180, or 270. |
| 105 int rotation_; | 102 int rotation_; |
| 106 | 103 |
| 104 base::WeakPtrFactory<V4L2CaptureDelegate> weak_factory_; |
| 105 |
| 107 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); | 106 DISALLOW_COPY_AND_ASSIGN(V4L2CaptureDelegate); |
| 108 }; | 107 }; |
| 109 | 108 |
| 110 } // namespace media | 109 } // namespace media |
| 111 | 110 |
| 112 #endif // MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ | 111 #endif // MEDIA_CAPTURE_VIDEO_LINUX_V4L2_CAPTURE_DELEGATE_H_ |
| OLD | NEW |