[video] use video_config in video_thread

Each "board" (e.g. ARDrone2 or Bebop) defines a video_config_t for each camera,
then you only need to specify 'front_camera' or 'bottom_camera' instead of setting all parameters
This commit is contained in:
Felix Ruess
2015-09-14 23:47:33 +02:00
parent f94ccb8c89
commit 6dd0b562f8
16 changed files with 85 additions and 75 deletions
+1 -4
View File
@@ -33,11 +33,8 @@
<define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/> <define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/>
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
+1 -4
View File
@@ -39,10 +39,7 @@
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/> <define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="cv_blob_locator.xml"/> <load name="cv_blob_locator.xml"/>
+1 -4
View File
@@ -38,11 +38,8 @@
<define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/> <define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/>
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
+1 -4
View File
@@ -38,11 +38,8 @@
<define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/> <define name="FILE_LOGGER_PATH" value="/data/ftp/internal_000"/>
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
+1 -4
View File
@@ -39,10 +39,7 @@
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/> <define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="cv_blob_locator.xml"/> <load name="cv_blob_locator.xml"/>
@@ -36,7 +36,9 @@
<load name="agl_dist.xml"> <load name="agl_dist.xml">
<define name="USE_SONAR"/> <define name="USE_SONAR"/>
</load> </load>
<load name="video_thread.xml"/> <load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="front_camera"/>
</load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
<configure name="VIEWVIDEO_USE_NC" value="TRUE"/> <configure name="VIEWVIDEO_USE_NC" value="TRUE"/>
</load> </load>
@@ -36,7 +36,9 @@
<load name="agl_dist.xml"> <load name="agl_dist.xml">
<define name="USE_SONAR"/> <define name="USE_SONAR"/>
</load> </load>
<load name="video_thread.xml"/> <load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="front_camera"/>
</load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
<define name="VIDEO_SOCK_OUT_OFFSET" value="$(AC_ID)"/> <define name="VIDEO_SOCK_OUT_OFFSET" value="$(AC_ID)"/>
<define name="VIDEO_DOWNSIZE_FACTOR" value="2"/> <define name="VIDEO_DOWNSIZE_FACTOR" value="2"/>
+5 -1
View File
@@ -32,7 +32,11 @@
<load name="air_data.xml"/> <load name="air_data.xml"/>
<load name="geo_mag.xml"/> <load name="geo_mag.xml"/>
<!--load name="logger_file.xml"/--> <!--load name="logger_file.xml"/-->
<!--load name="video_thread.xml"/--> <!--
<load name="video_thread.xml">
<define name="VIDEO_THREAD_CAMERA" value="front_camera"/>
</load>
-->
<!--load name="video_rtp_stream.xml"/--> <!--load name="video_rtp_stream.xml"/-->
</modules> </modules>
+1 -4
View File
@@ -33,10 +33,7 @@
</load--> </load-->
<load name="video_thread.xml"> <load name="video_thread.xml">
<define name="VIDEO_THREAD_FPS" value="4"/> <define name="VIDEO_THREAD_FPS" value="4"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video0"/> <define name="VIDEO_THREAD_CAMERA" value="bottom_camera"/>
<define name="VIDEO_THREAD_SUBDEV" value="/dev/v4l-subdev0"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="640,480"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="60"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/ftp/internal_000/images"/>
</load> </load>
<load name="video_rtp_stream.xml"> <load name="video_rtp_stream.xml">
+9 -5
View File
@@ -3,16 +3,20 @@
<module name="video_thread" dir="computer_vision"> <module name="video_thread" dir="computer_vision">
<doc> <doc>
<description> <description>
Video streaming for Linux devices Read video in a thread.
Only for Linux devices.
To be used in other modules for further processing (e.g. opticflow, QR code, streaming).
- Sends a RTP/UDP stream of the camera
- Possibility to save an image(shot) on the internal memory (JPEG, full size, best quality) - Possibility to save an image(shot) on the internal memory (JPEG, full size, best quality)
</description> </description>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video1" description="The video device to capture from"/> <define name="VIDEO_THREAD_CAMERA" value="bottom_camera|front_camera" description="which camera video config to use"/>
<define name="VIDEO_THREAD_DEVICE_SIZE" value="1280,720" description="Video capture size (width, height)"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="10" description="Amount of V4L2 image buffers"/>
<define name="VIDEO_THREAD_FPS" value="4" description="Video stream frame rate"/> <define name="VIDEO_THREAD_FPS" value="4" description="Video stream frame rate"/>
<define name="VIDEO_THREAD_SHOT_PATH" value="/data/video/images" description="Path where the images should be saved"/> <define name="VIDEO_THREAD_SHOT_PATH" value="/data/video/images" description="Path where the images should be saved"/>
<define name="VIDEO_THREAD_DEVICE" value="/dev/video1" description="The video device to capture from (only if VIDEO_THREAD_CAMERA is not defined)"/>
<define name="VIDEO_THREAD_DEVICE_VIDEO_WIDTH" value="1280" description="Video capture width (only if VIDEO_THREAD_CAMERA is not defined)"/>
<define name="VIDEO_THREAD_DEVICE_VIDEO_HEIGHT" value="720" description="Video capture height (only if VIDEO_THREAD_CAMERA is not defined)"/>
<define name="VIDEO_THREAD_DEVICE_BUFFERS" value="10" description="Amount of V4L2 image buffers (only if VIDEO_THREAD_CAMERA is not defined)"/>
</doc> </doc>
<settings> <settings>
<dl_settings> <dl_settings>
+4 -2
View File
@@ -36,21 +36,23 @@
#include "peripherals/video_device.h" #include "peripherals/video_device.h"
struct video_device_t front_camera = { struct video_config_t front_camera = {
.w = 1280, .w = 1280,
.h = 720, .h = 720,
.dev_name = "/dev/video1", .dev_name = "/dev/video1",
.subdev_name = NULL, .subdev_name = NULL,
.format = V4L2_PIX_FMT_UYVY, .format = V4L2_PIX_FMT_UYVY,
.buf_cnt = 10,
.filters = NULL .filters = NULL
}; };
struct video_device_t bottom_camera = { struct video_config_t bottom_camera = {
.w = 320, .w = 320,
.h = 240, .h = 240,
.dev_name = "/dev/video2", .dev_name = "/dev/video2",
.subdev_name = NULL, .subdev_name = NULL,
.format = V4L2_PIX_FMT_UYVY, .format = V4L2_PIX_FMT_UYVY,
.buf_cnt = 10,
.filters = NULL .filters = NULL
}; };
+2 -2
View File
@@ -10,8 +10,8 @@
#endif #endif
/* Cameras */ /* Cameras */
extern struct video_device_t bottom_camera; extern struct video_config_t bottom_camera;
extern struct video_device_t front_camera; extern struct video_config_t front_camera;
/* Default actuators driver */ /* Default actuators driver */
#define DEFAULT_ACTUATORS "boards/ardrone/actuators.h" #define DEFAULT_ACTUATORS "boards/ardrone/actuators.h"
+2 -2
View File
@@ -37,8 +37,8 @@
#define ActuatorsDefaultCommit() ActuatorsBebopCommit() #define ActuatorsDefaultCommit() ActuatorsBebopCommit()
/* Cameras */ /* Cameras */
extern struct video_device_t bottom_camera; extern struct video_config_t bottom_camera;
extern struct video_device_t front_camera; extern struct video_config_t front_camera;
/* by default activate onboard baro */ /* by default activate onboard baro */
#ifndef USE_BARO_BOARD #ifndef USE_BARO_BOARD
+4 -2
View File
@@ -39,21 +39,23 @@
#include "boards/bebop.h" #include "boards/bebop.h"
struct video_device_t bottom_camera = { struct video_config_t bottom_camera = {
.w = 640, .w = 640,
.h = 480, .h = 480,
.dev_name = "/dev/video0", .dev_name = "/dev/video0",
.subdev_name = NULL, .subdev_name = NULL,
.format = V4L2_PIX_FMT_UYVY, .format = V4L2_PIX_FMT_UYVY,
.buf_cnt = 60,
.filters = NULL .filters = NULL
}; };
struct video_device_t front_camera = { struct video_config_t front_camera = {
.w = 1408, .w = 1408,
.h = 2112, .h = 2112,
.dev_name = "/dev/video1", .dev_name = "/dev/video1",
.subdev_name = "/dev/v4l-subdev1", .subdev_name = "/dev/v4l-subdev1",
.format = V4L2_PIX_FMT_SGBRG10, .format = V4L2_PIX_FMT_SGBRG10,
.buf_cnt = 80,
.filters = NULL //{DeMosaic, AEC, ABW} .filters = NULL //{DeMosaic, AEC, ABW}
}; };
@@ -38,6 +38,10 @@
#include "lib/v4l/v4l2.h" #include "lib/v4l/v4l2.h"
#include "lib/vision/image.h" #include "lib/vision/image.h"
#include "lib/encoding/jpeg.h" #include "lib/encoding/jpeg.h"
#include "peripherals/video_device.h"
// include board for bottom_camera and front_camera on ARDrone2 and Bebop
#include BOARD_CONFIG
#if JPEG_WITH_EXIF_HEADER #if JPEG_WITH_EXIF_HEADER
#include "lib/exif/exif_module.h" #include "lib/exif/exif_module.h"
@@ -47,25 +51,32 @@
#include <pthread.h> #include <pthread.h>
#include "rt_priority.h" #include "rt_priority.h"
// The video device /// The camera video config (usually bottom_camera or front_camera)
#ifndef VIDEO_THREAD_DEVICE #ifndef VIDEO_THREAD_CAMERA
#define VIDEO_THREAD_DEVICE /dev/video1 #warning "Are you sure you don't want to use the bottom_camera or front_camera?"
#endif
PRINT_CONFIG_VAR(VIDEO_THREAD_DEVICE)
// The video device size (width, height)
#ifndef VIDEO_THREAD_DEVICE_SIZE
#define VIDEO_THREAD_DEVICE_SIZE 1280,720
#endif
#define __SIZE_HELPER(x, y) #x", "#y
#define _SIZE_HELPER(x) __SIZE_HELPER(x)
PRINT_CONFIG_MSG("VIDEO_THREAD_DEVICE_SIZE = " _SIZE_HELPER(VIDEO_THREAD_DEVICE_SIZE))
// The video device buffers (the amount of V4L2 buffers) // The video device buffers (the amount of V4L2 buffers)
#ifndef VIDEO_THREAD_DEVICE_BUFFERS #ifndef VIDEO_THREAD_DEVICE_BUFFERS
#define VIDEO_THREAD_DEVICE_BUFFERS 10 #define VIDEO_THREAD_DEVICE_BUFFERS 10
#endif #endif
PRINT_CONFIG_VAR(VIDEO_THREAD_DEVICE_BUFFERS) PRINT_CONFIG_VAR(VIDEO_THREAD_DEVICE_BUFFERS)
#ifndef VIDEO_THREAD_SUBDEV
#define VIDEO_THREAD_SUBDEV NULL
#endif
#ifndef VIDEO_THREAD_FILTERS
#define VIDEO_THREAD_FILTERS NULL
#endif
struct video_config_t custom_camera = {
.w = VIDEO_THREAD_VIDEO_WIDTH,
.h = VIDEO_THREAD_VIDEO_HEIGHT,
.dev_name = STRINGIFY(VIDEO_THREAD_DEVICE),
.subdev_name = VIDEO_THREAD_SUBDEV,
.buf_cnt = VIDEO_THREAD_DEVICE_BUFFERS,
.filters = VIDEO_THREAD_FILTERS
};
#define VIDEO_THREAD_CAMERA custom_camera
#endif
PRINT_CONFIG_VAR(VIDEO_THREAD_CAMERA)
// Frames Per Seconds // Frames Per Seconds
#ifndef VIDEO_THREAD_FPS #ifndef VIDEO_THREAD_FPS
@@ -95,8 +106,26 @@ struct video_thread_t video_thread = {
* Handles all the video streaming and saving of the image shots * Handles all the video streaming and saving of the image shots
* This is a sepereate thread, so it needs to be thread safe! * This is a sepereate thread, so it needs to be thread safe!
*/ */
static void *video_thread_function(void *data __attribute__((unused))) static void *video_thread_function(void *data)
{ {
struct video_config_t *vid = (struct video_config_t *)data;
// Initialize the V4L2 subdevice if needed
if (vid->subdev_name != NULL) {
if (!v4l2_init_subdev(vid->subdev_name, 0, 1, vid->format, vid->w, vid->h)) {
printf("[video_thread] Could not initialize the %s subdevice.\n", vid->subdev_name);
return 0;
}
}
// Initialize the V4L2 device
video_thread.dev = v4l2_init(vid->dev_name, vid->w, vid->h, vid->buf_cnt, vid->format);
if (video_thread.dev == NULL) {
printf("[video_thread] Could not initialize the %s V4L2 device.\n", vid->dev_name);
return 0;
}
// Start the streaming of the V4L2 device // Start the streaming of the V4L2 device
if (!v4l2_start_capture(video_thread.dev)) { if (!v4l2_start_capture(video_thread.dev)) {
printf("[video_thread-thread] Could not start capture of %s.\n", video_thread.dev->name); printf("[video_thread-thread] Could not start capture of %s.\n", video_thread.dev->name);
@@ -176,24 +205,6 @@ static void *video_thread_function(void *data __attribute__((unused)))
*/ */
void video_thread_init(void) void video_thread_init(void)
{ {
#ifdef VIDEO_THREAD_SUBDEV
PRINT_CONFIG_MSG("[video_thread] Configuring a subdevice!")
PRINT_CONFIG_VAR(VIDEO_THREAD_SUBDEV)
// Initialize the V4L2 subdevice (TODO: fix hardcoded path, which and code)
if (!v4l2_init_subdev(STRINGIFY(VIDEO_THREAD_SUBDEV), 0, 1, V4L2_MBUS_FMT_UYVY8_2X8, VIDEO_THREAD_DEVICE_SIZE)) {
printf("[video_thread] Could not initialize the %s subdevice.\n", STRINGIFY(VIDEO_THREAD_SUBDEV));
return;
}
#endif
// Initialize the V4L2 device
video_thread.dev = v4l2_init(STRINGIFY(VIDEO_THREAD_DEVICE), VIDEO_THREAD_DEVICE_SIZE, VIDEO_THREAD_DEVICE_BUFFERS, V4L2_PIX_FMT_UYVY);
if (video_thread.dev == NULL) {
printf("[video_thread] Could not initialize the %s V4L2 device.\n", STRINGIFY(VIDEO_THREAD_DEVICE));
return;
}
// Create the shot directory // Create the shot directory
char save_name[128]; char save_name[128];
sprintf(save_name, "mkdir -p %s", STRINGIFY(VIDEO_THREAD_SHOT_PATH)); sprintf(save_name, "mkdir -p %s", STRINGIFY(VIDEO_THREAD_SHOT_PATH));
@@ -215,7 +226,7 @@ void video_thread_start(void)
// Start the streaming thread // Start the streaming thread
pthread_t tid; pthread_t tid;
if (pthread_create(&tid, NULL, video_thread_function, NULL) != 0) { if (pthread_create(&tid, NULL, video_thread_function, (void*)(&VIDEO_THREAD_CAMERA)) != 0) {
printf("[vievideo] Could not create streaming thread.\n"); printf("[vievideo] Could not create streaming thread.\n");
return; return;
} }
+2 -1
View File
@@ -32,12 +32,13 @@
#include "modules/computer_vision/lib/v4l/v4l2.h" #include "modules/computer_vision/lib/v4l/v4l2.h"
/** V4L2 device settings */ /** V4L2 device settings */
struct video_device_t { struct video_config_t {
int w; ///< Width int w; ///< Width
int h; ///< Height int h; ///< Height
char* dev_name; ///< path to device char* dev_name; ///< path to device
char* subdev_name; ///< path to sub device char* subdev_name; ///< path to sub device
uint32_t format; ///< Video format uint32_t format; ///< Video format
uint8_t buf_cnt; ///< Amount of V4L2 video device buffers
void* filters; ///< filters to use void* filters; ///< filters to use
}; };