From c5f2aba9b20089f184ce175b58a33a881ea9e0b1 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期五, 16 四月 2021 18:23:13 +0800 Subject: [PATCH] 修复 流已经关闭后,再次调用关闭流的接口,返回超时 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 55 ++++++++++++++++++++++++++++++++++++++----------------- 1 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index b2c1597..183a544 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -4,12 +4,13 @@ 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.vmanager.service.IPlayService; +import com.genersoft.iot.vmp.service.IPlayService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -117,6 +118,10 @@ if (logger.isDebugEnabled()) { logger.debug("ZLM HOOK on_play API璋冪敤锛屽弬鏁帮細" + json.toString()); } + ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json); + if (subscribe != null ) { + subscribe.response(json); + } JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); @@ -215,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(); @@ -235,25 +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); + // 娴佹秷澶辩Щ闄edis 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"); - StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId); - if ("rtp".equals(app) && !regist ) { - 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) && "rtsp".equals(schema)){ - zlmMediaListManager.updateMediaList(); + 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) ){ + if (regist) { + zlmMediaListManager.addMedia(app, streamId); + }else { + zlmMediaListManager.removeMedia(app, streamId); + } + } } } + JSONObject ret = new JSONObject(); ret.put("code", 0); ret.put("msg", "success"); @@ -285,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); } @@ -319,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]; -- Gitblit v1.8.0