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/video/capture/linux/video_capture_device_factory_linux.h" | 5 #include "media/video/capture/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 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
20 #if defined(OS_CHROMEOS) | 20 #if defined(OS_CHROMEOS) |
21 #include "media/video/capture/linux/video_capture_device_chromeos.h" | 21 #include "media/video/capture/linux/video_capture_device_chromeos.h" |
22 #endif | 22 #endif |
23 #include "media/video/capture/linux/video_capture_device_linux.h" | 23 #include "media/video/capture/linux/video_capture_device_linux.h" |
24 | 24 |
25 namespace media { | 25 namespace media { |
26 | 26 |
27 static bool HasUsableFormats(int fd, uint32 capabilities) { | 27 static bool HasUsableFormats(int fd, uint32 capabilities) { |
28 const std::list<int>& usable_fourccs = | 28 const std::list<uint32_t>& usable_fourccs = |
29 VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false); | 29 VideoCaptureDeviceLinux::GetListOfUsableFourCCs(false); |
30 | 30 |
31 static const struct { | 31 static const struct { |
32 int capability; | 32 int capability; |
33 v4l2_buf_type buf_type; | 33 v4l2_buf_type buf_type; |
34 } kCapabilityAndBufferTypes[] = { | 34 } kCapabilityAndBufferTypes[] = { |
35 {V4L2_CAP_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE}, | 35 {V4L2_CAP_VIDEO_CAPTURE, V4L2_BUF_TYPE_VIDEO_CAPTURE}, |
36 {V4L2_CAP_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE} | 36 {V4L2_CAP_VIDEO_CAPTURE_MPLANE, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE} |
37 }; | 37 }; |
38 | 38 |
39 for (const auto& capability_and_buffer_type : kCapabilityAndBufferTypes) { | 39 for (const auto& capability_and_buffer_type : kCapabilityAndBufferTypes) { |
40 v4l2_fmtdesc fmtdesc = {}; | 40 v4l2_fmtdesc fmtdesc = {}; |
41 if (capabilities & capability_and_buffer_type.capability) { | 41 if (capabilities & capability_and_buffer_type.capability) { |
42 fmtdesc.type = capability_and_buffer_type.buf_type; | 42 fmtdesc.type = capability_and_buffer_type.buf_type; |
43 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0; | 43 for (; HANDLE_EINTR(ioctl(fd, VIDIOC_ENUM_FMT, &fmtdesc)) == 0; |
44 ++fmtdesc.index) { | 44 ++fmtdesc.index) { |
45 if (std::find(usable_fourccs.begin(), usable_fourccs.end(), | 45 if (std::find(usable_fourccs.begin(), usable_fourccs.end(), |
46 fmtdesc.pixelformat) != usable_fourccs.end()) | 46 fmtdesc.pixelformat) != usable_fourccs.end()) |
47 return true; | 47 return true; |
48 } | 48 } |
49 } | 49 } |
50 } | 50 } |
| 51 DLOG(ERROR) << "No usable formats found"; |
51 return false; | 52 return false; |
52 } | 53 } |
53 | 54 |
54 static std::list<float> GetFrameRateList(int fd, | 55 static std::list<float> GetFrameRateList(int fd, |
55 uint32 fourcc, | 56 uint32 fourcc, |
56 uint32 width, | 57 uint32 width, |
57 uint32 height) { | 58 uint32 height) { |
58 std::list<float> frame_rates; | 59 std::list<float> frame_rates; |
59 | 60 |
60 v4l2_frmivalenum frame_interval = {}; | 61 v4l2_frmivalenum frame_interval = {}; |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // supported capture format. Devices that have capture and output | 176 // supported capture format. Devices that have capture and output |
176 // capabilities at the same time are memory-to-memory and are skipped, see | 177 // capabilities at the same time are memory-to-memory and are skipped, see |
177 // http://crbug.com/139356. | 178 // http://crbug.com/139356. |
178 v4l2_capability cap; | 179 v4l2_capability cap; |
179 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) && | 180 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) && |
180 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE || | 181 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE || |
181 cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) && | 182 cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) && |
182 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) && | 183 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) && |
183 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) && | 184 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) && |
184 HasUsableFormats(fd.get(), cap.capabilities)) { | 185 HasUsableFormats(fd.get(), cap.capabilities)) { |
185 VideoCaptureDevice::Name device_name(base::StringPrintf("%s", cap.card), | 186 device_names->push_back(VideoCaptureDevice::Name( |
186 unique_id); | 187 base::StringPrintf("%s", cap.card), unique_id, |
187 device_names->push_back(device_name); | 188 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) |
| 189 ? VideoCaptureDevice::Name::V4L2_MULTI_PLANE |
| 190 : VideoCaptureDevice::Name::V4L2_SINGLE_PLANE)); |
188 } | 191 } |
189 } | 192 } |
190 } | 193 } |
191 | 194 |
192 void VideoCaptureDeviceFactoryLinux::GetDeviceSupportedFormats( | 195 void VideoCaptureDeviceFactoryLinux::GetDeviceSupportedFormats( |
193 const VideoCaptureDevice::Name& device, | 196 const VideoCaptureDevice::Name& device, |
194 VideoCaptureFormats* supported_formats) { | 197 VideoCaptureFormats* supported_formats) { |
195 DCHECK(thread_checker_.CalledOnValidThread()); | 198 DCHECK(thread_checker_.CalledOnValidThread()); |
196 if (device.id().empty()) | 199 if (device.id().empty()) |
197 return; | 200 return; |
198 base::ScopedFD fd(HANDLE_EINTR(open(device.id().c_str(), O_RDONLY))); | 201 base::ScopedFD fd(HANDLE_EINTR(open(device.id().c_str(), O_RDONLY))); |
199 if (!fd.is_valid()) // Failed to open this device. | 202 if (!fd.is_valid()) // Failed to open this device. |
200 return; | 203 return; |
201 supported_formats->clear(); | 204 supported_formats->clear(); |
202 | 205 |
203 const v4l2_buf_type kCaptureTypes[] = {V4L2_BUF_TYPE_VIDEO_CAPTURE, | 206 DCHECK_NE(device.capture_api_type(), |
204 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE}; | 207 VideoCaptureDevice::Name::API_TYPE_UNKNOWN); |
205 for (const auto& buf_type : kCaptureTypes) | 208 const v4l2_buf_type buf_type = |
206 GetSupportedFormatsForV4L2BufferType(fd.get(), buf_type, supported_formats); | 209 (device.capture_api_type() == VideoCaptureDevice::Name::V4L2_MULTI_PLANE) |
| 210 ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE |
| 211 : V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| 212 GetSupportedFormatsForV4L2BufferType(fd.get(), buf_type, supported_formats); |
| 213 |
207 return; | 214 return; |
208 } | 215 } |
209 | 216 |
210 // static | 217 // static |
211 VideoCaptureDeviceFactory* | 218 VideoCaptureDeviceFactory* |
212 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( | 219 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( |
213 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { | 220 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { |
214 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); | 221 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); |
215 } | 222 } |
216 | 223 |
217 } // namespace media | 224 } // namespace media |
OLD | NEW |