v4l2uvc.c
Go to the documentation of this file.
1 /*******************************************************************************
2 # uvcview: Sdl video Usb Video Class grabber . #
3 #This package work with the Logitech UVC based webcams with the mjpeg feature. #
4 #All the decoding is in user space with the embedded jpeg decoder #
5 #. #
6 # Copyright (C) 2005 2006 Laurent Pinchart && Michel Xhaard #
7 # #
8 # This program is free software; you can redistribute it and/or modify #
9 # it under the terms of the GNU General Public License as published by #
10 # the Free Software Foundation; either version 2 of the License, or #
11 # (at your option) any later version. #
12 # #
13 # This program is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU General Public License for more details. #
17 # #
18 # You should have received a copy of the GNU General Public License #
19 # along with this program; if not, write to the Free Software #
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
21 # #
22 *******************************************************************************/
23 
24 #include <stdlib.h>
25 #include <math.h>
26 #include <float.h>
27 
28 #include <libv4l2.h>
29 #include <SDL.h>
30 
31 #include "luvcview/v4l2uvc.h"
32 
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
36 
37 
38 static int debug = 0;
39 
40 int jpeg_decode (unsigned char **pic, unsigned char *buf, int *width, int *height);
41 
42 static int init_v4l2(struct vdIn *vd);
43 
44 static int float_to_fraction_recursive(double f, double p, int *num, int *den)
45 {
46  int whole = (int)f;
47  f = fabs(f - whole);
48 
49  if(f > p) {
50  int n, d;
51  int a = float_to_fraction_recursive(1 / f, p + p / f, &n, &d);
52  *num = d;
53  *den = d * a + n;
54  }
55  else {
56  *num = 0;
57  *den = 1;
58  }
59  return whole;
60 }
61 
62 static void float_to_fraction(float f, int *num, int *den)
63 {
64  int whole = float_to_fraction_recursive(f, FLT_EPSILON, num, den);
65  *num += whole * *den;
66 }
67 
68 int check_videoIn(struct vdIn *vd, char *device)
69 {
70  int ret;
71  if (vd == NULL || device == NULL)
72  return -1;
73  vd->videodevice = (char *) calloc(1, 16 * sizeof(char));
74  snprintf(vd->videodevice, 12, "%s", device);
75  printf("Device information:\n");
76  printf(" Device path: %s\n", vd->videodevice);
77  if ((vd->fd = v4l2_open(vd->videodevice, O_RDWR)) == -1) {
78  perror("ERROR opening V4L interface");
79  exit(1);
80  }
81  memset(&vd->cap, 0, sizeof(struct v4l2_capability));
82  ret = v4l2_ioctl(vd->fd, VIDIOC_QUERYCAP, &vd->cap);
83  if (ret < 0) {
84  printf("Error opening device %s: unable to query device.\n",
85  vd->videodevice);
86  goto fatal;
87  }
88  if ((vd->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
89  printf("Error opening device %s: video capture not supported.\n",
90  vd->videodevice);
91  }
92  if (!(vd->cap.capabilities & V4L2_CAP_STREAMING)) {
93  printf("%s does not support streaming i/o\n", vd->videodevice);
94  }
95  if (!(vd->cap.capabilities & V4L2_CAP_READWRITE)) {
96  printf("%s does not support read i/o\n", vd->videodevice);
97  }
98  enum_frame_formats(vd->fd, NULL, 0);
99 fatal:
100  v4l2_close(vd->fd);
101  free(vd->videodevice);
102  return 0;
103 }
104 int
105 init_videoIn(struct vdIn *vd, char *device, int width, int height, float fps,
106  int format, int grabmethod, char *avifilename)
107 {
108  int ret = -1;
109  int i;
110  if (vd == NULL || device == NULL)
111  return -1;
112  if (width == 0 || height == 0)
113  return -1;
114  if (grabmethod < 0 || grabmethod > 1)
115  grabmethod = 1; //mmap by default;
116  vd->videodevice = NULL;
117  vd->status = NULL;
118  vd->pictName = NULL;
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));
122  snprintf(vd->videodevice, 12, "%s", device);
123  printf("Device information:\n");
124  printf(" Device path: %s\n", vd->videodevice);
125  vd->recordtime = 0;
126  vd->framecount = 0;
127  vd->recordstart = 0;
128  vd->getPict = 0;
129  vd->signalquit = 1;
130  vd->width = width;
131  vd->height = height;
132  vd->fps = fps;
133  vd->formatIn = format;
134  vd->grabmethod = grabmethod;
135  vd->fileCounter = 0;
136  vd->rawFrameCapture = 0;
137  vd->rfsBytesWritten = 0;
138  vd->rfsFramesWritten = 0;
139  vd->captureFile = NULL;
140  vd->bytesWritten = 0;
141  vd->framesWritten = 0;
142  if (init_v4l2(vd) < 0) {
143  printf(" Init v4L2 failed !! exit fatal\n");
144  goto error;;
145  }
146  /* alloc a temp buffer to reconstruct the pict */
147  vd->framesizeIn = (vd->width * vd->height << 1);
148  switch (vd->formatIn) {
149  case V4L2_PIX_FMT_MJPEG:
150  vd->tmpbuffer =
151  (unsigned char *) calloc(1, (size_t) vd->framesizeIn);
152  if (!vd->tmpbuffer)
153  goto error;
154  vd->framebuffer =
155  (unsigned char *) calloc(1,
156  (size_t) vd->width * (vd->height +
157  8) * 2);
158  break;
159  case V4L2_PIX_FMT_YUYV:
160  case V4L2_PIX_FMT_UYVY:
161  vd->framebuffer =
162  (unsigned char *) calloc(1, (size_t) vd->framesizeIn);
163  break;
164  default:
165  printf(" should never arrive exit fatal !!\n");
166  goto error;
167  break;
168  }
169  if (!vd->framebuffer)
170  goto error;
171  return 0;
172  error:
173  free(vd->videodevice);
174  free(vd->status);
175  free(vd->pictName);
176  v4l2_close(vd->fd);
177  return -1;
178 }
179 int enum_controls(int vd) //struct vdIn *vd)
180 {
181  struct v4l2_queryctrl queryctrl;
182  struct v4l2_querymenu querymenu;
183  struct v4l2_control control_s;
184  struct v4l2_input* getinput;
185 
186  //Name of the device
187  getinput=(struct v4l2_input *) calloc(1, sizeof(struct v4l2_input));
188  memset(getinput, 0, sizeof(struct v4l2_input));
189  getinput->index=0;
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);
192 
193  //subroutine to read menu items of controls with type 3
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;
200  querymenu.index++) {
201  if (0 == ioctl (vd, VIDIOC_QUERYMENU, &querymenu)) {
202  printf (" index:%d name:%s\n", querymenu.index, querymenu.name);
203  SDL_Delay(10);
204  } else {
205  printf ("error getting control menu");
206  break;
207  }
208  }
209  }
210 
211  //predefined controls
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;
216  queryctrl.id++) {
217  if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
218  if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
219  continue;
220  control_s.id=queryctrl.id;
221  v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
222  SDL_Delay(10);
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)
227  enumerate_menu ();
228  } else {
229  if (errno == EINVAL)
230  continue;
231  perror ("error getting base controls");
232  goto fatal_controls;
233  }
234  }
235 
236  //driver specific controls
237  printf ("V4L2_CID_PRIVATE_BASE (driver specific controls):\n");
238  for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
239  queryctrl.id++) {
240  if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
241  if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
242  continue;
243  control_s.id=queryctrl.id;
244  v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
245  SDL_Delay(20);
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)
250  enumerate_menu ();
251  } else {
252  if (errno == EINVAL)
253  break;
254  perror ("error getting private base controls");
255  goto fatal_controls;
256  }
257  }
258  return 0;
259  fatal_controls:
260  return -1;
261 }
262 int save_controls(int vd, const char* filename)
263 {
264  struct v4l2_queryctrl queryctrl;
265  struct v4l2_control control_s;
266  FILE *configfile;
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");
272  }
273  else {
274  fprintf(configfile, "id value # luvcview control settings configuration file\n");
275  for (queryctrl.id = V4L2_CID_BASE;
276  queryctrl.id < V4L2_CID_LASTP1;
277  queryctrl.id++) {
278  if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
279  if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
280  continue;
281  control_s.id=queryctrl.id;
282  v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
283  SDL_Delay(10);
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);
290  SDL_Delay(10);
291  }
292  }
293  for (queryctrl.id = V4L2_CID_PRIVATE_BASE;;
294  queryctrl.id++) {
295  if (0 == ioctl (vd, VIDIOC_QUERYCTRL, &queryctrl)) {
296  if (queryctrl.flags & V4L2_CTRL_FLAG_DISABLED)
297  continue;
298  if ((queryctrl.id==134217735) || (queryctrl.id==134217736))
299  continue;
300  control_s.id=queryctrl.id;
301  v4l2_ioctl(vd, VIDIOC_G_CTRL, &control_s);
302  SDL_Delay(10);
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);
309  } else {
310  if (errno == EINVAL)
311  break;
312  }
313  }
314  fflush(configfile);
315  fclose(configfile);
316  SDL_Delay(100);
317  }
318 }
319 
320 
321 int load_controls(int vd, const char* filename) //struct vdIn *vd)
322 {
323  struct v4l2_control control;
324  FILE *configfile;
325  memset (&control, 0, sizeof (control));
326  configfile = fopen(filename, "r");
327  if ( configfile == NULL) {
328  perror("configfile luvcview.cfg open failed");
329  }
330  else {
331  printf("loading controls from luvcview.cfg\n");
332  char buffer[512];
333  fgets(buffer, sizeof(buffer), configfile);
334  while (NULL !=fgets(buffer, sizeof(buffer), configfile) )
335  {
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);
339  else
340  printf("OK id:%d val:%d\n", control.id, control.value);
341  SDL_Delay(20);
342  }
343  fclose(configfile);
344  }
345 }
346 
347 static int init_v4l2(struct vdIn *vd)
348 {
349  int i;
350  int ret = 0;
351 
352  if ((vd->fd = v4l2_open(vd->videodevice, O_RDWR)) == -1) {
353  perror("ERROR opening V4L interface");
354  exit(1);
355  }
356  memset(&vd->cap, 0, sizeof(struct v4l2_capability));
357  ret = v4l2_ioctl(vd->fd, VIDIOC_QUERYCAP, &vd->cap);
358  if (ret < 0) {
359  printf("Error opening device %s: unable to query device.\n",
360  vd->videodevice);
361  goto fatal;
362  }
363 
364  if ((vd->cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) == 0) {
365  printf("Error opening device %s: video capture not supported.\n",
366  vd->videodevice);
367  goto fatal;;
368  }
369  if (vd->grabmethod) {
370  if (!(vd->cap.capabilities & V4L2_CAP_STREAMING)) {
371  printf("%s does not support streaming i/o\n", vd->videodevice);
372  goto fatal;
373  }
374  } else {
375  if (!(vd->cap.capabilities & V4L2_CAP_READWRITE)) {
376  printf("%s does not support read i/o\n", vd->videodevice);
377  goto fatal;
378  }
379  }
380 
381  printf("Stream settings:\n");
382 
383  // Enumerate the supported formats to check whether the requested one
384  // is available. If not, we try to fall back to YUYV.
385  unsigned int device_formats[16] = { 0 }; // Assume no device supports more than 16 formats
386  int requested_format_found = 0, fallback_format = -1;
387  if(enum_frame_formats(vd->fd, device_formats, ARRAY_SIZE(device_formats))) {
388  printf("Unable to enumerate frame formats");
389  goto fatal;
390  }
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;
394  break;
395  }
396  if(device_formats[i] == V4L2_PIX_FMT_MJPEG || device_formats[i] == V4L2_PIX_FMT_YUYV
397  || device_formats[i] == V4L2_PIX_FMT_UYVY)
398 
399  fallback_format = i;
400  }
401  if(requested_format_found) {
402  // The requested format is supported
403  printf(" Frame format: "FOURCC_FORMAT"\n", FOURCC_ARGS(vd->formatIn));
404  }
405  else if(fallback_format >= 0) {
406  // The requested format is not supported but there's a fallback format
407  printf(" Frame format: "FOURCC_FORMAT" ("FOURCC_FORMAT
408  " is not supported by device)\n",
409  FOURCC_ARGS(device_formats[0]), FOURCC_ARGS(vd->formatIn));
410  vd->formatIn = device_formats[0];
411  }
412  else {
413  // The requested format is not supported and no fallback format is available
414  printf("ERROR: Requested frame format "FOURCC_FORMAT" is not available "
415  "and no fallback format was found.\n", FOURCC_ARGS(vd->formatIn));
416  goto fatal;
417  }
418 
419  // Set pixel format and frame size
420  memset(&vd->fmt, 0, sizeof(struct v4l2_format));
421  vd->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
422  vd->fmt.fmt.pix.width = vd->width;
423  vd->fmt.fmt.pix.height = vd->height;
424  vd->fmt.fmt.pix.pixelformat = vd->formatIn;
425  vd->fmt.fmt.pix.field = V4L2_FIELD_ANY;
426  ret = v4l2_ioctl(vd->fd, VIDIOC_S_FMT, &vd->fmt);
427  if (ret < 0) {
428  perror("Unable to set format");
429  goto fatal;
430  }
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",
434  vd->fmt.fmt.pix.width, vd->fmt.fmt.pix.height, vd->width, vd->height);
435  vd->width = vd->fmt.fmt.pix.width;
436  vd->height = vd->fmt.fmt.pix.height;
437  /* look the format is not part of the deal ??? */
438  //vd->formatIn = vd->fmt.fmt.pix.pixelformat;
439  }
440  else {
441  printf(" Frame size: %dx%d\n", vd->width, vd->height);
442  }
443 
444  /* set framerate */
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;
449 
450  // Convert the frame rate into a fraction for V4L2
451  int n = 0, d = 0;
452  float_to_fraction(vd->fps, &n, &d);
453  setfps->parm.capture.timeperframe.numerator = d;
454  setfps->parm.capture.timeperframe.denominator = n;
455 
456  ret = v4l2_ioctl(vd->fd, VIDIOC_S_PARM, setfps);
457  if(ret == -1) {
458  perror("Unable to set frame rate");
459  goto fatal;
460  }
461  ret = v4l2_ioctl(vd->fd, VIDIOC_G_PARM, setfps);
462  if(ret == 0) {
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",
467  confirmed_fps,
468  vd->fps);
469  vd->fps = confirmed_fps;
470  }
471  else {
472  printf(" Frame rate: %g fps\n", vd->fps);
473  }
474  }
475  else {
476  perror("Unable to read out current frame rate");
477  goto fatal;
478  }
479 
480  /* request buffers */
481  memset(&vd->rb, 0, sizeof(struct v4l2_requestbuffers));
482  vd->rb.count = NB_BUFFER;
483  vd->rb.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
484  vd->rb.memory = V4L2_MEMORY_MMAP;
485 
486  ret = v4l2_ioctl(vd->fd, VIDIOC_REQBUFS, &vd->rb);
487  if (ret < 0) {
488  perror("Unable to allocate buffers");
489  goto fatal;
490  }
491  /* map the buffers */
492  for (i = 0; i < NB_BUFFER; i++) {
493  memset(&vd->buf, 0, sizeof(struct v4l2_buffer));
494  vd->buf.index = i;
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);
498  if (ret < 0) {
499  perror("Unable to query buffer");
500  goto fatal;
501  }
502  if (debug)
503  printf("length: %u offset: %u\n", vd->buf.length,
504  vd->buf.m.offset);
505  vd->mem[i] = v4l2_mmap(0 /* start anywhere */ ,
506  vd->buf.length, PROT_READ, MAP_SHARED, vd->fd,
507  vd->buf.m.offset);
508  if (vd->mem[i] == MAP_FAILED) {
509  perror("Unable to map buffer");
510  goto fatal;
511  }
512  if (debug)
513  printf("Buffer mapped at address %p.\n", vd->mem[i]);
514  }
515  /* Queue the buffers. */
516  for (i = 0; i < NB_BUFFER; ++i) {
517  memset(&vd->buf, 0, sizeof(struct v4l2_buffer));
518  vd->buf.index = i;
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);
522  if (ret < 0) {
523  perror("Unable to queue buffer");
524  goto fatal;;
525  }
526  }
527  return 0;
528 fatal:
529  return -1;
530 
531 }
532 
533 static int video_enable(struct vdIn *vd)
534 {
535  int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
536  int ret;
537 
538  ret = v4l2_ioctl(vd->fd, VIDIOC_STREAMON, &type);
539  if (ret < 0) {
540  perror("Unable to start capture");
541  return ret;
542  }
543  vd->isstreaming = 1;
544  return 0;
545 }
546 
547 static int video_disable(struct vdIn *vd)
548 {
549  int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
550  int ret;
551 
552  ret = v4l2_ioctl(vd->fd, VIDIOC_STREAMOFF, &type);
553  if (ret < 0) {
554  perror("Unable to stop capture");
555  return ret;
556  }
557  vd->isstreaming = 0;
558  return 0;
559 }
560 
561 
562 int uvcGrab(struct vdIn *vd)
563 {
564 #define HEADERFRAME1 0xaf
565  int ret;
566 
567  if (!vd->isstreaming)
568  if (video_enable(vd))
569  goto err;
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);
574  if (ret < 0) {
575  perror("Unable to dequeue buffer");
576  goto err;
577  }
578 
579  /* Capture a single raw frame */
580  if (vd->rawFrameCapture && vd->buf.bytesused > 0) {
581  FILE *frame = NULL;
582  char filename[13];
583  int ret;
584 
585  /* Disable frame capturing unless we're in frame stream mode */
586  if(vd->rawFrameCapture == 1)
587  vd->rawFrameCapture = 0;
588 
589  /* Create a file name and open the file */
590  sprintf(filename, "frame%03u.raw", vd->fileCounter++ % 1000);
591  frame = fopen(filename, "wb");
592  if(frame == NULL) {
593  perror("Unable to open file for raw frame capturing");
594  goto end_capture;
595  }
596 
597  /* Write the raw data to the file */
598  ret = fwrite(vd->mem[vd->buf.index], vd->buf.bytesused, 1, frame);
599  if(ret < 1) {
600  perror("Unable to write to file");
601  goto end_capture;
602  }
603  printf("Saved raw frame to %s (%u bytes)\n", filename, vd->buf.bytesused);
604  if(vd->rawFrameCapture == 2) {
605  vd->rfsBytesWritten += vd->buf.bytesused;
606  vd->rfsFramesWritten++;
607  }
608 
609 
610  /* Clean up */
611 end_capture:
612  if(frame)
613  fclose(frame);
614  }
615 
616 
617 
618  /* Capture raw stream data */
619  if (vd->captureFile && vd->buf.bytesused > 0) {
620  int ret;
621  ret = fwrite(vd->mem[vd->buf.index], vd->buf.bytesused, 1, vd->captureFile);
622  if (ret < 1) {
623  perror("Unable to write raw stream to file");
624  fprintf(stderr, "Stream capturing terminated.\n");
625  fclose(vd->captureFile);
626  vd->captureFile = NULL;
627  vd->framesWritten = 0;
628  vd->bytesWritten = 0;
629  } else {
630  vd->framesWritten++;
631  vd->bytesWritten += vd->buf.bytesused;
632  if (debug)
633  printf("Appended raw frame to stream file (%u bytes)\n", vd->buf.bytesused);
634  }
635  }
636 
637  switch (vd->formatIn) {
638  case V4L2_PIX_FMT_MJPEG:
639  if(vd->buf.bytesused <= HEADERFRAME1) { /* Prevent crash on empty image */
640 /* if(debug)*/
641  printf("Ignoring empty buffer ...\n");
642  return 0;
643  }
644  memcpy(vd->tmpbuffer, vd->mem[vd->buf.index],vd->buf.bytesused);
645  if (jpeg_decode(&vd->framebuffer, vd->tmpbuffer, &vd->width,
646  &vd->height) < 0) {
647  printf("jpeg decode errors\n");
648  goto err;
649  }
650  if (debug)
651  printf("bytes in used %d\n", vd->buf.bytesused);
652  break;
653  case V4L2_PIX_FMT_YUYV:
654  case V4L2_PIX_FMT_UYVY:
655  if (vd->buf.bytesused > vd->framesizeIn)
656  memcpy(vd->framebuffer, vd->mem[vd->buf.index],
657  (size_t) vd->framesizeIn);
658  else
659  memcpy(vd->framebuffer, vd->mem[vd->buf.index],
660  (size_t) vd->buf.bytesused);
661  break;
662  default:
663  goto err;
664  break;
665  }
666  ret = v4l2_ioctl(vd->fd, VIDIOC_QBUF, &vd->buf);
667  if (ret < 0) {
668  perror("Unable to requeue buffer");
669  goto err;
670  }
671 
672  return 0;
673  err:
674  vd->signalquit = 0;
675  return -1;
676 }
677 int close_v4l2(struct vdIn *vd)
678 {
679  if (vd->isstreaming)
680  video_disable(vd);
681  if (vd->tmpbuffer)
682  free(vd->tmpbuffer);
683  vd->tmpbuffer = NULL;
684  free(vd->framebuffer);
685  vd->framebuffer = NULL;
686  free(vd->videodevice);
687  free(vd->status);
688  free(vd->pictName);
689  vd->videodevice = NULL;
690  vd->status = NULL;
691  vd->pictName = NULL;
692 }
693 
694 /* return >= 0 ok otherwhise -1 */
695 static int isv4l2Control(struct vdIn *vd, int control,
696  struct v4l2_queryctrl *queryctrl)
697 {
698 int err =0;
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) {
705  return 1;
706  } else if (queryctrl->type & V4L2_CTRL_TYPE_INTEGER) {
707  return 0;
708  } else {
709  printf("contol %s unsupported\n", (char *) queryctrl->name);
710  }
711  return -1;
712 }
713 
714 int v4l2GetControl(struct vdIn *vd, int control)
715 {
716  struct v4l2_queryctrl queryctrl;
717  struct v4l2_control control_s;
718  int err;
719  if (isv4l2Control(vd, control, &queryctrl) < 0)
720  return -1;
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");
724  return -1;
725  }
726  return control_s.value;
727 }
728 
729 int v4l2SetControl(struct vdIn *vd, int control, int value)
730 {
731  struct v4l2_control control_s;
732  struct v4l2_queryctrl queryctrl;
733  int min, max, step, val_def;
734  int err;
735  if (isv4l2Control(vd, control, &queryctrl) < 0)
736  return -1;
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");
746  return -1;
747  }
748  }
749  return 0;
750 }
751 int v4l2UpControl(struct vdIn *vd, int control)
752 {
753  struct v4l2_control control_s;
754  struct v4l2_queryctrl queryctrl;
755  int min, max, current, step, val_def;
756  int err;
757 
758  if (isv4l2Control(vd, control, &queryctrl) < 0)
759  return -1;
760  min = queryctrl.minimum;
761  max = queryctrl.maximum;
762  step = queryctrl.step;
763  val_def = queryctrl.default_value;
764  current = v4l2GetControl(vd, control);
765  current += step;
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");
772  return -1;
773  }
774  printf ("Control name:%s set to value:%d\n", queryctrl.name, control_s.value);
775  } else {
776  printf ("Control name:%s already has max value:%d\n", queryctrl.name, max);
777  }
778  return control_s.value;
779 }
780 int v4l2DownControl(struct vdIn *vd, int control)
781 {
782  struct v4l2_control control_s;
783  struct v4l2_queryctrl queryctrl;
784  int min, max, current, step, val_def;
785  int err;
786  if (isv4l2Control(vd, control, &queryctrl) < 0)
787  return -1;
788  min = queryctrl.minimum;
789  max = queryctrl.maximum;
790  step = queryctrl.step;
791  val_def = queryctrl.default_value;
792  current = v4l2GetControl(vd, control);
793  current -= step;
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");
800  return -1;
801  }
802  printf ("Control name:%s set to value:%d\n", queryctrl.name, control_s.value);
803  }
804  else {
805  printf ("Control name:%s already has min value:%d\n", queryctrl.name, min);
806  }
807  return control_s.value;
808 }
809 int v4l2ToggleControl(struct vdIn *vd, int control)
810 {
811  struct v4l2_control control_s;
812  struct v4l2_queryctrl queryctrl;
813  int current;
814  int err;
815  if (isv4l2Control(vd, control, &queryctrl) != 1)
816  return -1;
817  current = v4l2GetControl(vd, control);
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");
822  return -1;
823  }
824  return control_s.value;
825 }
826 int v4l2ResetControl(struct vdIn *vd, int control)
827 {
828  struct v4l2_control control_s;
829  struct v4l2_queryctrl queryctrl;
830  int val_def;
831  int err;
832  if (isv4l2Control(vd, control, &queryctrl) < 0)
833  return -1;
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");
839  return -1;
840  }
841 
842  return 0;
843 }
844 
845 int v4l2ResetPan(struct vdIn *vd)
846 {
847  int control = V4L2_CID_PAN_RESET;
848  struct v4l2_control control_s;
849  struct v4l2_queryctrl queryctrl;
850  int err;
851 
852  if (isv4l2Control(vd, control, &queryctrl) < 0)
853  return -1;
854 
855  control_s.id = control;
856  control_s.value = 1;
857  if ((err = v4l2_ioctl(vd->fd, VIDIOC_S_CTRL, &control_s)) < 0) {
858  printf("ERROR: Unable to reset pan (error = %d)\n", errno);
859  return -1;
860  }
861 
862  return 0;
863 }
864 
865 int v4l2ResetTilt(struct vdIn *vd)
866 {
867  int control = V4L2_CID_TILT_RESET;
868  struct v4l2_control control_s;
869  struct v4l2_queryctrl queryctrl;
870  int err;
871 
872  if (isv4l2Control(vd, control, &queryctrl) < 0)
873  return -1;
874 
875  control_s.id = control;
876  control_s.value = 1;
877  if ((err = v4l2_ioctl(vd->fd, VIDIOC_S_CTRL, &control_s)) < 0) {
878  printf("ERROR: Unable to reset tilt (error = %d)\n", errno);
879  return -1;
880  }
881 
882  return 0;
883 }
884 
885 int v4l2ResetPanTilt(struct vdIn *vd)
886 {
887  int control = V4L2_CID_PANTILT_RESET;
888  struct v4l2_control control_s;
889  struct v4l2_queryctrl queryctrl;
890  unsigned char val;
891  int err;
892 
893  if (isv4l2Control(vd, control, &queryctrl) < 0)
894  return -1;
895 
896  control_s.id = control;
897  control_s.value = 3;
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);
900  return -1;
901  }
902 
903  return 0;
904 }
905 
906 int v4L2UpDownPan(struct vdIn *vd, short inc)
907 {
908  int control = V4L2_CID_PAN_RELATIVE;
909  struct v4l2_control control_s;
910  struct v4l2_queryctrl queryctrl;
911  int err;
912 
913  if (isv4l2Control(vd, control, &queryctrl) < 0)
914  return -1;
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");
919  return -1;
920  }
921  return 0;
922 }
923 
924 int v4L2UpDownTilt(struct vdIn *vd, short inc)
925 { int control = V4L2_CID_TILT_RELATIVE;
926  struct v4l2_control control_s;
927  struct v4l2_queryctrl queryctrl;
928  int err;
929 
930  if (isv4l2Control(vd, control, &queryctrl) < 0)
931  return -1;
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");
936  return -1;
937  }
938  return 0;
939 }
940 
941 int v4L2UpDownPanTilt(struct vdIn *vd, short inc_p, short inc_t) {
942  int p_control = V4L2_CID_PAN_RELATIVE;
943  int t_control = V4L2_CID_TILT_RELATIVE;
944  struct v4l2_ext_controls control_s_array;
945  struct v4l2_queryctrl queryctrl;
946  struct v4l2_ext_control control_s[2];
947  int err;
948 
949  if(isv4l2Control(vd, p_control, &queryctrl) < 0 ||
950  isv4l2Control(vd, t_control, &queryctrl) < 0)
951  return -1;
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;
957 
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;
962 
963  if ((err = v4l2_ioctl(vd->fd, VIDIOC_S_EXT_CTRLS, &control_s_array)) < 0) {
964  printf("ioctl pan-tilt updown control error\n");
965  return -1;
966  }
967  return 0;
968 }
969 
970 #if 0
971 
972 union pantilt {
973  struct {
974  short pan;
975  short tilt;
976  } s16;
977  int value;
978 } __attribute__((packed)) ;
979 
980 int v4L2UpDownPan(struct vdIn *vd, short inc)
981 { int control = V4L2_CID_PANTILT_RELATIVE;
982  struct v4l2_control control_s;
983  struct v4l2_queryctrl queryctrl;
984  int err;
985 
986  union pantilt pan;
987 
988  control_s.id = control;
989  if (isv4l2Control(vd, control, &queryctrl) < 0)
990  return -1;
991 
992  pan.s16.pan = inc;
993  pan.s16.tilt = 0;
994 
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");
998  return -1;
999  }
1000  return 0;
1001 }
1002 
1003 int v4L2UpDownTilt(struct vdIn *vd, short inc)
1004 { int control = V4L2_CID_PANTILT_RELATIVE;
1005  struct v4l2_control control_s;
1006  struct v4l2_queryctrl queryctrl;
1007  int err;
1008  union pantilt pan;
1009  control_s.id = control;
1010  if (isv4l2Control(vd, control, &queryctrl) < 0)
1011  return -1;
1012 
1013  pan.s16.pan= 0;
1014  pan.s16.tilt = inc;
1015 
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");
1019  return -1;
1020  }
1021  return 0;
1022 }
1023 #endif
1024 
1025 int v4l2SetLightFrequencyFilter(struct vdIn *vd, int flt)
1026 { int control = V4L2_CID_POWER_LINE_FREQUENCY;
1027  struct v4l2_control control_s;
1028  struct v4l2_queryctrl queryctrl;
1029  int err;
1030  control_s.id = control;
1031  if (isv4l2Control(vd, control, &queryctrl) < 0)
1032  return -1;
1033 
1034  control_s.value = flt;
1035 
1036  if ((err = v4l2_ioctl(vd->fd, VIDIOC_S_CTRL, &control_s)) < 0) {
1037  printf("ioctl set_light_frequency_filter error\n");
1038  return -1;
1039  }
1040  return 0;
1041 }
1042 int enum_frame_intervals(int dev, __u32 pixfmt, __u32 width, __u32 height)
1043 {
1044  int ret;
1045  struct v4l2_frmivalenum fival;
1046 
1047  memset(&fival, 0, sizeof(fival));
1048  fival.index = 0;
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) {
1055  printf("%u/%u, ",
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);
1061  break;
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);
1068  break;
1069  }
1070  fival.index++;
1071  }
1072  printf("\n");
1073  if (ret != 0 && errno != EINVAL) {
1074  perror("ERROR enumerating frame intervals");
1075  return errno;
1076  }
1077 
1078  return 0;
1079 }
1080 int enum_frame_sizes(int dev, __u32 pixfmt)
1081 {
1082  int ret;
1083  struct v4l2_frmsizeenum fsize;
1084 
1085  memset(&fsize, 0, sizeof(fsize));
1086  fsize.index = 0;
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);
1092  ret = enum_frame_intervals(dev, pixfmt,
1093  fsize.discrete.width, fsize.discrete.height);
1094  if (ret != 0)
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");
1102  break;
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");
1111  break;
1112  }
1113  fsize.index++;
1114  }
1115  if (ret != 0 && errno != EINVAL) {
1116  perror("ERROR enumerating frame sizes");
1117  return errno;
1118  }
1119 
1120  return 0;
1121 }
1122 
1123 int enum_frame_formats(int dev, unsigned int *supported_formats, unsigned int max_formats)
1124 {
1125  int ret;
1126  struct v4l2_fmtdesc fmt;
1127 
1128  memset(&fmt, 0, sizeof(fmt));
1129  fmt.index = 0;
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,
1136  fmt.description);
1137  ret = enum_frame_sizes(dev, fmt.pixelformat);
1138  if(ret != 0)
1139  printf(" Unable to enumerate frame sizes.\n");
1140  }
1141  else if(fmt.index < max_formats) {
1142  supported_formats[fmt.index] = fmt.pixelformat;
1143  }
1144 
1145  fmt.index++;
1146  }
1147  if (errno != EINVAL) {
1148  perror("ERROR enumerating frame formats");
1149  return errno;
1150  }
1151 
1152  return 0;
1153 }
int v4l2ResetPanTilt(struct vdIn *vd)
Definition: v4l2uvc.c:885
#define NB_BUFFER
Definition: v4l2uvc.h:38
int fd
Definition: v4l2uvc.h:44
int recordtime
Definition: v4l2uvc.h:78
int v4l2GetControl(struct vdIn *vd, int control)
Definition: v4l2uvc.c:714
int grabmethod
Definition: v4l2uvc.h:56
int signalquit
Definition: v4l2uvc.h:63
int framecount
Definition: v4l2uvc.h:76
unsigned char * tmpbuffer
Definition: v4l2uvc.h:53
float fps
Definition: v4l2uvc.h:59
FILE * captureFile
Definition: v4l2uvc.h:73
char * pictName
Definition: v4l2uvc.h:47
int load_controls(int vd, const char *filename)
Definition: v4l2uvc.c:321
int v4l2DownControl(struct vdIn *vd, int control)
Definition: v4l2uvc.c:780
int jpeg_decode(unsigned char **pic, unsigned char *buf, int *width, int *height)
Definition: utils.c:282
int check_videoIn(struct vdIn *vd, char *device)
Definition: v4l2uvc.c:68
static int video_disable(struct vdIn *vd)
Definition: v4l2uvc.c:547
int formatIn
Definition: v4l2uvc.h:60
#define V4L2_CID_TILT_RESET
int v4l2ToggleControl(struct vdIn *vd, int control)
Definition: v4l2uvc.c:809
unsigned int rfsFramesWritten
Definition: v4l2uvc.h:70
int v4l2SetControl(struct vdIn *vd, int control, int value)
Definition: v4l2uvc.c:729
#define V4L2_CID_PAN_RELATIVE
int close_v4l2(struct vdIn *vd)
Definition: v4l2uvc.c:677
static int init_v4l2(struct vdIn *vd)
Definition: v4l2uvc.c:347
int rawFrameCapture
Definition: v4l2uvc.h:66
int enum_controls(int vd)
Definition: v4l2uvc.c:179
static int debug
Definition: v4l2uvc.c:38
int v4l2ResetControl(struct vdIn *vd, int control)
Definition: v4l2uvc.c:826
struct v4l2_requestbuffers rb
Definition: v4l2uvc.h:51
unsigned int rfsBytesWritten
Definition: v4l2uvc.h:71
int v4L2UpDownPanTilt(struct vdIn *vd, short inc_p, short inc_t)
Definition: v4l2uvc.c:941
static int float_to_fraction_recursive(double f, double p, int *num, int *den)
Definition: v4l2uvc.c:44
struct v4l2_buffer buf
Definition: v4l2uvc.h:50
int height
Definition: v4l2uvc.h:58
int v4l2SetLightFrequencyFilter(struct vdIn *vd, int flt)
Definition: v4l2uvc.c:1025
int isstreaming
Definition: v4l2uvc.h:55
struct v4l2_format fmt
Definition: v4l2uvc.h:49
int width
Definition: v4l2uvc.h:57
int v4l2ResetTilt(struct vdIn *vd)
Definition: v4l2uvc.c:865
int enum_frame_formats(int dev, unsigned int *supported_formats, unsigned int max_formats)
Definition: v4l2uvc.c:1123
int enum_frame_intervals(int dev, __u32 pixfmt, __u32 width, __u32 height)
Definition: v4l2uvc.c:1042
#define FOURCC_FORMAT
Definition: v4l2uvc.c:34
Definition: v4l2uvc.h:43
char * status
Definition: v4l2uvc.h:46
#define HEADERFRAME1
int uvcGrab(struct vdIn *vd)
Definition: v4l2uvc.c:562
unsigned int bytesWritten
Definition: v4l2uvc.h:75
int enum_frame_sizes(int dev, __u32 pixfmt)
Definition: v4l2uvc.c:1080
int min(int a, int b)
int save_controls(int vd, const char *filename)
Definition: v4l2uvc.c:262
int v4l2UpControl(struct vdIn *vd, int control)
Definition: v4l2uvc.c:751
unsigned char * framebuffer
Definition: v4l2uvc.h:54
static int isv4l2Control(struct vdIn *vd, int control, struct v4l2_queryctrl *queryctrl)
Definition: v4l2uvc.c:695
#define ARRAY_SIZE(a)
Definition: v4l2uvc.c:33
#define FOURCC_ARGS(c)
Definition: v4l2uvc.c:35
#define V4L2_CID_TILT_RELATIVE
int v4L2UpDownTilt(struct vdIn *vd, short inc)
Definition: v4l2uvc.c:924
int recordstart
Definition: v4l2uvc.h:77
int v4L2UpDownPan(struct vdIn *vd, short inc)
Definition: v4l2uvc.c:906
static int video_enable(struct vdIn *vd)
Definition: v4l2uvc.c:533
static void float_to_fraction(float f, int *num, int *den)
Definition: v4l2uvc.c:62
struct v4l2_capability cap
Definition: v4l2uvc.h:48
unsigned int framesWritten
Definition: v4l2uvc.h:74
int init_videoIn(struct vdIn *vd, char *device, int width, int height, float fps, int format, int grabmethod, char *avifilename)
Definition: v4l2uvc.c:105
#define V4L2_CID_PANTILT_RESET
int framesizeIn
Definition: v4l2uvc.h:62
#define V4L2_CID_PAN_RESET
void * mem[NB_BUFFER]
Definition: v4l2uvc.h:52
char * videodevice
Definition: v4l2uvc.h:45
unsigned int fileCounter
Definition: v4l2uvc.h:68
int v4l2ResetPan(struct vdIn *vd)
Definition: v4l2uvc.c:845
int getPict
Definition: v4l2uvc.h:65


tuw_uvc
Author(s): Markus Bader
autogenerated on Mon Jun 10 2019 15:39:24