1 // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "media_v4l2_device.h" 6 7 8 // Checks whether /dev/videoX is a video capture device. Return value 0 means 9 // it is a capture device. 1 otherwise. 10 int main(int argc, char** argv) { 11 if (argc < 2) { 12 printf("Usage: media_v4l2_is_capture_device /dev/videoX\n"); 13 return 1; 14 } 15 16 V4L2Device v4l2_dev(argv[1], V4L2Device::IO_METHOD_MMAP, 4); 17 if (!v4l2_dev.OpenDevice()) { 18 printf("[Error] Can not open device '%s'\n", argv[1]); 19 return 1; 20 } 21 22 bool is_capture_device = false; 23 v4l2_capability caps; 24 if (!v4l2_dev.ProbeCaps(&caps, false)) { 25 printf("[Error] Can not probe caps on device '%s'\n", argv[1]); 26 } else { 27 // mem2mem devices have V4L2_CAP_VIDEO_OUTPUT but real cameras do not. 28 is_capture_device = ((caps.capabilities & V4L2_CAP_VIDEO_CAPTURE) && 29 !(caps.capabilities & V4L2_CAP_VIDEO_OUTPUT)); 30 } 31 v4l2_dev.CloseDevice(); 32 33 return is_capture_device ? 0 : 1; 34 } 35