private UInt32 StartRecvStream(string cameraCode, string pRemoteSendStreamIp, uint uiRemoteSendStreamVideoPort, uint uiRemoteSendStreamAudioPort, uint uiLocalVideoPort, uint uiLocalAudioPort)
{
NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
logEx.Trace("Enter: eLTEVideoMonitor.StartRecvStream cameraCode :{0},pRemoteSendStreamIp:{1},uiRemoteSendStreamVideoPort:{2},uiRemoteSendStreamAudioPort:{3},uiLocalVideoPort = {4},uiLocalAudioPort ={5}",
cameraCode, pRemoteSendStreamIp, uiRemoteSendStreamVideoPort, uiRemoteSendStreamAudioPort, uiLocalVideoPort, uiLocalAudioPort);
//用户参数,4字节整数
IntPtr pUser = Marshal.AllocHGlobal(4);
try
{
//接收视频码流RTP端口号
uint uiLocalRecvStreamVideoRtpPort = uiLocalVideoPort;
//接收音频码流RTP端口号
uint uiLocalRecvStreamAudioRtpPort = uiLocalAudioPort;
//通道号
UInt32 uiChannel = 0;
//string strLocal = GetLocalIP(ip, iPort, ilocalPort);
if (string.IsNullOrEmpty(localIP))
{
localIP = GetLocalIP(ip, iPort, ilocalPort);
}
//获取可用通道
IVS_NETSOURCE_RESULT iRet = NetSourcedInterface.IVS_NETSOURCE_GetChannel(ref uiChannel);
if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
{
logEx.Error("eLTEVideoMonitor.IVS_NETSOURCE_GetChannel failed. cameraCode :{0}", cameraCode);
return CgwConst.T28181_ERROR_HANDLE;
}
Marshal.Copy(new int[1] { Convert.ToInt32(uiChannel) }, 0, pUser, 1);
//设置媒体流回调函数
NetSourcedInterface.IVS_NETSOURCE_SetDataCallBack(uiChannel, realPlayCallback, pUser);
//异常回调函数
NetSourcedInterface.IVS_NETSOURCE_SetExceptionCallBack(netExceptionCallBack, pUser);
//协议类型 UDP
iRet = NetSourcedInterface.IVS_NETSOURCE_SetProtocolType(uiChannel, 1);
if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
{
logEx.Error("eLTEVideoMonitor.IVS_NETSOURCE_SetProtocolType failed. cameraCode :{0}", cameraCode);
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
iRet = NetSourcedInterface.IVS_NETSOURCE_SetLocalRecvStreamIP(uiChannel, localIP);
if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
{
logEx.Error("eLTEVideoMonitor.IVS_NETSOURCE_SetLocalRecvStreamIP failed. cameraCode :{0}", cameraCode);
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
iRet = NetSourcedInterface.IVS_NETSOURCE_SetLocalRecvStreamPort(uiChannel, uiLocalRecvStreamVideoRtpPort, uiLocalRecvStreamAudioRtpPort);
if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
{
logEx.Error("eLTEVideoMonitor.IVS_NETSOURCE_GetLocalRecvStreamPort failed. cameraCode :{0}", cameraCode);
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
iRet = NetSourcedInterface.IVS_NETSOURCE_OpenNetStream(uiChannel, pRemoteSendStreamIp, uiRemoteSendStreamVideoPort, uiRemoteSendStreamAudioPort);
if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
{
logEx.Error("eLTEVideoMonitor.IVS_NETSOURCE_OpenNetStream failed. cameraCode :{0}", cameraCode);
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
iRet = NetSourcedInterface.IVS_NETSOURCE_StartRecvStream(uiChannel);
if (iRet == IVS_NETSOURCE_RESULT.SUCCESS)
{
channelInPtrDic.Add(uiChannel, pUser);
logEx.Info("eLTEVideoMonitor.IVS_NETSOURCE_StartRecvStream pChannel: {0}, cameraCode :{1} ", uiChannel, cameraCode);
return uiChannel;
}
else
{
logEx.Error("eLTEVideoMonitor.StartRecvStream failed. cameraCode :{0}", cameraCode);
this.lteSdkClient.StopP2PVideo(Convert.ToInt32(cameraCode));
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
}
catch (System.Exception ex)
{
logEx.Error("StartRecvStream failed.Exception message:{0},cameraCode :{0}", ex.Message, cameraCode);
Marshal.FreeHGlobal(pUser);
return CgwConst.T28181_ERROR_HANDLE;
}
}