#include <stdio.h>
#include <stdlib.h>
#include <linux/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <linux/videodev2.h>
#include <errno.h>
#include "rgb133v4l2.h"
Defines | |
#define | CAPS(x) if (caps & x) { printf("%s" #x "\n", prefix); } |
Functions | |
void | DumpCaps (__u32 caps, char *prefix) |
int | main (int argc, char *argv[]) |
Variables | |
const char * | deviceFormat = "/dev/video%d" |
#define CAPS | ( | x | ) | if (caps & x) { printf("%s" #x "\n", prefix); } |
void DumpCaps | ( | __u32 | caps, | |
char * | prefix | |||
) |
00018 { 00019 #if defined(V4L2_CAP_VIDEO_CAPTURE) 00020 CAPS(V4L2_CAP_VIDEO_CAPTURE); 00021 #endif 00022 #if defined(V4L2_CAP_VIDEO_CAPTURE_MPLANE) 00023 CAPS(V4L2_CAP_VIDEO_CAPTURE_MPLANE); 00024 #endif 00025 #if defined(V4L2_CAP_VIDEO_OUTPUT) 00026 CAPS(V4L2_CAP_VIDEO_OUTPUT); 00027 #endif 00028 #if defined(V4L2_CAP_VIDEO_OUTPUT_MPLANE) 00029 CAPS(V4L2_CAP_VIDEO_OUTPUT_MPLANE); 00030 #endif 00031 #if defined(V4L2_CAP_VIDEO_M2M) 00032 CAPS(V4L2_CAP_VIDEO_M2M); 00033 #endif 00034 #if defined(V4L2_CAP_VIDEO_M2M_MPLANE) 00035 CAPS(V4L2_CAP_VIDEO_M2M_MPLANE); 00036 #endif 00037 #if defined(V4L2_CAP_VIDEO_OVERLAY) 00038 CAPS(V4L2_CAP_VIDEO_OVERLAY); 00039 #endif 00040 #if defined(V4L2_CAP_VBI_CAPTURE) 00041 CAPS(V4L2_CAP_VBI_CAPTURE); 00042 #endif 00043 #if defined(V4L2_CAP_VBI_OUTPUT) 00044 CAPS(V4L2_CAP_VBI_OUTPUT); 00045 #endif 00046 #if defined(V4L2_CAP_SLICED_VBI_CAPTURE) 00047 CAPS(V4L2_CAP_SLICED_VBI_CAPTURE); 00048 #endif 00049 #if defined(V4L2_CAP_SLICED_VBI_OUTPUT) 00050 CAPS(V4L2_CAP_SLICED_VBI_OUTPUT); 00051 #endif 00052 #if defined(V4L2_CAP_RDS_CAPTURE) 00053 CAPS(V4L2_CAP_RDS_CAPTURE); 00054 #endif 00055 #if defined(V4L2_CAP_VIDEO_OUTPUT_OVERLAY) 00056 CAPS(V4L2_CAP_VIDEO_OUTPUT_OVERLAY); 00057 #endif 00058 #if defined(V4L2_CAP_HW_FREQ_SEEK) 00059 CAPS(V4L2_CAP_HW_FREQ_SEEK); 00060 #endif 00061 #if defined(V4L2_CAP_RDS_OUTPUT) 00062 CAPS(V4L2_CAP_RDS_OUTPUT); 00063 #endif 00064 #if defined(V4L2_CAP_TUNER) 00065 CAPS(V4L2_CAP_TUNER); 00066 #endif 00067 #if defined(V4L2_CAP_AUDIO) 00068 CAPS(V4L2_CAP_AUDIO); 00069 #endif 00070 #if defined(V4L2_CAP_RADIO) 00071 CAPS(V4L2_CAP_RADIO); 00072 #endif 00073 #if defined(V4L2_CAP_MODULATOR) 00074 CAPS(V4L2_CAP_MODULATOR); 00075 #endif 00076 #if defined(V4L2_CAP_READWRITE) 00077 CAPS(V4L2_CAP_READWRITE); 00078 #endif 00079 #if defined(V4L2_CAP_ASYNCIO) 00080 CAPS(V4L2_CAP_ASYNCIO); 00081 #endif 00082 #if defined(V4L2_CAP_STREAMING) 00083 CAPS(V4L2_CAP_STREAMING); 00084 #endif 00085 #if defined(V4L2_CAP_DEVICE_CAPS) 00086 CAPS(V4L2_CAP_DEVICE_CAPS); 00087 #endif 00088 }
int main | ( | int | argc, | |
char * | argv[] | |||
) |
00091 { 00092 int i = 0; 00093 char device[16]; 00094 int file_descriptor; 00095 00096 sprintf(device, deviceFormat, i); 00097 00098 while ((file_descriptor=open(device, O_RDWR)) != -1) 00099 { 00100 /* we opened a device, find its properties */ 00101 int retval; 00102 struct v4l2_capability caps; 00103 00104 if ((retval = ioctl(file_descriptor, VIDIOC_QUERYCAP, &caps)) >= 0) 00105 { 00106 printf("Device %d (%s) is a v4l2 device\n", i, device); 00107 printf("Driver name is: %s\n", caps.driver); 00108 printf("Card name is: %s\n", caps.card); 00109 printf("Bus position: %s\n", caps.bus_info); 00110 printf("Version: %d.%d.%d\n", caps.version >> 16 & 0xFF, caps.version >> 8 & 0xFF, caps.version & 0xFF); 00111 00112 #if defined(V4L2_CAP_DEVICE_CAPS) 00113 printf("Driver capabilities:\n"); 00114 DumpCaps(caps.capabilities, " "); 00115 if (caps.capabilities & V4L2_CAP_DEVICE_CAPS) 00116 { 00117 printf("Device capabilities:\n"); 00118 DumpCaps(caps.device_caps, " "); 00119 } 00120 #endif 00121 printf("\n"); 00122 // Enumerate inputs: 00123 { 00124 struct v4l2_input ip; 00125 00126 ip.index = 0; 00127 while (ioctl(file_descriptor, VIDIOC_ENUMINPUT, &ip) == 0) 00128 { 00129 ip.index++; 00130 printf("Input %d has name: %s\n", ip.index, ip.name); 00131 } 00132 printf("There are %d input(s) on this device.\n\n", ip.index); 00133 } 00134 // Enumerate standard controls 00135 { 00136 struct v4l2_queryctrl qc; 00137 int i = 0; 00138 qc.id = V4L2_CID_BASE; 00139 while (qc.id <= V4L2_CID_LASTP1) 00140 { 00141 if (ioctl(file_descriptor, VIDIOC_QUERYCTRL, &qc) == 0) 00142 { 00143 i++; 00144 if (qc.flags & V4L2_CTRL_FLAG_DISABLED) 00145 { 00146 // Control is disabled, move onto the next. 00147 printf("Control %s is disabled\n", qc.name); 00148 qc.id++; 00149 continue; 00150 } 00151 printf ("Control %s has minimum of %d and maximum of %d\n", qc.name, qc.minimum, qc.maximum); 00152 } 00153 qc.id++; 00154 } 00155 printf("There are a total of %d standard controls\n\n", i); 00156 } 00157 // Enumerate custom controls (i.e. generic parameters which aren't in the V4L2 control list) 00158 { 00159 struct v4l2_queryctrl qc; 00160 int i=0; 00161 qc.id = V4L2_CID_PRIVATE_BASE; 00162 while (ioctl(file_descriptor, VIDIOC_QUERYCTRL, &qc) == 0) 00163 { 00164 i++; 00165 if (qc.flags & V4L2_CTRL_FLAG_DISABLED) 00166 { 00167 // Control is disabled, move onto the next. 00168 printf ("Private Control %s is disabled\n", qc.name); 00169 qc.id++; 00170 continue; 00171 } 00172 printf ("Private Control %s has minimum of %d and maximum of %d\n", qc.name, qc.minimum, qc.maximum); 00173 qc.id++; 00174 } 00175 printf ("There are a total of %d custom controls\n", i); 00176 } 00177 00178 00179 } else { 00180 printf("Retval was %d with errno as %d\n", retval, errno); 00181 printf("Device %d (%s) isn't a v4l2 device\n", i, device); 00182 goto next; 00183 } 00184 next: 00185 printf ("\n"); 00186 00187 close(file_descriptor); 00188 i++; 00189 sprintf(device, deviceFormat, i); 00190 } 00191 printf("\nEnumerated %d capture devices\n", i); 00192 }
const char* deviceFormat = "/dev/video%d" |