Porting the old video pipeline to the new pipeline in SDK video_stage.c based on Navigation example. Incomplete.

Esse commit está contido em:
Mani Monajjemi
2012-06-28 11:20:08 -07:00
commit 1133c4b24a
5 arquivos alterados com 215 adições e 135 exclusões
+3 -2
Ver Arquivo
@@ -30,6 +30,7 @@ rosbuild_gensrv()
set(SDK ARDroneLib/)
link_directories(${PROJECT_SOURCE_DIR}/lib/)
include_directories(${SDK} ${SDK}/Soft/Common ${SDK}/Soft/Lib ${SDK}/VP_SDK ${SDK}/VP_SDK/VP_Os/linux)
include_directories(${SDK} ${SDK}/FFMPEG/Includes ${SDK}/Soft/Common ${SDK}/Soft/Lib ${SDK}/VP_SDK ${SDK}/VP_SDK/VP_Os/linux )
rosbuild_add_executable(ardrone_driver src/ardrone_driver.cpp src/video.cpp src/ardrone_sdk.cpp src/teleop_twist.cpp)
target_link_libraries(ardrone_driver vlib pc_ardrone sdk SDL)
#target_link_libraries(ardrone_driver vlib pc_ardrone sdk SDL avcodec avdevice avfilter avformat avutil swscale)
target_link_libraries(ardrone_driver vlib pc_ardrone sdk SDL avcodec avutil swscale)
+47 -2
Ver Arquivo
@@ -1,6 +1,5 @@
#include "ardrone_sdk.h"
#include "teleop_twist.h"
#include "video.h"
navdata_demo_t navdata;
navdata_phys_measures_t navdata_phys;
@@ -27,7 +26,53 @@ extern "C" {
}
ardrone_application_default_config.bitrate_ctrl_mode = 1;
ardrone_tool_input_add(&teleop);
START_THREAD(video_update_thread, 0);
uint8_t post_stages_index = 0;
//Alloc structs
specific_parameters_t * params = (specific_parameters_t *)vp_os_calloc(1,sizeof(specific_parameters_t));
specific_stages_t * driver_pre_stages = (specific_stages_t*)vp_os_calloc(1, sizeof(specific_stages_t));
specific_stages_t * driver_post_stages = (specific_stages_t*)vp_os_calloc(1, sizeof(specific_stages_t));
vp_api_picture_t * in_picture = (vp_api_picture_t*) vp_os_calloc(1, sizeof(vp_api_picture_t));
vp_api_picture_t * out_picture = (vp_api_picture_t*) vp_os_calloc(1, sizeof(vp_api_picture_t));
in_picture->width = STREAM_WIDTH;
in_picture->height = STREAM_HEIGHT;
out_picture->framerate = 30;
out_picture->format = PIX_FMT_RGB24;
out_picture->width = STREAM_WIDTH;
out_picture->height = STREAM_HEIGHT;
out_picture->y_buf = (uint8_t*) vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT * 3 );
out_picture->cr_buf = NULL;
out_picture->cb_buf = NULL;
out_picture->y_line_size = STREAM_WIDTH * 3;
out_picture->cb_line_size = 0;
out_picture->cr_line_size = 0;
//Alloc the lists
driver_pre_stages->stages_list = NULL;
driver_post_stages->stages_list = (vp_api_io_stage_t*)vp_os_calloc(NB_DRIVER_POST_STAGES,sizeof(vp_api_io_stage_t));
driver_post_stages->stages_list[post_stages_index].name = "ExtractData";
driver_post_stages->stages_list[post_stages_index].type = VP_API_OUTPUT_SDL;
driver_post_stages->stages_list[post_stages_index].cfg = NULL;
driver_post_stages->stages_list[post_stages_index++].funcs = vp_stages_export_funcs;
driver_pre_stages->length = 0;
driver_post_stages->length = post_stages_index;
params->in_pic = in_picture;
params->out_pic = out_picture;
params->pre_processing_stages_list = driver_pre_stages;
params->post_processing_stages_list = driver_post_stages;
params->needSetPriority = 0;
params->priority = 0;
START_THREAD(video_stage, params);
video_stage_init();
//START_THREAD(video_update_thread, 0);
//START_THREAD(mani, 0);
return C_OK;
}
+42 -33
Ver Arquivo
@@ -1,56 +1,65 @@
#ifndef _ARDRONE_SDK_H_
#define _ARDRONE_SDK_H_
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <termios.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
// TODO: Move these two defines to CMake
#ifndef FFMPEG_SUPPORT
#define FFMPEG_SUPPORT
#endif
#include <sys/time.h>
#include <time.h>
#ifndef USE_LINUX
#define USE_LINUX
#endif
// TODO: Research more on this issue, move the flag to CMake
// The FFMPEG library INT macros fix
#if defined __cplusplus
# define __STDC_CONSTANT_MACROS
#endif
#include <stdint.h>
extern "C" {
#include <VP_Api/vp_api.h>
#include <VP_Api/vp_api_error.h>
#include <VP_Api/vp_api_stage.h>
#include <VP_Api/vp_api_picture.h>
#include <VP_Stages/vp_stages_io_file.h>
#ifdef USE_ELINUX
#include <VP_Stages/vp_stages_V4L2_i_camif.h>
#else
#include <VP_Stages/vp_stages_i_camif.h>
#endif
#include <VP_Os/vp_os_print.h>
#include <VP_Os/vp_os_malloc.h>
#include <VP_Os/vp_os_delay.h>
#include <VP_Stages/vp_stages_yuv2rgb.h>
#include <VP_Stages/vp_stages_buffer_to_picture.h>
//#include <VP_Api/vp_api.h>
//#include <VP_Api/vp_api_error.h>
//#include <VP_Api/vp_api_stage.h>
//#include <VP_Api/vp_api_picture.h>
//#include <VP_Stages/vp_stages_io_file.h>
//#include <VP_Stages/vp_stages_i_camif.h>
//
//#include <VP_Os/vp_os_print.h>
//#include <VP_Os/vp_os_malloc.h>
//#include <VP_Os/vp_os_delay.h>
//#include <VP_Stages/vp_stages_yuv2rgb.h>
//#include <VP_Stages/vp_stages_buffer_to_picture.h>
//#include <VLIB/Stages/vlib_stage_decode.h>
#include <config.h>
#ifdef JPEG_CAPTURE
#include <VP_Stages/vp_stages_io_jpeg.h>
#else
#include <VLIB/Stages/vlib_stage_decode.h>
#endif
#include <video_encapsulation.h>
#include <ardrone_tool/ardrone_version.h>
#include <ardrone_tool/ardrone_tool.h>
#include <ardrone_tool/ardrone_tool_configuration.h>
#include <ardrone_tool/Com/config_com.h>
#include <ardrone_tool/UI/ardrone_input.h>
#include <ardrone_tool/Video/video_com_stage.h>
#include <ardrone_tool/Control/ardrone_control.h>
#include <ardrone_tool/Navdata/ardrone_navdata_client.h>
#include "video.h"
#include <ardrone_tool/Video/video_stage.h>
#include <ardrone_tool/Video/video_recorder_pipeline.h>
extern video_decoder_config_t vec;
}
#define NB_DRIVER_POST_STAGES 10
extern navdata_vision_detect_t navdata_detect;
extern navdata_phys_measures_t navdata_phys;
extern navdata_demo_t navdata;
extern navdata_time_t arnavtime;
#endif
+122 -92
Ver Arquivo
@@ -5,6 +5,9 @@
unsigned char buffer[STREAM_WIDTH * STREAM_HEIGHT * 3];
int current_frame_id = 0;
static uint8_t* pixbuf_data = NULL;
static vp_os_mutex_t video_update_lock = PTHREAD_MUTEX_INITIALIZER;
PIPELINE_HANDLE pipeline_handle;
extern "C" C_RESULT export_stage_open( void *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
{
@@ -13,9 +16,16 @@ extern "C" C_RESULT export_stage_open( void *cfg, vp_api_io_data_t *in, vp_api_i
extern "C" C_RESULT export_stage_transform( void *cfg, vp_api_io_data_t *in, vp_api_io_data_t *out)
{
fprintf(stderr, "In Transform before copy\n");
//memcpy(buffer, in->buffers[0], STREAM_WIDTH * STREAM_HEIGHT * 3);
printf("In Transform after copy\n");
PRINT("In Transform before copy\n");
vp_os_mutex_lock(&video_update_lock);
/* Get a reference to the last decoded picture */
pixbuf_data = (uint8_t*)in->buffers[0];
/* Copy the entire buffer, TODO: can we movet this to the thread to make the transform faster?*/
memcpy(buffer, in->buffers[0], STREAM_WIDTH * STREAM_HEIGHT * 3);
//memcpy(buffer, in->buffers[0], in->size);
vp_os_mutex_unlock(&video_update_lock);
PRINT("In Transform after copy\n");
current_frame_id++;
return (SUCCESS);
}
@@ -35,94 +45,114 @@ const vp_api_stage_funcs_t vp_stages_export_funcs =
DEFINE_THREAD_ROUTINE(video_update_thread, data)
{
printf("Starting video capture thread ...\n");
C_RESULT res;
vp_api_io_pipeline_t pipeline;
vp_api_io_data_t out;
vp_api_io_stage_t stages[NB_STAGES];
vp_api_picture_t picture;
video_com_config_t icc;
vlib_stage_decoding_config_t vec;
vp_stages_yuv2rgb_config_t yuv2rgbconf;
/// Picture configuration
picture.format = PIX_FMT_YUV420P;
picture.width = STREAM_WIDTH;
picture.height = STREAM_HEIGHT;
picture.framerate = 30;
picture.y_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT );
picture.cr_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT / 4 );
picture.cb_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT / 4 );
picture.y_line_size = STREAM_WIDTH;
picture.cb_line_size = STREAM_WIDTH / 2;
picture.cr_line_size = STREAM_WIDTH / 2;
vp_os_memset(&icc, 0, sizeof( icc ));
vp_os_memset(&vec, 0, sizeof( vec ));
vp_os_memset(&yuv2rgbconf, 0, sizeof( yuv2rgbconf ));
icc.com = COM_VIDEO();
icc.buffer_size = 100000;
icc.protocol = VP_COM_UDP;
COM_CONFIG_SOCKET_VIDEO(&icc.socket, VP_COM_CLIENT, VIDEO_PORT, wifi_ardrone_ip);
vec.width = STREAM_WIDTH;
vec.height = STREAM_HEIGHT;
vec.picture = &picture;
#ifdef USE_VIDEO_YUV
vec.luma_only = FALSE;
#else
vec.luma_only = TRUE;
#endif // USE_VIDEO_YUV
vec.block_mode_enable = TRUE;
vec.luma_only = FALSE;
yuv2rgbconf.rgb_format = VP_STAGES_RGB_FORMAT_RGB24;
if( CAMIF_H_CAMERA_USED == CAMIF_CAMERA_OVTRULY_UPSIDE_DOWN_ONE_BLOCKLINE_LESS )
yuv2rgbconf.mode = VP_STAGES_YUV2RGB_MODE_UPSIDE_DOWN;
pipeline.nb_stages = 0;
stages[pipeline.nb_stages].type = VP_API_INPUT_SOCKET;
stages[pipeline.nb_stages].cfg = (void *)&icc;
stages[pipeline.nb_stages].funcs = video_com_funcs;
pipeline.nb_stages++;
stages[pipeline.nb_stages].type = VP_API_FILTER_DECODER;
stages[pipeline.nb_stages].cfg = (void*)&vec;
stages[pipeline.nb_stages].funcs = vlib_decoding_funcs;
pipeline.nb_stages++;
stages[pipeline.nb_stages].type = VP_API_FILTER_YUV2RGB;
stages[pipeline.nb_stages].cfg = (void*)&yuv2rgbconf;
stages[pipeline.nb_stages].funcs = vp_stages_yuv2rgb_funcs;
pipeline.nb_stages++;
stages[pipeline.nb_stages].type = VP_API_OUTPUT_SDL;
stages[pipeline.nb_stages].cfg = (void *)&vec;
stages[pipeline.nb_stages].funcs = vp_stages_export_funcs;
pipeline.nb_stages++;
pipeline.stages = &stages[0];
PIPELINE_HANDLE pipeline_handle;
res = vp_api_open(&pipeline, &pipeline_handle);
if( SUCCEED(res) ) {
while( SUCCEED(vp_api_run(&pipeline, &out)) ) {
}
vp_api_close(&pipeline, &pipeline_handle);
}
return (THREAD_RET)0;
// PRINT("***** Starting video capture thread ...\n");
// C_RESULT res;
//
// vp_api_io_pipeline_t pipeline;
// vp_api_io_data_t out;
// vp_api_io_stage_t stages[NB_STAGES];
//
// vp_api_picture_t picture;
//
// video_com_config_t icc;
// vlib_stage_decoding_config_t vec;
// vp_stages_yuv2rgb_config_t yuv2rgbconf;
//
// /// Picture configuration
// picture.format = PIX_FMT_YUV420P;
// picture.width = STREAM_WIDTH;
// picture.height = STREAM_HEIGHT;
// picture.framerate = 30;
//
// picture.y_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT );
// picture.cr_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT / 4 );
// picture.cb_buf = (uint8_t *)vp_os_malloc( STREAM_WIDTH * STREAM_HEIGHT / 4 );
//
// picture.y_line_size = STREAM_WIDTH;
// picture.cb_line_size = STREAM_WIDTH / 2;
// picture.cr_line_size = STREAM_WIDTH / 2;
//
// vp_os_memset(&icc, 0, sizeof( icc ));
// vp_os_memset(&vec, 0, sizeof( vec ));
// vp_os_memset(&yuv2rgbconf, 0, sizeof( yuv2rgbconf ));
//
// PRINT("***** Before COM ...\n");
// icc.com = COM_VIDEO();
// icc.buffer_size = (1024*1024);
// icc.protocol = VP_COM_UDP;
// COM_CONFIG_SOCKET_VIDEO(&icc.socket, VP_COM_CLIENT, VIDEO_PORT, wifi_ardrone_ip);
//
// vec.width = STREAM_WIDTH;
// vec.height = STREAM_HEIGHT;
// vec.picture = &picture;
// vec.luma_only = FALSE;
// vec.block_mode_enable = TRUE;
//
// yuv2rgbconf.rgb_format = VP_STAGES_RGB_FORMAT_RGB24;
//// if( CAMIF_H_CAMERA_USED == CAMIF_CAMERA_OVTRULY_UPSIDE_DOWN_ONE_BLOCKLINE_LESS )
//// yuv2rgbconf.mode = VP_STAGES_YUV2RGB_MODE_UPSIDE_DOWN;
//
// pipeline.nb_stages = 0;
//
// stages[pipeline.nb_stages].type = VP_API_INPUT_SOCKET;
// stages[pipeline.nb_stages].cfg = (void *)&icc;
// stages[pipeline.nb_stages].funcs = video_com_funcs;
//
// pipeline.nb_stages++;
//
// stages[pipeline.nb_stages].type = VP_API_FILTER_DECODER;
// stages[pipeline.nb_stages].cfg = (void*)&vec;
// stages[pipeline.nb_stages].funcs = vlib_decoding_funcs;
//
// pipeline.nb_stages++;
//
// stages[pipeline.nb_stages].type = VP_API_FILTER_YUV2RGB;
// stages[pipeline.nb_stages].cfg = (void*)&yuv2rgbconf;
// stages[pipeline.nb_stages].funcs = vp_stages_yuv2rgb_funcs;
//
// pipeline.nb_stages++;
//
// stages[pipeline.nb_stages].type = VP_API_OUTPUT_SDL;
// stages[pipeline.nb_stages].cfg = NULL;//(void *)&vec;
// stages[pipeline.nb_stages].funcs = vp_stages_export_funcs;
//
// pipeline.nb_stages++;
//
// pipeline.stages = &stages[0];
// //res = vp_api_open(&pipeline, &pipeline_handle);
//
// PRINT("***** Before Main Block ...\n");
// if( !ardrone_tool_exit() )
// {
// PRINT("\n Video stage thread initialisation\n\n");
//
// res = vp_api_open(&pipeline, &pipeline_handle);
// PRINT("***** API OPEN ... %d \n", res);
// if (SUCCEED(res)) {
// PRINT("API OPEN Successfull \n");
// int loop = SUCCESS;
// out.status = VP_API_STATUS_PROCESSING;
// while (!ardrone_tool_exit() && (loop == SUCCESS)) {
// if (SUCCEED(vp_api_run(&pipeline, &out))) {
// if ((out.status == VP_API_STATUS_PROCESSING || out.status == VP_API_STATUS_STILL_RUNNING)) {
// loop = SUCCESS;
// }
// } else loop = -1; // Finish this thread
// }
//
// vp_api_close(&pipeline, &pipeline_handle);
// }
// }
//
// PRINT(" Video stage thread ended\n\n");
// return (THREAD_RET)0;
// if( SUCCEED(res) ) {
// while( SUCCEED(vp_api_run(&pipeline, &out)) ) {
// }
//
// vp_api_close(&pipeline, &pipeline_handle);
// }
//
// return (THREAD_RET)0;
}
+1 -6
Ver Arquivo
@@ -19,16 +19,11 @@
#define MODE3_PIP_HEIGHT 42
extern video_com_multisocket_config_t icc;
extern parrot_video_encapsulation_codecs_t video_stage_decoder_lastDetectedCodec;
//extern parrot_video_encapsulation_codecs_t video_stage_decoder_lastDetectedCodec;
extern const vp_api_stage_funcs_t vp_stages_export_funcs;
extern unsigned char buffer[]; // size STREAM_WIDTH * STREAM_HEIGHT * 3
extern int current_frame_id; // this will be incremented for every frame
static int32_t pixbuf_width = 0;
static int32_t pixbuf_height = 0;
static int32_t pixbuf_rowstride = 0;
static uint8_t* pixbuf_data = NULL;
PROTO_THREAD_ROUTINE(video_update_thread, data);
#endif