Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
v4l2.h File Reference

Capture images from a V4L2 device (Video for Linux 2) More...

#include <linux/v4l2-subdev.h>
#include <pthread.h>
#include <sys/time.h>
#include "std.h"
#include "modules/computer_vision/lib/vision/image.h"
+ Include dependency graph for v4l2.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  v4l2_img_buf
 
struct  v4l2_device
 

Macros

#define V4L2_IMG_NONE   255
 There currently no image available. More...
 

Functions

bool v4l2_init_subdev (char *subdev_name, uint8_t pad, uint16_t code, struct img_size_t size)
 Initialize a V4L2 subdevice. More...
 
struct v4l2_devicev4l2_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. More...
 
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 access is granted. More...
 
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 get access to the current image. More...
 
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, because else all buffers are locked. More...
 
bool v4l2_start_capture (struct v4l2_device *dev)
 Start capturing images in streaming mode (Thread safe) More...
 
bool v4l2_stop_capture (struct v4l2_device *dev)
 Stop capturing of the image stream (Thread safe) This function is blocking until capturing thread is closed. More...
 
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 the device. More...
 

Detailed Description

Capture images from a V4L2 device (Video for Linux 2)

Definition in file v4l2.h.


Data Structure Documentation

struct v4l2_img_buf

Definition at line 41 of file v4l2.h.

+ Collaboration diagram for v4l2_img_buf:
Data Fields
void * buf Pointer to the memory mapped buffer.
size_t length The size of the buffer.
uint32_t pprz_timestamp The time of the image in us since system startup.
struct timeval timestamp The time value of the image.
struct v4l2_device

Definition at line 49 of file v4l2.h.

+ Collaboration diagram for v4l2_device:
Data Fields
struct v4l2_img_buf * buffers The memory mapped image buffers.
uint8_t buffers_cnt The number of image buffers.
volatile uint8_t buffers_deq_idx The current dequeued index.
int fd The file pointer to the device.
uint16_t h The height of the image.
pthread_mutex_t mutex Mutex lock for enqueue/dequeue of buffers (change the deq_idx)
char * name The name of the device.
pthread_t thread The thread that handles the images.
uint16_t w The width of the image.

Macro Definition Documentation

#define V4L2_IMG_NONE   255

There currently no image available.

Definition at line 38 of file v4l2.h.

Referenced by v4l2_capture_thread(), v4l2_image_get(), v4l2_image_get_nonblock(), and v4l2_start_capture().

Function Documentation

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 the device.

Note that this also stops the capturing if it is still capturing.

Parameters
[in]*devThe video for linux device to close(cleanup)

Definition at line 521 of file v4l2.c.

References v4l2_img_buf::buf, v4l2_device::buffers, v4l2_device::buffers_cnt, v4l2_device::fd, v4l2_img_buf::length, v4l2_device::name, and v4l2_stop_capture().

+ Here is the call graph for this function:

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, because else all buffers are locked.

Parameters
[in]*devThe video for linux device which the image is from
[in]*imgThe image to free

Definition at line 406 of file v4l2.c.

References image_t::buf_idx, CLEAR, v4l2_device::fd, and v4l2_device::name.

Referenced by bebop_front_camera_thread(), and video_thread_function().

+ Here is the caller graph for this function:

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 access is granted.

This should not take that long, because it is only locked while enqueueing an image. Make sure you free the image after processing with v4l2_image_free()!

Parameters
[in]*devThe V4L2 video device we want to get an image from
[out]*imgThe image that we got from the video device

Definition at line 332 of file v4l2.c.

References v4l2_img_buf::buf, image_t::buf, image_t::buf_idx, image_t::buf_size, v4l2_device::buffers, v4l2_device::buffers_deq_idx, image_t::h, v4l2_device::h, IMAGE_YUV422, v4l2_img_buf::length, v4l2_device::mutex, v4l2_img_buf::pprz_timestamp, image_t::pprz_ts, v4l2_img_buf::timestamp, image_t::ts, image_t::type, V4L2_IMG_NONE, image_t::w, and v4l2_device::w.

Referenced by bebop_front_camera_thread(), and video_thread_function().

+ Here is the caller graph for this function:

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 get access to the current image.

Make sure you free the image after processing with v4l2_image_free())!

Parameters
[in]*devThe V4L2 video device we want to get an image from
[out]*imgThe image that we got from the video device
Returns
Whether we got an image or not

Definition at line 371 of file v4l2.c.

References v4l2_img_buf::buf, image_t::buf, image_t::buf_idx, image_t::buf_size, v4l2_device::buffers, v4l2_device::buffers_deq_idx, image_t::h, v4l2_device::h, IMAGE_YUV422, v4l2_img_buf::length, v4l2_device::mutex, v4l2_img_buf::pprz_timestamp, image_t::pprz_ts, v4l2_img_buf::timestamp, image_t::ts, image_t::type, V4L2_IMG_NONE, image_t::w, and v4l2_device::w.

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.

Note that the device must be closed with v4l2_close(dev) at the end.

Parameters
[in]device_nameThe video device name (like /dev/video1)
[in]width,heightThe width and height of the images
[in]buffers_cntThe amount of buffers used for mapping
Returns
The newly create V4L2 device

Definition at line 183 of file v4l2.c.

References v4l2_img_buf::buf, buffers, v4l2_device::buffers, v4l2_device::buffers_cnt, CLEAR, dev, fd, v4l2_device::fd, v4l2_device::h, img_size_t::h, crop_t::h, v4l2_img_buf::length, v4l2_device::name, v4l2_device::w, img_size_t::w, crop_t::w, crop_t::x, and crop_t::y.

Referenced by bebop_front_camera_init(), and initialize_camera().

+ Here is the caller graph for this function:

bool v4l2_init_subdev ( char *  subdev_name,
uint8_t  pad,
uint16_t  code,
struct img_size_t  size 
)

Initialize a V4L2 subdevice.

Parameters
[in]*subdev_nameThe subdevice name (like /dev/v4l-subdev0)
[in]pad,whichThe way the subdevice should comminicate and be connected to the real device.
[in]codeThe encoding the subdevice uses (like V4L2_MBUS_FMT_UYVY8_2X8, see the V4L2 manual for available encodings)
[in]width,heightThe width and height of the images
Returns
Whether the subdevice was successfully initialized

Definition at line 136 of file v4l2.c.

References CLEAR, fd, img_size_t::h, and img_size_t::w.

Referenced by bebop_front_camera_init(), and initialize_camera().

+ Here is the caller graph for this function:

bool v4l2_start_capture ( struct v4l2_device dev)

Start capturing images in streaming mode (Thread safe)

Parameters
[in]*devThe video for linux device to start capturing from
Returns
It resturns TRUE if it successfully started capture, but keep in mind that if it is already started it will return FALSE.

Definition at line 427 of file v4l2.c.

References v4l2_device::buffers_cnt, v4l2_device::buffers_deq_idx, CLEAR, v4l2_device::fd, v4l2_device::name, v4l2_device::thread, v4l2_capture_thread(), and V4L2_IMG_NONE.

Referenced by bebop_front_camera_thread(), and video_thread_function().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool v4l2_stop_capture ( struct v4l2_device dev)

Stop capturing of the image stream (Thread safe) This function is blocking until capturing thread is closed.

Parameters
[in]*devThe video for linux device to stop capturing
Returns
TRUE if it successfully stopped capturing. Note that it also returns FALSE when the capturing is already stopped.

Definition at line 486 of file v4l2.c.

References v4l2_device::fd, v4l2_device::name, and v4l2_device::thread.

Referenced by bebop_front_camera_stop(), stop_video_thread(), and v4l2_close().

+ Here is the caller graph for this function: