648540858
2022-03-04 ee746e53cda8e35ede1d966b582160caeb1ca562
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -181,12 +181,11 @@
   @PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
   public ResponseEntity<String> onPublish(@RequestBody JSONObject json) {
      logger.debug("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
      logger.info("[ ZLM HOOK ]on_publish API调用,参数:" + json.toString());
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      ret.put("msg", "success");
      ret.put("enableHls", true);
      ret.put("enableMP4", userSetup.isRecordPushLive());
      String mediaServerId = json.getString("mediaServerId");
      ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
      if (subscribe != null) {
@@ -200,6 +199,11 @@
      }
       String app = json.getString("app");
       String stream = json.getString("stream");
      if ("rtp".equals(app)) {
         ret.put("enableMP4", userSetup.getRecordSip());
      }else {
         ret.put("enableMP4", userSetup.isRecordPushLive());
      }
      StreamInfo streamInfo = redisCatchStorage.queryPlaybackByStreamId(stream);
      // 录像回放时不进行录像下载
@@ -332,6 +336,11 @@
         }else {
            mediaServerService.removeCount(mediaServerId);
         }
         if (item.getOriginType() == OriginType.PULL.ordinal()
               || item.getOriginType() == OriginType.FFMPEG_PULL.ordinal()) {
            // 设置拉流代理上线/离线
            streamProxyService.updateStatus(regist, app, streamId);
         }
         if ("rtp".equals(app) && !regist ) {
            StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
            if (streamInfo!=null){
@@ -349,12 +358,16 @@
               if (mediaServerItem != null){
                  if (regist) {
                     StreamPushItem streamPushItem = null;
                     StreamInfo streamInfoByAppAndStream = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks);
                     item.setStreamInfo(streamInfoByAppAndStream);
                     redisCatchStorage.addStream(mediaServerItem, type, app, streamId, item);
                     if (item.getOriginType() == OriginType.RTSP_PUSH.ordinal()
                           || item.getOriginType() == OriginType.RTMP_PUSH.ordinal()
                           || item.getOriginType() == OriginType.RTC_PUSH.ordinal() ) {
                        streamPushItem = zlmMediaListManager.addPush(item);
                     }
                     List<GbStream> gbStreams = new ArrayList<>();
                     if (streamPushItem == null || streamPushItem.getGbId() == null) {
                        GbStream gbStream = storager.getGbStream(app, streamId);
@@ -426,14 +439,16 @@
            if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
               ret.put("close", false);
            } else {
               cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
               cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId(),
                     streamInfoForPlayCatch.getStream());
               redisCatchStorage.stopPlay(streamInfoForPlayCatch);
               storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
            }
         }else{
            StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlaybackByStreamId(streamId);
            if (streamInfoForPlayBackCatch != null) {
               cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(), streamInfoForPlayBackCatch.getChannelId());
               cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(),
                     streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream());
               redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch);
            }else {
               StreamInfo streamInfoForDownload = redisCatchStorage.queryDownloadByStreamId(streamId);