/// <summary> /// PTZ云台控制 /// </summary> /// <param name="deviceId">设备ID</param> /// <param name="ucommand">控制命令</param> /// <param name="dwStop">开始或结束</param> /// <param name="dwSpeed">速度</param> public void PtzContrl(string deviceId, int ucommand, int dwStop, int dwSpeed) { if (LocalEndPoint == null) { OnSIPServiceChange(deviceId, SipServiceStatus.Wait); return; } string fromTag = CallProperties.CreateNewTag(); string toTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPRequest catalogReq = QueryItems(fromTag, toTag, cSeq, callId); string cmdStr = GetPtzCmd(ucommand, dwStop, dwSpeed); PTZControl ptz = new PTZControl() { CommandType = CommandType.DeviceControl, DeviceID = deviceId, SN = new Random().Next(9999), PTZCmd = cmdStr }; string xmlBody = PTZControl.Instance.Save <PTZControl>(ptz); catalogReq.Body = xmlBody; Transport.SendRequest(RemoteEndPoint, catalogReq); _catalogTask = new TaskTiming(catalogReq, Transport); this.SendRequestTimeout += _catalogTask.MessageSendRequestTimeout; _catalogTask.Start(); }
/// <summary> /// 目录订阅请求 /// </summary> /// <returns></returns> private SIPRequest SubscribeCatalog(SIPEndPoint remoteEndPoint, string remoteSIPId) { string fromTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPURI remoteUri = new SIPURI(remoteSIPId, remoteEndPoint.ToHost(), ""); SIPURI localUri = new SIPURI(LocalSIPId, LocalEP.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, fromTag); SIPToHeader to = new SIPToHeader(null, remoteUri, null); SIPRequest catalogReq = _transport.GetRequest(SIPMethodsEnum.SUBSCRIBE, remoteUri); catalogReq.Header.From = from; catalogReq.Header.Contact = new List <SIPContactHeader> { new SIPContactHeader(null, localUri) }; catalogReq.Header.Allow = null; catalogReq.Header.To = to; catalogReq.Header.UserAgent = SIPConstants.SIP_USERAGENT_STRING; catalogReq.Header.Event = "Catalog";//"presence";//"Catalog;id=1894"; catalogReq.Header.Expires = 60000; catalogReq.Header.CSeq = cSeq; catalogReq.Header.CallId = callId; catalogReq.Header.ContentType = "application/MANSCDP+xml";//"Application/MANSCDP+xml" return(catalogReq); }
/// <summary> /// 查询设备目录请求 /// </summary> /// <returns></returns> private SIPRequest QueryItems(SIPEndPoint remoteEndPoint, string remoteSIPId) { string fromTag = CallProperties.CreateNewTag(); string toTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPURI remoteUri = new SIPURI(RemoteSIPId, RemoteEndPoint.ToHost(), ""); SIPURI localUri = new SIPURI(LocalSIPId, LocalEndPoint.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, fromTag); //SIPToHeader to = new SIPToHeader(null, remoteUri, toTag); SIPToHeader to = new SIPToHeader(null, remoteUri, null); SIPRequest catalogReq = Transport.GetRequest(SIPMethodsEnum.MESSAGE, remoteUri); catalogReq.Header.From = from; catalogReq.Header.Contact = null; catalogReq.Header.Allow = null; catalogReq.Header.To = to; catalogReq.Header.UserAgent = UserAgent; catalogReq.Header.CSeq = cSeq; catalogReq.Header.CallId = callId; catalogReq.Header.ContentType = "application/MANSCDP+xml"; return(catalogReq); }
/// <summary> /// 设备目录查询 /// </summary> /// <param name="deviceId">目的设备编码</param> public void DeviceCatalogQuery(string deviceId) { if (LocalEndPoint == null) { OnSIPServiceChange(deviceId, SipServiceStatus.Wait); return; } string fromTag = CallProperties.CreateNewTag(); string toTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPRequest catalogReq = QueryItems(fromTag, toTag, cSeq, callId); CatalogQuery catalog = new CatalogQuery() { CommandType = CommandType.Catalog, DeviceID = deviceId, SN = new Random().Next(9999) }; string xmlBody = CatalogQuery.Instance.Save <CatalogQuery>(catalog); catalogReq.Body = xmlBody; Transport.SendRequest(RemoteEndPoint, catalogReq); _catalogTask = new TaskTiming(catalogReq, Transport); this.SendRequestTimeout += _catalogTask.MessageSendRequestTimeout; _catalogTask.Start(); }
/// <summary> /// 暂停录像播放 /// </summary> public void BackVideoPauseControlReq() { if (_msgCore.LocalEndPoint == null) { OnSIPServiceChange(_deviceName + "-" + _deviceId, SipServiceStatus.Wait); return; } if (_mediaPort == null) { _mediaPort = _msgCore.SetMediaPort(); } string localIp = _msgCore.LocalEndPoint.Address.ToString(); string fromTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); //this.Stop(); SIPRequest realReq = BackVideoPauseControlReq(localIp, _mediaPort, fromTag, cSeq, callId); _msgCore.Transport.SendRequest(_msgCore.RemoteEndPoint, realReq); _realTask = new TaskTiming(realReq, _msgCore.Transport); _msgCore.SendRequestTimeout += _realTask.MessageSendRequestTimeout; _realTask.OnCloseRTPChannel += Task_OnCloseRTPChannel; _realTask.Start(); }
/// <summary> /// 录像点播请求 /// </summary> /// <param name="localIp">本地ip</param> /// <param name="mediaPort">端口号</param> /// <param name="startTime">开始时间</param> /// <param name="stopTime">结束时间</param> /// <param name="fromTag">from tag</param> /// <param name="cSeq">序号</param> /// <param name="callId">呼叫编号</param> /// <returns></returns> private SIPRequest BackVideoReq(int[] mediaPort, uint startTime, uint stopTime) { string localIp = _msgCore.LocalEndPoint.Address.ToString(); string fromTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPURI remoteUri = new SIPURI(_deviceId, _remoteEndPoint.ToHost(), ""); SIPURI localUri = new SIPURI(_msgCore.LocalSIPId, _msgCore.LocalEndPoint.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, fromTag); SIPToHeader to = new SIPToHeader(null, remoteUri, null); SIPRequest backReq = _msgCore.Transport.GetRequest(SIPMethodsEnum.INVITE, remoteUri); SIPContactHeader contactHeader = new SIPContactHeader(null, localUri); backReq.Header.Contact.Clear(); backReq.Header.Contact.Add(contactHeader); backReq.Header.Allow = null; backReq.Header.From = from; backReq.Header.To = to; backReq.Header.UserAgent = _msgCore.UserAgent; backReq.Header.CSeq = cSeq; backReq.Header.CallId = callId; backReq.Header.Subject = SetSubject(); backReq.Header.ContentType = "application/sdp"; backReq.Body = SetMediaReq(localIp, mediaPort, startTime, stopTime); _realReqSession = backReq; return(backReq); }
/// <summary> /// PTZ云台控制 /// </summary> /// <param name="ucommand">控制命令</param> /// <param name="dwStop">开始或结束</param> /// <param name="dwSpeed">速度</param> public void PtzContrl(int ucommand, int dwStop, int dwSpeed) { lock (_msgCore.RemoteTrans) { if (!_msgCore.RemoteTrans.ContainsKey(_remoteEndPoint.ToString())) { OnSIPServiceChange(_deviceName + "-" + _deviceId + _remoteEndPoint.ToString(), SipServiceStatus.Wait); return; } } string fromTag = CallProperties.CreateNewTag(); string toTag = CallProperties.CreateNewTag(); int cSeq = CallProperties.CreateNewCSeq(); string callId = CallProperties.CreateNewCallId(); SIPRequest catalogReq = PTZRequest(fromTag, toTag, cSeq, callId); string cmdStr = GetPtzCmd(ucommand, dwStop, dwSpeed); PTZControl ptz = new PTZControl() { CommandType = CommandType.DeviceControl, DeviceID = _deviceId, SN = new Random().Next(9999), PTZCmd = cmdStr }; string xmlBody = PTZControl.Instance.Save <PTZControl>(ptz); catalogReq.Body = xmlBody; _msgCore.Transport.SendRequest(_remoteEndPoint, catalogReq); }
/// <summary> /// 查询设备目录请求 /// </summary> /// <returns></returns> private SIPRequest QueryItems() { SIPURI remoteUri = new SIPURI(_sipAccount.RemoteSipId, _remoteEndPoint.ToHost(), ""); SIPURI localUri = new SIPURI(_sipAccount.LocalSipId, _localEndPoint.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, CallProperties.CreateNewTag()); SIPToHeader to = new SIPToHeader(null, remoteUri, null); SIPRequest queryReq = _m_sipTransport.GetRequest(SIPMethodsEnum.DO, remoteUri); queryReq.Header.From = from; queryReq.Header.Contact = null; queryReq.Header.Allow = null; queryReq.Header.To = to; queryReq.Header.CSeq = CallProperties.CreateNewCSeq(); queryReq.Header.CallId = CallProperties.CreateNewCallId(); queryReq.Header.ContentType = "Application/DDCP"; return(queryReq); }
/// <summary> /// 向上级平台注册 /// </summary> private void RegisterToPlatform() { string fromTag = CallProperties.CreateNewTag(); string callId = CallProperties.CreateNewCallId(); int cSeq = CallProperties.CreateNewCSeq(); string branch = CallProperties.CreateBranchId(); SIPURI localUri = new SIPURI(LocalSIPId, LocalEndPoint.ToHost(), ""); SIPURI remoteUri = new SIPURI(RemoteSIPId, RemoteEndPoint.ToHost(), ""); SIPRequest registerReq = new SIPRequest(SIPMethodsEnum.REGISTER, remoteUri); SIPViaHeader via = new SIPViaHeader(LocalEndPoint, branch); SIPViaSet viaSet = new SIPViaSet(); viaSet.PushViaHeader(via); SIPFromHeader from = new SIPFromHeader(null, localUri, fromTag); SIPToHeader to = new SIPToHeader(null, localUri, null); SIPHeader header = new SIPHeader(from, to, cSeq, callId); registerReq.Header = header; SIPContactHeader contact = new SIPContactHeader(null, localUri); header.Contact = new List <SIPContactHeader>(); header.Contact.Add(contact); header.Vias = viaSet; header.AuthenticationHeader = _auth; header.Expires = 3600; header.CSeqMethod = SIPMethodsEnum.REGISTER; header.MaxForwards = 70; header.ContentLength = 0; header.UserAgent = SIPConstants.SIP_SERVER_STRING; Transport.SendRequest(RemoteEndPoint, registerReq); }
/// <summary> /// 监控视频请求 /// </summary> /// <returns></returns> private SIPRequest InviteRequest() { SIPURI uri = new SIPURI(_cameraId, _remoteEndPoint.ToHost(), ""); SIPRequest inviteRequest = _m_sipTransport.GetRequest(SIPMethodsEnum.INVITE, uri); SIPFromHeader from = new SIPFromHeader(null, _sipRequest.URI, CallProperties.CreateNewTag()); SIPHeader header = new SIPHeader(from, inviteRequest.Header.To, CallProperties.CreateNewCSeq(), CallProperties.CreateNewCallId()); header.ContentType = "application/DDCP"; header.Expires = inviteRequest.Header.Expires; header.CSeqMethod = inviteRequest.Header.CSeqMethod; header.Vias = inviteRequest.Header.Vias; header.MaxForwards = inviteRequest.Header.MaxForwards; header.UserAgent = _userAgent; inviteRequest.Header.From = from; inviteRequest.Header = header; _realReqSession = inviteRequest; return(inviteRequest); }
/// <summary> /// 录像文件查询 /// </summary> /// <param name="startTime">开始时间</param> /// <param name="endTime">结束时间</param> public int RecordFileQuery(DateTime startTime, DateTime endTime) { lock (_msgCore.RemoteTrans) { if (!_msgCore.RemoteTrans.ContainsKey(_remoteEndPoint.ToString())) { OnSIPServiceChange(_deviceName + "-" + _deviceId + _remoteEndPoint.ToString(), SipServiceStatus.Wait); return(0); } } this.Stop(); SIPURI remoteUri = new SIPURI(_deviceId, _remoteEndPoint.ToHost(), ""); SIPURI localUri = new SIPURI(_msgCore.LocalSIPId, _msgCore.LocalEndPoint.ToHost(), ""); SIPFromHeader from = new SIPFromHeader(null, localUri, CallProperties.CreateNewTag()); SIPToHeader to = new SIPToHeader(null, remoteUri, CallProperties.CreateNewTag()); SIPRequest recordFileReq = _msgCore.Transport.GetRequest(SIPMethodsEnum.MESSAGE, remoteUri); SIPContactHeader contactHeader = new SIPContactHeader(null, localUri); recordFileReq.Header.Contact.Clear(); recordFileReq.Header.Contact.Add(contactHeader); recordFileReq.Header.Allow = null; recordFileReq.Header.From = from; recordFileReq.Header.To = to; recordFileReq.Header.UserAgent = _msgCore.UserAgent; recordFileReq.Header.CSeq = CallProperties.CreateNewCSeq(); recordFileReq.Header.CallId = CallProperties.CreateNewCallId(); recordFileReq.Header.ContentType = "application/MANSCDP+xml"; string bTime = startTime.ToString("yyyy-MM-ddTHH:mm:ss"); string eTime = endTime.ToString("yyyy-MM-ddTHH:mm:ss"); RecordQuery record = new RecordQuery() { DeviceID = _deviceId, SN = new Random().Next(1, 3000), CmdType = CommandType.RecordInfo, Secrecy = 0, StartTime = bTime, EndTime = eTime, Type = "time" }; _recordTotal = -1; string xmlBody = RecordQuery.Instance.Save <RecordQuery>(record); recordFileReq.Body = xmlBody; _msgCore.Transport.SendRequest(_remoteEndPoint, recordFileReq); DateTime recordQueryTime = DateTime.Now; while (_recordTotal < 0) { Thread.Sleep(50); if (DateTime.Now.Subtract(recordQueryTime).TotalSeconds > 2) { logger.Debug(_deviceName + "[" + _deviceId + "] 等待录像查询超时"); _recordTotal = 0; break; } } return(_recordTotal); }