#include "common/sample_common.h"
#include "rkmedia_api.h"
+extern int32_t camera_enable( uint32_t camera_id );
+extern int32_t camera_disable( void );
+
static int32_t stop = 0;
static bool quit = false;
static uint32_t camera_id = 0;
}
STHandle g_SThandle = NULL;
-static int sentime_ai_init(void)
+int sentime_ai_init(void)
{
STResult ret = ST_OK;
ret = STAsteriaSetI2CBusNumber(5);
return 0;
}
-static int sentime_ai_deinit(void)
+int sentime_ai_deinit(void)
{
if (g_SThandle != NULL)
STAsteriaDestroy(g_SThandle);
}
//zf有过修改,将void改成了int
-static int rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn, uint32_t video_width, uint32_t video_height)
+int rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn, uint32_t video_width, uint32_t video_height)
{
VI_CHN_ATTR_S vi_chn_attr;
int ret = 0;
}
}
-static int rk_vi_setfps(VI_CHN ViChn, int fps)
+int rk_vi_setfps(VI_CHN ViChn, int fps)
{
int ret;
MPP_FPS_ATTR_S fps_attr;
goto error;
}
- if (gr_camera_num == CAMERA_DOUBLE)
+ ///if (gr_camera_num == CAMERA_DOUBLE)
{
gr_info = mg_als_read(gr_ctrl->als_ctrl);
if (gr_info != NULL)
gr_info = NULL;
}
}
+
+ camera_enable( camera_id );
+ return 0;
error:
return -1;
}
// return -1;
// }
+#if 1
+int32_t gr_read_gesture(void);
+#else
static int32_t gr_read_gesture(void)
{
int32_t ret = -1;
return -2;
}
+#endif
+
static bool escalation = 1;
static int32_t repeating_gestures = -10;
static int32_t timeout = 0;
}
}
-
void *gr_task(void *param)
{
int ret;
uint32_t dp_timeout, gr_time;
uint32_t time_flasg;
+ uint32_t privacy =0;
+
gr_ctrl_t *p_gr = (gr_ctrl_t *)param;
gr_time = time(NULL);
+
+ my_privacy = -1;
+
+ camera_id = 0;
+
while (!stop)
{
usleep(100 * 1000);
- my_privacy = cfg_privacy_mode_read(p_gr->dev);
+ privacy = cfg_privacy_mode_read(p_gr->dev);
+ if( my_privacy != privacy ){
+ printf( "Privacy Mode %d -> %d\n", my_privacy, privacy );
+ my_privacy = privacy;
+ if( privacy ){
+ camera_disable();
+ }else{
+ gr_als_t(p_gr);
+ }
+ }
+
if (my_privacy == 1)
{
usleep(100 * 1000);
gr_ring_enable(p_gr->light_ctrl);
while (!stop)
{
+//--------------------------------------
+//check privacy
+ privacy = cfg_privacy_mode_read(p_gr->dev);
+ if( my_privacy != privacy ){
+ printf( "Privacy Mode %d -> %d\n", my_privacy, privacy );
+ my_privacy = privacy;
+ if( privacy ){
+ camera_disable();
+ reportdp_and_close_ring_gr(p_gr->light_ctrl);
+ break;
+ }
+ }
+//--------------------------------------
usleep(100 * 000);
if (time_flasg)
{
return NULL;
}
+#define IMAGE_CAPTURE_TEST
+
+#ifdef IMAGE_CAPTURE_TEST
+int save_stream_file(char* stream_path,unsigned char *p_data_buf,unsigned int img_len)
+{
+
+ int file;
+ file = open(stream_path, O_RDWR | O_CREAT | O_TRUNC , 0777);
+ if (file < 0) {
+ printf("failed: %s\n", strerror(errno));
+ return (-1);
+ }
+ lseek(file,0,SEEK_END);
+ int n_write =write(file,p_data_buf,img_len);
+ if(n_write !=-1)
+ {
+ // printf("write %d byte to file\n",n_write);
+ }
+ close(file);
+ return 0;
+}
+#endif
+
+#if 0
static void *ai_detect(void *arg)
{
}
return flag;
}
-
-
+#endif
int gr_register(gr_ctrl_t *gr_ctrl, uint32_t threshold_high, uint32_t threshold_low)
{
}
mg_als_cfg(gr_ctrl->als_ctrl, threshold_high, threshold_low);
+#if 0
camera_flag = detect_cameras_num();
+
if(camera_flag){
if(camera_flag == 1){
if(gr_camera_num == CAMERA_RGB){
return 0;
}
+#else
+ if (pthread_create(&gr_thread, NULL, gr_task, gr_ctrl) != 0)
+ {
+ printf("create hand_ic failed!");
+ stop = 1;
+ goto app_ext1;
+ }
+
+ return 0;
+#endif
app_ext1:
gr_close(gr_ctrl);
return -1;
}
-
-
#if 0
static gr_ctrl_t gr_ctrl;
--- /dev/null
+#include <stdio.h>
+#include <stdint.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <semaphore.h>
+#include <signal.h>
+#include <unistd.h>
+#include <sys/wait.h>
+
+#include "libsteria/st_asteria_api.h"
+//#include "libsteria/st_utils.h"
+#include "common/sample_common.h"
+#include "rkmedia_api.h"
+#include "device.h"
+
+#define ST_AI_IMAGE_W 1280 // 1920
+#define ST_AI_IMAGE_H 720 // 1080
+#define BODY_ATTRIBUTE
+
+
+#define CAM_SHM_NAME "camera_ctrl_shm"
+#define IMAGE_SIZE ((ST_AI_IMAGE_W ) * (ST_AI_IMAGE_H )*3/2)
+
+#define ISP_S_RGB 0
+#define ISP_S_IR 0
+#define ISP_D_RGB 0
+#define ISP_D_IR 1
+
+#define VI_RGB 1
+#define VI_IR 0
+
+#define SENSOR_NONE 0
+#define SENSOR_IR 1
+#define SENSOR_RGB 2
+#define SENSOR_ALL (SENSOR_IR|SENSOR_RGB)
+
+extern void printDetectResult(const STDetectResult *detectResult);
+extern int save_stream_file(char* stream_path,unsigned char *p_data_buf,unsigned int img_len);
+extern int rk_isp_init(char index, char *iq_dir);
+extern void rk_isp_deinit(char index);
+extern int rk_vi_init(VI_PIPE ViPipe, VI_CHN ViChn, uint32_t video_width, uint32_t video_height);
+extern int rk_vi_setfps(VI_CHN ViChn, int fps);
+extern int32_t gesture_recognition_start(mg_dev_t *dev);
+
+extern STHandle g_SThandle;
+extern int sentime_ai_init(void);
+
+typedef struct{
+ sem_t lock;
+ uint32_t cam_request; //父进程写, 子进程读取,用于切换, 0-全关,1-CAM1, 2-CAM2
+ uint32_t cam_valid; //子进程写, 父进程读取, 0-没有摄像头,1-CAM1, 2-CAM2, 3-CAM1+CAM2
+ uint32_t gs_action_id;
+ uint32_t gs_action_code;
+ uint32_t gs_action_valid;
+ uint32_t alive; //子进程写1, 如果是0 超时后杀子进程
+ uint32_t st; //0-normal, 1-摄像头初始化错误, 2-算法初始化错误, 3-sensor初始化错误,4-获取图像错误, 5,算法运行错误
+ // uint32_t frame; //图像序号,子进程写,父进程读
+ // int32_t img_size; //子进程写, 父进程读,父进程读取图像数据后清0, 0:无数据, >0:有数据, 读取后去写0, <0:错误
+ // uint8_t img[ IMAGE_SIZE ];
+} cam_shm_info_t;
+
+static int32_t s_debug_save_image; //1: 保存照片到/tmp/ nv文件, 0:关闭
+
+static cam_shm_info_t * p_cam_shm;
+static pid_t cam_pid;
+
+static uint32_t g_sensor_valid = 0; //设备有几路摄像头, 0-没有摄像头, 1-摄像头1(RGB), 2-摄像头2(IR), 3-两路摄像头(RGB+IR)
+static uint32_t g_sensor_curr = 0; //当前使用的摄像头, 0-关闭状态, 1-使用摄像头1(RGB), 2-使用摄像头2(IR)
+static uint8_t image_data[ IMAGE_SIZE ];
+static uint32_t image_size;
+
+static uint32_t sensor_to_isp( uint32_t sensor );
+static uint32_t sensor_to_vi( uint32_t sensor );
+
+int32_t get_image( uint32_t sensor, uint8_t *buff, uint32_t buff_size )
+{
+ MEDIA_BUFFER mb = NULL;
+ int32_t ret = -1;
+ uint32_t sz = 0;
+ uint32_t vi = 0;
+
+ vi = sensor_to_vi( sensor );
+ mb = RK_MPI_SYS_GetMediaBuffer(RK_ID_VI, vi, -1);
+ if (mb){
+ sz = RK_MPI_MB_GetSize(mb );
+ //printf( "--------get_image...%p, sz:%d\n",mb, sz );
+ if( sz > buff_size )
+ sz = buff_size;
+ memcpy(buff, RK_MPI_MB_GetPtr(mb), sz );
+ //printf( "img...addr:%p, size:%d\n", RK_MPI_MB_GetPtr(mb), RK_MPI_MB_GetSize(mb ) );
+ ret =sz;
+ RK_MPI_MB_ReleaseBuffer(mb);
+ }else{
+ printf( "get_image...fail!\n" );
+ }
+ return sz;
+}
+
+int32_t sensor_scan( void )
+{
+ uint32_t sensor = 0;
+
+ //扫描设备有几路摄像头
+ //0-没有摄像头, 1-摄像头1(RGB), 2-摄像头2(IR), 3-两路摄像头(RGB+IR)
+
+ if (!access("/sys/bus/i2c/drivers/gc2053/1-0037", 0))
+ {
+ printf( "found sensor: RGB[1-0037]\n" );
+ sensor |= SENSOR_RGB;
+ }
+ if (!access("/sys/bus/i2c/drivers/gc2053/3-0037", 0))
+ {
+ printf( "found sensor: IR[3-0037]\n" );
+ sensor |= SENSOR_IR;
+ }
+ printf( "found sensor: [%d]\n", sensor );
+ return sensor;
+}
+
+int32_t sensor_init( uint32_t sensor )
+{
+ int32_t ret = 0;
+
+ while(1){
+ printf( "ai init ...\n" );
+ //算法初始化
+ ret = sentime_ai_init();
+ if( ret ==0 ){
+ break;
+ }else if (ret == -15){
+ //授权过期,返回-15
+ printf("sentime_ai_init fail -15, retry...\n");
+ sleep(5);
+ }else{
+ printf("sentime_ai_init fail ret:%d, retry...\n", ret );
+ sleep(5);
+ }
+ }
+
+ RK_MPI_SYS_Init();
+
+ return ret;
+}
+
+static uint32_t sensor_to_isp( uint32_t sensor )
+{
+ if( g_sensor_valid == SENSOR_ALL ){
+ if( sensor == SENSOR_IR )
+ return ISP_D_IR;
+ else if( sensor == SENSOR_RGB )
+ return ISP_D_RGB;
+ }else{
+ if( sensor == SENSOR_IR )
+ return ISP_S_IR;
+ else if( sensor == SENSOR_RGB )
+ return ISP_S_RGB;
+ }
+
+ //printf( "error\n" );
+ return ISP_S_RGB;
+}
+
+static uint32_t sensor_to_vi( uint32_t sensor )
+{
+ if( sensor == SENSOR_IR )
+ return VI_IR;
+ else if( sensor == SENSOR_RGB )
+ return VI_RGB;
+
+ //printf( "error\n" );
+ return VI_RGB;
+}
+
+int32_t is_valid_sensor( uint32_t sensor )
+{
+ return ( sensor & g_sensor_valid )?1:0;
+}
+
+char *sensor_name( uint32_t sensor )
+{
+ if( sensor == 0 ) return "Sensor_OFF";
+ else if( sensor == SENSOR_IR ) return "Sensor_IR-3-0037";
+ else if( sensor == SENSOR_RGB ) return "Sensor_RGB-1-0037";
+ else return "invalid Sensor";
+}
+
+int32_t sensor_switch( uint32_t sensor )
+{
+ uint32_t isp;
+ uint32_t vi;
+
+ int32_t ret = 0;
+
+ if( g_sensor_curr == sensor ){
+ printf( " sensor switch: same sensor:%d-%s\n", sensor, sensor_name(sensor) );
+ return 0;
+ }
+
+ if( sensor && !is_valid_sensor(sensor) ){
+ printf( " sensor switch: invalid sensor:%d\n", sensor );
+ return 0;
+ }
+
+ //1.关闭当前摄像头
+ if( g_sensor_curr && is_valid_sensor( g_sensor_curr ) ){
+ isp = sensor_to_isp( g_sensor_curr );
+ vi = sensor_to_vi( g_sensor_curr );
+ printf( "close sensor[%d - %s]\n", g_sensor_curr, sensor_name( g_sensor_curr ) );
+ RK_MPI_VI_DisableChn( vi, vi);
+ rk_isp_deinit( isp );
+ }
+
+ //2.开启指定摄像头
+ if( sensor == 0 ){
+ g_sensor_curr = sensor;
+ return 0;
+ }
+
+ isp = sensor_to_isp( sensor );
+ vi = sensor_to_vi( sensor );
+
+ printf( "open sensor[%d-%s], isp ch:%d, iv ch:%d\n", sensor, sensor_name(sensor), isp, vi );
+ ret = rk_isp_init(isp, "/etc/iqfiles/");
+ printf( "switch sensor, rk_isp_init ret:%d!\n", ret );
+ if( ret ){
+ printf( "switch sensor fail!, rk_isp_init error!\n" );
+ }else{
+ ret = rk_vi_init( vi , vi, ST_AI_IMAGE_W, ST_AI_IMAGE_H);
+ if( ret ){
+ printf( "switch sensor fail!, rk_vi_init error!\n" );
+ rk_isp_deinit( isp );
+ }else{
+ ret = rk_vi_setfps(vi, 15);
+ if( ret ){
+ RK_MPI_VI_DisableChn(vi, vi);
+ printf( "switch sensor fail!, rk_vi_setfps error!\n" );
+ }
+ }
+ }
+
+ if( ret == 0 ){
+ g_sensor_curr = sensor;
+ printf( "------ open sensor[%d-%s] successs\n", sensor, sensor_name(sensor) );
+ }else{
+ printf( "------ open sensor[%d-%s] fail, ret:%d\n", sensor, sensor_name(sensor), ret );
+ }
+
+ return ret;
+}
+
+int32_t get_gesture( uint8_t *image_data, uint32_t image_size, uint32_t *action_code, uint32_t*action_valid )
+{
+ //调用算法,返回识别到的动作
+ const STDetectResult *mg_detectResult = NULL;
+ STImage detectImage = {0};
+ detectImage.data = image_data;
+ detectImage.format = ST_PIXEL_FORMAT_NV12;
+ detectImage.width = ST_AI_IMAGE_W;
+ detectImage.height = ST_AI_IMAGE_H;
+ int32_t ret = -1;
+
+ if( s_debug_save_image ){
+ save_stream_file( "/tmp/capture_1280x720.NV12", image_data, image_size );
+ }
+
+ *action_valid = 0;
+ *action_code = 0;
+ if( g_SThandle ){
+ ret = 0;
+ STAsteriaDetect(g_SThandle, ST_DETECT_MODE_VIDEO, &detectImage, &mg_detectResult);
+
+ {
+ //printf( "detectResult:%p -handCount[%d] \n", mg_detectResult, mg_detectResult?mg_detectResult->handCount:0 );
+ //printDetectResult( mg_detectResult );
+ static int handCount = -1;
+ int cnt = mg_detectResult?mg_detectResult->handCount:-1;
+ if( handCount != cnt ){
+ printf( "handCount %d -> %d\n", handCount, cnt );
+ handCount = cnt;
+ }
+ }
+
+ if( mg_detectResult && mg_detectResult->handCount ){
+ int32_t code = 0;
+ switch (mg_detectResult->hands[0].action){
+ case ST_HAND_ACTION_SHOOT: code = GS_GUN; break;
+ case ST_HAND_ACTION_LITTLE_FINGER: code = GS_LITTLE_FINGER; break;
+ case ST_HAND_ACTION_ROCK_ON: code = GS_HORNED_HAND; break;
+ case ST_HAND_ACTION_I_LOVE_YOU: code = GS_ILOVEYOU; break;
+ case ST_HAND_ACTION_FOUR: code = GS_FOUR_FINGERS; break;
+ case ST_HAND_ACTION_THREE: code = GS_THREE_FINGERS; break;
+ case ST_HAND_ACTION_SIX: code = GS_WELL_PLAYED; break;
+ case ST_HAND_ACTION_INDEX_FINGER: code = GS_FINGERTIP; break;
+ case ST_HAND_ACTION_FINGER_HEART: code = GS_FINGER_HEART; break;
+ case ST_HAND_ACTION_FIST: code = GS_ROCK; break;
+ case ST_HAND_ACTION_PALM: code = GS_PAPER; break;
+ case ST_HAND_ACTION_THUMBS_UP: code = GS_THUMBS_UP; break;
+ case ST_HAND_ACTION_V: code = GS_SCISSORS; break;
+ case ST_HAND_ACTION_OK: code = GS_OK; break;
+ default: code = -1; break;
+ }
+ if( code >=0 ){
+ *action_valid = 1;
+ *action_code = code;
+ }
+ }
+ }
+ return ret;
+}
+
+//子进程入口函数, 负责摄像头管理和手势识别
+void camera_process( void )
+{
+ int mapfd;
+ uint32_t cam_req;
+ uint32_t cam_curr =0;
+ uint32_t action_valid = 0;
+ uint32_t action_code = 0;
+ static uint32_t act_id = 0;
+ int32_t err = 0;
+
+ if (!access("/tmp/save_gs_img", 0 ) ){
+ printf( "s_debug_save_image -> enable\n" );
+ s_debug_save_image = 1;
+ }
+
+ printf( "---------------------------\n" );
+ printf( "-------camera_ctrl---------\n" );
+ printf( "---------------------------\n" );
+
+ // 开辟一段共享内存
+ mapfd = shm_open(CAM_SHM_NAME, O_RDWR, S_IRUSR | S_IWUSR);
+ if(mapfd == -1){
+ perror("camera_ctrl:shm_open fail");
+ sleep(2);
+ exit(EXIT_FAILURE);
+ }
+
+ //共享内存映射
+ void* sp = mmap(NULL,sizeof( cam_shm_info_t),PROT_READ|PROT_WRITE,MAP_SHARED,mapfd,0);
+ if(sp == NULL){
+ perror("mmap fail");
+ close(mapfd);
+ sleep(2);
+ exit(EXIT_FAILURE);
+ }
+
+ p_cam_shm = ( cam_shm_info_t*)sp;
+
+ //检查设备是否识别到两路摄像头
+ g_sensor_valid = sensor_scan();
+
+ sem_wait( &p_cam_shm->lock );
+ p_cam_shm->cam_valid = g_sensor_valid;
+ sem_post( &p_cam_shm->lock );
+
+ //snesor初始化, 算法初始化
+ sensor_init( g_sensor_valid );
+
+ cam_curr = -1;
+
+ while(1){
+
+ sem_wait( &p_cam_shm->lock );
+ cam_req = p_cam_shm->cam_request;
+ sem_post( &p_cam_shm->lock );
+
+ if( g_sensor_curr != cam_req ){
+ if( cam_req && !is_valid_sensor(cam_req) ){
+ //摄像头无效,不执行切换
+ err=0;
+ }else if( sensor_switch( cam_req ) == 0 ){
+ //摄像头切换成功
+ printf( "sensor -> %d-%s\n",g_sensor_curr, sensor_name(g_sensor_curr) );
+ err=0;
+ }else{
+ //摄像头切换失败
+ if( err++ < 5 ){
+ //重试
+ printf( "oepn sensor[%s] fail, retry--%d\n", sensor_name( cam_req ), err );
+ usleep( 500*1000 );
+ continue;
+ }else{
+ err = 0;
+ printf( "open ssensor[%s] fail, exit\n", sensor_name( cam_req ) );
+ //退出进程,
+ break;
+ }
+ }
+ }
+
+ if( !g_sensor_curr ){
+ //摄像头关闭状态
+ //printf( "sub process -- sensor all off\n" );
+ usleep( 1000*1000 );
+ p_cam_shm->alive = 1;
+ continue;
+ }
+
+ //获取图像
+ image_size = sizeof( image_data );
+ if( get_image( g_sensor_curr, image_data, image_size ) != image_size ){
+ printf( "get image fail!\n" );
+ if( err++ > 60 ){
+ err = 0;
+ printf( "get image fail------exit!\n" );
+ break;
+ }
+ sleep(2);
+ continue;
+ }else{
+ err = 0;
+ }
+
+ //算法识别
+ if( get_gesture( image_data, image_size, &action_code, &action_valid ) == 0 ){
+
+ //获得结果,上报
+ sem_wait( &p_cam_shm->lock );
+ p_cam_shm->gs_action_code = action_code;
+ p_cam_shm->gs_action_valid = action_valid;
+ if( action_valid )
+ p_cam_shm->gs_action_id = act_id++;
+ else
+ p_cam_shm->gs_action_id = 0;
+ sem_post( &p_cam_shm->lock );
+
+ err=0;
+ }else{
+ printf( "get gesture fail!\n" );
+ if( err++ > 60 ){
+ err = 0;
+ printf( "get gesture fail------exit!\n" );
+ break;
+ }
+ sleep(2);
+ continue;
+ }
+
+ p_cam_shm->alive = 1;
+ usleep( 100*1000 );
+ }
+
+ close(mapfd);
+ //shm_unlink( CAM_SHM_NAME);
+ exit(0);
+}
+
+//--------------------------------------------------------------------------//
+//--------------------------------------------------------------------------//
+static uint32_t act_id = 0;
+static uint32_t act_code = 0;
+static uint32_t act_valid = 0;
+static uint32_t cam_req;
+
+int32_t gr_read_gesture(void)
+{
+ return act_valid? act_code : -1;
+}
+
+int32_t camera_disable( void )
+{
+ cam_req = 0;
+ return 0;
+}
+
+int32_t camera_enable( uint32_t camera_id )
+{
+ //camera_id: 0-IR 1-RGB
+ cam_req = camera_id==0?SENSOR_IR:SENSOR_RGB;
+ return 0;
+}
+
+//父进程
+void* gesture_task( void* param )
+{
+ int status = 0;
+ int mapfd;
+ mg_dev_t *dev;
+
+ dev = ( mg_dev_t*)param;
+
+ printf( "---------------------------\n" );
+ printf( "---------gesture_task------\n" );
+ printf( "---------------------------\n" );
+
+ // 开辟一段共享内存
+ mapfd = shm_open(CAM_SHM_NAME, O_RDWR|O_CREAT,S_IRUSR | S_IWUSR);
+ if(mapfd == -1){
+ perror("shm_open fail");
+ return NULL;
+ //exit(EXIT_FAILURE);
+ }
+
+ // ftruncate设置共享内存大小
+ if(ftruncate(mapfd, sizeof(cam_shm_info_t) ) == -1){
+ perror("ftruncate fail");
+ close(mapfd);
+ return NULL;
+ //exit(EXIT_FAILURE);
+ }
+
+ //共享内存映射
+ void* sp = mmap(NULL,sizeof( cam_shm_info_t ), PROT_READ|PROT_WRITE, MAP_SHARED,mapfd,0);
+ if(sp == NULL){
+ perror("mmap fail");
+ close(mapfd);
+ return NULL;
+ //exit(EXIT_FAILURE);
+ }
+
+ p_cam_shm = ( cam_shm_info_t*)sp;
+ memset( p_cam_shm, 0, sizeof( cam_shm_info_t ) );
+
+ // 初始化共享内存中包含互斥锁
+ if(sem_init(&p_cam_shm->lock, 1, 1) != 0) {
+ perror("sem_init fail");
+ close(mapfd);
+ return NULL;
+ //exit(EXIT_FAILURE);
+ }
+
+ sem_wait( &p_cam_shm->lock );
+ p_cam_shm->cam_request = 0;
+ p_cam_shm->cam_valid = 0;
+ //p_cam_shm->img_size = 0;
+ //memset( p_cam_shm->img, 0, IMAGE_SIZE );
+ sem_post( &p_cam_shm->lock );
+
+ {
+ //启动手势设别流程
+ gesture_recognition_start( dev );
+ }
+
+ while(1){
+
+ sem_wait( &p_cam_shm->lock );
+ if( p_cam_shm->cam_request != cam_req ){
+ p_cam_shm->cam_request = cam_req;
+ }
+ sem_post( &p_cam_shm->lock );
+
+ cam_pid = fork();
+ if( cam_pid == -1 ){
+ perror("fork fail");
+ sleep(5);
+ continue;
+ }
+ if( cam_pid == 0 ){
+
+ extern char* program_name;
+ if( program_name )
+ program_name = strdup( "/app/mg_app" );
+
+ execl( program_name, "camera-ctrl" );
+ }
+
+ //signal(SIGCHLD, cam_sig_handle);
+
+ int alive_err = 0;
+ while( 1 ){
+ usleep( 50*1000 );
+
+ if( cam_pid == waitpid(cam_pid, &status, WNOHANG) ){
+
+ printf( "waitpid pid:%d, status:%d, restart camer subprocess\n",cam_pid, status );
+ //重启子进程
+ break;
+ }
+
+ sem_wait( &p_cam_shm->lock );
+ if( p_cam_shm->cam_request != cam_req ){
+ printf( "cam_req:%d-%s -> %d-%s\n", p_cam_shm->cam_request, sensor_name( p_cam_shm->cam_request), cam_req, sensor_name( cam_req ) );
+ p_cam_shm->cam_request = cam_req;
+ }
+ if( p_cam_shm->gs_action_valid != act_valid
+ || p_cam_shm->gs_action_code != act_code
+ || p_cam_shm->gs_action_id != act_id ){
+ act_id = p_cam_shm->gs_action_id;
+ act_code = p_cam_shm->gs_action_code;
+ act_valid = p_cam_shm->gs_action_valid;
+ printf( " cam:%d/%d, gs act -- valid:%d, code:%d, id:%d\n",
+ p_cam_shm->cam_request, p_cam_shm->cam_valid,
+ act_valid, act_code, act_id );
+ }
+ if( p_cam_shm->alive == 0 ){
+ alive_err++;
+ }else{
+ alive_err = 0;
+ }
+ p_cam_shm->alive = 0;
+
+ sem_post( &p_cam_shm->lock );
+
+ if( alive_err > 1*60*20 ){ //1*60*20*50ms -> 1min
+ alive_err = 0;
+ //子进程1分钟没有回应,关闭子进程
+ printf( "-----------kill sub process!\n" );
+ kill( cam_pid, SIGKILL ); //
+ }
+ }//while 1
+ }//while 1
+ return NULL;
+}
+
+static pthread_t gs_tid;
+int32_t gesture_task_start( mg_dev_t *dev)
+{
+ if( pthread_create( &gs_tid, NULL, gesture_task, (void *)dev) != 0 ){
+ perror( "create gesture task!" );
+ return -1;
+ }
+ return 0;
+}
+