| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 #include "media/capture/video/linux/video_capture_device_factory_linux.h" | 5 #include "media/capture/video/linux/video_capture_device_factory_linux.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #if defined(OS_OPENBSD) | 9 #if defined(OS_OPENBSD) |
| 10 #include <sys/videoio.h> | 10 #include <sys/videoio.h> |
| 11 #else | 11 #else |
| 12 #include <linux/videodev2.h> | 12 #include <linux/videodev2.h> |
| 13 #endif | 13 #endif |
| 14 #include <sys/ioctl.h> | 14 #include <sys/ioctl.h> |
| 15 | 15 |
| 16 #include "base/files/file_enumerator.h" | 16 #include "base/files/file_enumerator.h" |
| 17 #include "base/files/scoped_file.h" | 17 #include "base/files/scoped_file.h" |
| 18 #include "base/posix/eintr_wrapper.h" | 18 #include "base/posix/eintr_wrapper.h" |
| 19 #if defined(OS_CHROMEOS) | 19 #if defined(OS_CHROMEOS) |
| 20 #include "media/capture/video/linux/video_capture_device_chromeos.h" | 20 #include "media/capture/video/linux/video_capture_device_chromeos.h" |
| 21 #endif | 21 #endif |
| 22 #include "media/capture/video/linux/video_capture_device_linux.h" | 22 #include "media/capture/video/linux/video_capture_device_linux.h" |
| 23 | 23 |
| 24 namespace media { | 24 namespace media { |
| 25 | 25 |
| 26 static bool HasUsableFormats(int fd, uint32 capabilities) { | 26 static bool HasUsableFormats(int fd, uint32_t capabilities) { |
| 27 const std::list<uint32_t>& usable_fourccs = | 27 const std::list<uint32_t>& usable_fourccs = |
| 28 VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false); | 28 VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false); |
| 29 | 29 |
| 30 static const struct { | 30 static const struct { |
| 31 int capability; | 31 int capability; |
| 32 v4l2_buf_type buf_type; | 32 v4l2_buf_type buf_type; |
| 33 } kCapabilityAndBufferTypes[] = { | 33 } kCapabilityAndBufferTypes[] = { |
| 34 {V4L2_CAP_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE}, | 34 {V4L2_CAP_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE}, |
| 35 {V4L2_CAP_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE}}; | 35 {V4L2_CAP_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE}}; |
| 36 | 36 |
| 37 for (const auto& capability_and_buffer_type : kCapabilityAndBufferTypes) { | 37 for (const auto& capability_and_buffer_type : kCapabilityAndBufferTypes) { |
| 38 v4l2_fmtdesc fmtdesc = {}; | 38 v4l2_fmtdesc fmtdesc = {}; |
| 39 if (capabilities & capability_and_buffer_type.capability) { | 39 if (capabilities & capability_and_buffer_type.capability) { |
| 40 fmtdesc.type = capability_and_buffer_type.buf_type; | 40 fmtdesc.type = capability_and_buffer_type.buf_type; |
| 41 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0; | 41 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0; |
| 42 ++fmtdesc.index) { | 42 ++fmtdesc.index) { |
| 43 if (std::find(usable_fourccs.begin(), usable_fourccs.end(), | 43 if (std::find(usable_fourccs.begin(), usable_fourccs.end(), |
| 44 fmtdesc.pixelformat) != usable_fourccs.end()) | 44 fmtdesc.pixelformat) != usable_fourccs.end()) |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 DLOG(ERROR) << "No usable formats found"; | 49 DLOG(ERROR) << "No usable formats found"; |
| 50 return false; | 50 return false; |
| 51 } | 51 } |
| 52 | 52 |
| 53 static std::list<float> GetFrameRateList(int fd, | 53 static std::list<float> GetFrameRateList(int fd, |
| 54 uint32 fourcc, | 54 uint32_t fourcc, |
| 55 uint32 width, | 55 uint32_t width, |
| 56 uint32 height) { | 56 uint32_t height) { |
| 57 std::list<float> frame_rates; | 57 std::list<float> frame_rates; |
| 58 | 58 |
| 59 v4l2_frmivalenum frame_interval = {}; | 59 v4l2_frmivalenum frame_interval = {}; |
| 60 frame_interval.pixel_format = fourcc; | 60 frame_interval.pixel_format = fourcc; |
| 61 frame_interval.width = width; | 61 frame_interval.width = width; |
| 62 frame_interval.height = height; | 62 frame_interval.height = height; |
| 63 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval)) == | 63 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval)) == |
| 64 0; | 64 0; |
| 65 ++frame_interval.index) { | 65 ++frame_interval.index) { |
| 66 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { | 66 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 215 } |
| 216 | 216 |
| 217 // static | 217 // static |
| 218 VideoCaptureDeviceFactory* | 218 VideoCaptureDeviceFactory* |
| 219 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 219 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
| 220 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 220 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
| 221 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); | 221 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); |
| 222 } | 222 } |
| 223 | 223 |
| 224 } // namespace media | 224 } // namespace media |
| OLD | NEW |