Chromium Code Reviews| Index: media/video/capture/linux/video_capture_device_linux.cc |
| diff --git a/media/video/capture/linux/video_capture_device_linux.cc b/media/video/capture/linux/video_capture_device_linux.cc |
| index b7a2e137ea9e42273c9636a82770f0f87e7314f2..24999b8d3ef6b4f54491b0548ef1de35c7becc52 100644 |
| --- a/media/video/capture/linux/video_capture_device_linux.cc |
| +++ b/media/video/capture/linux/video_capture_device_linux.cc |
| @@ -141,6 +141,77 @@ void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
| } |
| } |
| +void VideoCaptureDevice::GetDeviceSupportedFormats( |
| + const Name& device, |
| + VideoCaptureFormats* formats) { |
| + |
| + if (device.id().empty()) |
| + return; |
| + int fd; |
| + VideoCaptureFormats capture_formats; |
| + if ((fd = open(device.id().c_str(), O_RDONLY)) < 0) { |
| + // Failed to open this device. |
| + return; |
| + } |
| + |
| + formats->clear(); |
| + |
| + VideoCaptureCapability capture_format; |
| + // Retrieve the caps one by one, first get colorspace, then sizes, then |
| + // framerates. See http://linuxtv.org/downloads/v4l-dvb-apis for reference. |
| + v4l2_fmtdesc pixel_format = {}; |
| + pixel_format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; |
| + while (ioctl(fd, VIDIOC_ENUM_FMT, &pixel_format) == 0) { |
| + capture_format.color = |
| + V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat); |
|
perkj_chrome
2013/10/15 08:42:54
If you look at V4l2ColorToVideoCaptureColorFormat
mcasas
2013/10/15 11:32:09
Added the remaining colourspaces to V4l2...(); add
|
| + |
| + v4l2_frmsizeenum frame_size = {}; |
| + frame_size.pixel_format = pixel_format.pixelformat; |
| + while (ioctl(fd, VIDIOC_ENUM_FRAMESIZES, &frame_size) == 0) { |
| + if (frame_size.type == V4L2_FRMSIZE_TYPE_DISCRETE) { |
| + capture_format.width = frame_size.discrete.width; |
| + capture_format.height = frame_size.discrete.height; |
| + } else if (frame_size.type == V4L2_FRMSIZE_TYPE_STEPWISE) { |
| + // TODO(mcasas): see http://crbug.com/249953, support these devices. |
| + NOTIMPLEMENTED(); |
| + } else if (frame_size.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) { |
| + // TODO(mcasas): see http://crbug.com/249953, support these devices. |
| + NOTIMPLEMENTED(); |
| + } |
| + v4l2_frmivalenum frame_interval = {}; |
| + frame_interval.pixel_format = pixel_format.pixelformat; |
| + frame_interval.width = frame_size.discrete.width; |
| + frame_interval.height = frame_size.discrete.height; |
| + while (ioctl(fd, VIDIOC_ENUM_FRAMEINTERVALS, &frame_interval) == 0) { |
| + if (frame_interval.type == V4L2_FRMIVAL_TYPE_DISCRETE) { |
| + if (frame_interval.discrete.numerator != 0) { |
| + capture_format.frame_rate = |
| + static_cast<float>(frame_interval.discrete.denominator) / |
| + static_cast<float>(frame_interval.discrete.numerator); |
| + } else { |
| + capture_format.frame_rate = 0; |
| + } |
| + } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) { |
| + // TODO(mcasas): see http://crbug.com/249953, support these devices. |
| + NOTIMPLEMENTED(); |
| + break; |
| + } else if (frame_interval.type == V4L2_FRMIVAL_TYPE_STEPWISE) { |
| + // TODO(mcasas): see http://crbug.com/249953, support these devices. |
| + NOTIMPLEMENTED(); |
| + break; |
| + } |
| + formats->push_back(capture_format); |
| + ++frame_interval.index; |
| + } |
| + ++frame_size.index; |
| + } |
| + ++pixel_format.index; |
| + } |
| + |
| + close(fd); |
| + return; |
| +} |
| + |
| static bool ReadIdFile(const std::string path, std::string* id) { |
| char id_buf[kVidPidSize]; |
| FILE* file = fopen(path.c_str(), "rb"); |