Example #1
0
        /// <summary>
        /// 录像查询消息处理
        /// </summary>
        /// <param name="localSIPEndPoint">本地终结点</param>
        /// <param name="remoteEndPoint">远程终结点</param>
        /// <param name="response">sip响应</param>
        /// <param name="record">录像xml结构体</param>
        private void RecordInfoHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request, RecordInfo record)
        {
            MonitorKey key = new MonitorKey()
            {
                DeviceID = record.DeviceID,
                CmdType  = CommandType.Playback
            };

            MonitorService[key].RecordQueryTotal(record.SumNum);
            if (OnRecordInfoReceived != null && record.RecordItems != null)
            {
                OnRecordInfoReceived(record);
            }
        }
Example #2
0
        /// <summary>
        /// 目录查询响应消息处理
        /// </summary>
        /// <param name="localEP">本地终结点</param>
        /// <param name="remoteEP">远程终结点</param>
        /// <param name="request">sip请求</param>
        /// <param name="catalog">目录结构体</param>
        private void CatalogHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request, Catalog catalog)
        {
            foreach (var cata in catalog.DeviceList.Items)
            {
                if (cata == null)
                {
                    continue;
                }
                cata.RemoteEP = remoteEP.ToHost();
                DevCataType devCata = DevType.GetCataType(cata.DeviceID);
                if (devCata != DevCataType.Device)
                {
                    continue;
                }
                for (int i = 0; i < 2; i++)
                {
                    CommandType cmdType = i == 0 ? CommandType.Play : CommandType.Playback;
                    MonitorKey  key     = new MonitorKey()
                    {
                        DeviceID = cata.DeviceID,
                        CmdType  = cmdType
                    };
                    lock (MonitorService)
                    {
                        if (MonitorService.ContainsKey(key))
                        {
                            continue;
                        }
                        remoteEP.Port = _account.KeepaliveInterval;
                        ISIPMonitorService monitor = new SIPMonitorCore(this, cata.DeviceID, remoteEP, _account);
                        MonitorService.Add(key, monitor);
                    }
                }
            }

            if (OnCatalogReceived != null)
            {
                OnCatalogReceived(catalog);
            }
        }
Example #3
0
        public SIPMessageCore(IList <CameraInfo> cameras, SIPAccount account)
        {
            _serviceState = ServiceStatus.Wait;
            _account      = account;
            LocalEP       = SIPEndPoint.ParseSIPEndPoint("udp:" + account.LocalIP.ToString() + ":" + account.LocalPort);
            LocalSIPId    = account.LocalID;

            MonitorService = new Dictionary <MonitorKey, ISIPMonitorService>();
            Trans          = new Dictionary <string, string>();
            foreach (var channel in cameras)
            {
                for (int i = 0; i < 2; i++)
                {
                    CommandType cmdType = i == 0 ? CommandType.Play : CommandType.Playback;
                    MonitorKey  key     = new MonitorKey()
                    {
                        DeviceID = channel.ChannelID,
                        CmdType  = cmdType
                    };
                    ISIPMonitorService monitor = new SIPMonitorCore(this, channel.ChannelID, RemoteEP, account);
                    MonitorService.Add(key, monitor);
                }
            }
        }
Example #4
0
        /// <summary>
        /// Message消息处理
        /// </summary>
        /// <param name="localEP">本地终结点</param>
        /// <param name="remoteEP">远程终结点</param>
        /// <param name="request">sip请求</param>
        private void MessageHandle(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPRequest request)
        {
            SendResponse(localEP, remoteEP, request);

            //心跳消息
            KeepAlive keepAlive = KeepAlive.Instance.Read(request.Body);

            if (keepAlive != null && keepAlive.CmdType == CommandType.Keepalive)
            {
                KeepaliveHandle(localEP, remoteEP, request, keepAlive);
                return;
            }


            //设备目录
            Catalog catalog = Catalog.Instance.Read(request.Body);

            if (catalog != null && catalog.CmdType == CommandType.Catalog)
            {
                CatalogHandle(localEP, remoteEP, request, catalog);
                return;
            }

            //录像查询
            RecordInfo record = RecordInfo.Instance.Read(request.Body);

            if (record != null && record.CmdType == CommandType.RecordInfo)
            {
                RecordInfoHandle(localEP, remoteEP, request, record);
                return;
            }

            //媒体通知
            MediaStatus mediaStatus = MediaStatus.Instance.Read(request.Body);

            if (mediaStatus != null && mediaStatus.CmdType == CommandType.MediaStatus)
            {
                MonitorKey key = new MonitorKey()
                {
                    CmdType  = CommandType.Playback,
                    DeviceID = request.Header.From.FromURI.User
                };
                MonitorService[key].ByeVideoReq();
                //取值121表示历史媒体文件发送结束(回放结束/下载结束)
                //NotifyType未找到相关文档标明所有该类型值,暂时只处理121
                if (mediaStatus.NotifyType.Equals("121"))
                {
                    if (OnMediaStatusReceived != null)
                    {
                        OnMediaStatusReceived(remoteEP, mediaStatus);
                    }
                }
                return;
            }

            //设备状态查询
            DeviceStatus deviceStatus = DeviceStatus.Instance.Read(request.Body);

            if (deviceStatus != null && deviceStatus.CmdType == CommandType.DeviceStatus)
            {
                if (OnDeviceStatusReceived != null)
                {
                    OnDeviceStatusReceived(remoteEP, deviceStatus);
                }
                return;
            }

            //设备信息查询
            DeviceInfo deviceInfo = DeviceInfo.Instance.Read(request.Body);

            if (deviceInfo != null && deviceInfo.CmdType == CommandType.DeviceInfo)
            {
                if (OnDeviceInfoReceived != null)
                {
                    OnDeviceInfoReceived(remoteEP, deviceInfo);
                }
                return;
            }

            //设备配置查询
            DeviceConfigDownload devDownload = DeviceConfigDownload.Instance.Read(request.Body);

            if (devDownload != null && devDownload.CmdType == CommandType.ConfigDownload)
            {
                if (OnDeviceConfigDownloadReceived != null)
                {
                    OnDeviceConfigDownloadReceived(remoteEP, devDownload);
                }
            }

            //预置位查询
            PresetInfo preset = PresetInfo.Instance.Read(request.Body);

            if (preset != null && preset.CmdType == CommandType.PresetQuery)
            {
                if (OnPresetQueryReceived != null)
                {
                    OnPresetQueryReceived(remoteEP, preset);
                }
            }

            //报警通知
            Alarm alarm = Alarm.Instance.Read(request.Body);

            if (alarm != null && alarm.CmdType == CommandType.Alarm)//单兵上报经纬度
            {
                if (OnAlarmReceived != null)
                {
                    OnAlarmReceived(alarm);
                }
            }
        }
Example #5
0
        /// <summary>
        /// SIP响应消息
        /// </summary>
        /// <param name="localEP">本地终结点</param>
        /// <param name="remoteEP">远程终结点</param>
        /// <param name="response">sip响应</param>
        public void AddMessageResponse(SIPEndPoint localEP, SIPEndPoint remoteEP, SIPResponse response)
        {
            if (response.Status == SIPResponseStatusCodesEnum.Ok)
            {
                if (response.Header.CSeqMethod == SIPMethodsEnum.SUBSCRIBE)
                {
                    MonitorKey key = new MonitorKey()
                    {
                        CmdType  = CommandType.Play,
                        DeviceID = response.Header.To.ToURI.User
                    };
                    MonitorService[key].Subscribe(response);
                }
                else if (response.Header.ContentType.ToLower() == "application/sdp")
                {
                    CommandType cmdType     = CommandType.Play;
                    string      sessionName = GetSessionName(response.Body);
                    if (sessionName != null)
                    {
                        Enum.TryParse <CommandType>(sessionName, out cmdType);
                    }
                    MonitorKey key = new MonitorKey()
                    {
                        CmdType  = cmdType,
                        DeviceID = response.Header.To.ToURI.User
                    };
                    if (key.CmdType == CommandType.Download)
                    {
                        key.CmdType = CommandType.Playback;
                    }
                    lock (MonitorService)
                    {
                        string ip   = GetReceiveIP(response.Body);
                        int    port = GetReceivePort(response.Body, SDPMediaTypesEnum.video);
                        MonitorService[key].AckRequest(response.Header.To.ToTag, ip, port);
                    }
                }

                if (OnResponseCodeReceived != null)
                {
                    OnResponseCodeReceived(response.Status, "对方国标平台返回状态【成功】", remoteEP);
                }
            }
            else
            {
                switch (response.Status)
                {
                case SIPResponseStatusCodesEnum.BadRequest:                     //请求失败
                case SIPResponseStatusCodesEnum.InternalServerError:            //服务器内部错误
                case SIPResponseStatusCodesEnum.RequestTerminated:              //请求终止
                case SIPResponseStatusCodesEnum.CallLegTransactionDoesNotExist: //呼叫/事务不存在
                    OnResponseCodeReceived(response.Status, "对方国标平台返回状态【失败】", remoteEP);
                    break;

                case SIPResponseStatusCodesEnum.Trying:                     //等待处理
                    OnResponseCodeReceived(response.Status, "对方国标平台返回状态【正在尝试】", remoteEP);
                    break;

                default:
                    OnResponseCodeReceived(response.Status, "对方国标平台返回状态【其他】", remoteEP);
                    break;
                }
            }
        }