|
sessionParam.OnCommand = OnCommand;
sessionParam.OnNotify = OnNotify;
sessionParam.OnDialogCmd = OnDialogCommand;(该回调是用来做何操作,我一直是在这里做一些操作的)
以下是上传文件的代码:
bool OpenDialog()
{
if (!g_hSession || g_hDialog) return false;
BVCSP_DialogParam dialogParam;
memset(&dialogParam, 0, sizeof(dialogParam));
dialogParam.iSize = sizeof(dialogParam);
dialogParam.hSession = g_hSession;
strcpy(dialogParam.stTarget.szID, "PU_8953");
dialogParam.stTarget.iIndexMajor = BVCU_SUBDEV_INDEXMAJOR_DOWNLOAD;
dialogParam.iAVStreamDir = BVCU_MEDIADIR_DATASEND;
printf("open lib Dialog_Open 1\n");
dialogParam.stFileTarget.pPathFileName="/sdcard/sdcard/video/0123456789_19700105083843000_000001.MP4";//"/sdcard/zpf_test123.h264";
printf("open lib Dialog_Open 2\n");
dialogParam.stFileTarget.iStartTime_iOffset=0;
printf("open lib Dialog_Open 3\n");
FILE *fp=fopen(dialogParam.stFileTarget.pPathFileName,"rb");
if(!fp) return false;
fseek(fp,0L,SEEK_END);
int size=ftell(fp);
fclose(fp);
printf("open lib Dialog_Open size=%d\n",size);
dialogParam.stFileTarget.iEndTime_iFileSize=size;
printf("open lib Dialog_Open 4\n");
dialogParam.OnEvent = OnDialogEvent;
dialogParam.afterRecv = OnDialogAfterRecv;
BVCSP_DialogControlParam dialogControlParam;
memset(&dialogControlParam, 0, sizeof(dialogControlParam));
dialogControlParam.iTimeOut = 30 * 1000;
dialogControlParam.iDelayMax = 5000;
dialogControlParam.iDelayMin = 500;
dialogControlParam.iDelayVsSmooth = 3;
//hejianfeng add start
void *handle=getHandle();
typedef BVCU_Result (*BVCSP_Dialog_Open)(BVCSP_HDialog* phDialog, BVCSP_DialogParam* pParam, BVCSP_DialogControlParam* pControl);
BVCSP_Dialog_Open Dialog_Open = (BVCSP_Dialog_Open) dlsym(handle, "BVCSP_Dialog_Open");
if(!Dialog_Open)
{
printf("open lib Dialog_Open fail\n");
cout<<dlerror()<<endl;
dlclose(handle);
return false;
}
//hejianfeng add end
BVCU_Result bvReulst=Dialog_Open(&g_hDialog, &dialogParam, &dialogControlParam);
printf("open lib Dialog_Open \n");
cout<<bvReulst<<endl;
return BVCU_Result_SUCCEEDED(bvReulst);
}
void OnDialogEvent(BVCSP_HDialog hDialog, int iEventCode, BVCSP_Event_DialogCmd* pParam)
{
if (!pParam) return;
// BVCSP_DialogInfo dialogInfo;
//
// memset(&dialogInfo, 0, sizeof(dialogInfo));
switch (iEventCode)
{
case BVCSP_EVENT_SESSION_OPEN:
if (pParam->iResult == BVCU_RESULT_S_OK)
{
// BVCSP_GetDialogInfo(g_hDialog, &dialogInfo);
printf("打开设备: 的通道: 会话成功\n");
// FILE *fd=fopen("/sdcard/zpf_test123.h264","rb");
FILE *fd=fopen("/sdcard/sdcard/video/0123456789_19700105083843000_000001.MP4","rb");
if(!fd) return;
const int iDataLen = 100000;
char szData[iDataLen] = { 0 };
void *handle=getHandle();
typedef BVCU_Result (*BVCSP_Dialog_Write)(BVCSP_HDialog hDialog, BVCSP_Packet* pData);
BVCSP_Dialog_Write Dialog_Write = (BVCSP_Dialog_Write) dlsym(handle, "BVCSP_Dialog_Write");
if(!Dialog_Write)
{
printf("open lib Dialog_Write fail\n");
cout<<dlerror()<<endl;
dlclose(handle);
return ;
}
while (1)
{
int iReadSize = fread(szData, sizeof(char), iDataLen, fd);
memset(szData, 0, sizeof(szData));
BVCSP_Packet packet;
memset(&packet, 0, sizeof packet);
packet.iDataType = BVCSP_DATA_TYPE_VIDEO;
packet.iDataSize = iReadSize;
fread(szData, 1, iReadSize, fd);
packet.pData = szData;
BVCU_Result result=Dialog_Write(g_hDialog,&packet);
printf("open lib BVCSP_Dialog_Write success\n");
cout<<result<<endl;
printf("open lib BVCSP_Dialog_Write iReadSize=%d\n",iReadSize);
if (iReadSize < iDataLen){
break;
}
usleep(4);
}
fclose(fd);
}
else
{
printf("打开会话失败\n");
}
break;
case BVCSP_EVENT_SESSION_CLOSE:
if (pParam->iResult == BVCU_RESULT_S_OK)
{
printf("关闭会话成功\n");
}
else
{
printf("关闭会话失败\n");
}
break;
default:
break;
}
}
|
|