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

Side by Side Diff: trunk/src/media/video/capture/linux/video_capture_device_linux.cc

Issue 14824006: Revert 198820 "Move FileEnumerator to its own file, do some refa..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_linux.h" 5 #include "media/video/capture/linux/video_capture_device_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 #include <sys/mman.h> 15 #include <sys/mman.h>
16 16
17 #include <list> 17 #include <list>
18 #include <string> 18 #include <string>
19 19
20 #include "base/bind.h" 20 #include "base/bind.h"
21 #include "base/file_util.h" 21 #include "base/file_util.h"
22 #include "base/files/file_enumerator.h"
23 #include "base/stringprintf.h" 22 #include "base/stringprintf.h"
24 23
25 namespace media { 24 namespace media {
26 25
27 // Max number of video buffers VideoCaptureDeviceLinux can allocate. 26 // Max number of video buffers VideoCaptureDeviceLinux can allocate.
28 enum { kMaxVideoBuffers = 2 }; 27 enum { kMaxVideoBuffers = 2 };
29 // Timeout in microseconds v4l2_thread_ blocks waiting for a frame from the hw. 28 // Timeout in microseconds v4l2_thread_ blocks waiting for a frame from the hw.
30 enum { kCaptureTimeoutUs = 200000 }; 29 enum { kCaptureTimeoutUs = 200000 };
31 // The number of continuous timeouts tolerated before treated as error. 30 // The number of continuous timeouts tolerated before treated as error.
32 enum { kContinuousTimeoutLimit = 10 }; 31 enum { kContinuousTimeoutLimit = 10 };
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 return false; 93 return false;
95 } 94 }
96 95
97 void VideoCaptureDevice::GetDeviceNames(Names* device_names) { 96 void VideoCaptureDevice::GetDeviceNames(Names* device_names) {
98 int fd = -1; 97 int fd = -1;
99 98
100 // Empty the name list. 99 // Empty the name list.
101 device_names->clear(); 100 device_names->clear();
102 101
103 base::FilePath path("/dev/"); 102 base::FilePath path("/dev/");
104 base::FileEnumerator enumerator( 103 file_util::FileEnumerator enumerator(
105 path, false, base::FileEnumerator::FILES, "video*"); 104 path, false, file_util::FileEnumerator::FILES, "video*");
106 105
107 while (!enumerator.Next().empty()) { 106 while (!enumerator.Next().empty()) {
108 base::FileEnumerator::FileInfo info = enumerator.GetInfo(); 107 file_util::FileEnumerator::FindInfo info;
108 enumerator.GetFindInfo(&info);
109 109
110 Name name; 110 Name name;
111 name.unique_id = path.value() + info.GetName().value(); 111 name.unique_id = path.value() + info.filename;
112 if ((fd = open(name.unique_id.c_str() , O_RDONLY)) < 0) { 112 if ((fd = open(name.unique_id.c_str() , O_RDONLY)) < 0) {
113 // Failed to open this device. 113 // Failed to open this device.
114 continue; 114 continue;
115 } 115 }
116 // Test if this is a V4L2 capture device. 116 // Test if this is a V4L2 capture device.
117 v4l2_capability cap; 117 v4l2_capability cap;
118 if ((ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) && 118 if ((ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) &&
119 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) && 119 (cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) &&
120 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) { 120 !(cap.capabilities & V4L2_CAP_VIDEO_OUTPUT)) {
121 // This is a V4L2 video capture device 121 // This is a V4L2 video capture device
122 if (HasUsableFormats(fd)) { 122 if (HasUsableFormats(fd)) {
123 name.device_name = base::StringPrintf("%s", cap.card); 123 name.device_name = base::StringPrintf("%s", cap.card);
124 device_names->push_back(name); 124 device_names->push_back(name);
125 } else { 125 } else {
126 DVLOG(1) << "No usable formats reported by " << info.GetName().value(); 126 DVLOG(1) << "No usable formats reported by " << info.filename;
127 } 127 }
128 } 128 }
129 close(fd); 129 close(fd);
130 } 130 }
131 } 131 }
132 132
133 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) { 133 VideoCaptureDevice* VideoCaptureDevice::Create(const Name& device_name) {
134 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name); 134 VideoCaptureDeviceLinux* self = new VideoCaptureDeviceLinux(device_name);
135 if (!self) 135 if (!self)
136 return NULL; 136 return NULL;
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 buffer_pool_size_ = 0; 507 buffer_pool_size_ = 0;
508 } 508 }
509 509
510 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 510 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
511 DVLOG(1) << reason; 511 DVLOG(1) << reason;
512 state_ = kError; 512 state_ = kError;
513 observer_->OnError(); 513 observer_->OnError();
514 } 514 }
515 515
516 } // namespace media 516 } // namespace media
OLDNEW
« no previous file with comments | « trunk/src/gpu/tools/compositor_model_bench/compositor_model_bench.cc ('k') | trunk/src/net/base/directory_lister.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698