예제 #1
0
        /// <summary>
        /// 云台控制
        /// </summary>
        /// <param name="deviceID">设备编码</param>
        /// <param name="PTZCmd">云台控制命令</param>
        /// <param name="controlPriority">优先级</param>
        /// <returns></returns>
        public EM_SIP_RESULT PtzControl(string deviceID, string ptzCmd, string controlPriority)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.PtzControl deviceID = {0}.", deviceID);
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                //设备目录查询消息体
                string xmlstr = @"<?xml version='1.0'?><Control><CmdType>DeviceControl</CmdType><SN>" + DeviceControlSN + "</SN><DeviceID>" + deviceID + @"</DeviceID>
                                    <PTZCmd>" + ptzCmd + @"</PTZCmd>
                                    <Info>
                                    <ControlPriority>" + controlPriority + @"</ControlPriority>
                                    </Info></Control>";
                DeviceControlSN++;
                iRet = SipSDKInterface.SIP_SDK_MESSAGE(deviceID, xmlstr);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.PtzControl Error = {0}.", Enum.GetName(typeof(EM_SIP_RESULT), iRet));
                }
                logEx.Trace("Leave: SipStackAdapter.PtzControl deviceID = {0}.", deviceID);
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.PtzControl Error = {0}.", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #2
0
        /// <summary>
        /// 该函数用于发送SIP ACK消息
        /// </summary>
        /// <param name="iResponseID">iResponseID</param>
        public EM_SIP_RESULT SIP_SDK_ACK(int iResponseID)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_ACK().");
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                iRet = SipSDKInterface.SIP_SDK_ACK(iResponseID);

                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_ACK ,iResponseID:{0}", iResponseID);
                }
                else
                {
                    logEx.Info("SipStackAdapter.SIP_SDK_ACK ,iResponseID={0}", iResponseID);
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_ACK ,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #3
0
        /// <summary>
        /// 该函数用于发送SIP Invite消息
        /// </summary>
        /// <param name="pAccount">对方账号</param>
        /// <param name="pSdpBody">SDP描述字符串</param>
        public EM_SIP_RESULT SIP_SDK_INVITE(string pAccount, string pSdpBody, ref int iResponseID, StringBuilder strRemoteBody)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_INVITE().");
            iResponseID = 0;
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                iRet = SipSDKInterface.SIP_SDK_INVITE(pAccount, pSdpBody, ref iResponseID, strRemoteBody);
                SIP_SDK_ACK(iResponseID);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_INVITE ,pSdpBody:{0}", pSdpBody);
                }
                else
                {
                    logEx.Info("SipStackAdapter.SIP_SDK_INVITE ,iResponseID={0}", iResponseID);
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_INVITE ,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #4
0
        /// <summary>
        /// sip保活
        /// </summary>
        /// <param name="localSignalGateway">网关对接T28181监控平台时,网关视为监控平台外域,该编码是标识网关的域编码,即是监控平台配置界面添加网关时的外域编码。</param>
        public void StartKeepalive(string serverID, string localID)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: T28181VideoMonitor.StartConnectRegisterSip().");
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            //初始话定时器
            this.keepLiveTimer.AutoReset = true;
            this.keepLiveTimer.Elapsed  += new System.Timers.ElapsedEventHandler((x, y)
                                                                                 =>
            {
                //sip保活,deviceID为用户名
                string strBody = @"<?xml version='1.0'?><Notify><CmdType>Keepalive</CmdType><SN>" + KeepaliveSN + "</SN><DeviceID>" + localID + "</DeviceID><Status>OK</Status></Notify>";
                KeepaliveSN++;
                iRet = SipSDKInterface.SIP_SDK_MESSAGE(serverID, strBody);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Warn("SipStackAdapter.Keepalive Failed");
                    //保活失败,重新注册. zWX231378 .2015/6/24
                    SIP_SDK_REGISTER();
                }
                else
                {
                    logEx.Trace("SipStackAdapter.Keepalive Success");
                }
            });
            //保活时间为10秒
            this.keepLiveTimer.Interval = CgwConst.Thread_Sleep_Time * 10;
            keepLiveTimer.Start();
        }
예제 #5
0
        /// <summary>
        /// 该函数用于发送SIP Register消息
        /// </summary>
        public EM_SIP_RESULT SIP_SDK_REGISTER()
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_REGISTER().");
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                iRet = SipSDKInterface.SIP_SDK_REGISTER();

                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_REGISTER Error = {0}.", Enum.GetName(typeof(EM_SIP_RESULT), iRet));
                }
                else
                {
                    logEx.Info("SipStackAdapter.SIP_SDK_REGISTER Success");
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_REGISTER ,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #6
0
        /// <summary>
        /// 停止接收rtp数据包
        /// </summary>
        /// <param name="cameraCode"></param>
        public EM_SIP_RESULT StopRecvStream(UInt32 channel)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.StopRecvStream channel = {0}.", channel);

            try
            {
                //停止实况
                int responseID = 0;
                foreach (KeyValuePair <UInt32, int> kvp in channelResponseIDDic)
                {
                    if (kvp.Key == channel)
                    {
                        responseID = kvp.Value;
                        channelResponseIDDic.Remove(kvp.Key);
                        break;
                    }
                }
                EM_SIP_RESULT iRet = SIP_SDK_BYE(responseID);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("StopRecvStream failed channel={0}", channel);
                }
                //释放用户数据内存
                foreach (KeyValuePair <UInt32, IntPtr> kvp in channelInPtrDic)
                {
                    if (kvp.Key == channel)
                    {
                        Marshal.FreeHGlobal(kvp.Value);
                        channelInPtrDic.Remove(kvp.Key);
                        break;
                    }
                }

                //释放NETSOURCE通道资源
                IVS_NETSOURCE_RESULT iNet = IVS_NETSOURCE_FreeChannel(channel);
                if (iNet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("IVS_NETSOURCE_FreeChannel failed channel={0}", channel);
                    return(EM_SIP_RESULT.RET_FAILURE);
                }
                return(iRet);
            }
            catch (System.Exception ex)
            {
                logEx.Error("StopRecvStream failed.Exception message:{0}", ex.Message);
                return(EM_SIP_RESULT.RET_FAILURE);
            }
        }
예제 #7
0
        /// <summary>
        /// 获取系统设备列表
        /// </summary>
        /// <param name="serverSignalGateway">要查询的域编码</param>
        /// <param name="deviceID">要查询的根设备编码</param>
        public void GetDeviceList(string serverSignalGateway, string deviceID)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.GetDeviceList deviceID = {0}.", deviceID);

            try
            {
                //设备总数清空
                if (deviceItemOperateLock.TryEnterWriteLock(CgwConst.ENTER_LOCK_WAIT_TIME))
                {
                    deviceNum = 0;
                    deviceList.Clear();
                }
            }
            finally
            {
                deviceItemOperateLock.ExitWriteLock();
            }

            try
            {
                //设备目录查询消息体
                string xmlstr = "<?xml version='1.0'?>" +
                                "<Query><CmdType>Catalog</CmdType><SN>" + iCateLogSN + "</SN><DeviceID>" + deviceID + "</DeviceID></Query>";

                iCateLogSN++;
                EM_SIP_RESULT iRet = SipSDKInterface.SIP_SDK_MESSAGE(serverSignalGateway, xmlstr);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.GetDeviceList Error = {0}.", Enum.GetName(typeof(EM_SIP_RESULT), iRet));
                    isRefreshSucess = false;
                }
                logEx.Trace("Leave: SipStackAdapter.GetDeviceList deviceID = {0}.", deviceID);
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.GetDeviceList Error = {0}.", ex.ToString());
                isRefreshSucess = false;
            }
        }
예제 #8
0
        /// <summary>
        /// 该函数用于发送subscribe消息
        /// </summary>
        public EM_SIP_RESULT SIP_SDK_Subscribe(string pBody)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_Subscribe().");
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                iRet = SipSDKInterface.SIP_SDK_Subscribe(pBody);

                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_Subscribe ,pBody:{0}", pBody);
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_Subscribe ,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #9
0
        /// <summary>
        /// 该函数用于发送SIP BYE消息
        /// </summary>
        public EM_SIP_RESULT SIP_SDK_BYE(int responseID)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_BYE() responseID ={0}.", responseID);
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                iRet = SipSDKInterface.SIP_SDK_BYE(responseID);

                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_BYE Error = {0}.", Enum.GetName(typeof(EM_SIP_RESULT), iRet));
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_BYE,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #10
0
        /// <summary>
        /// 初始化SIP协议栈
        /// </summary>
        public EM_SIP_RESULT SIP_SDK_Init(string pSipAccount, string pSipPasswd, string pLocalID, int iLocalPort, string pServerSipAccount, string pServerSipPasswd, string pServerID, string pServerIP, int iServerPort, EventHandler receivedAllDevice)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.SIP_SDK_Init().");
            EM_SIP_RESULT iRet = EM_SIP_RESULT.RET_FAILURE;

            try
            {
                //string pLocalIP = GetLocalIP(pServerIP, iServerPort, iLocalPort);
                if (string.IsNullOrEmpty(localIP))
                {
                    localIP = GetLocalIP(pServerIP, iServerPort, iLocalPort);
                }
                ReceivedAllDevice = receivedAllDevice;

                sip_CallBack = SIP_CallBackMethod;

                iRet = SipSDKInterface.SIP_SDK_Init(pSipAccount, pSipPasswd, pLocalID, localIP, iLocalPort, pServerSipAccount, pServerSipPasswd, pServerID, pServerIP, iServerPort, sip_CallBack);
                if (iRet != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_Init Failed ,pAccount:{0}", pSipAccount);
                }

                //设置NETSOURCE日志目录
                IVS_NETSOURCE_RESULT iNet = NetSourcedInterface.IVS_NETSOURCE_Init(AppDomain.CurrentDomain.BaseDirectory + "\\logs");
                if (iNet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("SipStackAdapter.IVS_NETSOURCE_Init Failed,pAccount:{0}", pSipAccount);
                    iRet = EM_SIP_RESULT.RET_FAILURE;
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("SipStackAdapter.SIP_SDK_Init ,Exception:{0}", ex.ToString());
                iRet = EM_SIP_RESULT.RET_FAILURE;
            }
            return(iRet);
        }
예제 #11
0
        /// <summary>
        /// 打开通道,开始接收实况RTP数据流
        /// </summary>
        /// <param name="cameraCode">摄像机编码</param>
        /// <returns></returns>
        public UInt32 StartRecvStream(string cameraCode, string domain, string iSipPort, string localPort)
        {
            NLogEx.LoggerEx logEx = new NLogEx.LoggerEx(log);
            logEx.Trace("Enter: SipStackAdapter.StartRecvStream  cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);

            try
            {
                //接收视频码流RTP端口号
                uint uiLocalRecvStreamVideoRtpPort = 0;
                //接收音频码流RTP端口号
                uint uiLocalRecvStreamAudioRtpPort = 0;
                //通道号
                UInt32 uiChannel = 0;
                //string strLocal = GetLocalIP(domain, Convert.ToInt32(iSipPort), Convert.ToInt32(localPort));

                if (string.IsNullOrEmpty(localIP))
                {
                    localIP = GetLocalIP(domain, Convert.ToInt32(iSipPort), Convert.ToInt32(localPort));
                }
                string strLocal = localIP;

                //获取可用通道
                NetSourcedInterface.IVS_NETSOURCE_GetChannel(ref uiChannel);

                //用户参数,4字节整数
                IntPtr pUser = Marshal.AllocHGlobal(4);
                Marshal.Copy(new int[1] {
                    Convert.ToInt32(uiChannel)
                }, 0, pUser, 1);

                //设置媒体流回调函数
                NetSourcedInterface.IVS_NETSOURCE_SetDataCallBack(uiChannel, cbDataCallBack, pUser);
                //异常回调函数
                IVS_NETSOURCE_RESULT iRet = NetSourcedInterface.IVS_NETSOURCE_SetExceptionCallBack(cbNetExceptionCallBack, pUser);

                //协议类型 UDP
                iRet = NetSourcedInterface.IVS_NETSOURCE_SetProtocolType(uiChannel, 1);
                if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("SipStackAdapter.StartRecvStream.IVS_NETSOURCE_SetProtocolType failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }

                iRet = NetSourcedInterface.IVS_NETSOURCE_SetLocalRecvStreamIP(uiChannel, localIP);
                if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("SipStackAdapter.StartRecvStream.IVS_NETSOURCE_SetLocalRecvStreamIP failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }

                iRet = NetSourcedInterface.IVS_NETSOURCE_GetLocalRecvStreamPort(uiChannel, ref uiLocalRecvStreamVideoRtpPort, ref uiLocalRecvStreamAudioRtpPort);
                if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("SipStackAdapter.StartRecvStream.IVS_NETSOURCE_GetLocalRecvStreamPort failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }

                //Invite消息体
                string strRealPlay = "v=0\r\n"
                                     + "o=" + cameraCode + @" 0 0 IN IP4 " + strLocal + "\r\n"
                                     + "s=Play\r\n"
                                     + "c=IN IP4 " + strLocal + "\r\n"
                                     + "t=0 0\r\n"
                                     + "m=video " + uiLocalRecvStreamVideoRtpPort + " RTP/AVP 96 98 97\r\n"
                                     + "a=recvonly\r\n"
                                     + "a=rtpmap:96 PS/90000\r\n"
                                     + "a=rtpmap:98 H264/90000\r\n"
                                     + "a=rtpmap:97 MPEG4/90000\r\n";

                //发送SIP Invite消息
                int iResponseID = 0;
                //制定字符串长度为1024
                StringBuilder strRemoteBody = new StringBuilder(1024);
                //发送SIP Invite消息
                EM_SIP_RESULT iSip = SIP_SDK_INVITE(cameraCode, strRealPlay, ref iResponseID, strRemoteBody);
                if (iSip != EM_SIP_RESULT.RET_SUCCESS)
                {
                    logEx.Error("SipStackAdapter.SIP_SDK_INVITE failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }

                //源端发送码流IP;
                string pRemoteSendStreamIp = "";
                //源端发送视频码流RTP端口号
                uint uiRemoteSendStreamVideoPort = 0;
                GetInviteRemoteIPPort(strRemoteBody.ToString(), ref pRemoteSendStreamIp, ref uiRemoteSendStreamVideoPort);

                iRet = NetSourcedInterface.IVS_NETSOURCE_OpenNetStream(uiChannel, pRemoteSendStreamIp, uiRemoteSendStreamVideoPort, 0);//无音频,传入0
                if (iRet != IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    logEx.Error("SipStackAdapter.StartRecvStream failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }

                iRet = NetSourcedInterface.IVS_NETSOURCE_StartRecvStream(uiChannel);
                if (iRet == IVS_NETSOURCE_RESULT.SUCCESS)
                {
                    channelResponseIDDic.Add(uiChannel, iResponseID);
                    channelInPtrDic.Add(uiChannel, pUser);
                    logEx.Info("SipStackAdapter.StartRecvStream pChannel: {0}, cameraCode :{1},domain = {2},iSipPort ={3} ", uiChannel, cameraCode, domain, iSipPort);
                    return(uiChannel);
                }
                else
                {
                    logEx.Error("SipStackAdapter.StartRecvStream failed. cameraCode :{0},domain = {1},iSipPort ={2}", cameraCode, domain, iSipPort);
                    StopRecvStream(uiChannel);
                    Marshal.FreeHGlobal(pUser);
                    return(CgwConst.T28181_ERROR_HANDLE);
                }
            }
            catch (System.Exception ex)
            {
                logEx.Error("StartRecvStream failed.Exception message:{0},cameraCode :{0},domain = {1},iSipPort ={2}", ex.Message, cameraCode, domain, iSipPort);
                return(CgwConst.T28181_ERROR_HANDLE);
            }
        }