static int sys_set_network(int eth, int dhcp, unsigned int ipaddr, unsigned int gatewayaddr, unsigned int netmaskaddr) { if(eth != ETH0 && eth != ETH0_1) { ERR_PRN("eth %d is invaild\n", eth); return -1; } // char cmd[256] = {0}; // char ip[16] = {0}; // char netmask[16] = {0}; // char gateway[16] = {0}; // struct in_addr addr ; if(dhcp == 0) { SetEthConfigIP(eth, ipaddr, netmaskaddr); SetEthConfigGW(eth, gatewayaddr); } else if(dhcp == 1) { //just eht0 have dhcp if(eth != ETH0) { ERR_PRN("eth %d is invaild\n", eth); return -1; } SetEthDhcp(); } return 0; }
static int WriteData(int s, void *pBuf, int nSize) { int nWriteLen = 0; int nRet = 0; int nCount = 0; while(nWriteLen < nSize) { nRet = send(s, (char *)pBuf + nWriteLen, nSize - nWriteLen, 0); if(nRet < 0) { if((errno == ENOBUFS || errno == 11) && (nCount < 10)) { ERR_PRN("network buffer have been full! errno[%d]:[%s]\n", errno, strerror(errno)); usleep(10000); nCount++; continue; } ERR_PRN("ENOBUFS:[%d] socket:[%d] errno[%d]:[%s]\n", ENOBUFS, s, errno, strerror(errno)); return nRet; } else if(nRet == 0) { ERR_PRN("Send Net Data Error nRet= %d\n", nRet); continue; } nWriteLen += nRet; nCount = 0; } return nWriteLen; }
//eth0 ,eth0:1 //获取实际网口的网络信息 int sys_get_network(int eth, unsigned int *ip, unsigned int *gateway, unsigned int *netmask) { if(eth != ETH0 && eth != ETH0_1) { ERR_PRN("eth %d is invaild\n", eth); return -1; } int dhcp = 0; dhcp = g_network_info.dhcp[eth]; //static ip info if(dhcp == 0) { *ip = g_network_info.dwAddr[eth]; *gateway = g_network_info.dwGateWay[eth]; *netmask = g_network_info.dwNetMask[eth]; return 0; } else if(dhcp == 1) { //just eht0 have dhcp if(eth != ETH0) { ERR_PRN("eth %d is invaild\n", eth); return -1; } *ip = GetIPaddr("eth0"); *netmask = GetNetmask("eth0"); *gateway = GetBroadcast("eth0"); return 0; } return -1; }
static int multicast_list_delete_node(MULTICAST_Output_Server_NODE *node) { if(g_mult_head == NULL || node == NULL) { ERR_PRN("\n"); return -1; } MULTICAST_Output_Server_NODE *temp = NULL; //MULTICAST_Output_Server_NODE *temp2 = NULL; mid_mutex_lock(g_mult_head->mutex); temp = g_mult_head->first; PRINTF("temp=%p,node=%p\n", temp, node); if(temp == node) { g_mult_head->first = node->next; g_mult_head->num --; } else { while(temp->next != node && temp->next != NULL) { temp = temp->next; } if(temp->next == NULL) { PRINTF("ERROR,can't find the node\n"); temp->next = NULL; } else { temp->next = node->next; g_mult_head->num --; } } if(g_mult_head->num < 0) { ERR_PRN("\n"); } //close the socket // multicast_client_delete(&(node->client[0])); stream_client_close(node->client); //close tc num tc_del_element(node->tc_num); node->tc_num = -1; multicast_node_delete(&node); mid_mutex_unlock(g_mult_head->mutex); multicast_list_print_all(); return 0; }
static MULTICAST_Output_Server_NODE *multicast_list_find_node(stream_output_server_config *config) { if(g_mult_head == NULL) { ERR_PRN("\n"); return NULL; } int ret = 0; MULTICAST_Output_Server_NODE *temp = NULL; mid_mutex_lock(g_mult_head->mutex); temp = g_mult_head->first; while(temp != NULL) { ret = multicast_compare_config(&(temp->config), config); if(ret == 1) { PRINTF("i find the node ,for server %s:%d-%d.\n", config->main_ip, config->video_port, config->audio_port); break; } temp = temp->next; } mid_mutex_unlock(g_mult_head->mutex); if(temp == NULL) { return NULL; } return temp; }
int app_rtsp_server_add(stream_output_server_config *config, stream_output_server_config *newconfig) { if(g_rtsp_shandle == NULL) { PRINTF("\n"); return -1; } if((config->status == S_DEL) || (config->type != TYPE_RTSP)) { ERR_PRN("Error,status=%d,type=%d\n", config->status, config->type); return -1; } //int i = 0; mid_mutex_lock(g_rtsp_shandle->mutex); memcpy(&(g_rtsp_shandle->config), config, sizeof(stream_output_server_config)); g_rtsp_shandle->config.status = S_ACTIVE; g_rtsp_shandle->s_used = ISUSED; app_rtsp_set_active(g_rtsp_shandle->config.status); mid_mutex_unlock(g_rtsp_shandle->mutex); //save to flash app_rtsp_config_fwrite(0); return 0; }
static int multicast_list_add_node(MULTICAST_Output_Server_NODE *node) { if(g_mult_head == NULL || node == NULL) { ERR_PRN("\n"); return -1; } MULTICAST_Output_Server_NODE *temp = NULL; mid_mutex_lock(g_mult_head->mutex); if(g_mult_head->first == NULL) { g_mult_head->first = node; } else { temp = g_mult_head->first; while(temp->next != NULL) { temp = temp->next; } temp->next = node; } g_mult_head->num++; PRINTF("g_mult_head->num = %d\n", g_mult_head->num); mid_mutex_unlock(g_mult_head->mutex); return 0; }
//设置网络信息 if change,ret = 1; static int sys_change_network_info(int eth, int dhcp, unsigned int ip, unsigned int gateway, unsigned int netmask) { if((eth != ETH0 && eth != ETH0_1) || (dhcp != 0 && dhcp != 1)) { ERR_PRN("eth =%d ,dhcp=%d is invaild\n", eth, dhcp); return -1; } int ret = 0; int change = 0; struct in_addr addr1, addr2; // char temp[200]; //memset(temp, 0, sizeof(temp)); memcpy(&addr1, &ip, 4); memcpy(&addr2, &(g_network_info.dwAddr[eth]), 4); if(dhcp == g_network_info.dhcp[eth] && dhcp == 1) { PRINTF("the %d eth network is not change\n", eth); return 0; } ret = CheckIPNetmask(ip, netmask, gateway); if(ret == 0) { PRINTF("Set IP addr error!!!!\n"); return -1; } if(dhcp == 0) { //dhcp == 0 PRINTF("new ip is #%s#,----old=#%s#\n", inet_ntoa(addr1), inet_ntoa(addr2)); if(g_network_info.dwAddr[eth] != ip) { change = 1; g_network_info.dwAddr[eth] = ip; } if(g_network_info.dwGateWay[eth] != gateway) { change = 1; g_network_info.dwGateWay[ETH0] = gateway; g_network_info.dwGateWay[ETH0_1] = gateway; } if(g_network_info.dwNetMask[eth] != netmask) { change = 1; g_network_info.dwNetMask[eth] = netmask; } } if(dhcp != g_network_info.dhcp[eth]) { change = 1; g_network_info.dhcp[eth] = dhcp; } return change; }
//设置串号并保存 int app_set_serialno(char *serialno) { if(serialno == NULL) { ERR_PRN("serial no is NULL\n"); return -1; } PRINTF("serialno=%s\n", serialno); if(strcmp(g_product_info.serialNum, serialno) != 0) { snprintf(g_product_info.serialNum, sizeof(g_product_info.serialNum), "%s", serialno); write_product_info(&g_product_info); PRINTF("change serial NO = [%s]\n", g_product_info.serialNum); return 0; } return 0; }
static int multicast_list_check_full() { if(g_mult_head == NULL) { ERR_PRN("\n"); return -1; } int num = 0; mid_mutex_lock(g_mult_head->mutex); num = multicast_list_get_num(g_mult_head); mid_mutex_unlock(g_mult_head->mutex); if(num >= MULTICAST_MAX_SERVER_NUM) { return 1; } else { return 0; } }
static int multicast_list_get_num(MULTICAST_OUTPUT_SERVER_HEAD *head) { if(head == NULL) { ERR_PRN("\n"); return 0; } int i = 0; MULTICAST_Output_Server_NODE *node = head->first; while(node != NULL) { i++; node = node->next; } if(i != head->num) { PRINTF("Warnning,the node num is not same,%d=%d\n", i, head->num); } head->num = i; return i; }
static void multicast_list_print_all() { if(g_mult_head == NULL) { ERR_PRN("\n"); return ; } MULTICAST_Output_Server_NODE *node = NULL; mid_mutex_lock(g_mult_head->mutex); int i = 0; node = g_mult_head->first; PRINTF("MULT node num=%d\n", g_mult_head->num); while(node != NULL) { PRINTF("the %d server.\n", i); multicast_node_printf(node); node = node->next; i++; } mid_mutex_unlock(g_mult_head->mutex); return ; }
void *recv_client_msg_thread(void *pParams) { PRINTF("pid=%d\n", getpid()); char szData[2048] = {0}; unsigned int nLen; int total_len; int sSocket; int nPos; int index = -1; MsgHead msg_info; client_msg_arg_t *arg = (client_msg_arg_t *)pParams; nPos = arg->pos; index = arg->index; PRINTF("[enter recv_client_msg_thread] index:[%d] pos:[%d]\n", index, nPos); char user_id[16] = {0}; int msg_code = 0; char passkey[64] = {0}; int count = 0; struct timeval timeout ; int ret = 0; if(pParams != NULL) { PRINTF("enter free(pParams)\n"); free(pParams); //free memory pParams = NULL; } sSocket = GETSOCK_NEW(index, nPos); PRINTF("index:[%d] sockfd =%d,pos =%d\n", index, sSocket, nPos); timeout.tv_sec = 3 ; //3 timeout.tv_usec = 0; ret = setsockopt(sSocket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout)); if(ret == -1) { ERR_PRN("setsockopt() Set Send Time Failed\n"); } sem_post(&g_new_tcp_lock[index]); PRINTF("recv_client_msg_thread sem_post!!!!\n"); set_ip_matrix_userid(index, user_id); while(gRunStatus[index]) { memset(szData, 0, sizeof(szData)); if(sSocket <= 0) { goto ExitClientMsg; } total_len = tcp_recv(sSocket, &msg_info, sizeof(msg_info), 0); if(total_len == -1) { ERR_PRN("error:%d,error msg: = %s\n", errno, strerror(errno)); goto ExitClientMsg; } if(ntohs(msg_info.sVer) != 2012) { ERR_PRN(" sver error:%d,error msg: = %s\n", errno, strerror(errno)); goto ExitClientMsg; } total_len = ntohs(msg_info.sLen) - sizeof(msg_info); if(total_len <= 0) { PRINTF("nMsgLen < HEAD_LEN\n"); goto ExitClientMsg; } if(total_len > 0) { nLen = tcp_recv(sSocket, szData, total_len, 0); if(nLen == -1 || nLen < total_len) { ERR_PRN("nLen < nMsgLen -HEAD_LEN\n"); goto ExitClientMsg; } if(parse_cli_xml_msg(index, nPos, szData, &msg_code, passkey, user_id) < 0) { ERR_PRN("parse xml msg failed\n"); //goto ExitClientMsg; } } #if 0 if(process_cli_xml_msg(nPos, msg_code, passkey, user_id) < 0) { PRINTF("process xml msg failed\n"); //goto ExitClientMsg; } #endif //PRINTF( "Switch End!\n"); } ExitClientMsg: //cli_pthread_id[nPos] = 0; PRINTF("Exit Client Msg thread:%d nPos = %d sSocket = %d\n", pthread_self(), nPos, sSocket); if(sSocket == GETSOCK_NEW(index, nPos)) { PRINTF("Exit Client Msg index:[%d] nPos = %d sSocket = %d\n", index, nPos, sSocket); SETCLIUSED_NEW(index, nPos, FALSE); SET_SEND_AUDIO_NEW(index, nPos, FALSE); SETCLILOGIN_NEW(index, nPos, FALSE); SETLOWRATEFLAG_NEW(index, nPos, STOP); SET_SEND_VIDEO_NEW(index, nPos, FALSE); SET_PARSE_LOW_RATE_FLAG(index, nPos, INVALID_SOCKET); SET_FIX_RESOLUTION_FLAG(index, nPos, FALSE); //IISCloseLowRate_new(); set_heart_count(index, nPos, FALSE); close(sSocket); SETSOCK_NEW(index, nPos, INVALID_SOCKET); #ifdef SUPPORT_IP_MATRIX if(get_audio_lock_resolution(index) > 0 && (GET_PASSKEY_FLAG(index, nPos) == 1)) { cut_audio_lock_resolution(index); } if(get_video_lock_resolution(index) > 0 && (GET_PASSKEY_FLAG(index, nPos) == 1)) { cut_video_lock_resolution(index); } if(get_ipmatrix_lock_resolution(index) > 0 && (GET_PASSKEY_FLAG(index, nPos) == 1)) { cut_ipmatrix_lock_resolution(index); } SET_PASSKEY_FLAG(index, nPos, 0); #endif } else { int cli ; for(cli = 0; cli < MAX_CLIENT; cli++) { PRINTF("index:[%d] socket = %d, blogin=%d,bused=%d,sendAudioFlag=%d\n", index, g_client_para[index].cliDATA[cli].sSocket, g_client_para[index].cliDATA[cli].bLogIn, g_client_para[index].cliDATA[cli].bUsed, g_client_para[index].cliDATA[cli].sendAudioFlag); } PRINTF("index:[%d] socket =%d,pos=%d,s=%d\n", index, sSocket, nPos, GETSOCK_NEW(index, nPos)); } pthread_detach(pthread_self()); pthread_exit(NULL); }
int MMP_set_sysparam(int input, MMPSysParam *info, int mmp) { if(input < 0 || input > SIGNAL_INPUT_MAX) { ERR_PRN("input=%d is failed.\n", input); return -1; } int ret = -1; int change = 0; int mac_change = 0; int eth = ETH0; // int dhcp = 0; //mmp need dhcp = 0 int mp_status = get_mp_status(); Enc2000_Sys net_info; int len = 0; if(IS_MP_STATUS == mp_status) { if(mmp == MAIN_MMP) { eth = ETH0; } else if(mmp == SECOND_MMP) { eth = ETH0_1; } } else { if(MAIN_MMP == mmp) { eth = ETH0; } else if(SECOND_MMP == mmp) { eth = ETH0_1; } } app_get_network(&net_info, &len); if(eth == ETH0) { if(info->dwAddr == net_info.eth1.dwAddr) { PRINTF("info->dwAddr == net_info.eth1.dwAddr\n"); return 0; } } else if(eth == ETH0_1) { if(info->dwAddr == net_info.eth0.dwAddr) { PRINTF("info->dwAddr == net_info.eth0.dwAddr\n"); return 0; } } change = sys_change_network_info(eth, 0, info->dwAddr, info->dwGateWay, info->dwNetMask); mac_change = sys_change_mac(eth, info->szMacAddr); PRINTF("eth=%d.change=%d \n\n", eth, change); if(change == 1 || mac_change == 1) { PRINTF("the network is change=%d \n", change); // write_network_info(0, &g_network_info); ret = write_network_info(); } PRINTF(".ret=%d \n\n", ret); return ret; }
/*update program*/ int update_program(int sSocket, char *data, int len) { unsigned long filesize; unsigned char *p; unsigned long nLen; unsigned char temp[20]; int ret; FILE *fp = NULL; p = NULL; p = malloc(8 * 1024); PRINTF("The File Updata Buffer Is 64KB!\n"); if(!p) { ERR_PRN("Malloc 8KB Buffer Failed!\n"); } else { PRINTF("The Buffer Addr 0x%x\n", (unsigned int)p); } if((fp = fopen("/update.tgz", "w+")) == NULL) { ERR_PRN("open %s error \n", "update.tgz"); return -1; } PRINTF("szData:%x, %x, %x, %x, %x, %x,%x\n", data[0], data[1], data[2], data[HEAD_LEN], data[HEAD_LEN + 1], data[HEAD_LEN + 2], data[HEAD_LEN + 3]); filesize = ((unsigned char)data[HEAD_LEN]) | ((unsigned char)data[HEAD_LEN + 1]) << 8 | ((unsigned char)data[HEAD_LEN + 2]) << 16 | ((unsigned char)data[HEAD_LEN + 3]) << 24; PRINTF("Updata file size = 0x%x! \n", (unsigned int)filesize); while(filesize) { nLen = recv(sSocket, p, 8 * 1024, 0); PRINTF("recv Updata File 0x%x Bytes!\n", (unsigned int)nLen); if(nLen <= 0) { free(p); fclose(fp); p = NULL; return -1; } ret = fwrite(p, 1, nLen, fp); if(ret < 0) { ERR_PRN("product update faith!\n"); free(p); fclose(fp); p = NULL; PackHeaderMSG((BYTE *)temp, MSG_UpdataFile_FAILS, HEAD_LEN); WriteData(sSocket, temp, HEAD_LEN); return -1; } PRINTF("write data ...........................:0x%x\n", (unsigned int)filesize); filesize = filesize - nLen; } PRINTF("recv finish......................\n"); free(p); fclose(fp); ret = updatesystem("/update.tgz"); if(ret == 0) { PackHeaderMSG((BYTE *)temp, MSG_UpdataFile_SUCC, HEAD_LEN); } else { PackHeaderMSG((BYTE *)temp, MSG_UpdataFile_FAILS, HEAD_LEN); } WriteData(sSocket, temp, HEAD_LEN); system("sync"); sleep(5); /*重启*/ PRINTF("----------------reboot----------\n"); system("reboot -f"); return 0; }
Void app_web_set_mp_layout(UInt32 layout, UInt32 win1, UInt32 win2) { UInt32 devId = 0; Int32 ret = 0; SwMsLink_CreateParams *swMsCreateArgs = &(gEnc2000.swmsLink[0].create_params); SwMsLink_LayoutPrm *layoutInfo; SwMsLink_LayoutWinInfo *winInfo, *winInfo2; UInt32 outWidth, outHeight, widthAlign, heightAlign; UInt32 outputfps; // UInt32 old_layout = get_mp_layout(); PRINTF("layout=%d\n", layout); getoutsize(swMsCreateArgs->maxOutRes, &outWidth, &outHeight); widthAlign = 8; heightAlign = 1; if(devId > 1) { devId = 0; } layoutInfo = &swMsCreateArgs->layoutPrm; outputfps = layoutInfo->outputFPS; memset(layoutInfo, 0, sizeof(*layoutInfo)); layoutInfo->onlyCh2WinMapChanged = FALSE; layoutInfo->outputFPS = outputfps; layoutInfo->numWin = 2; PRINTF("win1=%d,win2=%d\n", win1, win2); if((win1 < SIGNAL_INPUT_1 || win1 > SIGNAL_INPUT_2) || (win2 < SIGNAL_INPUT_1 || win2 > SIGNAL_INPUT_2) || (win2 == win1)) { ERR_PRN("WARNING:win1 =%d|| win2=%d\n", win1, win2); return ; } switch(layout) { case MP_LAYOUT_1 : { PRINTF("---MP_LAYOUT_1---\n"); winInfo = &layoutInfo->winInfo[0]; winInfo->width = SystemUtils_align(outWidth / 3, widthAlign); winInfo->height = SystemUtils_align(outHeight / 3, heightAlign); winInfo->startX = 0; winInfo->startY = 0; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[1]; winInfo2->width = SystemUtils_align(outWidth * 2 / 3, widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = winInfo->width; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } case MP_LAYOUT_2 : { PRINTF("---MP_LAYOUT_2---\n"); winInfo = &layoutInfo->winInfo[0]; winInfo->width = SystemUtils_align(outWidth / 2, widthAlign); winInfo->height = SystemUtils_align(outHeight, heightAlign); winInfo->startX = 0; winInfo->startY = 0; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[1]; winInfo2->width = SystemUtils_align(outWidth / 2, widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = winInfo->width; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } case MP_LAYOUT_3: { PRINTF("---MP_LAYOUT_3---\n"); winInfo = &layoutInfo->winInfo[1]; winInfo->width = SystemUtils_align(outWidth / 3, widthAlign); winInfo->height = SystemUtils_align(outHeight / 3, heightAlign); winInfo->startX = 0; winInfo->startY = 0; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[0]; winInfo2->width = SystemUtils_align(outWidth, widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = 0; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } case MP_LAYOUT_4: { PRINTF("---MP_LAYOUT_4---\n"); winInfo = &layoutInfo->winInfo[1]; winInfo->width = SystemUtils_align(outWidth / 3, widthAlign); winInfo->height = SystemUtils_align(outHeight / 3, heightAlign); winInfo->startX = 0; winInfo->startY = outHeight - winInfo->height; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[0]; winInfo2->width = SystemUtils_align(outWidth, widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = 0; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } case MP_LAYOUT_5: { PRINTF("---MP_LAYOUT_5---\n"); winInfo = &layoutInfo->winInfo[1]; winInfo->width = SystemUtils_align((outWidth) / 3, widthAlign); winInfo->height = SystemUtils_align(outHeight / 3, heightAlign); winInfo->startX = outWidth - winInfo->width; winInfo->startY = 0; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[0]; winInfo2->width = SystemUtils_align((outWidth), widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = 0; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } case MP_LAYOUT_6: { PRINTF("---MP_LAYOUT_6---\n"); winInfo = &layoutInfo->winInfo[1]; winInfo->width = SystemUtils_align((outWidth) / 3, widthAlign); winInfo->height = SystemUtils_align(outHeight / 3, heightAlign); winInfo->startX = outWidth - winInfo->width; winInfo->startY = outHeight - winInfo->height; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[0]; winInfo2->width = SystemUtils_align((outWidth), widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = 0; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } default: PRINTF("---MP_LAYOUT_2---\n"); winInfo = &layoutInfo->winInfo[0]; winInfo->width = SystemUtils_align(outWidth / 2, widthAlign); winInfo->height = SystemUtils_align(outHeight, heightAlign); winInfo->startX = 0; winInfo->startY = 0; winInfo->bypass = FALSE; winInfo->channelNum = win1; winInfo2 = &layoutInfo->winInfo[1]; winInfo2->width = SystemUtils_align(outWidth / 2, widthAlign); winInfo2->height = SystemUtils_align(outHeight, heightAlign); winInfo2->startX = winInfo->width; winInfo2->startY = 0; winInfo2->bypass = FALSE; winInfo2->channelNum = win2; break; } app_set_swap_layout(layout, win1, win2); ret = swms_set_layout(gEnc2000.swmsLink[0].link_id, layoutInfo); set_mp_layout(layout); PRINTF("ret=%d\n", ret); }
int read_mp_config(int *mp_status) { char temp[64] = {0}; int ret = 0 ; int layout = 1; int i = 0; const char config_file[64] = MP_CONFIG; // int input=SIGNAL_INPUT_1; int audio_input = SIGNAL_INPUT_1; if(mp_status == NULL) { return -1; } ret = ConfigGetKey((char *)config_file, "MP", "mp", temp); if(ret != 0) { ERR_PRN("Failed to Get mp \n"); return -1; } *mp_status = atoi(temp); ret = ConfigGetKey((char *)config_file, "MP", "audio_input", temp); if(ret != 0) { ERR_PRN("Failed to Get audio_input \n"); return -1; } audio_input = atoi(temp); input_set_audio_input(audio_input); ret = ConfigGetKey((char *)config_file, "MP", "layout", temp); if(ret != 0) { ERR_PRN("Failed to Get layout \n"); return -1; } layout = atoi(temp); set_mp_layout(layout); for(i = MP_LAYOUT_1; i < MP_LAYOUT_MAX; i++) { char title[16] = {0}; int win1 = SIGNAL_INPUT_1, win2 = SIGNAL_INPUT_1; sprintf(title, "layout=%d", i); ret = ConfigGetKey((char *)config_file, title, "win1", temp); if(ret != 0) { ERR_PRN("Failed to Get win1 \n"); return -1; } win1 = atoi(temp); ret = ConfigGetKey((char *)config_file, title, "win2", temp); if(ret != 0) { ERR_PRN("Failed to Get win2 \n"); return -1; } win2 = atoi(temp); app_set_swap_layout(i, win1, win2); PRINTF("layout_%d:win1=%d,win2=%d\n", i, win1, win2); } PRINTF("mp_status=%d,layout=%d,audio_input=%d\n", *mp_status, layout, audio_input); return 0; }
void *open_new_tcp_task(void *arg) { PRINTF("open_new_tcp_task is start\n"); int index = *(int *)arg; int serv_sockfd = -1, cli_sockfd; struct sockaddr_in serv_addr, cli_addr; int file_flag = -1; int len = 0; int opt = 1; int ipos = 0; int clientsocket = -1; int ret = 0; int ipaddr; PRINTF("open_new_tcp_task index:[%d]\n", index); sem_init((sem_t *)&g_new_tcp_lock[index], 0, 0); int eth = index; char ip[16] = {0}; InitClientData_new(index); ipaddr = get_local_ip("eth1", ip); PRINTF("open_new_tcp_task index:[%d] ipaddr:[%x]\n", index, ipaddr); RECREATE_TCP_SOCK: bzero(&serv_addr, sizeof(struct sockaddr_in)); serv_addr.sin_family = AF_INET; serv_addr.sin_port = htons(NEW_TCP_SOCK_PORT + index); serv_addr.sin_addr.s_addr = ipaddr; serv_sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(serv_sockfd < 0) { ERR_PRN("ListenTask create error:%d,error msg: = %s\n", errno, strerror(errno)); gRunStatus[index] = 0; return NULL; } setsockopt(serv_sockfd, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)); if(bind(serv_sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) < 0) { ERR_PRN("bind terror:%d,error msg: = %s\n", errno, strerror(errno)); gRunStatus[index] = 0; return NULL; } if(listen(serv_sockfd, 10) < 0) { ERR_PRN("listen error:%d,error msg: = %s", errno, strerror(errno)); gRunStatus[index] = 0; return NULL; } #if 0 if((file_flag = fcntl(serv_sockfd, F_GETFL, 0)) == -1) { ERR_PRN("fcntl F_GETFL error:%d,error msg: = %s\n", errno, strerror(errno)); //gblSetQuit(); return; } if(fcntl(serv_sockfd, F_SETFL, file_flag | O_NONBLOCK) == -1) { ERR_PRN("fcntl F_SETFL error:%d,error msg: = %s\n", errno, strerror(errno)); //gblSetQuit(); return; } #endif PRINTF("sockfd=%d\n", serv_sockfd); while(gRunStatus[index]) { memset(&cli_addr, 0, sizeof(struct sockaddr_in)); len = sizeof(struct sockaddr_in); cli_sockfd = accept(serv_sockfd , (void *)&cli_addr, &len); if(cli_sockfd > 0) { PRINTF("serv_sockfd=%d,cli_sockfd=%d\n", serv_sockfd, cli_sockfd); create_signal_cli_thread(index, cli_sockfd, &cli_addr); PRINTF("sem_wait() semphone inval!!!\n"); } else { if(errno == ECONNABORTED || errno == EAGAIN) { //软件原因中断 usleep(100000); continue; } usleep(3000000); } } for(ipos = 0; ipos < MAX_CLIENT_NUM; ipos++) { if(cli_pthread_id[index][ipos]) { clientsocket = GETSOCK_NEW(index, ipos); if(clientsocket != INVALID_SOCKET) { close(clientsocket); SETSOCK_NEW(index, ipos, INVALID_SOCKET); } if(pthread_join(cli_pthread_id[index][ipos], &ret) == 0) { if(ret == THREAD_FAILURE) { ERR_PRN("drawtimethread ret == THREAD_FAILURE \n"); } } } } }
static int app_rtsp_config_fwrite(int reset) { if(g_rtsp_shandle == NULL) { ERR_PRN("\n"); return -1; } // int total = 0; int ret = 0; //int value = 0; // int i = 0; char bak_name[512] = {0}; // char section[256] = {0}; char cmd[512] = {0}; int value = 0; int used = 0; sprintf(bak_name, "%s.bak", RTSP_SERVER_CONFIG_INI); stream_output_server_config config ; mid_mutex_lock(g_rtsp_shandle->mutex); config = g_rtsp_shandle->config; used = g_rtsp_shandle->s_used; mid_mutex_unlock(g_rtsp_shandle->mutex); /*写接口到bak文件*/ value = config.tc_flag; ret = app_ini_write_int(bak_name, "rtsp", "tc", value); if(ret == -1) { ERR_PRN("\n"); return -1; } // value = config.active; // ret = app_ini_write_int(bak_name, "rtsp", "active", value); // if(ret == -1) { // ERR_PRN("\n"); // return -1; // } value = config.tos; ret = app_ini_write_int(bak_name, "rtsp", "tos", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.ttl; ret = app_ini_write_int(bak_name, "rtsp", "ttl", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.mtu; ret = app_ini_write_int(bak_name, "rtsp", "mtu", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.audio_port; ret = app_ini_write_int(bak_name, "rtsp", "audio_port", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.video_port; ret = app_ini_write_int(bak_name, "rtsp", "video_port", value); if(ret == -1) { ERR_PRN("\n"); return -1; } //ip ret = app_ini_write_string(bak_name, "rtsp", "main_ip", config.main_ip); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.type; ret = app_ini_write_int(bak_name, "rtsp", "type", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.status; ret = app_ini_write_int(bak_name, "rtsp", "status", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = used; if(reset == 1) { value = 0; } ret = app_ini_write_int(bak_name, "rtsp", "used", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config.tc_rate; ret = app_ini_write_int(bak_name, "rtsp", "tc_rate", value); if(ret == -1) { ERR_PRN("\n"); return -1; } /*拷贝bak文件到ini*/ if(ret != -1) { sprintf(cmd, "cp -rf %s %s;rm -rf %s", bak_name, RTSP_SERVER_CONFIG_INI, bak_name); system(cmd); PRINTF("i will run cmd:%s\n", cmd); } /*拷贝bak文件到ini*/ return ret; }
void app_mp_video_control() { if(g_video_control_handle == NULL) { ERR_PRN("g_video_control_handle is not init\n"); return ; } int channel = 0; int enc_chid = 0; VideoEnodeInfo *info = NULL; int scale, outwidth, outheight, width, height, input, high_stream; input = high_stream = outwidth = outheight = scale = width = height = -1; for(channel = CHANNEL_INPUT_MP; channel < MAX_CHANNEL; channel++) { channel_get_input_info(channel, &input, &high_stream); PRINTF("channel = %d \n", channel); mid_mutex_lock(g_video_control_handle->mutex[channel]); info = &(g_video_control_handle->info[channel]); enc_chid = channel_get_enc_chid(channel); if(enc_chid < 0) { ERR_PRN("enc_chid = %d is invaid\n", enc_chid); mid_mutex_unlock(g_video_control_handle->mutex[channel]); return ; } PRINTF("info->scbr=%d,fps=%d,bitrate=%d\n", info->scbr, info->framerate, info->bitrate); int framerate = check_video_fps(input, (info->framerate)); if(info->scbr == 0) { PRINTF("WARNING ... \n"); enc_set_fps(gEnc2000.encLink.link_id, enc_chid, (framerate), (info->quality) * 100 * 1100); } else { enc_set_fps(gEnc2000.encLink.link_id, enc_chid, (framerate) , (info->bitrate) * 1100); } //set gop enc_set_interval(gEnc2000.encLink.link_id, enc_chid, (info->gop)); mid_mutex_unlock(g_video_control_handle->mutex[channel]); //--------- outwidth = outheight = scale = width = height = -1; app_get_scale_status(channel, &scale, &outwidth, &outheight); if(scale == LOCK_SCALE) { capture_get_input_hw(input, &width, &height); if(height == 540 && width == 1920) { height = height * 2; } PRINTF("the %d channel is lock scale ,scale widht=%d,hight=%d\n", channel, outwidth, outheight); mp_set_resolution(input, high_stream, outwidth, outheight, width, height); } else { if(CHANNEL_INPUT_MP == channel) { mp_set_resolution(input, high_stream, 1920, 1080, 1920, 1080); } else { mp_set_resolution(input, high_stream, 352, 288, 1920, 1080); } PRINTF("the %d channle is not lock scale\n", channel); } } return ; }
int create_signal_cli_thread(int index, int sockfd, struct sockaddr_in *cli_addr) { char newipconnect[20] = {0}; //打印客户端ip// inet_ntop(AF_INET, (void *) & (cli_addr->sin_addr), newipconnect, 16); PRINTF("sockfd =%d ip =%s\n", sockfd, newipconnect); int nPos = 0; int nLen = 0; int cli_num = 0; char send_buf[256] = {0}; char user_id[8] = {0}; char dtype[16] = {0}; unsigned int cur_time = 0; GetDeviceType(dtype); nPos = GetNullClientData_new(index); cli_num = read_client_num(index); PRINTF("GetNullClientData_new[%d] = %d\n", index, nPos); nLen = sizeof(struct sockaddr_in); if(-1 == nPos || cli_num >= 6) { //需要告警上报 package_head_msg(send_buf, 30087, dtype, "0", user_id); tcp_send_data(sockfd, send_buf); ERR_PRN("ERROR: max client error\n"); close(sockfd); sockfd = -1; } else { int nSize = 0; int result; client_msg_arg_t *arg = malloc(sizeof(client_msg_arg_t)); /* set client used */ PRINTF("index : [%d]pos =%d,sockfd =%d\n", index, nPos, sockfd); SETCLIUSED_NEW(index, nPos, TRUE); SETCLILOGIN_NEW(index, nPos, TRUE); SETSOCK_NEW(index, nPos, sockfd); cur_time = getCurrentTime(); SETCONNECTTIME_NEW(index, nPos, cur_time); nSize = 1; if((setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (void *)&nSize, sizeof(nSize))) == -1) { perror("setsockopt failed"); } nSize = 0; nLen = sizeof(nLen); result = getsockopt(sockfd, SOL_SOCKET, SO_SNDBUF, &nSize , &nLen); if(result) { ERR_PRN("getsockopt() errno:%d socket:%d result:%d\n", errno, sockfd, result); } nSize = 1; PRINTF("Clent:%s connected,nPos:%d socket:%d!\n", newipconnect, nPos, sockfd); //Create ClientMsg task! arg->pos = nPos; arg->index = index; result = pthread_create(&cli_pthread_id[index][nPos], NULL, (void *)recv_client_msg_thread, (void *)arg); if(result) { close(sockfd); sockfd = -1; ERR_PRN("creat pthread ClientMsg error = %d!\n" , errno); return 0; } sem_wait(&g_new_tcp_lock[index]); } }
int write_mp_config() { char temp[64] = {0}; int ret = 0 ; int i = 0 ; int input = SIGNAL_INPUT_MP; int layout = 1; int audio_input = SIGNAL_INPUT_1; const char config_file[64] = MP_CONFIG ; int mp_status = get_mp_status(); sprintf(temp, "%d", mp_status); ret = ConfigSetKey((char *)config_file, "MP", "mp", temp); if(ret != 0) { ERR_PRN("Failed to Set mp \n"); return -1; } input_get_audio_input(input, &audio_input); sprintf(temp, "%d", audio_input); ret = ConfigSetKey((char *)config_file, "MP", "audio_input", temp); if(ret != 0) { ERR_PRN("Failed to Set audio_input \n"); return -1; } layout = get_mp_layout(); sprintf(temp, "%d", layout); ret = ConfigSetKey((char *)config_file, "MP", "layout", temp); if(ret != 0) { ERR_PRN("Failed to Set layout \n"); return -1; } for(i = MP_LAYOUT_1; i < MP_LAYOUT_MAX; i++) { char title[16] = {0}; int win1 = SIGNAL_INPUT_1, win2 = SIGNAL_INPUT_2; app_get_swap_layout(i, &win1, &win2); sprintf(title, "layout=%d", i); sprintf(temp, "%d", win1); ret = ConfigSetKey((char *)config_file, title, "win1", temp); if(ret != 0) { ERR_PRN("Failed to Set win1 \n"); return -1; } sprintf(temp, "%d", win2); ret = ConfigSetKey((char *)config_file, title, "win2", temp); if(ret != 0) { ERR_PRN("Failed to Set win2 \n"); return -1; } } PRINTF("mp_status=%d,layout=%d,audio_input=%d\n", mp_status, layout, audio_input); return ret; }
static int app_rtsp_global_config_fwrite(rtsp_server_config *config) { if(config == NULL) { ERR_PRN("\n"); return -1; } int ret = 0; char bak_name[512] = {0}; char cmd[512] = {0}; int value = 0; // int used = 0; sprintf(bak_name, "%s.bak", RTSP_SERVER_GLOBAL_CONFIG_INI); value = config->s_port; ret = app_ini_write_int(bak_name, "rtsp_config", "s_port", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config->active; ret = app_ini_write_int(bak_name, "rtsp_config", "active", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config->s_mtu; ret = app_ini_write_int(bak_name, "rtsp_config", "s_mtu", value); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config->mult_flag; ret = app_ini_write_int(bak_name, "rtsp_config", "mult_flag", value); if(ret == -1) { ERR_PRN("\n"); return -1; } ret = app_ini_write_string(bak_name, "rtsp_config", "mult_ip", config->mult_ip); if(ret == -1) { ERR_PRN("\n"); return -1; } value = config->mult_port; ret = app_ini_write_int(bak_name, "rtsp_config", "mult_port", value); if(ret == -1) { ERR_PRN("\n"); return -1; } /*拷贝bak文件到ini*/ sprintf(cmd, "cp -rf %s %s;rm -rf %s", bak_name, RTSP_SERVER_GLOBAL_CONFIG_INI, bak_name); system(cmd); PRINTF("i will run cmd:%s\n", cmd); return 0; }