| | |
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamPush;
|
| | | import com.genersoft.iot.vmp.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.gb28181.utils.NumericUtil;
|
| | | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
| | | import com.genersoft.iot.vmp.service.IMediaServerService;
|
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
| | | import com.genersoft.iot.vmp.utils.GitUtil;
|
| | | import gov.nist.javax.sip.SipProviderImpl;
|
| | | import com.genersoft.iot.vmp.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.utils.GitUtil;
|
| | | import gov.nist.javax.sip.message.SIPRequest;
|
| | | import gov.nist.javax.sip.message.SIPResponse;
|
| | | import org.slf4j.Logger;
|
| | |
| | | import javax.sip.ResponseEvent;
|
| | | import javax.sip.SipException;
|
| | | import javax.sip.header.CallIdHeader;
|
| | | import javax.sip.*;
|
| | | import javax.sip.header.*;
|
| | | import javax.sip.message.Request;
|
| | | import java.text.ParseException;
|
| | |
|
| | |
| | |
|
| | | @Autowired
|
| | | private ZlmHttpHookSubscribe subscribe;
|
| | |
|
| | | @Autowired
|
| | | private GitUtil gitUtil;
|
| | |
|
| | |
|
| | |
|
| | |
| | | if (inviteStreamCallback != null) {
|
| | | inviteStreamCallback.call(new InviteStreamInfo(mediaServerItem, null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), "rtp", ssrcInfo.getStream()));
|
| | | }
|
| | |
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent, okEvent -> {
|
| | | ResponseEvent responseEvent = (ResponseEvent) okEvent.event;
|
| | | SIPResponse response = (SIPResponse) responseEvent.getResponse();
|
| | | streamSession.put(device.getDeviceId(), channelId,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()).getCallId(), ssrcInfo.getStream(), ssrcInfo.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.download);
|
| | | streamSession.put(device.getDeviceId(), channelId, response.getCallIdHeader().getCallId(), ssrcInfo.getStream(), ssrcInfo.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.download);
|
| | | });
|
| | | }
|
| | |
|
| | | @Override
|
| | | public void talkStreamCmd(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, String callId, ZlmHttpHookSubscribe.Event event, ZlmHttpHookSubscribe.Event eventForPush, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | public void talkStreamCmd(MediaServerItem mediaServerItem, SendRtpItem sendRtpItem, Device device, String channelId, String callId, ZlmHttpHookSubscribe.Event event, ZlmHttpHookSubscribe.Event eventForPush, SipSubscribe.Event okEvent, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | |
|
| | | String stream = ssrcInfo.getStream();
|
| | | String stream = sendRtpItem.getStream();
|
| | |
|
| | | if (device == null) {
|
| | | return;
|
| | | }
|
| | | if (!mediaServerItem.isRtpEnable()) {
|
| | | // 单端口暂不支持语音对讲
|
| | | logger.info("[语音对讲] 单端口暂不支持此操作");
|
| | | // 单端口暂不支持语音喊话
|
| | | logger.info("[语音喊话] 单端口暂不支持此操作");
|
| | | return;
|
| | | }
|
| | |
|
| | | logger.info("[语音对讲] {} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getIp(), ssrcInfo.getPort());
|
| | | logger.info("[语音喊话] {} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getIp(), sendRtpItem.getPort());
|
| | | HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed("rtp", stream, true, "rtsp", mediaServerItem.getId());
|
| | | subscribe.addSubscribe(hookSubscribeForStreamChange, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
|
| | | if (event != null) {
|
| | |
| | | }
|
| | | });
|
| | |
|
| | | CallIdHeader callIdHeader = device.getTransport().equalsIgnoreCase("TCP") ? tcpSipProvider.getNewCallId()
|
| | | : udpSipProvider.getNewCallId();
|
| | | CallIdHeader callIdHeader = sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()), device.getTransport());
|
| | | callIdHeader.setCallId(callId);
|
| | | HookSubscribeForStreamPush hookSubscribeForStreamPush = HookSubscribeFactory.on_publish("rtp", stream, null, mediaServerItem.getId());
|
| | | subscribe.addSubscribe(hookSubscribeForStreamPush, (MediaServerItem mediaServerItemInUse, JSONObject json) -> {
|
| | |
| | | content.append("c=IN IP4 " + mediaServerItem.getSdpIp() + "\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | |
|
| | | content.append("m=audio " + ssrcInfo.getPort() + " RTP/AVP 8\r\n");
|
| | | content.append("m=audio " + sendRtpItem.getPort() + " TCP/RTP/AVP 8\r\n");
|
| | | content.append("a=setup:passive\r\n");
|
| | | content.append("a=connection:new\r\n");
|
| | | content.append("a=sendrecv\r\n");
|
| | | content.append("a=rtpmap:8 PCMA/8000\r\n");
|
| | |
|
| | | content.append("y=" + ssrcInfo.getSsrc() + "\r\n");//ssrc
|
| | | content.append("y=" + sendRtpItem.getSsrc() + "\r\n");//ssrc
|
| | | // f字段:f= v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
| | | content.append("f=v/////a/1/8/1" + "\r\n");
|
| | |
|
| | | Request request = headerProvider.createInviteRequest(device, channelId, content.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, ssrcInfo.getSsrc(), callIdHeader);
|
| | | transmitRequest(device.getTransport(), request, (e -> {
|
| | | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
|
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
|
| | | Request request = headerProvider.createInviteRequest(device, channelId, content.toString(),
|
| | | SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null, sendRtpItem.getSsrc(), callIdHeader);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, (e -> {
|
| | | streamSession.remove(device.getDeviceId(), channelId, sendRtpItem.getStream());
|
| | | mediaServerService.releaseSsrc(mediaServerItem.getId(), sendRtpItem.getSsrc());
|
| | | errorEvent.response(e);
|
| | | }), e -> {
|
| | | // 这里为例避免一个通道的点播只有一个callID这个参数使用一个固定值
|
| | | ResponseEvent responseEvent = (ResponseEvent) e.event;
|
| | | SIPResponse response = (SIPResponse) responseEvent.getResponse();
|
| | | streamSession.put(device.getDeviceId(), channelId, "talk", stream, ssrcInfo.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.play);
|
| | | streamSession.put(device.getDeviceId(), channelId, "talk", stream, sendRtpItem.getSsrc(), mediaServerItem.getId(), response, VideoStreamSessionManager.SessionType.talk);
|
| | | okEvent.response(e);
|
| | | });
|
| | | }
|
| | |
| | | * 视频流停止, 不使用回调
|
| | | */
|
| | | @Override
|
| | | public synchronized void streamByeCmd(Device device, String channelId, String stream, String callId) throws InvalidArgumentException, ParseException, SipException, SsrcTransactionNotFoundException {
|
| | | public void streamByeCmd(Device device, String channelId, String stream, String callId) throws InvalidArgumentException, ParseException, SipException, SsrcTransactionNotFoundException {
|
| | | streamByeCmd(device, channelId, stream, callId, null);
|
| | | }
|
| | |
|
| | |
| | | * 视频流停止
|
| | | */
|
| | | @Override
|
| | | public synchronized void streamByeCmd(Device device, String channelId, String stream, String callId, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException, SsrcTransactionNotFoundException {
|
| | | SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, callId, stream);
|
| | | public void streamByeCmd(Device device, String channelId, String stream, String callId, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException, SsrcTransactionNotFoundException {
|
| | | SsrcTransaction ssrcTransaction;
|
| | | if (callId != null) {
|
| | | ssrcTransaction = streamSession.getSsrcTransaction(null, null, callId, null);
|
| | | }else {
|
| | | ssrcTransaction = streamSession.getSsrcTransaction(device.getDeviceId(), channelId, null, stream);
|
| | | }
|
| | | if (ssrcTransaction == null) {
|
| | | throw new SsrcTransactionNotFoundException(device.getDeviceId(), channelId, callId, stream);
|
| | | }
|
| | |
| | | }
|
| | |
|
| | | @Override
|
| | | public synchronized void streamByeCmd(Device device, String channelId, SipTransactionInfo sipTransactionInfo, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException, SsrcTransactionNotFoundException {
|
| | | public void streamByeCmd(Device device, String channelId, SipTransactionInfo sipTransactionInfo, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException, SsrcTransactionNotFoundException {
|
| | | Request byteRequest = headerProvider.createByteRequest(device, channelId, sipTransactionInfo);
|
| | | transmitRequest(device.getTransport(), byteRequest, null, okEvent);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), byteRequest, null, okEvent);
|
| | | }
|
| | |
|
| | | /**
|
| | | /**
|
| | | * 语音广播
|
| | | *
|
| | | * @param device 视频设备
|
| | |
| | | broadcastXml.append("<TargetID>" + channelId + "</TargetID>\r\n");
|
| | | broadcastXml.append("</Notify>\r\n");
|
| | |
|
| | |
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, broadcastXml.toString(), SipUtils.getNewViaTag(), SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent, okEvent);
|
| | |
|
| | | }
|
| | |
|
| | |
| | | * @param recordCmdStr 录像命令:Record / StopRecord
|
| | | */
|
| | | @Override
|
| | | public void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | public void recordCmd(Device device, String channelId, String recordCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | | cmdXml.append("<?xml version=\"1.0\" encoding=\"" + charset + "\"?>\r\n");
|
| | |
| | |
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent,okEvent);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param guardCmdStr "SetGuard"/"ResetGuard"
|
| | | */
|
| | | @Override
|
| | | public void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | public void guardCmd(Device device, String guardCmdStr, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | |
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | | cmdXml.append("<GuardCmd>" + guardCmdStr + "</GuardCmd>\r\n");
|
| | | cmdXml.append("</Control>\r\n");
|
| | |
|
| | |
|
| | | |
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent,okEvent);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * @param device 视频设备
|
| | | */
|
| | | @Override
|
| | | public void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | public void alarmCmd(Device device, String alarmMethod, String alarmType, SipSubscribe.Event errorEvent, SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | |
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | |
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent,okEvent);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | * 看守位控制命令
|
| | | *
|
| | | * @param device 视频设备
|
| | | * @param channelId 通道id,非通道则是设备本身
|
| | | * @param frontCmd 上级平台的指令,如果存在则直接下发
|
| | | * @param enabled 看守位使能:1 = 开启,0 = 关闭
|
| | | * @param resetTime 自动归位时间间隔,开启看守位时使用,单位:秒(s)
|
| | | * @param presetIndex 调用预置位编号,开启看守位时使用,取值范围0~255
|
| | | */
|
| | | @Override
|
| | | public void homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | | public void homePositionCmd(Device device, String channelId, String enabled, String resetTime, String presetIndex, SipSubscribe.Event errorEvent,SipSubscribe.Event okEvent) throws InvalidArgumentException, SipException, ParseException {
|
| | |
|
| | | StringBuffer cmdXml = new StringBuffer(200);
|
| | | String charset = device.getCharset();
|
| | |
| | |
|
| | |
|
| | | Request request = headerProvider.createMessageRequest(device, cmdXml.toString(), null, SipUtils.getNewFromTag(), null,sipSender.getNewCallIdHeader(sipLayer.getLocalIp(device.getLocalIp()),device.getTransport()));
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent);
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()), request, errorEvent,okEvent);
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | logger.debug("拉框信令: " + request.toString());
|
| | | sipSender.transmitRequest(sipLayer.getLocalIp(device.getLocalIp()),request);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|