panlinlin
2021-04-16 c5f2aba9b20089f184ce175b58a33a881ea9e0b1
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -4,6 +4,7 @@
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;
@@ -219,7 +220,7 @@
      // String app = json.getString("app");
      // String stream = json.getString("stream");
      ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
      ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json);
      if (subscribe != null) subscribe.response(json);
      JSONObject ret = new JSONObject();
@@ -239,30 +240,41 @@
      if (logger.isDebugEnabled()) {
         logger.debug("ZLM HOOK on_stream_changed API调用,参数:" + json.toString());
      }
      ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, json);
      if (subscribe != null) subscribe.response(json);
      // 流消失移除redis play
      String app = json.getString("app");
      String streamId = json.getString("stream");
      String schema = json.getString("schema");
      JSONArray tracks = json.getJSONArray("tracks");
      boolean regist = json.getBoolean("regist");
      if (tracks != null) {
         System.out.println("222222" + schema);
      }
      if ("rtmp".equals(schema)){
      if ("rtp".equals(app) && !regist ) {
         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);
         }
      }else {
         if (!"rtp".equals(app) && "rtmp".equals(schema)){
            if (regist) {
               zlmMediaListManager.addMedia(app, streamId);
            }else {
               zlmMediaListManager.removeMedia(app, streamId);
         if ("rtp".equals(app) && !regist ) {
            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);
            }
         }else {
            if (!"rtp".equals(app) ){
               if (regist) {
                  zlmMediaListManager.addMedia(app, streamId);
               }else {
                  zlmMediaListManager.removeMedia(app, streamId);
               }
            }
         }
      }
      JSONObject ret = new JSONObject();
      ret.put("code", 0);
      ret.put("msg", "success");
@@ -294,12 +306,12 @@
            if (redisCatchStorage.isChannelSendingRTP(streamInfo.getChannelId())) {
               ret.put("close", false);
            } else {
               cmder.streamByeCmd(streamId);
               cmder.streamByeCmd(streamInfo.getDeviceID(), streamInfo.getChannelId());
               redisCatchStorage.stopPlay(streamInfo);
               storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
            }
         }else{
            cmder.streamByeCmd(streamId);
            cmder.streamByeCmd(streamInfo.getDeviceID(), streamInfo.getChannelId());
            streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
            redisCatchStorage.stopPlayback(streamInfo);
         }
@@ -328,7 +340,7 @@
         String app = json.getString("app");
         String streamId = json.getString("stream");
            StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
         if ("rtp".equals(app) && streamId.indexOf("gb_play") > -1 && streamInfo == null) {
         if ("rtp".equals(app) && streamId.contains("gb_play") && streamInfo == null) {
            String[] s = streamId.split("_");
            if (s.length == 4) {
               String deviceId = s[2];