|
1.我在传输视频文件时,总会收到BVCSP_EVENT_DIALOG_CLOSE导致文件传输失败。
2.传输时间间隔怎么写合适,我用公司局域网。- void FileDialog_OnEvent(BVCSP_HDialog hDialog, int iEventCode, BVCSP_Event_DialogCmd *pParam){
- println("FileDialog_OnEvent iEventCode : %d hDialog : %d",iEventCode,hDialog);
- int result = pParam->iResult;
- if(!BVCU_Result_SUCCEEDED(result))
- return;
- if(iEventCode == BVCSP_EVENT_DIALOG_OPEN){
- std::thread fileThread([hDialog](){
- BVCSP_Packet packet;
- memset(&packet,0,sizeof(packet));
- char buffer[801] = {0};
- FILE *fptr = fopen("/sdcard/sdcard/video/Cam_Encoder0.mp4","rb");
- if(fptr == NULL){
- println("do not find this file");
- return;
- }
- int size = 0;
- int tmp = 0;
- while(!feof(fptr)){
- size = fread(buffer,1,800,fptr);
- tmp += size;
- packet.iDataSize = size;
- packet.pData = buffer;
- packet.iDataType = BVCSP_DATA_TYPE_TSP;
- int ret = BVCSP_Dialog_Write(hDialog,&packet);
- while(ret<0)
- {
- ret = BVCSP_Dialog_Write(hDialog,&packet);
- println("BVCSP_Dialog_Write while result %d",ret);
- sleep(2);
- }
- println("BVCSP_Dialog_Write result %d",ret);
- // usleep(30*1000);
- }
- println("send finished");
- println("send size %d",tmp);
- fclose(fptr);
- });
- fileThread.detach();
- }else if(iEventCode == BVCSP_EVENT_DIALOG_UPDATE){
- //iEventCode == BVCSP_EVENT_DIALOG_UPDATE
- }else{
- //close dialog
- println("close dialog");
- }
- }
- BVCU_Result sendFileToNRU() {
- BVCSP_DialogParam dialogParam;
- memset(&dialogParam, 0, sizeof(dialogParam));
- dialogParam.iSize = sizeof(dialogParam);
- dialogParam.hSession = pu.session;
- strcpy(dialogParam.stTarget.szID, "NRU_"); //NRU_
- dialogParam.stTarget.iIndexMajor = BVCU_SUBDEV_INDEXMAJOR_DOWNLOAD;
- dialogParam.iAVStreamDir = BVCU_MEDIADIR_DATASEND;
- time_t t;
- tm * lt;
- time (&t);//获取Unix时间戳。
- lt = localtime (&t);//转为时间结构。
- char path[128] = {0};
- //主动上传时文件文件路径以及文件名称要规范
- //
- sprintf(path,"/PU_%X/Video/20190611/PU_%X_00_%02d%02d%02d_%02d%02d%02d_record.mp4",pu.puid,pu.puid,lt->tm_year + 1900,lt->tm_mon,lt->tm_mday,lt->tm_hour,lt->tm_min,lt->tm_sec);
- dialogParam.stFileTarget.pPathFileName = (char*) path;
- dialogParam.stFileTarget.iStartTime_iOffset = 0;
- FILE *fp = fopen("/sdcard/sdcard/video/Cam_Encoder0.mp4", "rb");
- if (!fp) {
- return BVCU_RESULT_E_BADREQUEST;
- }
- fseek(fp, 0L, SEEK_END);
- int size = ftell(fp);
- fclose(fp);
- dialogParam.stFileTarget.iEndTime_iFileSize = size;
- LOGD(
- "uploadFile pPathFileName=%s,file size=%d", dialogParam.stFileTarget.pPathFileName, size);
- dialogParam.OnEvent = FileDialog_OnEvent;
- dialogParam.afterRecv = Dialog_afterRecv;
- BVCSP_DialogControlParam dialogControlParam;
- memset(&dialogControlParam, 0, sizeof(dialogControlParam));
- dialogControlParam.iTimeOut = 30 * 1000;
- dialogControlParam.iDelayMax = 50000;
- dialogControlParam.iDelayMin = 0;
- dialogControlParam.iDelayVsSmooth = BVCSP_NETWORK_DVSS_MAX;
- BVCU_Result result = BVCSP_Dialog_Open(&pu.file2Dialog, &dialogParam,
- &dialogControlParam);
- LOGD("uploadFile BVCSP_Dialog_Open,BVCU_Result=%d", result);
- return result;
- }
copycode |
|