Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
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;
47 };
48 
49 /* V4L2 device */
50 struct v4l2_device {
51  char *name;
52  int fd;
53  pthread_t thread;
58  pthread_mutex_t mutex;
60 };
61 
62 /* External functions */
63 bool v4l2_init_subdev(char *subdev_name, uint8_t pad, uint16_t code, struct img_size_t size);
64 struct v4l2_device *v4l2_init(char *device_name, struct img_size_t size, struct crop_t crop, uint8_t buffers_cnt,
65  uint32_t _pixelformat);
66 void v4l2_image_get(struct v4l2_device *dev, struct image_t *img);
67 bool v4l2_image_get_nonblock(struct v4l2_device *dev, struct image_t *img);
68 void v4l2_image_free(struct v4l2_device *dev, struct image_t *img);
69 bool v4l2_start_capture(struct v4l2_device *dev);
70 bool v4l2_stop_capture(struct v4l2_device *dev);
71 void v4l2_close(struct v4l2_device *dev);
72 
73 #endif /* _CV_LIB_V4L2_H */
Image helper functions like resizing, color filter, converters...
Definition: image.h:92
Definition: image.h:44
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
void * buf
Pointer to the memory mapped buffer.
Definition: v4l2.h:45
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:184
uint16_t w
The width of the image.
Definition: v4l2.h:54
struct v4l2_img_buf * buffers
The memory mapped image buffers.
Definition: v4l2.h:59
int fd
The file pointer to the device.
Definition: v4l2.h:52
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:137
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:537
volatile uint8_t buffers_deq_idx
The current dequeued index.
Definition: v4l2.h:57
bool v4l2_start_capture(struct v4l2_device *dev)
Start capturing images in streaming mode (Thread safe)
Definition: v4l2.c:439
uint8_t buffers_cnt
The number of image buffers.
Definition: v4l2.h:56
uint16_t h
The height of the image.
Definition: v4l2.h:55
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:344
char * name
The name of the device.
Definition: v4l2.h:51
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:418
struct timeval timestamp
The time value of the image.
Definition: v4l2.h:43
uint32_t pprz_timestamp
The time of the image in us since system startup.
Definition: v4l2.h:44
pthread_t thread
The thread that handles the images.
Definition: v4l2.h:53
pthread_mutex_t mutex
Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
Definition: v4l2.h:58
uint32_t physp
Physical address pointer.
Definition: v4l2.h:46
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:502
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:383
size_t length
The size of the buffer.
Definition: v4l2.h:42
unsigned short uint16_t
Typedef defining 16 bit unsigned short type.
Definition: vl53l1_types.h:88
unsigned int uint32_t
Typedef defining 32 bit unsigned int type.
Definition: vl53l1_types.h:78
unsigned char uint8_t
Typedef defining 8 bit unsigned char type.
Definition: vl53l1_types.h:98