Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: media/video/capture/linux/video_capture_device_factory_linux.cc

Issue 1031583002: Revert of Linux Video Capture: Add V4L2VideoCaptureDelegate{Single,Multi}Plane. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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<uint32_t>& usable_fourccs = 28 const std::list<int>& 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";
52 return false; 51 return false;
53 } 52 }
54 53
55 static std::list<float> GetFrameRateList(int fd, 54 static std::list<float> GetFrameRateList(int fd,
56 uint32 fourcc, 55 uint32 fourcc,
57 uint32 width, 56 uint32 width,
58 uint32 height) { 57 uint32 height) {
59 std::list<float> frame_rates; 58 std::list<float> frame_rates;
60 59
61 v4l2_frmivalenum frame_interval = {}; 60 v4l2_frmivalenum frame_interval = {};
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 // supported capture format. Devices that have capture and output 175 // supported capture format. Devices that have capture and output
177 // capabilities at the same time are memory-to-memory and are skipped, see 176 // capabilities at the same time are memory-to-memory and are skipped, see
178 // http://crbug.com/139356. 177 // http://crbug.com/139356.
179 v4l2_capability cap; 178 v4l2_capability cap;
180 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) && 179 if ((HANDLE_EINTR(ioctl(fd.get(), VIDIOC_QUERYCAP, &cap)) == 0) &&
181 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE || 180 ((cap.capabilities & V4L2_CAP_VIDEO_CAPTURE ||
182 cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) && 181 cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) &&
183 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) && 182 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) &&
184 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) && 183 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT_MPLANE)) &&
185 HasUsableFormats(fd.get(), cap.capabilities)) { 184 HasUsableFormats(fd.get(), cap.capabilities)) {
186 device_names->push_back(VideoCaptureDevice::Name( 185 VideoCaptureDevice::Name device_name(base::StringPrintf("%s", cap.card),
187 base::StringPrintf("%s", cap.card), unique_id, 186 unique_id);
188 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE_MPLANE) 187 device_names->push_back(device_name);
189 ? VideoCaptureDevice::Name::V4L2_MULTI_PLANE
190 : VideoCaptureDevice::Name::V4L2_SINGLE_PLANE));
191 } 188 }
192 } 189 }
193 } 190 }
194 191
195 void VideoCaptureDeviceFactoryLinux::GetDeviceSupportedFormats( 192 void VideoCaptureDeviceFactoryLinux::GetDeviceSupportedFormats(
196 const VideoCaptureDevice::Name& device, 193 const VideoCaptureDevice::Name& device,
197 VideoCaptureFormats* supported_formats) { 194 VideoCaptureFormats* supported_formats) {
198 DCHECK(thread_checker_.CalledOnValidThread()); 195 DCHECK(thread_checker_.CalledOnValidThread());
199 if (device.id().empty()) 196 if (device.id().empty())
200 return; 197 return;
201 base::ScopedFD fd(HANDLE_EINTR(open(device.id().c_str(), O_RDONLY))); 198 base::ScopedFD fd(HANDLE_EINTR(open(device.id().c_str(), O_RDONLY)));
202 if (!fd.is_valid()) // Failed to open this device. 199 if (!fd.is_valid()) // Failed to open this device.
203 return; 200 return;
204 supported_formats->clear(); 201 supported_formats->clear();
205 202
206 DCHECK_NE(device.capture_api_type(), 203 const v4l2_buf_type kCaptureTypes[] = {V4L2_BUF_TYPE_VIDEO_CAPTURE,
207 VideoCaptureDevice::Name::API_TYPE_UNKNOWN); 204 V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE};
208 const v4l2_buf_type buf_type = 205 for (const auto& buf_type : kCaptureTypes)
209 (device.capture_api_type() == VideoCaptureDevice::Name::V4L2_MULTI_PLANE) 206 GetSupportedFormatsForV4L2BufferType(fd.get(), buf_type, supported_formats);
210 ? V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE
211 : V4L2_BUF_TYPE_VIDEO_CAPTURE;
212 GetSupportedFormatsForV4L2BufferType(fd.get(), buf_type, supported_formats);
213
214 return; 207 return;
215 } 208 }
216 209
217 // static 210 // static
218 VideoCaptureDeviceFactory* 211 VideoCaptureDeviceFactory*
219 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory( 212 VideoCaptureDeviceFactory::CreateVideoCaptureDeviceFactory(
220 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) { 213 scoped_refptr<base::SingleThreadTaskRunner> ui_task_runner) {
221 return new VideoCaptureDeviceFactoryLinux(ui_task_runner); 214 return new VideoCaptureDeviceFactoryLinux(ui_task_runner);
222 } 215 }
223 216
224 } // namespace media 217 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698