33 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) 34 #define FOURCC_FORMAT "%c%c%c%c" 35 #define FOURCC_ARGS(c) (c) & 0xFF, ((c) >> 8) & 0xFF, ((c) >> 16) & 0xFF, ((c) >> 24) & 0xFF 40 int jpeg_decode (
unsigned char **pic,
unsigned char *buf,
int *width,
int *height);
71 if (vd == NULL || device == NULL)
73 vd->
videodevice = (
char *) calloc(1, 16 *
sizeof(
char));
75 printf(
"Device information:\n");
78 perror(
"ERROR opening V4L interface");
81 memset(&vd->
cap, 0,
sizeof(
struct v4l2_capability));
82 ret = v4l2_ioctl(vd->
fd, VIDIOC_QUERYCAP, &vd->
cap);
84 printf(
"Error opening device %s: unable to query device.\n",
88 if ((vd->
cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
89 printf(
"Error opening device %s: video capture not supported.\n",
92 if (!(vd->
cap.capabilities & V4L2_CAP_STREAMING)) {
93 printf(
"%s does not support streaming i/o\n", vd->
videodevice);
95 if (!(vd->
cap.capabilities & V4L2_CAP_READWRITE)) {
96 printf(
"%s does not support read i/o\n", vd->
videodevice);
106 int format,
int grabmethod,
char *avifilename)
110 if (vd == NULL || device == NULL)
112 if (width == 0 || height == 0)
114 if (grabmethod < 0 || grabmethod > 1)
119 vd->
videodevice = (
char *) calloc(1, 16 *
sizeof(
char));
120 vd->
status = (
char *) calloc(1, 100 *
sizeof(
char));
121 vd->
pictName = (
char *) calloc(1, 80 *
sizeof(
char));
123 printf(
"Device information:\n");
143 printf(
" Init v4L2 failed !! exit fatal\n");
149 case V4L2_PIX_FMT_MJPEG:
151 (
unsigned char *) calloc(1, (
size_t) vd->
framesizeIn);
155 (
unsigned char *) calloc(1,
159 case V4L2_PIX_FMT_YUYV:
160 case V4L2_PIX_FMT_UYVY:
162 (
unsigned char *) calloc(1, (
size_t) vd->
framesizeIn);
165 printf(
" should never arrive exit fatal !!\n");
181 struct v4l2_queryctrl queryctrl;
182 struct v4l2_querymenu querymenu;
183 struct v4l2_control control_s;
184 struct v4l2_input* getinput;
187 getinput=(
struct v4l2_input *) calloc(1,
sizeof(
struct v4l2_input));
188 memset(getinput, 0,
sizeof(
struct v4l2_input));
190 v4l2_ioctl(vd,VIDIOC_ENUMINPUT , getinput);
191 printf (
"Available controls of device '%s' (Type 1=Integer 2=Boolean 3=Menu 4=Button)\n", getinput->name);
194 void enumerate_menu (
void) {
195 printf (
" Menu items:\n");
196 memset (&querymenu, 0,
sizeof (querymenu));
197 querymenu.id = queryctrl.id;
198 for (querymenu.index = queryctrl.minimum;
199 querymenu.index <= queryctrl.maximum;
201 if (0 == ioctl (vd, VIDIOC_QUERYMENU, &querymenu)) {
202 printf (
" index:%d name:%s\n", querymenu.index, querymenu.name);
205 printf (
"error getting control menu");
212 printf (
"V4L2_CID_BASE (predefined controls):\n");
213 memset (&queryctrl, 0,
sizeof (queryctrl));
214 for (queryctrl.id = V4L2_CID_BASE;
215 queryctrl.id < V4L2_CID_LASTP1;
217 if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
218 if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
220 control_s.id=queryctrl.id;
221 v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
223 printf (
" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%-5d now:%d\n",
224 queryctrl.id, queryctrl.name, queryctrl.type, queryctrl.minimum,
225 queryctrl.maximum, queryctrl.step, queryctrl.default_value, control_s.value);
226 if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
231 perror (
"error getting base controls");
237 printf (
"V4L2_CID_PRIVATE_BASE (driver specific controls):\n");
238 for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
240 if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
241 if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
243 control_s.id=queryctrl.id;
244 v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
246 printf (
" index:%-10d name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%-5d now:%d\n",
247 queryctrl.id, queryctrl.name, queryctrl.type, queryctrl.minimum,
248 queryctrl.maximum, queryctrl.step, queryctrl.default_value, control_s.value);
249 if (queryctrl.type == V4L2_CTRL_TYPE_MENU)
254 perror (
"error getting private base controls");
264 struct v4l2_queryctrl queryctrl;
265 struct v4l2_control control_s;
267 memset (&queryctrl, 0,
sizeof (queryctrl));
268 memset (&control_s, 0,
sizeof (control_s));
269 configfile = fopen(filename,
"w");
270 if ( configfile == NULL) {
271 perror(
"saving configfile luvcview.cfg failed");
274 fprintf(configfile,
"id value # luvcview control settings configuration file\n");
275 for (queryctrl.id = V4L2_CID_BASE;
276 queryctrl.id < V4L2_CID_LASTP1;
278 if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
279 if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
281 control_s.id=queryctrl.id;
282 v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
284 fprintf (configfile,
"%-10d %-10d # name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%d\n",
285 queryctrl.id, control_s.value, queryctrl.name, queryctrl.type, queryctrl.minimum,
286 queryctrl.maximum, queryctrl.step, queryctrl.default_value);
287 printf (
"%-10d %-10d # name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%d\n",
288 queryctrl.id, control_s.value, queryctrl.name, queryctrl.type, queryctrl.minimum,
289 queryctrl.maximum, queryctrl.step, queryctrl.default_value);
293 for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
295 if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
296 if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
298 if ((queryctrl.id==134217735) || (queryctrl.id==134217736))
300 control_s.id=queryctrl.id;
301 v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
303 fprintf (configfile,
"%-10d %-10d # name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%d\n",
304 queryctrl.id, control_s.value, queryctrl.name, queryctrl.type, queryctrl.minimum,
305 queryctrl.maximum, queryctrl.step, queryctrl.default_value);
306 printf (
"%-10d %-10d # name:%-32s type:%d min:%-5d max:%-5d step:%-5d def:%d\n",
307 queryctrl.id, control_s.value, queryctrl.name, queryctrl.type, queryctrl.minimum,
308 queryctrl.maximum, queryctrl.step, queryctrl.default_value);
323 struct v4l2_control control;
325 memset (&control, 0,
sizeof (control));
326 configfile = fopen(filename,
"r");
327 if ( configfile == NULL) {
328 perror(
"configfile luvcview.cfg open failed");
331 printf(
"loading controls from luvcview.cfg\n");
333 fgets(buffer,
sizeof(buffer), configfile);
334 while (NULL !=fgets(buffer,
sizeof(buffer), configfile) )
336 sscanf(buffer,
"%i%i", &control.id, &control.value);
337 if (v4l2_ioctl(vd, VIDIOC_S_CTRL, &control))
338 printf(
"ERROR id:%d val:%d\n", control.id, control.value);
340 printf(
"OK id:%d val:%d\n", control.id, control.value);
353 perror(
"ERROR opening V4L interface");
356 memset(&vd->
cap, 0,
sizeof(
struct v4l2_capability));
357 ret = v4l2_ioctl(vd->
fd, VIDIOC_QUERYCAP, &vd->
cap);
359 printf(
"Error opening device %s: unable to query device.\n",
364 if ((vd->
cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
365 printf(
"Error opening device %s: video capture not supported.\n",
370 if (!(vd->
cap.capabilities & V4L2_CAP_STREAMING)) {
371 printf(
"%s does not support streaming i/o\n", vd->
videodevice);
375 if (!(vd->
cap.capabilities & V4L2_CAP_READWRITE)) {
376 printf(
"%s does not support read i/o\n", vd->
videodevice);
381 printf(
"Stream settings:\n");
385 unsigned int device_formats[16] = { 0 };
386 int requested_format_found = 0, fallback_format = -1;
388 printf(
"Unable to enumerate frame formats");
391 for(i = 0; i <
ARRAY_SIZE(device_formats) && device_formats[i]; i++) {
392 if(device_formats[i] == vd->
formatIn) {
393 requested_format_found = 1;
396 if(device_formats[i] == V4L2_PIX_FMT_MJPEG || device_formats[i] == V4L2_PIX_FMT_YUYV
397 || device_formats[i] == V4L2_PIX_FMT_UYVY)
401 if(requested_format_found) {
405 else if(fallback_format >= 0) {
408 " is not supported by device)\n",
414 printf(
"ERROR: Requested frame format "FOURCC_FORMAT" is not available " 420 memset(&vd->
fmt, 0,
sizeof(
struct v4l2_format));
421 vd->
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
425 vd->
fmt.fmt.pix.field = V4L2_FIELD_ANY;
426 ret = v4l2_ioctl(vd->
fd, VIDIOC_S_FMT, &vd->
fmt);
428 perror(
"Unable to set format");
431 if ((vd->
fmt.fmt.pix.width != vd->
width) ||
432 (vd->
fmt.fmt.pix.height != vd->
height)) {
433 printf(
" Frame size: %ux%u (requested size %ux%u is not supported by device)\n",
441 printf(
" Frame size: %dx%d\n", vd->
width, vd->
height);
445 struct v4l2_streamparm* setfps;
446 setfps=(
struct v4l2_streamparm *) calloc(1,
sizeof(
struct v4l2_streamparm));
447 memset(setfps, 0,
sizeof(
struct v4l2_streamparm));
448 setfps->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
453 setfps->parm.capture.timeperframe.numerator = d;
454 setfps->parm.capture.timeperframe.denominator = n;
456 ret = v4l2_ioctl(vd->
fd, VIDIOC_S_PARM, setfps);
458 perror(
"Unable to set frame rate");
461 ret = v4l2_ioctl(vd->
fd, VIDIOC_G_PARM, setfps);
463 float confirmed_fps = (float)setfps->parm.capture.timeperframe.denominator / (
float)setfps->parm.capture.timeperframe.numerator;
464 if (confirmed_fps != (
float)n / (float)d) {
465 printf(
" Frame rate: %g fps (requested frame rate %g fps is " 466 "not supported by device)\n",
469 vd->
fps = confirmed_fps;
472 printf(
" Frame rate: %g fps\n", vd->
fps);
476 perror(
"Unable to read out current frame rate");
481 memset(&vd->
rb, 0,
sizeof(
struct v4l2_requestbuffers));
483 vd->
rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
484 vd->
rb.memory = V4L2_MEMORY_MMAP;
486 ret = v4l2_ioctl(vd->
fd, VIDIOC_REQBUFS, &vd->
rb);
488 perror(
"Unable to allocate buffers");
493 memset(&vd->
buf, 0,
sizeof(
struct v4l2_buffer));
495 vd->
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
496 vd->
buf.memory = V4L2_MEMORY_MMAP;
497 ret = v4l2_ioctl(vd->
fd, VIDIOC_QUERYBUF, &vd->
buf);
499 perror(
"Unable to query buffer");
503 printf(
"length: %u offset: %u\n", vd->
buf.length,
505 vd->
mem[i] = v4l2_mmap(0 ,
506 vd->
buf.length, PROT_READ, MAP_SHARED, vd->
fd,
508 if (vd->
mem[i] == MAP_FAILED) {
509 perror(
"Unable to map buffer");
513 printf(
"Buffer mapped at address %p.\n", vd->
mem[i]);
517 memset(&vd->
buf, 0,
sizeof(
struct v4l2_buffer));
519 vd->
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
520 vd->
buf.memory = V4L2_MEMORY_MMAP;
521 ret = v4l2_ioctl(vd->
fd, VIDIOC_QBUF, &vd->
buf);
523 perror(
"Unable to queue buffer");
535 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
538 ret = v4l2_ioctl(vd->
fd, VIDIOC_STREAMON, &type);
540 perror(
"Unable to start capture");
549 int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
552 ret = v4l2_ioctl(vd->
fd, VIDIOC_STREAMOFF, &type);
554 perror(
"Unable to stop capture");
564 #define HEADERFRAME1 0xaf 570 memset(&vd->
buf, 0,
sizeof(
struct v4l2_buffer));
571 vd->
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
572 vd->
buf.memory = V4L2_MEMORY_MMAP;
573 ret = v4l2_ioctl(vd->
fd, VIDIOC_DQBUF, &vd->
buf);
575 perror(
"Unable to dequeue buffer");
590 sprintf(filename,
"frame%03u.raw", vd->
fileCounter++ % 1000);
591 frame = fopen(filename,
"wb");
593 perror(
"Unable to open file for raw frame capturing");
598 ret = fwrite(vd->
mem[vd->
buf.index], vd->
buf.bytesused, 1, frame);
600 perror(
"Unable to write to file");
603 printf(
"Saved raw frame to %s (%u bytes)\n", filename, vd->
buf.bytesused);
623 perror(
"Unable to write raw stream to file");
624 fprintf(stderr,
"Stream capturing terminated.\n");
633 printf(
"Appended raw frame to stream file (%u bytes)\n", vd->
buf.bytesused);
638 case V4L2_PIX_FMT_MJPEG:
641 printf(
"Ignoring empty buffer ...\n");
647 printf(
"jpeg decode errors\n");
651 printf(
"bytes in used %d\n", vd->
buf.bytesused);
653 case V4L2_PIX_FMT_YUYV:
654 case V4L2_PIX_FMT_UYVY:
660 (
size_t) vd->
buf.bytesused);
666 ret = v4l2_ioctl(vd->
fd, VIDIOC_QBUF, &vd->
buf);
668 perror(
"Unable to requeue buffer");
696 struct v4l2_queryctrl *queryctrl)
699 queryctrl->id = control;
700 if ((err= v4l2_ioctl(vd->
fd, VIDIOC_QUERYCTRL, queryctrl)) < 0) {
701 perror(
"ioctl querycontrol error");
702 }
else if (queryctrl->flags & V4L2_CTRL_FLAG_DISABLED) {
703 printf(
"control %s disabled\n", (
char *) queryctrl->name);
704 }
else if (queryctrl->flags & V4L2_CTRL_TYPE_BOOLEAN) {
706 }
else if (queryctrl->type & V4L2_CTRL_TYPE_INTEGER) {
709 printf(
"contol %s unsupported\n", (
char *) queryctrl->name);
716 struct v4l2_queryctrl queryctrl;
717 struct v4l2_control control_s;
721 control_s.id = control;
722 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_G_CTRL, &control_s)) < 0) {
723 printf(
"ioctl get control error\n");
726 return control_s.value;
731 struct v4l2_control control_s;
732 struct v4l2_queryctrl queryctrl;
733 int min, max, step, val_def;
737 min = queryctrl.minimum;
738 max = queryctrl.maximum;
739 step = queryctrl.step;
740 val_def = queryctrl.default_value;
741 if ((value >= min) && (value <= max)) {
742 control_s.id = control;
743 control_s.value = value;
744 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
745 printf(
"ioctl set control error\n");
753 struct v4l2_control control_s;
754 struct v4l2_queryctrl queryctrl;
755 int min, max, current, step, val_def;
760 min = queryctrl.minimum;
761 max = queryctrl.maximum;
762 step = queryctrl.step;
763 val_def = queryctrl.default_value;
766 printf(
"max %d, min %d, step %d, default %d ,current %d\n",max,min,step,val_def,current);
767 if (current <= max) {
768 control_s.id = control;
769 control_s.value = current;
770 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
771 printf(
"ioctl set control error\n");
774 printf (
"Control name:%s set to value:%d\n", queryctrl.name, control_s.value);
776 printf (
"Control name:%s already has max value:%d\n", queryctrl.name, max);
778 return control_s.value;
782 struct v4l2_control control_s;
783 struct v4l2_queryctrl queryctrl;
784 int min, max, current, step, val_def;
788 min = queryctrl.minimum;
789 max = queryctrl.maximum;
790 step = queryctrl.step;
791 val_def = queryctrl.default_value;
794 printf(
"max %d, min %d, step %d, default %d ,current %d\n",max,min,step,val_def,current);
795 if (current >= min) {
796 control_s.id = control;
797 control_s.value = current;
798 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
799 printf(
"ioctl set control error\n");
802 printf (
"Control name:%s set to value:%d\n", queryctrl.name, control_s.value);
805 printf (
"Control name:%s already has min value:%d\n", queryctrl.name, min);
807 return control_s.value;
811 struct v4l2_control control_s;
812 struct v4l2_queryctrl queryctrl;
818 control_s.id = control;
819 control_s.value = !current;
820 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
821 printf(
"ioctl toggle control error\n");
824 return control_s.value;
828 struct v4l2_control control_s;
829 struct v4l2_queryctrl queryctrl;
834 val_def = queryctrl.default_value;
835 control_s.id = control;
836 control_s.value = val_def;
837 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
838 printf(
"ioctl reset control error\n");
848 struct v4l2_control control_s;
849 struct v4l2_queryctrl queryctrl;
855 control_s.id = control;
857 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
858 printf(
"ERROR: Unable to reset pan (error = %d)\n", errno);
868 struct v4l2_control control_s;
869 struct v4l2_queryctrl queryctrl;
875 control_s.id = control;
877 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
878 printf(
"ERROR: Unable to reset tilt (error = %d)\n", errno);
888 struct v4l2_control control_s;
889 struct v4l2_queryctrl queryctrl;
896 control_s.id = control;
898 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
899 printf(
"ERROR: Unable to reset pan/tilt (error = %d)\n", errno);
909 struct v4l2_control control_s;
910 struct v4l2_queryctrl queryctrl;
915 control_s.id = control;
916 control_s.value = inc;
917 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
918 printf(
"ioctl pan updown control error\n");
926 struct v4l2_control control_s;
927 struct v4l2_queryctrl queryctrl;
932 control_s.id = control;
933 control_s.value = inc;
934 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
935 printf(
"ioctl tiltupdown control error\n");
944 struct v4l2_ext_controls control_s_array;
945 struct v4l2_queryctrl queryctrl;
946 struct v4l2_ext_control control_s[2];
952 control_s_array.count = 2;
953 control_s_array.ctrl_class = V4L2_CTRL_CLASS_USER;
954 control_s_array.reserved[0] = 0;
955 control_s_array.reserved[1] = 0;
956 control_s_array.controls = control_s;
958 control_s[0].id = p_control;
959 control_s[0].value = inc_p;
960 control_s[1].id = t_control;
961 control_s[1].value = inc_t;
963 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_EXT_CTRLS, &control_s_array)) < 0) {
964 printf(
"ioctl pan-tilt updown control error\n");
978 } __attribute__((packed)) ;
981 {
int control = V4L2_CID_PANTILT_RELATIVE;
982 struct v4l2_control control_s;
983 struct v4l2_queryctrl queryctrl;
988 control_s.id = control;
995 control_s.value = pan.value ;
996 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
997 printf(
"ioctl pan updown control error\n");
1004 {
int control = V4L2_CID_PANTILT_RELATIVE;
1005 struct v4l2_control control_s;
1006 struct v4l2_queryctrl queryctrl;
1009 control_s.id = control;
1016 control_s.value = pan.value;
1017 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
1018 printf(
"ioctl tiltupdown control error\n");
1026 {
int control = V4L2_CID_POWER_LINE_FREQUENCY;
1027 struct v4l2_control control_s;
1028 struct v4l2_queryctrl queryctrl;
1030 control_s.id = control;
1034 control_s.value = flt;
1036 if ((err = v4l2_ioctl(vd->
fd, VIDIOC_S_CTRL, &control_s)) < 0) {
1037 printf(
"ioctl set_light_frequency_filter error\n");
1045 struct v4l2_frmivalenum fival;
1047 memset(&fival, 0,
sizeof(fival));
1049 fival.pixel_format = pixfmt;
1050 fival.width = width;
1051 fival.height = height;
1052 printf(
"\tTime interval between frame: ");
1053 while ((ret = v4l2_ioctl(dev, VIDIOC_ENUM_FRAMEINTERVALS, &fival)) == 0) {
1054 if (fival.type == V4L2_FRMIVAL_TYPE_DISCRETE) {
1056 fival.discrete.numerator, fival.discrete.denominator);
1057 }
else if (fival.type == V4L2_FRMIVAL_TYPE_CONTINUOUS) {
1058 printf(
"{min { %u/%u } .. max { %u/%u } }, ",
1059 fival.stepwise.min.numerator, fival.stepwise.min.numerator,
1060 fival.stepwise.max.denominator, fival.stepwise.max.denominator);
1062 }
else if (fival.type == V4L2_FRMIVAL_TYPE_STEPWISE) {
1063 printf(
"{min { %u/%u } .. max { %u/%u } / " 1064 "stepsize { %u/%u } }, ",
1065 fival.stepwise.min.numerator, fival.stepwise.min.denominator,
1066 fival.stepwise.max.numerator, fival.stepwise.max.denominator,
1067 fival.stepwise.step.numerator, fival.stepwise.step.denominator);
1073 if (ret != 0 && errno != EINVAL) {
1074 perror(
"ERROR enumerating frame intervals");
1083 struct v4l2_frmsizeenum fsize;
1085 memset(&fsize, 0,
sizeof(fsize));
1087 fsize.pixel_format = pixfmt;
1088 while ((ret = v4l2_ioctl(dev, VIDIOC_ENUM_FRAMESIZES, &fsize)) == 0) {
1089 if (fsize.type == V4L2_FRMSIZE_TYPE_DISCRETE) {
1090 printf(
"{ discrete: width = %u, height = %u }\n",
1091 fsize.discrete.width, fsize.discrete.height);
1093 fsize.discrete.width, fsize.discrete.height);
1095 printf(
" Unable to enumerate frame sizes.\n");
1096 }
else if (fsize.type == V4L2_FRMSIZE_TYPE_CONTINUOUS) {
1097 printf(
"{ continuous: min { width = %u, height = %u } .. " 1098 "max { width = %u, height = %u } }\n",
1099 fsize.stepwise.min_width, fsize.stepwise.min_height,
1100 fsize.stepwise.max_width, fsize.stepwise.max_height);
1101 printf(
" Refusing to enumerate frame intervals.\n");
1103 }
else if (fsize.type == V4L2_FRMSIZE_TYPE_STEPWISE) {
1104 printf(
"{ stepwise: min { width = %u, height = %u } .. " 1105 "max { width = %u, height = %u } / " 1106 "stepsize { width = %u, height = %u } }\n",
1107 fsize.stepwise.min_width, fsize.stepwise.min_height,
1108 fsize.stepwise.max_width, fsize.stepwise.max_height,
1109 fsize.stepwise.step_width, fsize.stepwise.step_height);
1110 printf(
" Refusing to enumerate frame intervals.\n");
1115 if (ret != 0 && errno != EINVAL) {
1116 perror(
"ERROR enumerating frame sizes");
1126 struct v4l2_fmtdesc fmt;
1128 memset(&fmt, 0,
sizeof(fmt));
1130 fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1131 while ((ret = v4l2_ioctl(dev, VIDIOC_ENUM_FMT, &fmt)) == 0) {
1132 if(supported_formats == NULL) {
1133 printf(
"{ pixelformat = '%c%c%c%c', description = '%s' }\n",
1134 fmt.pixelformat & 0xFF, (fmt.pixelformat >> 8) & 0xFF,
1135 (fmt.pixelformat >> 16) & 0xFF, (fmt.pixelformat >> 24) & 0xFF,
1139 printf(
" Unable to enumerate frame sizes.\n");
1141 else if(fmt.index < max_formats) {
1142 supported_formats[fmt.index] = fmt.pixelformat;
1147 if (errno != EINVAL) {
1148 perror(
"ERROR enumerating frame formats");
int v4l2ResetPanTilt(struct vdIn *vd)
int v4l2GetControl(struct vdIn *vd, int control)
unsigned char * tmpbuffer
int load_controls(int vd, const char *filename)
int v4l2DownControl(struct vdIn *vd, int control)
int jpeg_decode(unsigned char **pic, unsigned char *buf, int *width, int *height)
int check_videoIn(struct vdIn *vd, char *device)
static int video_disable(struct vdIn *vd)
#define V4L2_CID_TILT_RESET
int v4l2ToggleControl(struct vdIn *vd, int control)
unsigned int rfsFramesWritten
int v4l2SetControl(struct vdIn *vd, int control, int value)
#define V4L2_CID_PAN_RELATIVE
int close_v4l2(struct vdIn *vd)
static int init_v4l2(struct vdIn *vd)
int enum_controls(int vd)
int v4l2ResetControl(struct vdIn *vd, int control)
struct v4l2_requestbuffers rb
unsigned int rfsBytesWritten
int v4L2UpDownPanTilt(struct vdIn *vd, short inc_p, short inc_t)
static int float_to_fraction_recursive(double f, double p, int *num, int *den)
int v4l2SetLightFrequencyFilter(struct vdIn *vd, int flt)
int v4l2ResetTilt(struct vdIn *vd)
int enum_frame_formats(int dev, unsigned int *supported_formats, unsigned int max_formats)
int enum_frame_intervals(int dev, __u32 pixfmt, __u32 width, __u32 height)
int uvcGrab(struct vdIn *vd)
unsigned int bytesWritten
int enum_frame_sizes(int dev, __u32 pixfmt)
int save_controls(int vd, const char *filename)
int v4l2UpControl(struct vdIn *vd, int control)
unsigned char * framebuffer
static int isv4l2Control(struct vdIn *vd, int control, struct v4l2_queryctrl *queryctrl)
#define V4L2_CID_TILT_RELATIVE
int v4L2UpDownTilt(struct vdIn *vd, short inc)
int v4L2UpDownPan(struct vdIn *vd, short inc)
static int video_enable(struct vdIn *vd)
static void float_to_fraction(float f, int *num, int *den)
struct v4l2_capability cap
unsigned int framesWritten
int init_videoIn(struct vdIn *vd, char *device, int width, int height, float fps, int format, int grabmethod, char *avifilename)
#define V4L2_CID_PANTILT_RESET
#define V4L2_CID_PAN_RESET
int v4l2ResetPan(struct vdIn *vd)