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

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

Issue 91343002: Added supported formats caching to VideoCaptureManager. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Mad formatting corrected in certain files. Created 7 years 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 (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>
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } else { 139 } else {
140 DVLOG(1) << "No usable formats reported by " << info.GetName().value(); 140 DVLOG(1) << "No usable formats reported by " << info.GetName().value();
141 } 141 }
142 } 142 }
143 close(fd); 143 close(fd);
144 } 144 }
145 } 145 }
146 146
147 void VideoCaptureDevice::GetDeviceSupportedFormats( 147 void VideoCaptureDevice::GetDeviceSupportedFormats(
148 const Name& device, 148 const Name& device,
149 VideoCaptureCapabilities* formats) { 149 VideoCaptureFormats* supported_formats) {
150
151 if (device.id().empty()) 150 if (device.id().empty())
152 return; 151 return;
153 int fd; 152 int fd;
154 VideoCaptureCapabilities capture_formats; 153 if ((fd = open(device.id().c_str(), O_RDONLY)) < 0)
155 if ((fd = open(device.id().c_str(), O_RDONLY)) < 0) {
156 // Failed to open this device.
157 return; 154 return;
158 }
159 155
160 formats->clear(); 156 supported_formats->clear();
161 157 // Retrieve the caps one by one, first get pixel format, then sizes, then
162 VideoCaptureCapability capture_capability; 158 // frame rates. See http://linuxtv.org/downloads/v4l-dvb-apis for reference.
163 // Retrieve the caps one by one, first get colorspace, then sizes, then
164 // framerates. See http://linuxtv.org/downloads/v4l-dvb-apis for reference.
165 v4l2_fmtdesc pixel_format = {}; 159 v4l2_fmtdesc pixel_format = {};
166 pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 160 pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
167 while (ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format) == 0) { 161 while (ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format) == 0) {
168 capture_capability.supported_format.pixel_format = 162 VideoCaptureFormat supported_format;
163 supported_format.pixel_format =
169 V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat); 164 V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat);
170 if (capture_capability.supported_format.pixel_format == 165 if (supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN) {
171 PIXEL_FORMAT_UNKNOWN) {
172 continue; 166 continue;
173 } 167 }
174 168
175 v4l2_frmsizeenum frame_size = {}; 169 v4l2_frmsizeenum frame_size = {};
176 frame_size.pixel_format = pixel_format.pixelformat; 170 frame_size.pixel_format = pixel_format.pixelformat;
177 while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0) { 171 while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0) {
178 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) { 172 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
179 capture_capability.supported_format.frame_size.SetSize( 173 supported_format.frame_size.SetSize(
180 frame_size.discrete.width, frame_size.discrete.height); 174 frame_size.discrete.width, frame_size.discrete.height);
181 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE) { 175 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
182 // TODO(mcasas): see http://crbug.com/249953, support these devices. 176 // TODO(mcasas): see http://crbug.com/249953, support these devices.
183 NOTIMPLEMENTED(); 177 NOTIMPLEMENTED();
184 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) { 178 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
185 // TODO(mcasas): see http://crbug.com/249953, support these devices. 179 // TODO(mcasas): see http://crbug.com/249953, support these devices.
186 NOTIMPLEMENTED(); 180 NOTIMPLEMENTED();
187 } 181 }
188 v4l2_frmivalenum frame_interval = {}; 182 v4l2_frmivalenum frame_interval = {};
189 frame_interval.pixel_format = pixel_format.pixelformat; 183 frame_interval.pixel_format = pixel_format.pixelformat;
190 frame_interval.width = frame_size.discrete.width; 184 frame_interval.width = frame_size.discrete.width;
191 frame_interval.height = frame_size.discrete.height; 185 frame_interval.height = frame_size.discrete.height;
192 while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) == 0) { 186 while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) == 0) {
193 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { 187 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
194 if (frame_interval.discrete.numerator != 0) { 188 if (frame_interval.discrete.numerator != 0) {
195 capture_capability.supported_format.frame_rate = 189 supported_format.frame_rate =
196 static_cast<float>(frame_interval.discrete.denominator) / 190 static_cast<float>(frame_interval.discrete.denominator) /
197 static_cast<float>(frame_interval.discrete.numerator); 191 static_cast<float>(frame_interval.discrete.numerator);
198 } else { 192 } else {
199 capture_capability.supported_format.frame_rate = 0; 193 supported_format.frame_rate = 0;
200 } 194 }
201 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) { 195 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
202 // TODO(mcasas): see http://crbug.com/249953, support these devices. 196 // TODO(mcasas): see http://crbug.com/249953, support these devices.
203 NOTIMPLEMENTED(); 197 NOTIMPLEMENTED();
204 break; 198 break;
205 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_STEPWISE) { 199 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
206 // TODO(mcasas): see http://crbug.com/249953, support these devices. 200 // TODO(mcasas): see http://crbug.com/249953, support these devices.
207 NOTIMPLEMENTED(); 201 NOTIMPLEMENTED();
208 break; 202 break;
209 } 203 }
210 formats->push_back(capture_capability); 204 supported_formats->push_back(supported_format);
211 ++frame_interval.index; 205 ++frame_interval.index;
212 } 206 }
213 ++frame_size.index; 207 ++frame_size.index;
214 } 208 }
215 ++pixel_format.index; 209 ++pixel_format.index;
216 } 210 }
217 211
218 close(fd); 212 close(fd);
219 return; 213 return;
220 } 214 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 607
614 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 608 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
615 DCHECK(!v4l2_thread_.IsRunning() || 609 DCHECK(!v4l2_thread_.IsRunning() ||
616 v4l2_thread_.message_loop() == base::MessageLoop::current()); 610 v4l2_thread_.message_loop() == base::MessageLoop::current());
617 DVLOG(1) << reason; 611 DVLOG(1) << reason;
618 state_ = kError; 612 state_ = kError;
619 client_->OnError(); 613 client_->OnError();
620 } 614 }
621 615
622 } // namespace media 616 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698