File was renamed from src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java |
| | |
| | | package com.genersoft.iot.vmp.gb28181.transmit.request.impl;
|
| | |
|
| | | import javax.sdp.*;
|
| | | import javax.sip.*;
|
| | | import javax.sip.address.Address;
|
| | | import javax.sip.address.SipURI;
|
| | | import javax.sip.header.*;
|
| | | import javax.sip.message.Request;
|
| | | import javax.sip.message.Response;
|
| | | package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl; |
| | |
|
| | | import com.genersoft.iot.vmp.gb28181.bean.*;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.request.SIPRequestAbstractProcessor;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.ISIPRequestProcessor; |
| | | import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorParent; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
| | | import com.genersoft.iot.vmp.service.IMediaServerService;
|
| | | import com.genersoft.iot.vmp.service.IPlayService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
| | | import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
|
| | | import com.genersoft.iot.vmp.service.IPlayService;
|
| | | import gov.nist.javax.sip.address.AddressImpl;
|
| | | import gov.nist.javax.sip.address.SipUri;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.InitializingBean; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | |
|
| | | import javax.sdp.*; |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.RequestEvent; |
| | | import javax.sip.ServerTransaction; |
| | | import javax.sip.SipException; |
| | | import javax.sip.address.SipURI; |
| | | import javax.sip.header.FromHeader; |
| | | import javax.sip.message.Request; |
| | | import javax.sip.message.Response; |
| | | import java.text.ParseException;
|
| | | import java.util.Vector;
|
| | |
|
| | | /**
|
| | | * @Description:处理INVITE请求
|
| | | * @author: panll
|
| | | * @date: 2021年1月14日
|
| | | * SIP命令类型: INVITE请求 |
| | | */
|
| | | @SuppressWarnings("rawtypes")
|
| | | public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
|
| | | @Component |
| | | public class InviteRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor { |
| | |
|
| | | private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
|
| | | private final static Logger logger = LoggerFactory.getLogger(InviteRequestProcessor.class); |
| | |
|
| | | private String method = "INVITE"; |
| | | |
| | | @Autowired |
| | | private SIPCommanderFroPlatform cmderFroPlatform;
|
| | |
|
| | | @Autowired |
| | | private IVideoManagerStorager storager;
|
| | |
|
| | | @Autowired |
| | | private IRedisCatchStorage redisCatchStorage;
|
| | |
|
| | | @Autowired |
| | | private SIPCommander cmder;
|
| | |
|
| | | @Autowired |
| | | private IPlayService playService;
|
| | |
|
| | | @Autowired |
| | | private ZLMRTPServerFactory zlmrtpServerFactory;
|
| | |
|
| | | @Autowired |
| | | private IMediaServerService mediaServerService;
|
| | |
|
| | | public ZLMRTPServerFactory getZlmrtpServerFactory() {
|
| | | return zlmrtpServerFactory;
|
| | | }
|
| | | @Autowired |
| | | private SIPProcessorObserver sipProcessorObserver; |
| | |
|
| | | public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
|
| | | this.zlmrtpServerFactory = zlmrtpServerFactory;
|
| | | @Override |
| | | public void afterPropertiesSet() throws Exception { |
| | | // 添加消息处理的订阅 |
| | | sipProcessorObserver.addRequestProcessor(method, this); |
| | | }
|
| | |
|
| | | /**
|
| | |
| | | String mediaServerId = gbStream.getMediaServerId();
|
| | | mediaServerItem = mediaServerService.getOne(mediaServerId);
|
| | | if (mediaServerItem == null) {
|
| | | logger.info("[ app={}, stream={} ]zlm找不到,返回410",gbStream.getApp(), gbStream.getStream());
|
| | | logger.info("[ app={}, stream={} ]找不到zlm {},返回410",gbStream.getApp(), gbStream.getStream(), mediaServerId); |
| | | responseAck(evt, Response.GONE, "media server not found");
|
| | | return;
|
| | | }
|
| | |
| | | // 解析sdp消息, 使用jainsip 自带的sdp解析方式
|
| | | String contentString = new String(request.getRawContent());
|
| | |
|
| | | // jainSip不支持y=字段, 移除移除以解析。
|
| | | // jainSip不支持y=字段, 移除以解析。 |
| | | int ssrcIndex = contentString.indexOf("y=");
|
| | | // 检查是否有y字段 |
| | | String ssrcDefault = "0000000000"; |
| | | String ssrc; |
| | | SessionDescription sdp; |
| | | if (ssrcIndex >= 0) { |
| | | //ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段
|
| | | String ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
|
| | | ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); |
| | | String substring = contentString.substring(0, contentString.indexOf("y="));
|
| | | SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
|
| | | sdp = SdpFactory.getInstance().createSessionDescription(substring); |
| | | }else { |
| | | ssrc = ssrcDefault; |
| | | sdp = SdpFactory.getInstance().createSessionDescription(contentString); |
| | | } |
| | |
|
| | | // 获取支持的格式
|
| | | Vector mediaDescriptions = sdp.getMediaDescriptions(true);
|
| | |
| | |
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+"00000"+" 0 0 IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n");
|
| | | content.append("o="+ channelId +" 0 0 IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n"); |
| | | content.append("s=Play\r\n");
|
| | | content.append("c=IN IP4 "+mediaServerItemInUSe.getSdpIp()+"\r\n");
|
| | | content.append("t=0 0\r\n");
|
| | |
| | | // 未知错误。直接转发设备点播的错误
|
| | | Response response = null;
|
| | | try {
|
| | | response = getMessageFactory().createResponse(event.getResponse().getStatusCode(), evt.getRequest());
|
| | | response = getMessageFactory().createResponse(event.statusCode, evt.getRequest()); |
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | |
| | | // TODO 添加对tcp的支持
|
| | | StringBuffer content = new StringBuffer(200);
|
| | | content.append("v=0\r\n");
|
| | | content.append("o="+"00000"+" 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");
|
| | |
| | | } catch (SdpException e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | | /***
|
| | | * 回复状态码
|
| | | * 100 trying
|
| | | * 200 OK
|
| | | * 400
|
| | | * 404
|
| | | * @param evt
|
| | | * @throws SipException
|
| | | * @throws InvalidArgumentException
|
| | | * @throws ParseException
|
| | | */
|
| | | private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (statusCode >= 200) {
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | | }
|
| | |
|
| | | private void responseAck(RequestEvent evt, int statusCode, String msg) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
|
| | | response.setReasonPhrase(msg);
|
| | | ServerTransaction serverTransaction = getServerTransaction(evt);
|
| | | serverTransaction.sendResponse(response);
|
| | | if (statusCode >= 200) {
|
| | | if (serverTransaction.getDialog() != null) serverTransaction.getDialog().delete();
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * 回复带sdp的200
|
| | | * @param evt
|
| | | * @param sdp
|
| | | * @throws SipException
|
| | | * @throws InvalidArgumentException
|
| | | * @throws ParseException
|
| | | */
|
| | | private void responseAck(RequestEvent evt, String sdp) throws SipException, InvalidArgumentException, ParseException {
|
| | | Response response = getMessageFactory().createResponse(Response.OK, evt.getRequest());
|
| | | SipFactory sipFactory = SipFactory.getInstance();
|
| | | ContentTypeHeader contentTypeHeader = sipFactory.createHeaderFactory().createContentTypeHeader("APPLICATION", "SDP");
|
| | | response.setContent(sdp, contentTypeHeader);
|
| | |
|
| | | SipURI sipURI = (SipURI)evt.getRequest().getRequestURI();
|
| | |
|
| | | Address concatAddress = sipFactory.createAddressFactory().createAddress(
|
| | | sipFactory.createAddressFactory().createSipURI(sipURI.getUser(), sipURI.getHost()+":"+sipURI.getPort()
|
| | | ));
|
| | | response.addHeader(sipFactory.createHeaderFactory().createContactHeader(concatAddress));
|
| | | getServerTransaction(evt).sendResponse(response);
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | |
|
| | | public SIPCommanderFroPlatform getCmderFroPlatform() {
|
| | | return cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public void setCmderFroPlatform(SIPCommanderFroPlatform cmderFroPlatform) {
|
| | | this.cmderFroPlatform = cmderFroPlatform;
|
| | | }
|
| | |
|
| | | public IVideoManagerStorager getStorager() {
|
| | | return storager;
|
| | | }
|
| | |
|
| | | public void setStorager(IVideoManagerStorager storager) {
|
| | | this.storager = storager;
|
| | | }
|
| | |
|
| | | public SIPCommander getCmder() {
|
| | | return cmder;
|
| | | }
|
| | |
|
| | | public void setCmder(SIPCommander cmder) {
|
| | | this.cmder = cmder;
|
| | | }
|
| | |
|
| | | public IPlayService getPlayService() {
|
| | | return playService;
|
| | | }
|
| | |
|
| | | public void setPlayService(IPlayService playService) {
|
| | | this.playService = playService;
|
| | | }
|
| | |
|
| | | public IRedisCatchStorage getRedisCatchStorage() {
|
| | | return redisCatchStorage;
|
| | | }
|
| | |
|
| | | public void setRedisCatchStorage(IRedisCatchStorage redisCatchStorage) {
|
| | | this.redisCatchStorage = redisCatchStorage;
|
| | | }
|
| | |
|
| | | public IMediaServerService getMediaServerService() {
|
| | | return mediaServerService;
|
| | | }
|
| | |
|
| | | public void setMediaServerService(IMediaServerService mediaServerService) {
|
| | | this.mediaServerService = mediaServerService;
|
| | | }
|
| | | }
|