From 9c114823af3ed2230c911bc52cf2c432ca0d43df Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Fri, 12 Jan 2024 14:52:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vmp/media/zlm/ZLMHttpHookListener.java | 3 +- .../iot/vmp/media/zlm/dto/StreamProxy.java | 10 --- .../service/impl/StreamProxyServiceImpl.java | 83 +++++++++---------- .../streamProxy/StreamProxyController.java | 13 --- .../src/components/dialog/StreamProxyEdit.vue | 5 -- 5 files changed, 41 insertions(+), 73 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 45d89b15..37a95329 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -10,7 +10,6 @@ import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; -import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; @@ -548,7 +547,7 @@ public class ZLMHttpHookListener { // 无人观看自动移除 ret.put("close", true); streamProxyService.del(param.getApp(), param.getStream()); - String url = streamProxyItem.getUrl() != null ? streamProxyItem.getUrl() : streamProxyItem.getSrcUrl(); + String url = streamProxyItem.getUrl() != null ? streamProxyItem.getUrl() : streamProxyItem.getUrl(); logger.info("[{}/{}]<-[{}] 拉流代理无人观看已经移除", param.getApp(), param.getStream(), url); } else if (streamProxyItem.isEnableDisableNoneReader()) { // 无人观看停用 diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxy.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxy.java index 64d3af60..f5217c9d 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxy.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxy.java @@ -19,8 +19,6 @@ public class StreamProxy { private String mediaServerId; @Schema(description = "拉流地址") private String url; - @Schema(description = "拉流地址") - private String srcUrl; @Schema(description = "目标地址") private String dstUrl; @Schema(description = "超时时间") @@ -116,14 +114,6 @@ public class StreamProxy { this.url = url; } - public String getSrcUrl() { - return srcUrl; - } - - public void setSrcUrl(String srcUrl) { - this.srcUrl = srcUrl; - } - public String getDstUrl() { return dstUrl; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java index 34e8bb67..eb7c3887 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/StreamProxyServiceImpl.java @@ -250,55 +250,22 @@ public class StreamProxyServiceImpl implements IStreamProxyService { callback.run(code, msg, data); if (code == ErrorCode.SUCCESS.getCode()) { param.setStatus(true); - addProxyToDb(param); } else { - + if (param.isEnableRemoveNoneReader()) { + return; + } + param.setProxyError(msg); + param.setStatus(false); } + addProxyToDb(param); }); - - String talkKey = UUID.randomUUID().toString(); - String delayTalkKey = UUID.randomUUID().toString(); - - HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(param.getApp(), param.getStream(), true, "rtsp", mediaInfo.getId()); - hookSubscribe.addSubscribe(hookSubscribeForStreamChange, (mediaServerItem, response) -> { - dynamicTask.stop(talkKey); - param.setStatus(true); - addProxyToDb(param); - StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( - mediaInfo, param.getApp(), param.getStream(), null, null); - callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); - }); - - dynamicTask.startDelay(delayTalkKey, ()->{ - hookSubscribe.removeSubscribe(hookSubscribeForStreamChange); - dynamicTask.stop(talkKey); - callback.run(ErrorCode.ERROR100.getCode(), "启用超时,请检查源地址是否可用", null); - if (param.isEnableRemoveNoneReader()) { - return; - } - param.setProxyError("启用超时"); - param.setStatus(false); - addProxyToDb(param); - }, 10000); - JSONObject jsonObject = addStreamProxyToZlm(param); - if (jsonObject != null && jsonObject.getInteger("code") != 0) { - hookSubscribe.removeSubscribe(hookSubscribeForStreamChange); - dynamicTask.stop(talkKey); - callback.run(ErrorCode.ERROR100.getCode(), jsonObject.getString("msg"), null); - if (param.isEnableRemoveNoneReader()) { - return; - } - param.setProxyError("启用失败: " + jsonObject.getString("msg")); - param.setStatus(false); - addProxyToDb(param); - } } @Override public void edit(StreamProxy param, GeneralCallback callback) { MediaServerItem mediaInfo; StreamProxy streamProxyInDb = streamProxyMapper.selectOneById(param.getId()); - if (streamProxyInDb != null) { + if (streamProxyInDb == null) { throw new ControllerException(ErrorCode.ERROR100.getCode(), "代理不存在"); } if (ObjectUtils.isEmpty(param.getMediaServerId()) || "auto".equals(param.getMediaServerId())){ @@ -316,6 +283,36 @@ public class StreamProxyServiceImpl implements IStreamProxyService { // ffmpeg类型下,目标流地址变化,停止旧的,拉起新的 // 节点变化: 停止旧的,拉起新的 // ffmpeg命令模板变化: 停止旧的,拉起新的 + boolean stopOldProxy = !streamProxyInDb.getType().equals(param.getType()) + || !streamProxyInDb.getUrl().equals(param.getUrl()) + || !streamProxyInDb.getMediaServerId().equals(param.getMediaServerId()) + || (streamProxyInDb.getType().equals("ffmpeg") && ( + streamProxyInDb.getDstUrl().equals(param.getDstUrl()) + || streamProxyInDb.getFfmpegCmdKey().equals(param.getFfmpegCmdKey()) + )); + + // 如果是开启代理这是开启代理结束后的回调 + final GeneralCallback startProxyCallback = (code, msg, data) -> { + + }; + + if (stopOldProxy) { + stopProxy(param, mediaInfo, (code, msg, data) -> { + if (code == ErrorCode.SUCCESS.getCode()) { + if (param.isEnable()) { + startProxy(param, mediaInfo, startProxyCallback); + } + } + }); + }else { + if (param.isEnable()) { + startProxy(param, mediaInfo, startProxyCallback); + } + } + + + + if (ObjectUtils.isEmpty(streamProxyInDb.getGbId())) { if (!ObjectUtils.isEmpty(param.getGbId())) { // 之前是空的,现在添加了国标编号 @@ -447,7 +444,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { }, 10000); JSONObject result; if ("ffmpeg".equalsIgnoreCase(streamProxy.getType())){ - result = zlmresTfulUtils.addFFmpegSource(mediaInfo, streamProxy.getSrcUrl().trim(), streamProxy.getDstUrl(), + result = zlmresTfulUtils.addFFmpegSource(mediaInfo, streamProxy.getUrl().trim(), streamProxy.getDstUrl(), streamProxy.getTimeoutMs() + "", streamProxy.isEnableAudio(), streamProxy.isEnableMp4(), streamProxy.getFfmpegCmdKey()); }else { @@ -594,7 +591,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { zlmresTfulUtils.closeStreams(mediaServerItem, param.getApp(), param.getStream()); } if ("ffmpeg".equalsIgnoreCase(param.getType())){ - result = zlmresTfulUtils.addFFmpegSource(mediaServerItem, param.getSrcUrl().trim(), param.getDstUrl(), + result = zlmresTfulUtils.addFFmpegSource(mediaServerItem, param.getUrl().trim(), param.getDstUrl(), param.getTimeoutMs() + "", param.isEnableAudio(), param.isEnableMp4(), param.getFfmpegCmdKey()); }else { @@ -695,7 +692,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService { updateStreamProxy(streamProxy); }else { logger.info("启用代理失败: {}/{}->{}({})", app, stream, jsonObject.getString("msg"), - streamProxy.getSrcUrl() == null? streamProxy.getUrl():streamProxy.getSrcUrl()); + streamProxy.getUrl() == null? streamProxy.getUrl():streamProxy.getUrl()); } } else if (streamProxy != null && streamProxy.isEnable()) { return true ; diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java index 87f29d1e..c7443986 100755 --- a/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/vmanager/streamProxy/StreamProxyController.java @@ -6,7 +6,6 @@ import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.conf.security.JwtUtils; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; -import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.media.zlm.dto.StreamProxy; import com.genersoft.iot.vmp.service.IMediaServerService; @@ -27,8 +26,6 @@ import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; import org.springframework.web.context.request.async.DeferredResult; -import java.util.UUID; - @SuppressWarnings("rawtypes") /** * 拉流代理接口 @@ -142,11 +139,6 @@ public class StreamProxyController { if (ObjectUtils.isEmpty(param.getGbId())) { param.setGbId(null); } - if (ObjectUtils.isEmpty(param.getSrcUrl())) { - param.setSrcUrl(param.getUrl()); - }else { - param.setUrl(param.getSrcUrl()); - } DeferredResult result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); // 录像查询以channelId作为deviceId查询 @@ -189,11 +181,6 @@ public class StreamProxyController { if (ObjectUtils.isEmpty(param.getGbId())) { param.setGbId(null); } - if (ObjectUtils.isEmpty(param.getSrcUrl())) { - param.setSrcUrl(param.getUrl()); - }else { - param.setUrl(param.getSrcUrl()); - } DeferredResult result = new DeferredResult<>(userSetting.getPlayTimeout().longValue()); // 录像查询以channelId作为deviceId查询 diff --git a/web_src/src/components/dialog/StreamProxyEdit.vue b/web_src/src/components/dialog/StreamProxyEdit.vue index 7ed893a7..bf421e27 100755 --- a/web_src/src/components/dialog/StreamProxyEdit.vue +++ b/web_src/src/components/dialog/StreamProxyEdit.vue @@ -33,9 +33,6 @@ - - - @@ -158,7 +155,6 @@ export default { app: null, stream: null, url: "", - srcUrl: null, timeoutMs: null, ffmpegCmdKey: null, gbId: null, @@ -180,7 +176,6 @@ export default { app: [{ required: true, message: "请输入应用名", trigger: "blur" }], stream: [{ required: true, message: "请输入流ID", trigger: "blur" }], url: [{ required: true, message: "请输入要代理的流", trigger: "blur" }], - srcUrl: [{ required: true, message: "请输入要代理的流", trigger: "blur" }], timeoutMs: [{ required: true, message: "请输入FFmpeg推流成功超时时间", trigger: "blur" }], ffmpegCmdKey: [{ required: false, message: "请输入FFmpeg命令参数模板(可选)", trigger: "blur" }], },