Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
v4l2.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freek van Tienen <freek.v.tienen@gmail.com>
3  * Copyright (C) 2011 Hugo Perquin - http://blog.perquin.com
4  *
5  * This file is part of Paparazzi.
6  *
7  * Paparazzi is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * Paparazzi is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with paparazzi; see the file COPYING. If not, see
19  * <http://www.gnu.org/licenses/>.
20  *
21  */
22 
28 #ifndef _CV_LIB_V4L2_H
29 #define _CV_LIB_V4L2_H
30 
31 #include <linux/v4l2-subdev.h>
32 #include <pthread.h>
33 #include <sys/time.h>
34 
35 #include "std.h"
37 
38 #define V4L2_IMG_NONE 255
39 
40 /* V4L2 memory mapped image buffer */
41 struct v4l2_img_buf {
42  size_t length;
43  struct timeval timestamp;
45  void *buf;
46 };
47 
48 /* V4L2 device */
49 struct v4l2_device {
50  char *name;
51  int fd;
52  pthread_t thread;
57  pthread_mutex_t mutex;
59 };
60 
61 /* External functions */
62 bool v4l2_init_subdev(char *subdev_name, uint8_t pad, uint16_t code, struct img_size_t size);
63 struct v4l2_device *v4l2_init(char *device_name, struct img_size_t size, struct crop_t crop, uint8_t buffers_cnt,
64  uint32_t _pixelformat);
65 void v4l2_image_get(struct v4l2_device *dev, struct image_t *img);
66 bool v4l2_image_get_nonblock(struct v4l2_device *dev, struct image_t *img);
67 void v4l2_image_free(struct v4l2_device *dev, struct image_t *img);
68 bool v4l2_start_capture(struct v4l2_device *dev);
69 bool v4l2_stop_capture(struct v4l2_device *dev);
70 void v4l2_close(struct v4l2_device *dev);
71 
72 #endif /* _CV_LIB_V4L2_H */
unsigned short uint16_t
Definition: types.h:16
pthread_mutex_t mutex
Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
Definition: v4l2.h:57
Definition: image.h:79
void v4l2_image_get(struct v4l2_device *dev, struct image_t *img)
Get the latest image buffer and lock it (Thread safe, BLOCKING) This functions blocks until image acc...
Definition: v4l2.c:332
Definition: image.h:43
bool v4l2_stop_capture(struct v4l2_device *dev)
Stop capturing of the image stream (Thread safe) This function is blocking until capturing thread is ...
Definition: v4l2.c:486
void v4l2_image_free(struct v4l2_device *dev, struct image_t *img)
Free the image and enqueue the buffer (Thread safe) This must be done after processing the image...
Definition: v4l2.c:406
uint32_t pprz_timestamp
The time of the image in us since system startup.
Definition: v4l2.h:44
Image helper functions like resizing, color filter, converters...
uint16_t h
The height of the image.
Definition: v4l2.h:54
struct timeval timestamp
The time value of the image.
Definition: v4l2.h:43
bool v4l2_image_get_nonblock(struct v4l2_device *dev, struct image_t *img)
Get the latest image and lock it (Thread safe, NON BLOCKING) This function returns NULL if it can't g...
Definition: v4l2.c:371
unsigned long uint32_t
Definition: types.h:18
struct v4l2_img_buf * buffers
The memory mapped image buffers.
Definition: v4l2.h:58
void v4l2_close(struct v4l2_device *dev)
Close the V4L2 device (Thread safe) This needs to be preformed to clean up all the buffers and close ...
Definition: v4l2.c:521
size_t length
The size of the buffer.
Definition: v4l2.h:42
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:73
void * buf
Pointer to the memory mapped buffer.
Definition: v4l2.h:45
char * name
The name of the device.
Definition: v4l2.h:50
unsigned char uint8_t
Definition: types.h:14
bool v4l2_start_capture(struct v4l2_device *dev)
Start capturing images in streaming mode (Thread safe)
Definition: v4l2.c:427
uint8_t buffers_cnt
The number of image buffers.
Definition: v4l2.h:55
bool v4l2_init_subdev(char *subdev_name, uint8_t pad, uint16_t code, struct img_size_t size)
Initialize a V4L2 subdevice.
Definition: v4l2.c:136
volatile uint8_t buffers_deq_idx
The current dequeued index.
Definition: v4l2.h:56
pthread_t thread
The thread that handles the images.
Definition: v4l2.h:52
struct v4l2_device * v4l2_init(char *device_name, struct img_size_t size, struct crop_t crop, uint8_t buffers_cnt, uint32_t _pixelformat)
Initialize a V4L2(Video for Linux 2) device.
Definition: v4l2.c:183
uint16_t w
The width of the image.
Definition: v4l2.h:53
int fd
The file pointer to the device.
Definition: v4l2.h:51