openipc是github上一个基于HI35XX系列开发的openwrt系统。
openipc里面最重要的一个应用是minihttp,他承载了这个系统的灵魂——推送视频流服务。
但是根据群里面的小伙伴反应,这个服务容易卡死,而且是随机出现的。为了研究其原因,首先需要分析这个应用。
(一)SDK版本描述
openipc是根据官方SDK开发的。
openipc源码地址:openipc源码地址
说到海思官方的SDK,可以在这里找到:海思官方SDK
里面有个明显的分水岭,后缀C01跳跃到后缀C05,这其实是从linux转移到liteos,openipc是基于一个比较难找的linux SDK版本,即Hi3518E_V200R001C01SPC041.rar,这个连接下载的是050版本的,但都通用。
openipc视频流、音频流是基于SDK的MPP库,函数都是带有MPI的。可以参考SDK包下的:
01.software\board\document_cn\HiMPP IPC V2.0 媒体处理软件开发参考
群里大神修改后的源码地址:修改后的源码
(二)main程序粗略分析
int main(int argc, char *argv[])
{
chip_id();
isp_version();
if (parse_app_config("./minihttp.ini") != CONFIG_OK)
{
printf("Can't load app config './minihttp.ini'\n");
return EXIT_FAILURE;
}
start_server();
memset(&state, 0, sizeof(struct SDKState));
int s32MainFd;
if (app_config.rtsp_enable)
{
ringmalloc(1920 * 1080);
printf("RTSP server START, listen for client connecting...\n");
PrefsInit();
signal(SIGINT, IntHandl);
s32MainFd = tcp_listen(SERVER_RTSP_PORT_DEFAULT);
if (ScheduleInit() == ERR_FATAL)
{
fprintf(stderr, "Fatal: Can't start scheduler %s, %i \nServer is aborting.\n", __FILE__, __LINE__);
return 0;
}
RTP_port_pool_init(RTP_DEFAULT_PORT);
}
if (start_sdk(&state) == EXIT_FAILURE)
keepRunning = 0; // return EXIT_FAILURE;
// TODO when return EXIT_FAILURE need to deinitialize sdk correctly
if (app_config.night_mode_enable)
start_monitor_light_sensor();
if (app_config.http_post_enable)
start_http_post_send();
if (app_config.rtsp_enable)
{
struct timespec ts = {2, 0};
while (keepRunning)
{
nanosleep(&ts, NULL);
EventLoop(s32MainFd);
}
ringfree();
printf("RTSP server quit!\n");
}
else
{
while (keepRunning)
sleep(1);
}
stop_sdk(&state);
stop_server();
printf("Shutdown main thread\n");
return EXIT_SUCCESS;
}
1-读取minihttp.ini文件
这个文件里面是对minihttp的一些设置。
2-start_server()
初始化网络服务并创建【server_thread】线程,以监听socket信息,比如进来的网络连接
3- memset(&