int main(int argc, char **argv)
{
struct timespec start, end;
uint32_t j;
// // 获取开始时间
// clock_gettime(CLOCK_MONOTONIC, &start);
// // 执行一次内层循环
// for (j = 0; j < 1; j++)
// {
// // 空循环用于等待
// }
// // 获取结束时间
// clock_gettime(CLOCK_MONOTONIC, &end);
// // 计算时间差
// double elapsed_ns = (end.tv_sec - start.tv_sec) * 1e9 + (end.tv_nsec - start.tv_nsec);
// printf("One iteration of inner loop took %.2f ns\n", elapsed_ns);
/*{
pthread_attr_t attr;
size_t stacksize;
int result;
// 初始化属性对象
result = pthread_attr_init(&attr);
if (result != 0) {
perror("pthread_attr_init");
exit(EXIT_FAILURE);
}
// size_t stack_size = 128 * 1024; // 例如:128 KB
// pthread_attr_setstacksize(&attr, stack_size);
// pthread_create(&thread, &attr, thread_function, NULL);
// 获取当前的堆栈大小属性
result = pthread_attr_getstacksize(&attr, &stacksize);
if (result != 0) {
perror("pthread_attr_getstacksize");
pthread_attr_destroy(&attr);
exit(EXIT_FAILURE);
}
printf("Default thread stack size is: %zu bytes\n", stacksize);
// 清理属性对象
pthread_attr_destroy(&attr);
}*/
int ret;
char cmd;
struct test_resource *res;
#ifdef DEMO_NPU_SUPPORT
struct sample_ai_configs ai_ex_configs;
// 解析json,获取AI处理流程属性
memset(&ai_ex_configs, 0, sizeof(struct sample_ai_configs));
ret = get_json_conf(&ai_ex_configs);
if (ret == XMEDIA_FAILURE)
{
ai_ex_configs.is_enable = XMEDIA_FALSE;
}
#endif
InitQrQue(); // 队列深度为8,缓存大小为128*1024
LoadXyConfig();
signal(SIGINT, signalHandler);
LoadKo();
res = (struct test_resource *)malloc(sizeof(struct test_resource));
if (res == NULL)
{
DEMO_PRINT("malloc failed!\n");
return -1;
}
memset(res, 0x0, sizeof(struct test_resource));
ret = param_parse(argc, argv, res);
if (ret != 0)
{
free(res);
return -1;
}
ret = resource_init(res);
if (ret != 0)
{
DEMO_PRINT("resource_init failed!\n");
free(res);
return -1;
}
sys_init(res);
mipi_init(res);
vi_init(res);
isp_init(res);
vpss_init(res);
venc_init(res);
if (res->audio_enable == XMEDIA_TRUE)
{
audio_init(res);
}
pipeline_connect(res);
// rgn_handle_create(res);
// rgn_bind_chn(res);
// set_rgn_display_conf(res);
pipeline_start(res);
sensor_info_init(res);
// vgs_init(res);
usleep(10 * 1000);
#ifdef DEMO_NPU_SUPPORT
struct sample_media_configs ai_media_configs;
memset(&ai_media_configs, 0, sizeof(struct sample_media_configs));
ai_media_configs.vi_pipe = res->vi_pipe;
ai_media_configs.vpss_grp = res->vpss_grp;
ai_media_configs.vpss_chn = res->vpss_chn[2];
ai_media_configs.venc_chn = res->venc_chn[2];
demo_aisdk_start(&ai_media_configs, ai_ex_configs);
usleep(10 * 1000);
#endif
struct sample_media_configs_2 ai_media_configs;
memset(&ai_media_configs, 0, sizeof(struct sample_media_configs_2));
ai_media_configs.vi_pipe = res->vi_pipe;
ai_media_configs.vpss_grp = res->vpss_grp;
ai_media_configs.vpss_chn = res->vpss_chn[2];
ai_media_configs.venc_chn = res->venc_chn[2];
ai_media_configs.width = res->small_image_size.u32Width;
ai_media_configs.height = res->small_image_size.u32Height;
// ai_media_configs.width = 640;
// ai_media_configs.height = 360;
g_adec_chn = res->adec_chn;
usleep(10 * 1000);
xmedia_s32 vol_plan = 0;
audio_adp_codec_get_input_vol(&vol_plan);
audio_adp_ao_setvolume(res->ao_dev, res->ao_chn, vol_plan);
if (ret != XMEDIA_SUCCESS)
{
AUDIO_ERR("%s: XMEDIA_API_AO_SetVolume dev(%d) chn(%d) failed(0x%x)\n", __FUNCTION__, res->ao_dev, res->ao_chn, ret);
}
printf("vol_plan = %d\n", vol_plan);
audio_adp_ao_getvolume(res->ao_dev, res->ao_chn, &vol_plan);
printf("audio_adp_ao_getvolume vol_plan = %d\n", vol_plan);
vol_plan = 0; //-81~18Db 最好设为0 0往上就是100%+
audio_adp_ao_setvolume(res->ao_dev, res->ao_chn, vol_plan);
usleep(10 * 1000);
play_audio_file(START_UP_PCM_FILE);
start_qrcode(&ai_media_configs);
#if MOTO_ENABLE == 1
motor_init(250);
#endif
start_scene(res);
#if USE_XY == 0
notify_other_threads(is_sd_card_inserted("/dev/mmcblk0p1") ? STATE_INSERTED : STATE_REMOVED);
usleep(5 * 1000);
// pthread_attr_t attr;
int result;
// 初始化属性对象
// result = pthread_attr_init(&attr);
// size_t stack_size = 32 * 1024;
// pthread_attr_setstacksize(&attr, stack_size);
pthread_t pthid;
pthread_create(&pthid, NULL, thread_SD_status_proc, NULL);
pthread_detach(pthid);
// pthread_attr_destroy(&attr);
#endif
pthread_t pthid_osd_time;
pthread_create(&pthid_osd_time, NULL, thread_osd_time_proc, res);
pthread_detach(pthid_osd_time);
usleep(5 * 1000);
#if USE_XY == 1
StartXy(res->ai_chn, res->ai_dev, res->ao_chn, res->ao_dev);
#else
webrtc_start();
usleep(5 * 1000);
// printf("open test_adc.text file\n");
#endif
// printf("into 123\n");
while (1)
{
if (g_isExit > 0)
{
#if DEMO_BUTTOM_TEST == 1
// NotifyCmdToThread(moto_stepmsg, 'k');
// moto_stepmsg->runing = false;
// zn_set_signal(moto_stepmsg->psync);
// usleep(500 * 1000);
// if (moto_stepmsg->psync)free(moto_stepmsg->psync);
// if(moto_stepmsg)free(moto_stepmsg);
#endif
break;
}
else
{
// printf("get val = %d\n", g_adc_value);
// IR_auto_light_operations(50, 2);
// NotifyCmdToThread(moto_stepmsg, 'e');
}
#if DEMO_BUTTOM_TEST == 1
DEMO_PRINT("please input q to quit!\n");
scanf("%c", &cmd);
switch (cmd)
{
case 'q':
usleep(500 * 1000);
motor_deinit();
// moto_stepmsg->runing = false;
// zn_set_signal(moto_stepmsg->psync);
// if (moto_stepmsg->psync)free(moto_stepmsg->psync);
// if(moto_stepmsg)free(moto_stepmsg);
g_isExit = 1;
break;
#if MOTO_ENABLE == 1
case 'e':
printf("|||get adc value|||\n");
NotifyCmdToThread(moto_stepmsg, 'e');
printf("[%d][%s]adc_value = %d\n", __LINE__, __func__, g_adc_value);
break;
case 'f':
printf("|||demo_video put g|||\n");
printf("|||start Color To Grey|||\n");
Color_To_Grey(res->venc_chn[0], 1);
break;
case 'w':
printf("put w\n");
stepmotor_ptz_control(moto_stepmsg, 0, 1);
break;
case 's':
printf("put s\n");
stepmotor_ptz_control(moto_stepmsg, 0, -1);
break;
case 'a':
printf("put a\n");
stepmotor_ptz_control(moto_stepmsg, 1, 0);
break;
case 'd':
printf("put d\n");
stepmotor_ptz_control(moto_stepmsg, -1, 0);
break;
#endif
// 翻转
case 'y':
system("i2c_write 0 0x6e 0x17 0 1 1");
printf("y put\n");
break;
case 'h':
system("i2c_write 0 0x6e 0x17 3 1 1");
printf("h put\n");
break;
case 'g':
system("i2c_write 0 0x6e 0x17 1 1 1");
printf("g put\n");
break;
case 'j':
system("i2c_write 0 0x6e 0x17 2 1 1");
printf("j put\n");
break;
#if LED_IR_ENABLE == 1
case 'k':
// NotifyCmdToThread(moto_stepmsg, 'k');
LED_operations(0);
printf("k close led\n");
break;
case 'i':
// NotifyCmdToThread(moto_stepmsg, 'i');
LED_operations(1);
printf("i open led\n");
break;
case 'o':
// NotifyCmdToThread(moto_stepmsg, 'o');
LED_IR_operations(1);
printf("o open ir led\n");
break;
case 'l':
// NotifyCmdToThread(moto_stepmsg, 'l');
LED_IR_operations(0);
printf("l close ir led\n");
break;
case 'v':
IR_auto_light_operations(50, 0); // 开启红外自动模式
break;
case 'b':
IR_auto_light_operations(50, 1); // 开启红外自动模式
break;
case 'n':
IR_auto_light_operations(50, 2); // 开启红外自动模式
break;
#endif
// case '1':
// printf("start_scene\n");
// start_scene(res);
// printf("end_scene\n");
// break;
// case '2':
// printf("pause_scene\n");
// pause_scene(res);
// printf("end_scene\n");
// break;
// case '3':
// printf("start_scene\n");
// end_scene(res);
// printf("start_scene\n");
// break;
case 'z':
printf("start_setroi z\n");
SetRoi(0);
printf("end_setroi\n");
break;
case 'x':
printf("start_setroi x\n");
SetRoi(1);
printf("end_setroi\n");
break;
case 'c':
printf("start_setroi c\n");
SetRoi(2);
printf("end_setroi\n");
break;
default:
break;
}
usleep(200 * 1000);
#else
usleep(200 * 1000);
// NotifyCmdToThread(moto_stepmsg, 'h');
#endif
}
printf("exit this sample!\n");
#if MOTO_ENABLE == 1
motor_deinit();
printf("motor_deinit!!!!\n");
#endif
#if USE_XY == 0
webrtc_stop();
printf("webrtc_stop success!!!!\n");
#endif
// if(res->scene_auto) {
// scene_deinit();
// printf("scene_deinit success!!!!\n");
// }
ircut_deinit();
printf("ircut_deinit success!!!!\n");
demo_vi_stop_dump_raw_thread();
printf("demo_vi_stop_dump_raw_thread success!!!!\n");
#ifdef DEMO_NPU_SUPPORT
demo_aisdk_stop();
#endif
pipeline_stop(res);
printf("pipeline_stop success!!!!\n");
pipeline_disconnect(res);
printf("pipeline_disconnect success!!!!\n");
audio_deinit(res);
printf("audio_deinit success!!!!\n");
venc_deinit(res);
printf("venc_deinit success!!!!\n");
vpss_deinit(res);
printf("vpss_deinit success!!!!\n");
isp_deinit(res);
printf("isp_deinit success!!!!\n");
vi_deinit(res);
printf("vi_deinit success!!!!\n");
mipi_deinit(res);
printf("mipi_deinit success!!!!\n");
sys_deinit(res);
printf("sys_deinit success!!!!\n");
DeInitQrQue();
printf("DeInitQrQue success!!!!\n");
free(res);
printf("exit success!!!!\n");
return 0;
}
// manwcis
注释一下代码
最新发布