648540858
2023-01-05 6fa5b37b962b05b3aa4b7bf019eb47c4cdbb5738
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
@@ -1,24 +1,18 @@
package com.genersoft.iot.vmp.gb28181.transmit.event.request.impl;
import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.conf.DynamicTask;
import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
import com.genersoft.iot.vmp.gb28181.bean.AudioBroadcastCatch;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.conf.UserSetting;
import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform;
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
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.ZlmHttpHookSubscribe;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IDeviceService;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IPlayService;
import com.genersoft.iot.vmp.service.bean.RequestPushStreamMsg;
import com.genersoft.iot.vmp.service.redisMsg.RedisGbPlayMsgListener;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -29,15 +23,15 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import javax.sip.InvalidArgumentException;
import javax.sip.RequestEvent;
import javax.sip.SipException;
import javax.sip.address.SipURI;
import javax.sip.header.CallIdHeader;
import javax.sip.header.FromHeader;
import javax.sip.header.HeaderAddress;
import javax.sip.header.ToHeader;
import java.text.ParseException;
import java.util.HashMap;
import java.util.Map;
/**
 * SIP命令类型: ACK请求
@@ -46,7 +40,7 @@
@Component
public class AckRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor {
   private Logger logger = LoggerFactory.getLogger(AckRequestProcessor.class);
   private final Logger logger = LoggerFactory.getLogger(AckRequestProcessor.class);
   private final String method = "ACK";
   @Autowired
@@ -74,31 +68,20 @@
   private IMediaServerService mediaServerService;
   @Autowired
   private ZlmHttpHookSubscribe subscribe;
   @Autowired
   private DynamicTask dynamicTask;
   @Autowired
   private ISIPCommander cmder;
   @Autowired
   private IDeviceService deviceService;
   @Autowired
   private ISIPCommanderForPlatform commanderForPlatform;
   @Autowired
   private AudioBroadcastManager audioBroadcastManager;
   @Autowired
   private RedisGbPlayMsgListener redisGbPlayMsgListener;
   @Autowired
   private UserSetting userSetting;
   @Autowired
   private IPlayService playService;
   /**   
    * 处理  ACK请求
    *
    * @param evt
    */
   @Override
   public void process(RequestEvent evt) {
@@ -106,6 +89,7 @@
      String platformGbId = ((SipURI) ((HeaderAddress) evt.getRequest().getHeader(FromHeader.NAME)).getAddress().getURI()).getUser();
      logger.info("[收到ACK]: platformGbId->{}", platformGbId);
      if (userSetting.getPushStreamAfterAck()) {
      ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(platformGbId);
      // 取消设置的超时任务
      dynamicTask.stop(callIdHeader.getCallId());
@@ -134,16 +118,16 @@
         }
      }
   }
   }
   private void startSendRtpStreamHand(RequestEvent evt, SendRtpItem sendRtpItem, ParentPlatform parentPlatform,
                              JSONObject jsonObject, CallIdHeader callIdHeader) {
                              JSONObject jsonObject, Map<String, Object> param, CallIdHeader callIdHeader) {
      if (jsonObject == null) {
         logger.error("RTP推流失败: 请检查ZLM服务");
      } else if (jsonObject.getInteger("code") == 0) {
         logger.info("调用ZLM推流接口, 结果: {}",  jsonObject);
         logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,sendRtpItem.getApp(), sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getIp(), sendRtpItem.getPort());
         logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
      } else {
         logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"), JSON.toJSONString(sendRtpItem));
         logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"), JSON.toJSONString(param));
         if (sendRtpItem.isOnlyAudio()) {
            Device device = deviceService.getDevice(sendRtpItem.getDeviceId());
            AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId());
@@ -152,17 +136,12 @@
                  cmder.streamByeCmd(device, sendRtpItem.getChannelId(), audioBroadcastCatch.getSipTransactionInfo(), null);
               } catch (SipException | ParseException | InvalidArgumentException |
                      SsrcTransactionNotFoundException e) {
                  logger.error("[命令发送失败] 停止语音喊话: {}", e.getMessage());
               }
            }
         }else {
            // 向上级平台
            try {
               commanderForPlatform.streamByeCmd(parentPlatform, callIdHeader.getCallId());
            } catch (SipException | InvalidArgumentException | ParseException e) {
               logger.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage());
                  logger.error("[命令发送失败] 停止语音对讲: {}", e.getMessage());
            }
         }
      }
   }
   }
}