From a3649ca243f827f78b85dbb41af2c3d7d978aa89 Mon Sep 17 00:00:00 2001
From: panlinlin <648540858@qq.com>
Date: 星期二, 27 四月 2021 15:38:00 +0800
Subject: [PATCH] 优化mysql建库脚本
---
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 68 ++++++++++++++++++++--------------
1 files changed, 40 insertions(+), 28 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 835dd9c..fe84f70 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,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,40 @@
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");
-
- 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 (tracks != null) {
+ logger.info("[stream: " + streamId + "] on_stream_changed->>" + 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");
@@ -283,25 +294,26 @@
String streamId = json.getString("stream");
String app = json.getString("app");
- StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
-
if ("rtp".equals(app)){
JSONObject ret = new JSONObject();
ret.put("code", 0);
ret.put("close", true);
- if (streamInfo != null) {
- if (redisCatchStorage.isChannelSendingRTP(streamInfo.getChannelId())) {
+ StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId);
+ if (streamInfoForPlayCatch != null) {
+ if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) {
ret.put("close", false);
} else {
- cmder.streamByeCmd(streamId);
- redisCatchStorage.stopPlay(streamInfo);
- storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
+ cmder.streamByeCmd(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
+ redisCatchStorage.stopPlay(streamInfoForPlayCatch);
+ storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId());
}
}else{
- cmder.streamByeCmd(streamId);
- streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
- redisCatchStorage.stopPlayback(streamInfo);
+ StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlaybackByStreamId(streamId);
+ if (streamInfoForPlayBackCatch != null) {
+ cmder.streamByeCmd(streamInfoForPlayBackCatch.getDeviceID(), streamInfoForPlayBackCatch.getChannelId());
+ redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch);
+ }
}
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
}else {
@@ -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];
--
Gitblit v1.8.0