| | |
| | | import com.genersoft.iot.vmp.common.StreamInfo;
|
| | | import com.genersoft.iot.vmp.conf.DynamicTask;
|
| | | import com.genersoft.iot.vmp.conf.SipConfig;
|
| | | import com.genersoft.iot.vmp.conf.UserSetup;
|
| | | import com.genersoft.iot.vmp.conf.UserSetting;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.Device;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.InviteStreamCallback;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.InviteStreamInfo;
|
| | |
| | | import com.genersoft.iot.vmp.service.IMediaServerService;
|
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
| | | import gov.nist.javax.sip.SipProviderImpl;
|
| | | import gov.nist.javax.sip.SipStackImpl;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | |
| | | import javax.sip.*;
|
| | | import javax.sip.address.SipURI;
|
| | | import javax.sip.header.CallIdHeader;
|
| | | import javax.sip.header.ContentTypeHeader;
|
| | | import javax.sip.header.ExpiresHeader;
|
| | | import javax.sip.header.ViaHeader;
|
| | | import javax.sip.message.Request;
|
| | | import java.lang.reflect.Field;
|
| | |
| | | private SipConfig sipConfig;
|
| | |
|
| | | @Autowired
|
| | | private SipFactory sipFactory;
|
| | |
|
| | | @Autowired
|
| | | @Qualifier(value="tcpSipProvider")
|
| | | private SipProviderImpl tcpSipProvider;
|
| | |
|
| | |
| | | private VideoStreamSessionManager streamSession;
|
| | |
|
| | | @Autowired
|
| | | private IVideoManagerStorager storager;
|
| | | private IVideoManagerStorage storager;
|
| | |
|
| | | @Autowired
|
| | | private IRedisCatchStorage redisCatchStorage;
|
| | |
|
| | | @Autowired
|
| | | private UserSetup userSetup;
|
| | | private UserSetting userSetting;
|
| | |
|
| | | @Autowired
|
| | | private ZLMHttpHookSubscribe subscribe;
|
| | |
| | | try {
|
| | | String cmdStr= cmdString(leftRight, upDown, inOut, moveSpeed, zoomSpeed);
|
| | | StringBuffer ptzXml = new StringBuffer(200);
|
| | | ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | ptzXml.append("<Control>\r\n");
|
| | | ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | | ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
|
| | | ptzXml.append("<Info>\r\n");
|
| | | ptzXml.append("<ControlPriority>5</ControlPriority>\r\n");
|
| | | ptzXml.append("</Info>\r\n");
|
| | | ptzXml.append("</Control>\r\n");
|
| | |
|
| | |
| | | String cmdStr= frontEndCmdString(cmdCode, parameter1, parameter2, combineCode2);
|
| | | logger.debug("控制字符串:" + cmdStr);
|
| | | StringBuffer ptzXml = new StringBuffer(200);
|
| | | ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | ptzXml.append("<Control>\r\n");
|
| | | ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | | ptzXml.append("<PTZCmd>" + cmdStr + "</PTZCmd>\r\n");
|
| | | ptzXml.append("<Info>\r\n");
|
| | | ptzXml.append("<ControlPriority>5</ControlPriority>\r\n");
|
| | | ptzXml.append("</Info>\r\n");
|
| | | ptzXml.append("</Control>\r\n");
|
| | |
|
| | |
| | | * @param cmdString 前端控制指令串
|
| | | */
|
| | | @Override
|
| | | public boolean fronEndCmd(Device device, String channelId, String cmdString) {
|
| | | public boolean fronEndCmd(Device device, String channelId, String cmdString, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) {
|
| | | try {
|
| | | StringBuffer ptzXml = new StringBuffer(200);
|
| | | ptzXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | ptzXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | ptzXml.append("<Control>\r\n");
|
| | | ptzXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | ptzXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | ptzXml.append("<DeviceID>" + channelId + "</DeviceID>\r\n");
|
| | | ptzXml.append("<PTZCmd>" + cmdString + "</PTZCmd>\r\n");
|
| | | ptzXml.append("<Info>\r\n");
|
| | | ptzXml.append("<ControlPriority>5</ControlPriority>\r\n");
|
| | | ptzXml.append("</Info>\r\n");
|
| | | ptzXml.append("</Control>\r\n");
|
| | |
|
| | |
| | | : udpSipProvider.getNewCallId();
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, ptzXml.toString(), "z9hG4bK-ViaPtz-" + tm, "FromPtz" + tm, null, callIdHeader);
|
| | | transmitRequest(device, request);
|
| | | transmitRequest(device, request, errorEvent, okEvent);
|
| | | return true;
|
| | | } catch (SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | |
| | | content.append("c=IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | |
|
| | | if (userSetup.isSeniorSdp()) {
|
| | | if (userSetting.isSeniorSdp()) {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | |
| | |
|
| | | String streamMode = device.getStreamMode().toUpperCase();
|
| | |
|
| | | if (userSetup.isSeniorSdp()) {
|
| | | if (userSetting.isSeniorSdp()) {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | |
| | |
|
| | | String streamMode = device.getStreamMode().toUpperCase();
|
| | |
|
| | | if (userSetup.isSeniorSdp()) {
|
| | | if (userSetting.isSeniorSdp()) {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 126 125 99 34 98 97\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | |
| | | Request byeRequest = dialog.createRequest(Request.BYE);
|
| | | SipURI byeURI = (SipURI) byeRequest.getRequestURI();
|
| | | SIPRequest request = (SIPRequest)transaction.getRequest();
|
| | | byeURI.setHost(request.getRemoteAddress().getHostName());
|
| | | byeURI.setHost(request.getRemoteAddress().getHostAddress());
|
| | | byeURI.setPort(request.getRemotePort());
|
| | | ViaHeader viaHeader = (ViaHeader) byeRequest.getHeader(ViaHeader.NAME);
|
| | | String protocol = viaHeader.getTransport().toUpperCase();
|
| | |
| | | public boolean audioBroadcastCmd(Device device) {
|
| | | try {
|
| | | StringBuffer broadcastXml = new StringBuffer(200);
|
| | | broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | broadcastXml.append("<Notify>\r\n");
|
| | | broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
|
| | | broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public void audioBroadcastCmd(Device device, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer broadcastXml = new StringBuffer(200);
|
| | | broadcastXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | broadcastXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | broadcastXml.append("<Notify>\r\n");
|
| | | broadcastXml.append("<CmdType>Broadcast</CmdType>\r\n");
|
| | | broadcastXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean teleBootCmd(Device device) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean iFrameCmd(Device device, String channelId) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | String heartBeatInterval, String heartBeatCount, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Control>\r\n");
|
| | | cmdXml.append("<CmdType>DeviceConfig</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | String startTime, String endTime, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Query>\r\n");
|
| | | cmdXml.append("<CmdType>Alarm</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean deviceConfigQuery(Device device, String channelId, String configType, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Query>\r\n");
|
| | | cmdXml.append("<CmdType>ConfigDownload</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | public boolean presetQuery(Device device, String channelId, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | cmdXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | cmdXml.append("<Query>\r\n");
|
| | | cmdXml.append("<CmdType>PresetQuery</CmdType>\r\n");
|
| | | cmdXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | |
| | | * 订阅、取消订阅移动位置
|
| | | *
|
| | | * @param device 视频设备
|
| | | * @param expires 订阅超时时间
|
| | | * @param interval 上报时间间隔
|
| | | * @return true = 命令发送成功
|
| | | */
|
| | | public boolean mobilePositionSubscribe(Device device, int expires, int interval) {
|
| | | public boolean mobilePositionSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent ,SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer subscribePostitionXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | subscribePostitionXml.append("<CmdType>MobilePosition</CmdType>\r\n");
|
| | | subscribePostitionXml.append("<SN>" + (int)((Math.random()*9+1)*100000) + "</SN>\r\n");
|
| | | subscribePostitionXml.append("<DeviceID>" + device.getDeviceId() + "</DeviceID>\r\n");
|
| | | if (expires > 0) {
|
| | | subscribePostitionXml.append("<Interval>" + String.valueOf(interval) + "</Interval>\r\n");
|
| | | if (device.getSubscribeCycleForMobilePosition() > 0) {
|
| | | subscribePostitionXml.append("<Interval>" + String.valueOf(device.getMobilePositionSubmissionInterval()) + "</Interval>\r\n");
|
| | | }
|
| | | subscribePostitionXml.append("</Query>\r\n");
|
| | |
|
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | |
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | |
|
| | | Request request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, expires, "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
| | | transmitRequest(device, request);
|
| | | Request request;
|
| | | if (dialog != null) {
|
| | | logger.info("发送移动位置订阅消息时 dialog的状态为: {}", dialog.getState());
|
| | | request = dialog.createRequest(Request.SUBSCRIBE);
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
|
| | | ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
|
| | | request.addHeader(expireHeader);
|
| | | }else {
|
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | | request = headerProvider.createSubscribeRequest(device, subscribePostitionXml.toString(), "z9hG4bK-viaPos-" + tm, "fromTagPos" + tm, null, device.getSubscribeCycleForMobilePosition(), "presence" ,callIdHeader); //Position;id=" + tm.substring(tm.length() - 4));
|
| | | }
|
| | | transmitRequest(device, request, errorEvent, okEvent);
|
| | |
|
| | | return true;
|
| | |
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean catalogSubscribe(Device device, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
| | | public boolean catalogSubscribe(Device device, Dialog dialog, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) {
|
| | | try {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | public boolean dragZoomCmd(Device device, String channelId, String cmdString) {
|
| | | try {
|
| | | StringBuffer dragXml = new StringBuffer(200);
|
| | | dragXml.append("<?xml version=\"1.0\" ?>\r\n");
|
| | | String charset = device.getCharset();
|
| | | dragXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | | dragXml.append("<Control>\r\n");
|
| | | dragXml.append("<CmdType>DeviceControl</CmdType>\r\n");
|
| | | dragXml.append("<SN>" + (int) ((Math.random() * 9 + 1) * 100000) + "</SN>\r\n");
|