lawrencehj
2021-03-26 88dd1aca45c5d2c0fca78a60844112ee53eccbfa
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -1,19 +1,13 @@
package com.genersoft.iot.vmp.media.zlm;
import java.math.BigInteger;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaServerConfig;
import com.genersoft.iot.vmp.gb28181.bean.Device;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
import com.genersoft.iot.vmp.utils.IpUtil;
import com.genersoft.iot.vmp.vmanager.service.IPlayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -57,8 +51,8 @@
   @Autowired
   private IRedisCatchStorage redisCatchStorage;
   @Autowired
   private ZLMRESTfulUtils zlmresTfulUtils;
    @Autowired
    private ZLMMediaListManager zlmMediaListManager;
   @Autowired
   private ZLMHttpHookSubscribe subscribe;
@@ -217,8 +211,8 @@
         logger.debug("ZLM HOOK on_shell_login API调用,参数:" + json.toString());
      }
      // TODO 如果是带有rtpstream则开启按需拉流
      String app = json.getString("app");
      String stream = json.getString("stream");
      // String app = json.getString("app");
      // String stream = json.getString("stream");
      ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
      if (subscribe != null) subscribe.response(json);
@@ -243,6 +237,7 @@
      // 流消失移除redis play
      String app = json.getString("app");
      String streamId = json.getString("stream");
      String schema = json.getString("schema");
      boolean regist = json.getBoolean("regist");
      StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
      if ("rtp".equals(app) && !regist ) {
@@ -252,6 +247,10 @@
         }else{
            streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
            redisCatchStorage.stopPlayback(streamInfo);
         }
      }else {
         if (!"rtp".equals(app) && "rtsp".equals(schema)){
            zlmMediaListManager.updateMediaList();
         }
      }
      JSONObject ret = new JSONObject();
@@ -273,20 +272,25 @@
      }
      
      String streamId = json.getString("stream");
      cmder.streamByeCmd(streamId);
      StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
      if (streamInfo!=null){
         redisCatchStorage.stopPlay(streamInfo);
         storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
      }else{
         streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
         redisCatchStorage.stopPlayback(streamInfo);
      }
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      ret.put("close", true);
      if (streamInfo != null) {
         if (redisCatchStorage.isChannelSendingRTP(streamInfo.getChannelId())) {
            ret.put("close", false);
         } else {
            cmder.streamByeCmd(streamId);
            redisCatchStorage.stopPlay(streamInfo);
            storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
         }
      }else{
         cmder.streamByeCmd(streamId);
         streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
         redisCatchStorage.stopPlayback(streamInfo);
      }
      return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
   }