1 /* 2 Copyright (C) 2006 Mauro Carvalho Chehab <mchehab@kernel.org> 3 4 The libv4l2util Library is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Lesser General Public 6 License as published by the Free Software Foundation; either 7 version 2.1 of the License, or (at your option) any later version. 8 9 The libv4l2util Library is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 #include <stddef.h> 16 #include <stdint.h> 17 #include <sys/time.h> 18 #include <linux/videodev2.h> 19 20 struct drv_list { 21 void *curr; 22 struct drv_list *next; 23 }; 24 25 struct v4l2_t_buf { 26 void *start; 27 size_t length; 28 }; 29 30 typedef int v4l2_recebe_buffer (struct v4l2_buffer *v4l2_buf, struct v4l2_t_buf *buf); 31 32 struct v4l2_driver { 33 int fd; /* Driver descriptor */ 34 35 int debug; 36 37 /* V4L2 structs */ 38 struct v4l2_capability cap; 39 struct v4l2_streamparm parm; 40 41 /* Several lists to be used to store enumbered values */ 42 struct drv_list *stds,*inputs,*fmt_caps; 43 44 /* Stream control */ 45 struct v4l2_requestbuffers reqbuf; 46 struct v4l2_buffer **v4l2_bufs; 47 struct v4l2_t_buf *bufs; 48 uint32_t sizeimage,n_bufs; 49 50 /* Queue control */ 51 uint32_t waitq, currq; 52 }; 53 54 enum v4l2_direction { 55 V4L2_GET = 1, // Bit 1 56 V4L2_SET = 2, // Bit 2 57 V4L2_SET_GET = 3, // Bits 1 and 2 - sets then gets and compare 58 V4L2_TRY = 4, // Bit 3 59 V4L2_TRY_SET = 6, // Bits 3 and 2 - try then sets 60 V4L2_TRY_SET_GET = 7, // Bits 3, 2 and 1- try, sets and gets 61 }; 62 63 int v4l2_open (char *device, int debug, struct v4l2_driver *drv); 64 int v4l2_close (struct v4l2_driver *drv); 65 int v4l2_enum_stds (struct v4l2_driver *drv); 66 int v4l2_enum_input (struct v4l2_driver *drv); 67 int v4l2_enum_fmt (struct v4l2_driver *drv,enum v4l2_buf_type type); 68 int v4l2_get_parm (struct v4l2_driver *drv); 69 int v4l2_setget_std (struct v4l2_driver *drv, enum v4l2_direction dir, v4l2_std_id *id); 70 int v4l2_setget_input (struct v4l2_driver *drv, enum v4l2_direction dir, struct v4l2_input *input); 71 int v4l2_gettryset_fmt_cap (struct v4l2_driver *drv, enum v4l2_direction dir, 72 struct v4l2_format *fmt,uint32_t width, uint32_t height, 73 uint32_t pixelformat, enum v4l2_field field); 74 int v4l2_mmap_bufs(struct v4l2_driver *drv, unsigned int num_buffers); 75 int v4l2_free_bufs(struct v4l2_driver *drv); 76 int v4l2_start_streaming(struct v4l2_driver *drv); 77 int v4l2_stop_streaming(struct v4l2_driver *drv); 78 int v4l2_rcvbuf(struct v4l2_driver *drv, v4l2_recebe_buffer *v4l2_rec_buf); 79 int v4l2_getset_freq (struct v4l2_driver *drv, enum v4l2_direction dir, 80 double *freq); 81 82