648540858
2022-03-02 1dcdbc3742835ccab28a8983ae002d2bbdba87eb
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/ByeRequestProcessor.java
@@ -5,7 +5,8 @@
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.event.request.SIPRequestProcessorAbstract;
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;
@@ -13,6 +14,7 @@
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
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;
@@ -26,15 +28,14 @@
import java.util.HashMap;
import java.util.Map;
/**
 * @description: BYE请求处理器
 * @author: lawrencehj
 * @date:   2021年3月9日
/**
 * SIP命令类型: BYE请求
 */
@Component
public class ByeRequestProcessor extends SIPRequestProcessorAbstract {
public class ByeRequestProcessor extends SIPRequestProcessorParent implements InitializingBean, ISIPRequestProcessor {
   private Logger logger = LoggerFactory.getLogger(ByeRequestProcessor.class);
   private final Logger logger = LoggerFactory.getLogger(ByeRequestProcessor.class);
   private final String method = "BYE";
   @Autowired
   private ISIPCommander cmder;
@@ -50,8 +51,6 @@
   @Autowired
   private IMediaServerService mediaServerService;
   private String method = "BYE";
   @Autowired
   private SIPProcessorObserver sipProcessorObserver;
@@ -88,18 +87,29 @@
               MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
               zlmrtpServerFactory.stopSendRtpStream(mediaInfo, param);
               redisCatchStorage.deleteSendRTPServer(platformGbId, channelId);
               if (zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId) == 0) {
               int totalReaderCount = zlmrtpServerFactory.totalReaderCount(mediaInfo, sendRtpItem.getApp(), streamId);
               if (totalReaderCount == 0) {
                  logger.info(streamId + "无其它观看者,通知设备停止推流");
                  cmder.streamByeCmd(sendRtpItem.getDeviceId(), channelId);
               }else if (totalReaderCount == -1){
                  logger.warn(streamId + " 查找其它观看者失败");
               }
            }
            // 可能是设备主动停止
            Device device = storager.queryVideoDeviceByChannelId(platformGbId);
            if (device != null) {
               StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
               if (streamInfo != null) {
                  redisCatchStorage.stopPlay(streamInfo);
               if (sendRtpItem.isPlay()) {
                  StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(device.getDeviceId(), channelId);
                  if (streamInfo != null) {
                     redisCatchStorage.stopPlay(streamInfo);
                  }
               }else {
                  StreamInfo streamInfo = redisCatchStorage.queryPlaybackByDevice(device.getDeviceId(), channelId);
                  if (streamInfo != null) {
                     redisCatchStorage.stopPlayback(streamInfo);
                  }
               }
               storager.stopPlay(device.getDeviceId(), channelId);
               mediaServerService.closeRTPServer(device, channelId);
            }