|  |  | 
 |  |  | import java.util.Map;
 | 
 |  |  | 
 | 
 |  |  | import javax.sip.*;
 | 
 |  |  | //import javax.sip.message.Request;
 | 
 |  |  | import javax.sip.address.SipURI;
 | 
 |  |  | import javax.sip.header.FromHeader;
 | 
 |  |  | import javax.sip.header.HeaderAddress;
 | 
 |  |  | import javax.sip.header.ToHeader;
 | 
 |  |  | 
 | 
 |  |  | import com.genersoft.iot.vmp.common.StreamInfo;
 | 
 |  |  | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
 | 
 |  |  | 
 |  |  | import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
 | 
 |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
 | 
 |  |  | 
 | 
 |  |  | import org.springframework.stereotype.Component;
 | 
 |  |  | 
 | 
 |  |  | /**    
 | 
 |  |  |  * @Description:ACK请求处理器  
 | 
 |  |  |  * @author: swwheihei
 | 
 |  |  |  * @date:   2020年5月3日 下午5:31:45     
 | 
 |  |  |  */
 | 
 |  |  | @Component
 | 
 |  |  | public class AckRequestProcessor extends SIPRequestAbstractProcessor {
 | 
 |  |  | 
 | 
 |  |  |     //@Autowired
 | 
 |  |  |     private IRedisCatchStorage redisCatchStorage;
 | 
 |  |  | 
 | 
 |  |  |    //@Autowired
 | 
 |  |  |    private ZLMRTPServerFactory zlmrtpServerFactory;
 | 
 |  |  | 
 | 
 |  |  | 
 | 
 |  |  |    /**   
 | 
 |  |  |     * 处理  ACK请求
 | 
 |  |  | 
 |  |  |       Dialog dialog = evt.getDialog();
 | 
 |  |  |       if (dialog == null) return;
 | 
 |  |  |       //DialogState state = dialog.getState();
 | 
 |  |  |       if (/*request.getMethod().equals(Request.INVITE) &&*/ dialog.getState()== DialogState.CONFIRMED) {
 | 
 |  |  |          String remoteUri = dialog.getRemoteParty().getURI().toString();
 | 
 |  |  |          String localUri = dialog.getLocalParty().getURI().toString();
 | 
 |  |  |          String platformGbId = remoteUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
 | 
 |  |  |          String channelId = localUri.substring(remoteUri.indexOf(":") + 1, remoteUri.indexOf("@"));
 | 
 |  |  |       if (/*request.getMecodewwthod().equals(Request.INVITE) &&*/ dialog.getState()== DialogState.CONFIRMED) {
 | 
 |  |  |          String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
 | 
 |  |  |          String channelId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(ToHeader.NAME)).getAddress().getURI()).getUser();
 | 
 |  |  |          SendRtpItem sendRtpItem =  redisCatchStorage.querySendRTPServer(platformGbId, channelId);
 | 
 |  |  |          String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
 | 
 |  |  |          String deviceId = sendRtpItem.getDeviceId();
 | 
 |  |  |          StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
 | 
 |  |  |          StreamInfo streamInfo = null;
 | 
 |  |  |          if (deviceId == null) {
 | 
 |  |  |             streamInfo = new StreamInfo();
 | 
 |  |  |             streamInfo.setApp(sendRtpItem.getApp());
 | 
 |  |  |             streamInfo.setStreamId(sendRtpItem.getStreamId());
 | 
 |  |  |          }else {
 | 
 |  |  |             streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
 | 
 |  |  |             sendRtpItem.setStreamId(streamInfo.getStreamId());
 | 
 |  |  |             streamInfo.setApp("rtp");
 | 
 |  |  |          }
 | 
 |  |  | 
 | 
 |  |  |          redisCatchStorage.updateSendRTPSever(sendRtpItem);
 | 
 |  |  |          System.out.println(platformGbId);
 | 
 |  |  |          System.out.println(channelId);
 | 
 |  |  |          Map<String, Object> param = new HashMap<>();
 | 
 |  |  |          param.put("vhost","__defaultVhost__");
 | 
 |  |  |          param.put("app","rtp");
 | 
 |  |  |          param.put("app",streamInfo.getApp());
 | 
 |  |  |          param.put("stream",streamInfo.getStreamId());
 | 
 |  |  |          param.put("ssrc", sendRtpItem.getSsrc());
 | 
 |  |  |          param.put("dst_url",sendRtpItem.getIp());
 | 
 |  |  | 
 |  |  |          while (!rtpPushed) {
 | 
 |  |  |             try {
 | 
 |  |  |                if (System.currentTimeMillis() - startTime < 30 * 1000) {
 | 
 |  |  |                   if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) {
 | 
 |  |  |                   if (zlmrtpServerFactory.isStreamReady(streamInfo.getApp(), streamInfo.getStreamId())) {
 | 
 |  |  |                      rtpPushed = true;
 | 
 |  |  |                      System.out.println("已获取设备推流,开始向上级推流");
 | 
 |  |  |                      zlmrtpServerFactory.startSendRtpStream(param);
 | 
 |  |  |                   } else {
 | 
 |  |  |                      System.out.println("等待设备推流.......");
 | 
 |  |  |                      Thread.sleep(2000);
 | 
 |  |  |                      Thread.sleep(1000);
 | 
 |  |  |                      continue;
 | 
 |  |  |                   }
 | 
 |  |  |                } else {
 | 
 |  |  | 
 |  |  |    public void setZlmrtpServerFactory(ZLMRTPServerFactory zlmrtpServerFactory) {
 | 
 |  |  |       this.zlmrtpServerFactory = zlmrtpServerFactory;
 | 
 |  |  |    }
 | 
 |  |  | 
 | 
 |  |  | }
 |