Paparazzi UAS  v5.8.2_stable-0-g6260b7c
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Freek van Tienen <>
3  * Copyright (C) 2011 Hugo Perquin -
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
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  * <>.
20  *
21  */
28 #ifndef _CV_LIB_V4L2_H
29 #define _CV_LIB_V4L2_H
31 #include <linux/v4l2-subdev.h>
32 #include <pthread.h>
33 #include <sys/time.h>
35 #include "std.h"
38 #define V4L2_IMG_NONE 255
40 /* V4L2 memory mapped image buffer */
41 struct v4l2_img_buf {
42  size_t length;
43  struct timeval timestamp;
44  void *buf;
45 };
47 /* V4L2 device */
48 struct v4l2_device {
49  char *name;
50  int fd;
51  pthread_t thread;
56  pthread_mutex_t mutex;
58 };
60 /* External functions */
61 bool_t v4l2_init_subdev(char *subdev_name, uint8_t pad, uint8_t which, uint16_t code, uint16_t width, uint16_t height);
62 struct v4l2_device *v4l2_init(char *device_name, uint16_t width, uint16_t height, uint8_t buffers_cnt,
63  uint32_t _pixelformat);
64 void v4l2_image_get(struct v4l2_device *dev, struct image_t *img);
65 bool_t v4l2_image_get_nonblock(struct v4l2_device *dev, struct image_t *img);
66 void v4l2_image_free(struct v4l2_device *dev, struct image_t *img);
67 bool_t v4l2_start_capture(struct v4l2_device *dev);
68 bool_t v4l2_stop_capture(struct v4l2_device *dev);
69 void v4l2_close(struct v4l2_device *dev);
71 #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:56
struct v4l2_device * v4l2_init(char *device_name, uint16_t width, uint16_t height, uint8_t buffers_cnt, uint32_t _pixelformat)
Initialize a V4L2(Video for Linux 2) device.
Definition: v4l2.c:177
bool_t 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:446
bool_t v4l2_start_capture(struct v4l2_device *dev)
Start capturing images in streaming mode (Thread safe)
Definition: v4l2.c:387
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:294
Definition: image.h:42
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:366
Image helper functions like resizing, color filter, converters...
uint16_t h
The height of the image.
Definition: v4l2.h:53
struct timeval timestamp
The time value of the image.
Definition: v4l2.h:43
unsigned long uint32_t
Definition: types.h:18
struct v4l2_img_buf * buffers
The memory mapped image buffers.
Definition: v4l2.h:57
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:481
size_t length
The size of the buffer.
Definition: v4l2.h:42
static const struct usb_device_descriptor dev
Definition: usb_ser_hw.c:69
bool_t v4l2_init_subdev(char *subdev_name, uint8_t pad, uint8_t which, uint16_t code, uint16_t width, uint16_t height)
Initialize a V4L2 subdevice.
Definition: v4l2.c:130
void * buf
Pointer to the memory mapped buffer.
Definition: v4l2.h:44
char * name
The name of the device.
Definition: v4l2.h:49
bool_t 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:332
unsigned char uint8_t
Definition: types.h:14
uint8_t buffers_cnt
The number of image buffers.
Definition: v4l2.h:54
volatile uint8_t buffers_deq_idx
The current dequeued index.
Definition: v4l2.h:55
pthread_t thread
The thread that handles the images.
Definition: v4l2.h:51
uint16_t w
The width of the image.
Definition: v4l2.h:52
int fd
The file pointer to the device.
Definition: v4l2.h:50