panlinlin
2021-03-25 b37a77f23f995758178b6af38b89a860107d218d
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/InviteRequestProcessor.java
@@ -7,14 +7,10 @@
import javax.sip.SipFactory;
import javax.sip.address.Address;
import javax.sip.address.SipURI;
import javax.sip.header.ContentTypeHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderFactory;
import javax.sip.header.SubjectHeader;
import javax.sip.header.*;
import javax.sip.message.Request;
import javax.sip.message.Response;
import com.alibaba.fastjson.JSONObject;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.gb28181.bean.DeviceChannel;
@@ -27,17 +23,12 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.vmanager.play.bean.PlayResult;
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
import gov.nist.javax.sdp.fields.SDPFormat;
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.annotation.Autowired;
import java.io.IOException;
import java.text.ParseException;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
/**    
@@ -45,6 +36,7 @@
 * @author: panll
 * @date:   2021年1月14日
 */
@SuppressWarnings("rawtypes")
public class InviteRequestProcessor extends SIPRequestAbstractProcessor {
   private final static Logger logger = LoggerFactory.getLogger(MessageRequestProcessor.class);
@@ -83,20 +75,6 @@
         SipURI sipURI = (SipURI) request.getRequestURI();
         String channelId = sipURI.getUser();
         String platformId = null;
//         SubjectHeader subjectHeader = (SubjectHeader)request.getHeader(SubjectHeader.NAME);
//         // 查询通道是否存在 不存在回复404
//         if (subjectHeader != null) { // 存在则从subjectHeader 获取平台信息
//            String subject = subjectHeader.getSubject();
//            if (subject != null) {
//               String[] info1 = subject.split(",");
//               if (info1 != null && info1 .length == 2) {
//                  String[] info2 = info1[1].split(":");
//                  if (info2 != null && info2.length == 2) {
//                     platformId = info2[0];
//                  }
//               }
//            }
//         }
         FromHeader fromHeader = (FromHeader)request.getHeader(FromHeader.NAME);
         AddressImpl address = (AddressImpl) fromHeader.getAddress();
@@ -122,8 +100,10 @@
         // jainSip不支持y=字段, 移除移除以解析。
         int ssrcIndex = contentString.indexOf("y=");
         String ssrc = contentString.substring(ssrcIndex + 2, contentString.length())
               .replace("\r\n", "").replace("\n", "");
         String ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
         //ssrc规定长度为10字节,不取余下长度以避免后续还有“f=”字段
         // String ssrc = contentString.substring(ssrcIndex + 2, contentString.length())
         //       .replace("\r\n", "").replace("\n", "");
         String substring = contentString.substring(0, contentString.indexOf("y="));
         SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
@@ -131,9 +111,9 @@
         //  获取支持的格式
         Vector mediaDescriptions = sdp.getMediaDescriptions(true);
         // 查看是否支持PS 负载96
         String ip = null;
         //String ip = null;
         int port = -1;
         boolean recvonly = false;
         //boolean recvonly = false;
         boolean mediaTransmissionTCP = false;
         Boolean tcpActive = null;
         for (int i = 0; i < mediaDescriptions.size(); i++) {
@@ -143,7 +123,7 @@
            Vector mediaFormats = media.getMediaFormats(false);
            if (mediaFormats.contains("96")) {
               port = media.getMediaPort();
               String mediaType = media.getMediaType();
               //String mediaType = media.getMediaType();
               String protocol = media.getProtocol();
               // 区分TCP发流还是udp, 当前默认udp
@@ -169,7 +149,7 @@
         }
         String username = sdp.getOrigin().getUsername();
         String addressStr = sdp.getOrigin().getAddress();
         String sessionName = sdp.getSessionName().getValue();
         //String sessionName = sdp.getSessionName().getValue();
         logger.info("[上级点播]用户:{}, 地址:{}:{}, ssrc:{}", username, addressStr, port, ssrc);
         Device device = storager.queryVideoDeviceByPlatformIdAndChannelId(platformId, channelId);
@@ -178,7 +158,7 @@
            responseAck(evt, Response.SERVER_INTERNAL_ERROR);
            return;
         }
         SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(ip, port, platformId, ssrc, channelId,
         SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(addressStr, port, ssrc, platformId, device.getDeviceId(), channelId,
               mediaTransmissionTCP);
         if (tcpActive != null) {
            sendRtpItem.setTcpActive(tcpActive);
@@ -230,7 +210,9 @@
               e.printStackTrace();
            }
         }));
         playResult.getResult();
         if (logger.isDebugEnabled()) {
            logger.debug(playResult.getResult().toString());
         }
      } catch (SipException | InvalidArgumentException | ParseException e) {
         e.printStackTrace();
@@ -255,7 +237,7 @@
    * @throws ParseException
    */
   private void responseAck(RequestEvent evt, int statusCode) throws SipException, InvalidArgumentException, ParseException {
      Response response = getMessageFactory().createResponse(Response.TRYING, evt.getRequest());
      Response response = getMessageFactory().createResponse(statusCode, evt.getRequest());
      getServerTransaction(evt).sendResponse(response);
   }