| | |
| | | import org.springframework.util.StringUtils;
|
| | |
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.Address;
|
| | | import javax.sip.address.SipURI;
|
| | | import javax.sip.address.URI;
|
| | | import javax.sip.header.*;
|
| | | import javax.sip.message.Request;
|
| | | import java.lang.reflect.Field;
|
| | |
| | | //
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+ sipConfig.getId()+" 0 0 IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
|
| | | content.append("o="+ channelId+" 0 0 IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
|
| | | content.append("s=Play\r\n");
|
| | | content.append("c=IN IP4 "+ mediaServerItem.getSdpIp() +"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | |
| | | content.append("a=rtpmap:126 H264/90000\r\n");
|
| | | content.append("a=rtpmap:125 H264S/90000\r\n");
|
| | | content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
|
| | | content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
|
| | | content.append("a=fmtp:99 profile-level-id=3\r\n");
|
| | | content.append("a=rtpmap:99 H265/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
|
| | |
| | | }
|
| | | }else {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if("UDP".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 97 98 99\r\n");
|
| | | }
|
| | | content.append("a=recvonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | content.append("a=rtpmap:99 H265/90000\r\n");
|
| | | if ("TCP-PASSIVE".equals(streamMode)) { // tcp被动模式
|
| | | content.append("a=setup:passive\r\n");
|
| | | content.append("a=connection:new\r\n");
|
| | |
| | |
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+sipConfig.getId()+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
|
| | | content.append("o="+channelId+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
|
| | | content.append("s=Playback\r\n");
|
| | | content.append("u="+channelId+":0\r\n");
|
| | | content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
|
| | |
| | | content.append("a=rtpmap:126 H264/90000\r\n");
|
| | | content.append("a=rtpmap:125 H264S/90000\r\n");
|
| | | content.append("a=fmtp:125 profile-level-id=42e01e\r\n");
|
| | | content.append("a=rtpmap:99 MP4V-ES/90000\r\n");
|
| | | content.append("a=fmtp:99 profile-level-id=3\r\n");
|
| | | content.append("a=rtpmap:99 H265/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
|
| | |
| | | }
|
| | | }else {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if("UDP".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 97 98 99\r\n");
|
| | | }
|
| | | content.append("a=recvonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:99 H265/90000\r\n");
|
| | | if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
|
| | | content.append("a=setup:passive\r\n");
|
| | | content.append("a=connection:new\r\n");
|
| | |
| | |
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+sipConfig.getId()+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
|
| | | content.append("o="+channelId+" 0 0 IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
|
| | | content.append("s=Download\r\n");
|
| | | content.append("u="+channelId+":0\r\n");
|
| | | content.append("c=IN IP4 "+mediaServerItem.getSdpIp()+"\r\n");
|
| | |
| | | }
|
| | | }else {
|
| | | if("TCP-PASSIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if ("TCP-ACTIVE".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" TCP/RTP/AVP 96 97 98 99\r\n");
|
| | | }else if("UDP".equals(streamMode)) {
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 98 97\r\n");
|
| | | content.append("m=video "+ ssrcInfo.getPort() +" RTP/AVP 96 97 98 99\r\n");
|
| | | }
|
| | | content.append("a=recvonly\r\n");
|
| | | content.append("a=rtpmap:96 PS/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:97 MPEG4/90000\r\n");
|
| | | content.append("a=rtpmap:98 H264/90000\r\n");
|
| | | content.append("a=rtpmap:99 H265/90000\r\n");
|
| | | if("TCP-PASSIVE".equals(streamMode)){ // tcp被动模式
|
| | | content.append("a=setup:passive\r\n");
|
| | | content.append("a=connection:new\r\n");
|
| | |
| | | (MediaServerItem mediaServerItemInUse, JSONObject json)->{
|
| | | hookEvent.call(new InviteStreamInfo(mediaServerItem, json, callIdHeader.getCallId(), "rtp", ssrcInfo.getStream()));
|
| | | subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey);
|
| | | subscribeKey.put("regist", false);
|
| | | subscribeKey.put("schema", "rtmp");
|
| | | // 添加流注销的订阅,注销了后向设备发送bye
|
| | | subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey,
|
| | | (MediaServerItem mediaServerItemForEnd, JSONObject jsonForEnd)->{
|
| | | ClientTransaction transaction = streamSession.getTransaction(device.getDeviceId(), channelId, ssrcInfo.getStream(), callIdHeader.getCallId());
|
| | | if (transaction != null) {
|
| | | logger.info("[录像]下载结束, 发送BYE");
|
| | | streamByeCmd(device.getDeviceId(), channelId, ssrcInfo.getStream(), callIdHeader.getCallId());
|
| | | }
|
| | | });
|
| | | });
|
| | |
|
| | | Request request = headerProvider.createPlaybackInviteRequest(device, channelId, content.toString(), null, "fromplybck" + tm, null, callIdHeader, ssrcInfo.getSsrc());
|
| | |
| | | @Override
|
| | | public void streamByeCmd(String deviceId, String channelId, String stream, String callId, SipSubscribe.Event okEvent) {
|
| | | try {
|
| | | SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, null, stream);
|
| | | ClientTransaction transaction = streamSession.getTransactionByStream(deviceId, channelId, stream);
|
| | | SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, callId, stream);
|
| | | ClientTransaction transaction = streamSession.getTransaction(deviceId, channelId, stream, callId);
|
| | |
|
| | | if (transaction == null) {
|
| | | if (transaction == null ) {
|
| | | logger.warn("[ {} -> {}]停止视频流的时候发现事务已丢失", deviceId, channelId);
|
| | | SipSubscribe.EventResult<Object> eventResult = new SipSubscribe.EventResult<>();
|
| | | if (okEvent != null) {
|
| | |
| | | }
|
| | | SIPDialog dialog;
|
| | | if (callId != null) {
|
| | | dialog = streamSession.getDialogByCallId(deviceId, channelId, callId);
|
| | | dialog = streamSession.getDialogByCallId(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), callId);
|
| | | }else {
|
| | | if (stream == null) {
|
| | | if (stream == null && ssrcTransaction == null && ssrcTransaction.getStream() == null) {
|
| | | return;
|
| | | }
|
| | | dialog = streamSession.getDialogByStream(deviceId, channelId, stream);
|
| | | dialog = streamSession.getDialogByStream(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
| | | }
|
| | | if (ssrcTransaction != null) {
|
| | | MediaServerItem mediaServerItem = mediaServerService.getOne(ssrcTransaction.getMediaServerId());
|
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcTransaction.getSsrc());
|
| | | mediaServerService.closeRTPServer(deviceId, channelId, ssrcTransaction.getStream());
|
| | | streamSession.remove(deviceId, channelId, ssrcTransaction.getStream());
|
| | | }
|
| | | mediaServerService.releaseSsrc(ssrcTransaction.getMediaServerId(), ssrcTransaction.getSsrc());
|
| | | mediaServerService.closeRTPServer(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
| | | streamSession.remove(ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
| | |
|
| | | if (dialog == null) {
|
| | | logger.warn("[ {} -> {}]停止视频流的时候发现对话已丢失", deviceId, channelId);
|
| | | logger.warn("[ {} -> {}]停止视频流的时候发现对话已丢失", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
|
| | | return;
|
| | | }
|
| | | SipStack sipStack = udpSipProvider.getSipStack();
|
| | |
| | |
|
| | | Request request;
|
| | | if (dialog != null) {
|
| | | logger.info("发送移动位置订阅消息时 dialog的状态为: {}", dialog.getState());
|
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | request = dialog.createRequest(Request.SUBSCRIBE);
|
| | | ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
| | | request.setExpires(expiresHeader);
|
| | |
|
| | | request.setRequestURI(requestURI);
|
| | |
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | request.setContent(subscribePostitionXml.toString(), contentTypeHeader);
|
| | | ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
|
| | | request.addHeader(expireHeader);
|
| | |
|
| | | CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
| | | cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE));
|
| | | request.removeHeader(CSeqHeader.NAME);
|
| | | request.addHeader(cSeqHeader);
|
| | | }else {
|
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | | CallIdHeader callIdHeader = device.getTransport().equals("TCP") ? tcpSipProvider.getNewCallId()
|
| | |
| | |
|
| | | Request request;
|
| | | if (dialog != null) {
|
| | | logger.info("发送目录订阅消息时 dialog的状态为: {}", dialog.getState());
|
| | | SipURI requestURI = sipFactory.createAddressFactory().createSipURI(device.getDeviceId(), device.getHostAddress());
|
| | | request = dialog.createRequest(Request.SUBSCRIBE);
|
| | | ExpiresHeader expiresHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForCatalog());
|
| | | request.setExpires(expiresHeader);
|
| | |
|
| | | request.setRequestURI(requestURI);
|
| | |
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("Application", "MANSCDP+xml");
|
| | | request.setContent(cmdXml.toString(), contentTypeHeader);
|
| | | ExpiresHeader expireHeader = sipFactory.createHeaderFactory().createExpiresHeader(device.getSubscribeCycleForMobilePosition());
|
| | | request.addHeader(expireHeader);
|
| | |
|
| | | CSeqHeader cSeqHeader = (CSeqHeader)request.getHeader(CSeqHeader.NAME);
|
| | | cSeqHeader.setSeqNumber(redisCatchStorage.getCSEQ(Request.SUBSCRIBE));
|
| | | request.removeHeader(CSeqHeader.NAME);
|
| | | request.addHeader(cSeqHeader);
|
| | |
|
| | | }else {
|
| | | String tm = Long.toString(System.currentTimeMillis());
|
| | |
|
| | |
| | | sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> {
|
| | | errorEvent.response(eventResult);
|
| | | sipSubscribe.removeErrorSubscribe(eventResult.callId);
|
| | | sipSubscribe.removeOkSubscribe(eventResult.callId);
|
| | | }));
|
| | | }
|
| | | // 添加订阅
|
| | |
| | | sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult ->{
|
| | | okEvent.response(eventResult);
|
| | | sipSubscribe.removeOkSubscribe(eventResult.callId);
|
| | | sipSubscribe.removeErrorSubscribe(eventResult.callId);
|
| | | });
|
| | | }
|
| | |
|
| | |
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | |
| | | @Override
|
| | | public void playbackControlCmd(Device device, StreamInfo streamInfo, String content,SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) {
|
| | | try {
|
| | | Request request = headerProvider.createInfoRequest(device, streamInfo, content);
|
| | | if (request == null) {
|
| | | return;
|
| | | }
|
| | | logger.info(request.toString());
|
| | | ClientTransaction clientTransaction = null;
|
| | | if ("TCP".equals(device.getTransport())) {
|
| | | clientTransaction = tcpSipProvider.getNewClientTransaction(request);
|
| | | } else if ("UDP".equals(device.getTransport())) {
|
| | | clientTransaction = udpSipProvider.getNewClientTransaction(request);
|
| | | }
|
| | | CallIdHeader callIdHeader = (CallIdHeader)request.getHeader(CallIdHeader.NAME);
|
| | | if(errorEvent != null) {
|
| | | sipSubscribe.addErrorSubscribe(callIdHeader.getCallId(), (eventResult -> {
|
| | | errorEvent.response(eventResult);
|
| | | sipSubscribe.removeErrorSubscribe(eventResult.callId);
|
| | | sipSubscribe.removeOkSubscribe(eventResult.callId);
|
| | | }));
|
| | | }
|
| | | |
| | | if(okEvent != null) {
|
| | | sipSubscribe.addOkSubscribe(callIdHeader.getCallId(), eventResult -> {
|
| | | okEvent.response(eventResult);
|
| | | sipSubscribe.removeOkSubscribe(eventResult.callId);
|
| | | sipSubscribe.removeErrorSubscribe(eventResult.callId);
|
| | | });
|
| | | }
|
| | | clientTransaction.sendRequest();
|
| | | |
| | | } catch (SipException | ParseException | InvalidArgumentException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | @Override
|
| | | public boolean sendAlarmMessage(Device device, DeviceAlarm deviceAlarm) {
|