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

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: 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 150
151 if (device.id().empty()) 151 if (device.id().empty())
152 return; 152 return;
153 int fd; 153 int fd;
154 VideoCaptureCapabilities capture_formats; 154 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; 155 return;
158 }
159 156
160 formats->clear(); 157 supported_formats->clear();
161 158 // Retrieve the caps one by one, first get pixel format, then sizes, then
162 VideoCaptureCapability capture_capability; 159 // 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 = {}; 160 v4l2_fmtdesc pixel_format = {};
166 pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 161 pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
167 while (ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format) == 0) { 162 while (ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format) == 0) {
168 capture_capability.supported_format.pixel_format = 163 VideoCaptureFormat supported_format;
164 supported_format.pixel_format =
169 V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat); 165 V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat);
170 if (capture_capability.supported_format.pixel_format == 166 if (supported_format.pixel_format == PIXEL_FORMAT_UNKNOWN) {
171 PIXEL_FORMAT_UNKNOWN) {
172 continue; 167 continue;
173 } 168 }
174 169
175 v4l2_frmsizeenum frame_size = {}; 170 v4l2_frmsizeenum frame_size = {};
176 frame_size.pixel_format = pixel_format.pixelformat; 171 frame_size.pixel_format = pixel_format.pixelformat;
177 while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0) { 172 while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0) {
178 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) { 173 if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
179 capture_capability.supported_format.frame_size.SetSize( 174 supported_format.frame_size.SetSize(frame_size.discrete.width,
180 frame_size.discrete.width, frame_size.discrete.height); 175 frame_size.discrete.height);
181 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE) { 176 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
182 // TODO(mcasas): see http://crbug.com/249953, support these devices. 177 // TODO(mcasas): see http://crbug.com/249953, support these devices.
183 NOTIMPLEMENTED(); 178 NOTIMPLEMENTED();
184 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) { 179 } else if (frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
185 // TODO(mcasas): see http://crbug.com/249953, support these devices. 180 // TODO(mcasas): see http://crbug.com/249953, support these devices.
186 NOTIMPLEMENTED(); 181 NOTIMPLEMENTED();
187 } 182 }
188 v4l2_frmivalenum frame_interval = {}; 183 v4l2_frmivalenum frame_interval = {};
189 frame_interval.pixel_format = pixel_format.pixelformat; 184 frame_interval.pixel_format = pixel_format.pixelformat;
190 frame_interval.width = frame_size.discrete.width; 185 frame_interval.width = frame_size.discrete.width;
191 frame_interval.height = frame_size.discrete.height; 186 frame_interval.height = frame_size.discrete.height;
192 while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) == 0) { 187 while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) == 0) {
193 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { 188 if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
194 if (frame_interval.discrete.numerator != 0) { 189 if (frame_interval.discrete.numerator != 0) {
195 capture_capability.supported_format.frame_rate = 190 supported_format.frame_rate =
196 static_cast<float>(frame_interval.discrete.denominator) / 191 static_cast<float>(frame_interval.discrete.denominator) /
197 static_cast<float>(frame_interval.discrete.numerator); 192 static_cast<float>(frame_interval.discrete.numerator);
198 } else { 193 } else {
199 capture_capability.supported_format.frame_rate = 0; 194 supported_format.frame_rate = 0;
200 } 195 }
201 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) { 196 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
202 // TODO(mcasas): see http://crbug.com/249953, support these devices. 197 // TODO(mcasas): see http://crbug.com/249953, support these devices.
203 NOTIMPLEMENTED(); 198 NOTIMPLEMENTED();
204 break; 199 break;
205 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_STEPWISE) { 200 } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
206 // TODO(mcasas): see http://crbug.com/249953, support these devices. 201 // TODO(mcasas): see http://crbug.com/249953, support these devices.
207 NOTIMPLEMENTED(); 202 NOTIMPLEMENTED();
208 break; 203 break;
209 } 204 }
210 formats->push_back(capture_capability); 205 supported_formats->push_back(supported_format);
211 ++frame_interval.index; 206 ++frame_interval.index;
212 } 207 }
213 ++frame_size.index; 208 ++frame_size.index;
214 } 209 }
215 ++pixel_format.index; 210 ++pixel_format.index;
216 } 211 }
217 212
218 close(fd); 213 close(fd);
219 return; 214 return;
220 } 215 }
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 608
614 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) { 609 void VideoCaptureDeviceLinux::SetErrorState(const std::string& reason) {
615 DCHECK(!v4l2_thread_.IsRunning() || 610 DCHECK(!v4l2_thread_.IsRunning() ||
616 v4l2_thread_.message_loop() == base::MessageLoop::current()); 611 v4l2_thread_.message_loop() == base::MessageLoop::current());
617 DVLOG(1) << reason; 612 DVLOG(1) << reason;
618 state_ = kError; 613 state_ = kError;
619 client_->OnError(); 614 client_->OnError();
620 } 615 }
621 616
622 } // namespace media 617 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698