BOOL NET_DVR_SetRealDataCallBack(LONG lRealHandle,void(CALLBACK *fRealDataCallBack) (LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD dwUser),DWORD dwUser)
功能:设置回调函数,用户自己处理客户端收到的数据
参数说明:
lRealHandle:NET_DVR_RealPlay()的返回值
fRealDataCallBack:回调函数
dwUser:用户数据
回调函数说明:
lRealHandle:NET_DVR_RealPlay()的返回值 dwDataType:数据类型
#define NET_DVR_SYSHEAD 1 //系统头数据
#define NET_DVR_STREAMDATA 2 //流数据
pBuffer:存放数据的缓冲区指针
dwBufSize:缓冲区的大小
dwUser:用户数据,就是上面输入的用户数据
返回值:TRUE表示成功,FALSE表示失败。
注:此函数包括开始和停止用户处理客户端收到的数据,当fRealDataCallBack不为NULL时,开始用户处理客户端收到的数据,当设置为NULL表示停止用户处理客户端收到的数据.当用户开始接收数据时,第一个包是40个字节的文件头,用户可以用这个头来打开播放器,以后回调的就是压缩的码流。IP Camera设备下调用此接口返回的是经过转化的HIKVISION格式的MPEG4流数据。
请问这个回调函数怎么使用?看了半天DOMO没看明白。请做过的前辈指点一下,给点能实现这个功能的思路也可以。
5 个解决方案
#1
就是函数指针。
#2
1.先定义void(CALLBACK *fRealDataCallBack) (LONG lRealHandle, DWORD dwDataType, BYTE
*pBuffer,DWORD dwBufSize,DWORD dwUser)回调函数
2.然后调用NET_DVR_SetRealDataCallBack设置回调函数函数
*pBuffer,DWORD dwBufSize,DWORD dwUser)回调函数
2.然后调用NET_DVR_SetRealDataCallBack设置回调函数函数
#3
最关键的问题数据获得后,如何处理?
交给硬件解码?还是交给软件解码?
如何搞。
交给硬件解码?还是交给软件解码?
如何搞。
#4
解码卡还可以解决。关键软解码如何解决
#5
g_hWnd =m_show.GetSafeHwnd(); //获取窗口句柄
m_lPlayHandle = NET_DVR_PlayBackByTime(m_USERID, 1, &struStartTime, &struStopTime, g_hWnd);//注册连接,成功为1
//按时间回放
if(m_lPlayHandle < 0)
{
printf("NET_DVR_GetFileByTime fail,last error %d\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
if(!NET_DVR_PlayBackControl(m_lPlayHandle, NET_DVR_PLAYSTART, 0, NULL))
{
printf("play back control failed [%d]\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
//调用回调函数获取回调数据
NET_DVR_SetPlayDataCallBack(m_lPlayHandle,PlayDataCallBack,0);//回调函数不断的取历史数据
//历史视频回调函数
void CALLBACK PlayDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD pUser)
{
BOOL bRet = FALSE;
int i = 0;
LONG lIndex = nPort;
switch (dwDataType)
{
case NET_DVR_SYSHEAD://文件头数据
if (!PlayM4_GetPort(&lIndex))
{
nPort = -1;
break;
}
nPort = lIndex;
bRet = PlayM4_SetOverlayMode(lIndex, FALSE, COLORREF(0));//not play on overplay
bRet = PlayM4_SetStreamOpenMode(lIndex, STREAME_FILE);
if (dwBufSize > 0)
{
if (!PlayM4_OpenStream(nPort,pBuffer,dwBufSize,1024*1024))//
{
PlayM4_GetLastError(nPort);
break;
}
//////////////////////////////////////////////////////////////////////////
///设置解码回调函数
if (!PlayM4_SetDecCallBackEx(nPort,DecCBFun,NULL,NULL))
{
PlayM4_GetLastError(nPort);
break;
}
if (!PlayM4_Play(nPort,g_hWnd))
{
PlayM4_GetLastError(nPort);
break;
}
break;
/*******************************************************************************/
}
TRACE("Write Buffer: %d\n",dwBufSize);
break;
case NET_DVR_STREAMDATA://数据
BOOL inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
while (!inData)
{
Sleep(10);
inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
}
break;
}
return;
}
//////////////////////////////////////////////////////////////////////////
////解码回调
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)
{
long lFrameType = pFrameInfo->nType;
if (lFrameType ==T_AUDIO16)
{
TRACE("Audio nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,AudioFile);
OutputDebugString("test_DecCb_Write Audio16 \n");
}
else if(lFrameType ==T_YV12)
{
TRACE("Video nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,file);
OutputDebugString("test_DecCb_Write YUV \n");
}
else
{
}
}
m_lPlayHandle = NET_DVR_PlayBackByTime(m_USERID, 1, &struStartTime, &struStopTime, g_hWnd);//注册连接,成功为1
//按时间回放
if(m_lPlayHandle < 0)
{
printf("NET_DVR_GetFileByTime fail,last error %d\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
if(!NET_DVR_PlayBackControl(m_lPlayHandle, NET_DVR_PLAYSTART, 0, NULL))
{
printf("play back control failed [%d]\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
//调用回调函数获取回调数据
NET_DVR_SetPlayDataCallBack(m_lPlayHandle,PlayDataCallBack,0);//回调函数不断的取历史数据
//历史视频回调函数
void CALLBACK PlayDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD pUser)
{
BOOL bRet = FALSE;
int i = 0;
LONG lIndex = nPort;
switch (dwDataType)
{
case NET_DVR_SYSHEAD://文件头数据
if (!PlayM4_GetPort(&lIndex))
{
nPort = -1;
break;
}
nPort = lIndex;
bRet = PlayM4_SetOverlayMode(lIndex, FALSE, COLORREF(0));//not play on overplay
bRet = PlayM4_SetStreamOpenMode(lIndex, STREAME_FILE);
if (dwBufSize > 0)
{
if (!PlayM4_OpenStream(nPort,pBuffer,dwBufSize,1024*1024))//
{
PlayM4_GetLastError(nPort);
break;
}
//////////////////////////////////////////////////////////////////////////
///设置解码回调函数
if (!PlayM4_SetDecCallBackEx(nPort,DecCBFun,NULL,NULL))
{
PlayM4_GetLastError(nPort);
break;
}
if (!PlayM4_Play(nPort,g_hWnd))
{
PlayM4_GetLastError(nPort);
break;
}
break;
/*******************************************************************************/
}
TRACE("Write Buffer: %d\n",dwBufSize);
break;
case NET_DVR_STREAMDATA://数据
BOOL inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
while (!inData)
{
Sleep(10);
inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
}
break;
}
return;
}
//////////////////////////////////////////////////////////////////////////
////解码回调
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)
{
long lFrameType = pFrameInfo->nType;
if (lFrameType ==T_AUDIO16)
{
TRACE("Audio nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,AudioFile);
OutputDebugString("test_DecCb_Write Audio16 \n");
}
else if(lFrameType ==T_YV12)
{
TRACE("Video nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,file);
OutputDebugString("test_DecCb_Write YUV \n");
}
else
{
}
}
#1
就是函数指针。
#2
1.先定义void(CALLBACK *fRealDataCallBack) (LONG lRealHandle, DWORD dwDataType, BYTE
*pBuffer,DWORD dwBufSize,DWORD dwUser)回调函数
2.然后调用NET_DVR_SetRealDataCallBack设置回调函数函数
*pBuffer,DWORD dwBufSize,DWORD dwUser)回调函数
2.然后调用NET_DVR_SetRealDataCallBack设置回调函数函数
#3
最关键的问题数据获得后,如何处理?
交给硬件解码?还是交给软件解码?
如何搞。
交给硬件解码?还是交给软件解码?
如何搞。
#4
解码卡还可以解决。关键软解码如何解决
#5
g_hWnd =m_show.GetSafeHwnd(); //获取窗口句柄
m_lPlayHandle = NET_DVR_PlayBackByTime(m_USERID, 1, &struStartTime, &struStopTime, g_hWnd);//注册连接,成功为1
//按时间回放
if(m_lPlayHandle < 0)
{
printf("NET_DVR_GetFileByTime fail,last error %d\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
if(!NET_DVR_PlayBackControl(m_lPlayHandle, NET_DVR_PLAYSTART, 0, NULL))
{
printf("play back control failed [%d]\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
//调用回调函数获取回调数据
NET_DVR_SetPlayDataCallBack(m_lPlayHandle,PlayDataCallBack,0);//回调函数不断的取历史数据
//历史视频回调函数
void CALLBACK PlayDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD pUser)
{
BOOL bRet = FALSE;
int i = 0;
LONG lIndex = nPort;
switch (dwDataType)
{
case NET_DVR_SYSHEAD://文件头数据
if (!PlayM4_GetPort(&lIndex))
{
nPort = -1;
break;
}
nPort = lIndex;
bRet = PlayM4_SetOverlayMode(lIndex, FALSE, COLORREF(0));//not play on overplay
bRet = PlayM4_SetStreamOpenMode(lIndex, STREAME_FILE);
if (dwBufSize > 0)
{
if (!PlayM4_OpenStream(nPort,pBuffer,dwBufSize,1024*1024))//
{
PlayM4_GetLastError(nPort);
break;
}
//////////////////////////////////////////////////////////////////////////
///设置解码回调函数
if (!PlayM4_SetDecCallBackEx(nPort,DecCBFun,NULL,NULL))
{
PlayM4_GetLastError(nPort);
break;
}
if (!PlayM4_Play(nPort,g_hWnd))
{
PlayM4_GetLastError(nPort);
break;
}
break;
/*******************************************************************************/
}
TRACE("Write Buffer: %d\n",dwBufSize);
break;
case NET_DVR_STREAMDATA://数据
BOOL inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
while (!inData)
{
Sleep(10);
inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
}
break;
}
return;
}
//////////////////////////////////////////////////////////////////////////
////解码回调
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)
{
long lFrameType = pFrameInfo->nType;
if (lFrameType ==T_AUDIO16)
{
TRACE("Audio nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,AudioFile);
OutputDebugString("test_DecCb_Write Audio16 \n");
}
else if(lFrameType ==T_YV12)
{
TRACE("Video nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,file);
OutputDebugString("test_DecCb_Write YUV \n");
}
else
{
}
}
m_lPlayHandle = NET_DVR_PlayBackByTime(m_USERID, 1, &struStartTime, &struStopTime, g_hWnd);//注册连接,成功为1
//按时间回放
if(m_lPlayHandle < 0)
{
printf("NET_DVR_GetFileByTime fail,last error %d\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
if(!NET_DVR_PlayBackControl(m_lPlayHandle, NET_DVR_PLAYSTART, 0, NULL))
{
printf("play back control failed [%d]\n",NET_DVR_GetLastError());
NET_DVR_Logout(m_USERID);
NET_DVR_Cleanup();
return;
}
//调用回调函数获取回调数据
NET_DVR_SetPlayDataCallBack(m_lPlayHandle,PlayDataCallBack,0);//回调函数不断的取历史数据
//历史视频回调函数
void CALLBACK PlayDataCallBack(LONG lRealHandle, DWORD dwDataType, BYTE *pBuffer,DWORD dwBufSize,DWORD pUser)
{
BOOL bRet = FALSE;
int i = 0;
LONG lIndex = nPort;
switch (dwDataType)
{
case NET_DVR_SYSHEAD://文件头数据
if (!PlayM4_GetPort(&lIndex))
{
nPort = -1;
break;
}
nPort = lIndex;
bRet = PlayM4_SetOverlayMode(lIndex, FALSE, COLORREF(0));//not play on overplay
bRet = PlayM4_SetStreamOpenMode(lIndex, STREAME_FILE);
if (dwBufSize > 0)
{
if (!PlayM4_OpenStream(nPort,pBuffer,dwBufSize,1024*1024))//
{
PlayM4_GetLastError(nPort);
break;
}
//////////////////////////////////////////////////////////////////////////
///设置解码回调函数
if (!PlayM4_SetDecCallBackEx(nPort,DecCBFun,NULL,NULL))
{
PlayM4_GetLastError(nPort);
break;
}
if (!PlayM4_Play(nPort,g_hWnd))
{
PlayM4_GetLastError(nPort);
break;
}
break;
/*******************************************************************************/
}
TRACE("Write Buffer: %d\n",dwBufSize);
break;
case NET_DVR_STREAMDATA://数据
BOOL inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
while (!inData)
{
Sleep(10);
inData=PlayM4_InputData(nPort,pBuffer,dwBufSize);
}
break;
}
return;
}
//////////////////////////////////////////////////////////////////////////
////解码回调
void CALLBACK DecCBFun(long nPort,char * pBuf,long nSize,FRAME_INFO * pFrameInfo, long nReserved1,long nReserved2)
{
long lFrameType = pFrameInfo->nType;
if (lFrameType ==T_AUDIO16)
{
TRACE("Audio nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,AudioFile);
OutputDebugString("test_DecCb_Write Audio16 \n");
}
else if(lFrameType ==T_YV12)
{
TRACE("Video nStamp:%d\n",pFrameInfo->nStamp);
// fwrite(pBuf,nSize,1,file);
OutputDebugString("test_DecCb_Write YUV \n");
}
else
{
}
}