panlinlin
2021-01-10 658bec3ecc0453fce36b083bf6cbe03ee495d611
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -11,6 +11,7 @@
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;
@@ -20,6 +21,7 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -53,6 +55,9 @@
   private IVideoManagerStorager storager;
   @Autowired
   private IRedisCatchStorage redisCatchStorage;
   @Autowired
   private ZLMRESTfulUtils zlmresTfulUtils;
   @Autowired
@@ -64,6 +69,9 @@
   @Value("${media.ip}")
   private String mediaIp;
   @Value("${media.wanIp}")
   private String mediaWanIp;
   @Value("${media.port}")
   private int mediaPort;
@@ -74,13 +82,10 @@
   @ResponseBody
   @PostMapping(value = "/on_flow_report", produces = "application/json;charset=UTF-8")
   public ResponseEntity<String> onFlowReport(@RequestBody JSONObject json){
      if (logger.isDebugEnabled()) {
         logger.debug("ZLM HOOK on_flow_report API调用,参数:" + json.toString());
      }
      logger.debug("ZLM HOOK on_flow_report API调用,参数:" + json.toString());
      // TODO Auto-generated method stub
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      ret.put("msg", "success");
@@ -226,8 +231,13 @@
      if (logger.isDebugEnabled()) {
         logger.debug("ZLM HOOK on_shell_login API调用,参数:" + json.toString());
      }
      // TODO Auto-generated method stub
      // TODO 如果是带有rtpstream则开启按需拉流
      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);
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      ret.put("msg", "success");
@@ -249,13 +259,14 @@
      String app = json.getString("app");
      String streamId = json.getString("stream");
      boolean regist = json.getBoolean("regist");
      StreamInfo streamInfo = storager.queryPlayByStreamId(streamId);
      StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
      if ("rtp".equals(app) && !regist ) {
         if (streamInfo!=null){
            storager.stopPlay(streamInfo);
            redisCatchStorage.stopPlay(streamInfo);
            storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
         }else{
            streamInfo = storager.queryPlaybackByStreamId(streamId);
            storager.stopPlayback(streamInfo);
            streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
            redisCatchStorage.stopPlayback(streamInfo);
         }
      }
@@ -281,12 +292,13 @@
      String streamId = json.getString("stream");
      cmder.streamByeCmd(streamId);
      StreamInfo streamInfo = storager.queryPlayByStreamId(streamId);
      StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
      if (streamInfo!=null){
         storager.stopPlay(streamInfo);
         redisCatchStorage.stopPlay(streamInfo);
         storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
      }else{
         streamInfo = storager.queryPlaybackByStreamId(streamId);
         storager.stopPlayback(streamInfo);
         streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
         redisCatchStorage.stopPlayback(streamInfo);
      }
      
      JSONObject ret = new JSONObject();
@@ -311,7 +323,7 @@
      if (autoApplyPlay) {
         String app = json.getString("app");
         String streamId = json.getString("stream");
            StreamInfo streamInfo = storager.queryPlayByStreamId(streamId);
            StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
         if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) {
            String[] s = streamId.split("_");
            if (s.length == 4) {
@@ -354,8 +366,9 @@
//      List<MediaServerConfig> mediaServerConfigs = JSON.parseArray(JSON.toJSONString(json), MediaServerConfig.class);
//      MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0);
      MediaServerConfig mediaServerConfig = JSON.toJavaObject(json, MediaServerConfig.class);
      mediaServerConfig.setWanIp(StringUtils.isEmpty(mediaWanIp)? mediaIp: mediaWanIp);
      mediaServerConfig.setLocalIP(mediaIp);
      storager.updateMediaInfo(mediaServerConfig);
      redisCatchStorage.updateMediaInfo(mediaServerConfig);
      // TODO Auto-generated method stub
      
      JSONObject ret = new JSONObject();