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..1958db16cc9872cc370b3f44f2fc5a0e4fbbc02d 100644 |
--- a/media/video/capture/linux/video_capture_device_linux.cc |
+++ b/media/video/capture/linux/video_capture_device_linux.cc |
@@ -141,6 +141,86 @@ void VideoCaptureDevice::GetDeviceNames(Names* device_names) { |
} |
} |
+void VideoCaptureDevice::GetDeviceSupportedFormats( |
+ const Name& device, |
+ VideoCaptureFormats* const 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(); |
+ // Test if this is a V4L2 capture device. |
perkj_chrome
2013/10/13 12:12:48
no need for this - the |device| must come from Get
mcasas
2013/10/14 08:24:46
Done.
|
+ v4l2_capability device_capability; |
+ if (!((ioctl(fd, VIDIOC_QUERYCAP, &device_capability) == 0) && |
+ (device_capability.capabilities & V4L2_CAP_VIDEO_CAPTURE) && |
+ !(device_capability.capabilities & V4L2_CAP_VIDEO_OUTPUT))) { |
+ // The selected device is not video capture as we like it. |
+ close(fd); |
+ return; |
+ } |
+ |
+ 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) { |
perkj_chrome
2013/10/13 12:12:48
I don't think this function should return duplicat
mcasas
2013/10/14 08:24:46
This information is not for the user, but for the
|
+ capture_format.color = |
+ V4l2ColorToVideoCaptureColorFormat((int32)pixel_format.pixelformat); |
+ |
+ 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) { |
perkj_chrome
2013/10/13 12:12:49
I don't think we care about all frame rates either
mcasas
2013/10/14 08:24:46
One of the bugs related to this is asking for a fr
|
+ 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"); |