648540858
2022-10-17 82fd369ce554467f794c9aa66e453adecefc73a9
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -695,9 +695,12 @@
      String app = json.getString("app");
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      // 录像下载
      ret.put("close", userSetting.getStreamOnDemand());
      if ("rtp".equals(app)){
         ret.put("close", true);
         // 国标流, 点播/录像回放/录像下载
         StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId);
         // 点播
         if (streamInfoForPlayCatch != null) {
            // 收到无人观看说明流也没有在往上级推送
            if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
@@ -727,7 +730,9 @@
            redisCatchStorage.stopPlay(streamInfoForPlayCatch);
            storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
         }else{
            return ret;
         }
         // 录像回放
            StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null, streamId, null);
            if (streamInfoForPlayBackCatch != null ) {
               if (streamInfoForPlayBackCatch.isPause()) {
@@ -746,21 +751,18 @@
                  redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch.getDeviceID(),
                        streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream(), null);
               }
            }else {
            return ret;
         }
         // 录像下载
               StreamInfo streamInfoForDownload = redisCatchStorage.queryDownload(null, null, streamId, null);
               // 进行录像下载时无人观看不断流
               if (streamInfoForDownload != null) {
                  ret.put("close", false);
               }
            }
         }
         MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
         if (mediaServerItem != null && mediaServerItem.getStreamNoneReaderDelayMS() == -1) {
            ret.put("close", false);
         }
         return ret;
         }
      }else {
         // 非国标流 推流/拉流代理
         // 拉流代理
         StreamProxyItem streamProxyItem = streamProxyService.getStreamProxyByAppAndStream(app, streamId);
         if (streamProxyItem != null ) {
            if (streamProxyItem.isEnable_remove_none_reader()) {
@@ -772,12 +774,21 @@
            }else if (streamProxyItem.isEnable_disable_none_reader()) {
               // 无人观看停用
               ret.put("close", true);
               // 修改数据
               streamProxyService.stop(app, streamId);
            }else {
               ret.put("close", false);
            }
         }
         return ret;
      }
         // 推流具有主动性,暂时不做处理
//         StreamPushItem streamPushItem = streamPushService.getPush(app, streamId);
//         if (streamPushItem != null) {
//            // TODO 发送停止
//
//         }
      }
      return ret;
   }
   
   /**
@@ -792,10 +803,11 @@
      }
      String mediaServerId = json.getString("mediaServerId");
      MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
      if (userSetting.isAutoApplyPlay() && mediaInfo != null && mediaInfo.isRtpEnable()) {
      if (userSetting.isAutoApplyPlay() && mediaInfo != null) {
         String app = json.getString("app");
         String streamId = json.getString("stream");
         if ("rtp".equals(app)) {
            if (mediaInfo.isRtpEnable()) {
            String[] s = streamId.split("_");
            if (s.length == 2) {
               String deviceId = s[0];
@@ -806,6 +818,13 @@
               }
            }
         }
         }else {
            // 拉流代理
            StreamProxyItem streamProxyByAppAndStream = streamProxyService.getStreamProxyByAppAndStream(app, streamId);
            if (streamProxyByAppAndStream != null && streamProxyByAppAndStream.isEnable_disable_none_reader()) {
               streamProxyService.start(app, streamId);
            }
         }
      }
      JSONObject ret = new JSONObject();