648540858
2022-11-29 38a85d432ae9bb861dbcbf090d68fb3dca0d85f6
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
@@ -17,6 +17,7 @@
import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import gov.nist.javax.sip.message.SIPRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
@@ -87,7 +88,7 @@
   public void process(RequestEvent evt) {
      try {
         responseAck(getServerTransaction(evt), Response.OK);
         responseAck((SIPRequest) evt.getRequest(), Response.OK);
      } catch (SipException | InvalidArgumentException | ParseException e) {
         logger.error("[回复BYE信息失败],{}", e.getMessage());
      }
@@ -97,6 +98,16 @@
      if (sendRtpItem != null){
         logger.info("[收到bye] {}/{}", sendRtpItem.getPlatformId(), sendRtpItem.getChannelId());
         String streamId = sendRtpItem.getStreamId();
         MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
         if (mediaServerItem == null) {
            return;
         }
         Boolean ready = zlmrtpServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), streamId);
         if (!ready) {
            logger.info("[收到bye] 发现流{}/{}已经结束,不需处理", sendRtpItem.getApp(), sendRtpItem.getStreamId());
            return;
         }
         Map<String, Object> param = new HashMap<>();
         param.put("vhost","__defaultVhost__");
         param.put("app",sendRtpItem.getApp());
@@ -106,11 +117,12 @@
         MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
         redisCatchStorage.deleteSendRTPServer(sendRtpItem.getPlatformId(), sendRtpItem.getChannelId(), callIdHeader.getCallId(), null);
         zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
         int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId);
         if (totalReaderCount <= 0) {
            logger.info("[收到bye] {} 无其它观看者,通知设备停止推流", streamId);
            if (sendRtpItem.getPlayType().equals(InviteStreamType.PLAY)) {
               Device device = deviceService.queryDevice(sendRtpItem.getDeviceId());
               Device device = deviceService.getDevice(sendRtpItem.getDeviceId());
               if (device == null) {
                  logger.info("[收到bye] {} 通知设备停止推流时未找到设备信息", streamId);
               }
@@ -130,6 +142,7 @@
               redisCatchStorage.sendStreamPushRequestedMsg(messageForPushChannel);
            }
         }
         playService.stopAudioBroadcast(sendRtpItem.getDeviceId(), sendRtpItem.getChannelId());
      }