Paparazzi UAS  v5.18.0_stable
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 */
uint16_t
unsigned short uint16_t
Definition: types.h:16
v4l2_stop_capture
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
v4l2_device::thread
pthread_t thread
The thread that handles the images.
Definition: v4l2.h:53
v4l2_device::w
uint16_t w
The width of the image.
Definition: v4l2.h:54
uint32_t
unsigned long uint32_t
Definition: types.h:18
v4l2_img_buf::pprz_timestamp
uint32_t pprz_timestamp
The time of the image in us since system startup.
Definition: v4l2.h:44
v4l2_img_buf::buf
void * buf
Pointer to the memory mapped buffer.
Definition: v4l2.h:45
v4l2_img_buf::timestamp
struct timeval timestamp
The time value of the image.
Definition: v4l2.h:43
crop_t
Definition: image.h:92
v4l2_img_buf::physp
uint32_t physp
Physical address pointer.
Definition: v4l2.h:46
std.h
v4l2_start_capture
bool v4l2_start_capture(struct v4l2_device *dev)
Start capturing images in streaming mode (Thread safe)
Definition: v4l2.c:439
v4l2_image_free
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
dev
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:74
uint8_t
unsigned char uint8_t
Definition: types.h:14
image.h
v4l2_device::buffers_cnt
uint8_t buffers_cnt
The number of image buffers.
Definition: v4l2.h:56
v4l2_device::buffers_deq_idx
volatile uint8_t buffers_deq_idx
The current dequeued index.
Definition: v4l2.h:57
v4l2_image_get_nonblock
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
img_size_t
Definition: image.h:86
v4l2_device::fd
int fd
The file pointer to the device.
Definition: v4l2.h:52
v4l2_init_subdev
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
v4l2_device::h
uint16_t h
The height of the image.
Definition: v4l2.h:55
v4l2_init
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
v4l2_device::buffers
struct v4l2_img_buf * buffers
The memory mapped image buffers.
Definition: v4l2.h:59
v4l2_close
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
v4l2_img_buf::length
size_t length
The size of the buffer.
Definition: v4l2.h:42
v4l2_device::mutex
pthread_mutex_t mutex
Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
Definition: v4l2.h:58
v4l2_device
Definition: v4l2.h:50
v4l2_image_get
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
v4l2_device::name
char * name
The name of the device.
Definition: v4l2.h:51
image_t
Definition: image.h:44
v4l2_img_buf
Definition: v4l2.h:41