📄 codec_writedevparam.h
字号:
} else if (name=="aud_mode") { sprintf(lineVal, "%d", pParam->AudChnMode); } else { continue; } } else { if (name=="video_horizontal_size") { sprintf(lineVal, "%d", pParam->HResolu); } else if (name=="video_vertical_size") { sprintf(lineVal, "%d", pParam->VResolu); } else if (name=="video_bit_rate") { sprintf(lineVal, "%d", pParam->VidBitRate); } else if (name=="video_vbv_buffer_size") { sprintf(lineVal, "%d", pParam->VBVSize); } else if (name=="vid_video_format") { sprintf(lineVal, "%d", pParam->VidFmt); } else if (name=="mux_mpeg_coding_standard") { sprintf(lineVal, "%d", pParam->VidMpeg); } else if (name=="audio_sampling_rate") { sprintf(lineVal, "%d", pParam->AudSamRate); } else if (name=="audio_bit_rate") { sprintf(lineVal, "%d", pParam->AudBitRate); } else if (name=="audio_channel") { sprintf(lineVal, "%d", pParam->AudChnMode); } else { continue; } } strcat(lineCover, lineVal); strcpy(fileContent[lineCounter-1], lineCover); } if (fclose(file)!=0) printf("Cannot close config file\n"); //write fileContent to file file=fopen(filename,"w"); for(int i=0;i<lineCounter;i++) {// cout<<"write line "<<i<<": "<<fileContent[i]<<endl; fprintf(file,"%s\n",fileContent[i]); } fclose(file); return SUCCESS;}int API_WriteComConfigFile(const char* filename, ComConfigStruct *pParam) { cout<<"++API_WriteComConfigFile()"<<endl; FILE *file = fopen(filename, "r"); // open the config file if (file==NULL) { printf("Cannot find com config file: %s\n",filename); return FAILURE; } string line, name,val; int eq_pos; char lineTemp[8*1024]; char lineCover[8*1024]; char lineVal[MAX_LINE_VAL_LEN]; char netAddr[MAX_NET_ADDR_LEN]; char sPort[10]; char fileContent[MAX_FILE_LINE][8*1024]; int lineCounter=0; // read the file content line by line // fgets() return when encounter enter while (fgets(lineTemp, sizeof(lineTemp), file)!=NULL) { if (lineTemp[strlen(lineTemp)-1]=='\n') lineTemp[strlen(lineTemp)-1] = '\0'; strcpy(fileContent[lineCounter],lineTemp); lineCounter++; // string class: add "using namespace std" and include <string> // member func: swap(),erase(),insert(),clear(),replace()... line.erase(); // clear character string line.insert(0, lineTemp); // insert character string on position index 0 // find function returns the index. If nothing's found, string::npos returned if (line.find_first_not_of(" \t\n\r")==string::npos) continue; // skip ahead if line is empty if (line[0]=='#') continue; // skip ahead if the line is a comment // use line informaton to splits up name and value eq_pos = line.find("="); // check to see if entry is valid, can't find "=" if (eq_pos == string::npos) continue; // get name and value name.assign(line,0,eq_pos); val = line.substr(eq_pos+1); memset(lineCover, 0, sizeof(lineCover)); strcpy(lineCover,name.c_str()); strcat(lineCover,"="); memset(lineVal, 0, sizeof(lineVal)); if (name=="com1_baud_rate") { sprintf(lineVal, "%d", pParam->COM1.BaudRate); } else if (name=="com1_parity_type") { sprintf(lineVal, "%c", pParam->COM1.ParityType); } else if (name=="com1_data_bit") { sprintf(lineVal, "%d", pParam->COM1.DataBitLen); } else if (name=="com1_stop_bit") { sprintf(lineVal, "%d", pParam->COM1.StopBitLen); } else if (name=="com2_baud_rate") { sprintf(lineVal, "%d", pParam->COM2.BaudRate); } else if (name=="com2_parity_type") { sprintf(lineVal, "%c", pParam->COM2.ParityType); } else if (name=="com2_data_bit") { sprintf(lineVal, "%d", pParam->COM2.DataBitLen); } else if (name=="com2_stop_bit") { sprintf(lineVal, "%d", pParam->COM2.StopBitLen); } else if (name=="local_alarm_com") { sprintf(lineVal, "%d", pParam->LocalAlarmCom); } else if (name=="com_remote_address") { strcpy(netAddr, pParam->ComRemoteAddr.sIP); sprintf(sPort, "%d", pParam->ComRemoteAddr.nPort); strcat(netAddr, ":"); strcat(netAddr, sPort); strcpy(lineVal, netAddr); } else { continue; } strcat(lineCover, lineVal); strcpy(fileContent[lineCounter-1], lineCover); } if (fclose(file)!=0) printf("Cannot close config file\n"); //write fileContent to file file=fopen(filename,"w"); for(int i=0;i<lineCounter;i++) {// cout<<"write line "<<i<<": "<<fileContent[i]<<endl; fprintf(file,"%s\n",fileContent[i]); } fclose(file); return SUCCESS;}int CODEC_WriteDevParam (LPVOID pParam) { DevParamStruct *dev_param = (DevParamStruct *)pParam; cout<<"++CODEC_WriteDevParam()"<<endl; int retval; ConfigParamStruct cfg_param; CodecParamStruct codec_param; ComConfigStruct com_cfg; memset(&cfg_param, 0, sizeof(ConfigParamStruct)); memset(&codec_param, 0, sizeof(CodecParamStruct)); memset(&com_cfg, 0, sizeof(ComConfigStruct)); // get config param cfg_param.DevType = dev_param->DevType; cfg_param.DevID = dev_param->DevID; cfg_param.MediaType = dev_param->MediaType; cfg_param.TransProto= dev_param->TransProto; strcpy(cfg_param.local_network_ipaddr, dev_param->local_network_ipaddr); strcpy(cfg_param.local_network_mask, dev_param->local_network_mask); strcpy(cfg_param.local_network_gateway,dev_param->local_network_gateway); cfg_param.my_port = dev_param->my_port; memcpy(&(cfg_param.server_address), (char *)&(dev_param->server_address), sizeof(Net_Addr)); strcpy(cfg_param.control_ipaddr, dev_param->control_ipaddr); cfg_param.doMulticast = dev_param->doMulticast; memcpy(&(cfg_param.multicast_address), (char *)&(dev_param->multicast_address), sizeof(Net_Addr)); cfg_param.doNetSend = dev_param->doNetSend; cfg_param.iSendNum = dev_param->iSendNum; memcpy(&(cfg_param.send_target_list), (char *)&(dev_param->send_target_list), sizeof(cfg_param.send_target_list)); cfg_param.doFileWrite = dev_param->doFileWrite; // write config param to file char *cfgfilename = "./conf1/config.ini"; retval = API_WriteConfigFile(cfgfilename, &cfg_param); if(retval == FAILURE) { printf("write config file error, quiting...\n"); return FAILURE; } // get codec param _MEDIA_TYPE_ media_type; char codecfilename[MAX_FILE_NAME_LEN]; media_type = dev_param->MediaType; if (MEDIA_VES == media_type) { strcpy(codecfilename,"./conf1/codec_es.ini"); } else if (MEDIA_PS == media_type) { strcpy(codecfilename,"./conf1/codec_ps.ini"); } else if (MEDIA_TS == media_type) { strcpy(codecfilename,"./conf1/codec_ts.ini"); } else { printf("CODEC_WriteDevParam(): check media type unmatch\n"); return FAILURE; } codec_param.HResolu = dev_param->HResolu; codec_param.VResolu = dev_param->VResolu; codec_param.VidBitRate = dev_param->VidBitRate; codec_param.VBVSize = dev_param->VBVSize; codec_param.VidFmt = dev_param->VidFmt; codec_param.VidMpeg = dev_param->VidMpeg; codec_param.AudSamRate = dev_param->AudSamRate; codec_param.AudBitRate = dev_param->AudBitRate; codec_param.AudChnMode = dev_param->AudChnMode; // write codec param to file retval = API_WriteCodecFile(codecfilename, &codec_param); if(retval == FAILURE) { printf("write codec file error, quiting...\n"); return FAILURE; } // get com config param com_cfg.COM1.BaudRate = dev_param->com1_baud_rate; com_cfg.COM1.ParityType = dev_param->com1_parity_type; com_cfg.COM1.DataBitLen = dev_param->com1_data_bit; com_cfg.COM1.StopBitLen = dev_param->com1_stop_bit; com_cfg.COM2.BaudRate = dev_param->com2_baud_rate; com_cfg.COM2.ParityType = dev_param->com2_parity_type; com_cfg.COM2.DataBitLen = dev_param->com2_data_bit; com_cfg.COM2.StopBitLen = dev_param->com2_stop_bit; com_cfg.LocalAlarmCom = dev_param->local_alarm_com; memcpy(&(com_cfg.ComRemoteAddr),(char *)&(dev_param->com_remote_address), sizeof(Net_Addr)); // write com config param to file char *comcfgfilename="./conf1/config.ini"; retval = API_WriteComConfigFile(comcfgfilename, &com_cfg); if(retval == FAILURE) { printf("write com config file error, quiting...\n"); return FAILURE; } return SUCCESS;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -