From 7918f037342e95913fd6af62f32702930742456c Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 17 Oct 2022 16:38:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=8C=89=E9=9C=80=E6=8B=89?= =?UTF-8?q?=E6=B5=81=E9=85=8D=E7=BD=AE=EF=BC=8C=E6=8B=89=E6=B5=81=E4=BB=A3?= =?UTF-8?q?=E7=90=86=E6=94=AF=E6=8C=81=E6=8C=89=E9=9C=80=E6=8B=89=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql.sql | 1 - sql/update.sql | 5 + .../genersoft/iot/vmp/conf/MediaConfig.java | 8 -- .../genersoft/iot/vmp/conf/UserSetting.java | 10 ++ .../vmp/media/zlm/ZLMHttpHookListener.java | 93 +++++++++++-------- .../vmp/media/zlm/dto/MediaServerItem.java | 12 --- .../vmp/media/zlm/dto/StreamProxyItem.java | 2 +- .../service/impl/MediaServerServiceImpl.java | 2 - .../vmp/storager/dao/MediaServerMapper.java | 4 - .../vmp/storager/dao/StreamProxyMapper.java | 5 +- src/main/resources/all-application.yml | 4 +- .../src/components/dialog/MediaServerEdit.vue | 13 +-- .../src/components/dialog/StreamProxyEdit.vue | 11 ++- web_src/src/components/setting/Media.vue | 3 - 14 files changed, 91 insertions(+), 82 deletions(-) diff --git a/sql/mysql.sql b/sql/mysql.sql index 8c6c7b0b..a088c25a 100644 --- a/sql/mysql.sql +++ b/sql/mysql.sql @@ -277,7 +277,6 @@ CREATE TABLE `media_server` ( `rtspSSLPort` int NOT NULL, `autoConfig` int NOT NULL, `secret` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, - `streamNoneReaderDelayMS` int NOT NULL, `rtpEnable` int NOT NULL, `rtpPortRange` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, `sendRtpPortRange` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL, diff --git a/sql/update.sql b/sql/update.sql index e69de29b..e0d963b0 100644 --- a/sql/update.sql +++ b/sql/update.sql @@ -0,0 +1,5 @@ +alter table wvp.media_server + drop column streamNoneReaderDelayMS; + +alter table stream_proxy + add enable_disable_none_reader bit(1) default null; diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java index 35ff08ee..708f72be 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java @@ -69,9 +69,6 @@ public class MediaConfig{ @Value("${media.secret}") private String secret; - @Value("${media.stream-none-reader-delay-ms:15000}") - private int streamNoneReaderDelayMS = 15000; - @Value("${media.rtp.enable}") private boolean rtpEnable; @@ -151,10 +148,6 @@ public class MediaConfig{ return secret; } - public int getStreamNoneReaderDelayMS() { - return streamNoneReaderDelayMS; - } - public boolean isRtpEnable() { return rtpEnable; } @@ -219,7 +212,6 @@ public class MediaConfig{ mediaServerItem.setRtspSSLPort(rtspSSLPort); mediaServerItem.setAutoConfig(autoConfig); mediaServerItem.setSecret(secret); - mediaServerItem.setStreamNoneReaderDelayMS(streamNoneReaderDelayMS); mediaServerItem.setRtpEnable(rtpEnable); mediaServerItem.setRtpPortRange(rtpPortRange); mediaServerItem.setSendRtpPortRange(sendRtpPortRange); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java index cad6e69d..ea2655e2 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java @@ -33,6 +33,8 @@ public class UserSetting { private Boolean usePushingAsStatus = Boolean.TRUE; + private Boolean streamOnDemand = Boolean.TRUE; + private String serverId = "000000"; private String thirdPartyGBIdReg = "[\\s\\S]*"; @@ -146,4 +148,12 @@ public class UserSetting { public void setUsePushingAsStatus(Boolean usePushingAsStatus) { this.usePushingAsStatus = usePushingAsStatus; } + + public Boolean getStreamOnDemand() { + return streamOnDemand; + } + + public void setStreamOnDemand(Boolean streamOnDemand) { + this.streamOnDemand = streamOnDemand; + } } 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 e1689c94..bde4f827 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 @@ -558,9 +558,12 @@ public class ZLMHttpHookListener { String app = json.getString("app"); JSONObject ret = new JSONObject(); ret.put("code", 0); + // 录像下载 + ret.put("close", userSetting.getStreamOnDemand()); if ("rtp".equals(app)){ - ret.put("close", true); + // 国标流, 点播/录像回放/录像下载 StreamInfo streamInfoForPlayCatch = redisCatchStorage.queryPlayByStreamId(streamId); + // 点播 if (streamInfoForPlayCatch != null) { // 收到无人观看说明流也没有在往上级推送 if (redisCatchStorage.isChannelSendingRTP(streamInfoForPlayCatch.getChannelId())) { @@ -590,40 +593,39 @@ public class ZLMHttpHookListener { redisCatchStorage.stopPlay(streamInfoForPlayCatch); storager.stopPlay(streamInfoForPlayCatch.getDeviceID(), streamInfoForPlayCatch.getChannelId()); - }else{ - StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null, streamId, null); - if (streamInfoForPlayBackCatch != null ) { - if (streamInfoForPlayBackCatch.isPause()) { - ret.put("close", false); - }else { - Device device = deviceService.queryDevice(streamInfoForPlayBackCatch.getDeviceID()); - if (device != null) { - try { - cmder.streamByeCmd(device,streamInfoForPlayBackCatch.getChannelId(), - streamInfoForPlayBackCatch.getStream(), null); - } catch (InvalidArgumentException | ParseException | SipException | - SsrcTransactionNotFoundException e) { - logger.error("[无人观看]回放, 发送BYE失败 {}", e.getMessage()); - } - } - redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch.getDeviceID(), - streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream(), null); - } - + return ret; + } + // 录像回放 + StreamInfo streamInfoForPlayBackCatch = redisCatchStorage.queryPlayback(null, null, streamId, null); + if (streamInfoForPlayBackCatch != null ) { + if (streamInfoForPlayBackCatch.isPause()) { + ret.put("close", false); }else { - StreamInfo streamInfoForDownload = redisCatchStorage.queryDownload(null, null, streamId, null); - // 进行录像下载时无人观看不断流 - if (streamInfoForDownload != null) { - ret.put("close", false); + Device device = deviceService.queryDevice(streamInfoForPlayBackCatch.getDeviceID()); + if (device != null) { + try { + cmder.streamByeCmd(device,streamInfoForPlayBackCatch.getChannelId(), + streamInfoForPlayBackCatch.getStream(), null); + } catch (InvalidArgumentException | ParseException | SipException | + SsrcTransactionNotFoundException e) { + logger.error("[无人观看]回放, 发送BYE失败 {}", e.getMessage()); + } } + redisCatchStorage.stopPlayback(streamInfoForPlayBackCatch.getDeviceID(), + streamInfoForPlayBackCatch.getChannelId(), streamInfoForPlayBackCatch.getStream(), null); } + return ret; } - MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); - if (mediaServerItem != null && mediaServerItem.getStreamNoneReaderDelayMS() == -1) { + // 录像下载 + StreamInfo streamInfoForDownload = redisCatchStorage.queryDownload(null, null, streamId, null); + // 进行录像下载时无人观看不断流 + if (streamInfoForDownload != null) { ret.put("close", false); + return ret; } - return ret; }else { + // 非国标流 推流/拉流代理 + // 拉流代理 StreamProxyItem streamProxyItem = streamProxyService.getStreamProxyByAppAndStream(app, streamId); if (streamProxyItem != null ) { if (streamProxyItem.isEnable_remove_none_reader()) { @@ -635,12 +637,21 @@ public class ZLMHttpHookListener { }else if (streamProxyItem.isEnable_disable_none_reader()) { // 无人观看停用 ret.put("close", true); + // 修改数据 + streamProxyService.stop(app, streamId); }else { ret.put("close", false); } + return ret; } - return ret; + // 推流具有主动性,暂时不做处理 +// StreamPushItem streamPushItem = streamPushService.getPush(app, streamId); +// if (streamPushItem != null) { +// // TODO 发送停止 +// +// } } + return ret; } /** @@ -655,19 +666,27 @@ public class ZLMHttpHookListener { } String mediaServerId = json.getString("mediaServerId"); MediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId); - if (userSetting.isAutoApplyPlay() && mediaInfo != null && mediaInfo.isRtpEnable()) { + if (userSetting.isAutoApplyPlay() && mediaInfo != null) { String app = json.getString("app"); String streamId = json.getString("stream"); if ("rtp".equals(app)) { - String[] s = streamId.split("_"); - if (s.length == 2) { - String deviceId = s[0]; - String channelId = s[1]; - Device device = redisCatchStorage.getDevice(deviceId); - if (device != null) { - playService.play(mediaInfo,deviceId, channelId, null, null, null); + if (mediaInfo.isRtpEnable()) { + String[] s = streamId.split("_"); + if (s.length == 2) { + String deviceId = s[0]; + String channelId = s[1]; + Device device = redisCatchStorage.getDevice(deviceId); + if (device != null) { + playService.play(mediaInfo,deviceId, channelId, null, null, null); + } } } + }else { + // 拉流代理 + StreamProxyItem streamProxyByAppAndStream = streamProxyService.getStreamProxyByAppAndStream(app, streamId); + if (streamProxyByAppAndStream != null && streamProxyByAppAndStream.isEnable_disable_none_reader()) { + streamProxyService.start(app, streamId); + } } } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java index ec09ce5a..bf58187e 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java @@ -54,9 +54,6 @@ public class MediaServerItem{ @Schema(description = "ZLM鉴权参数") private String secret; - @Schema(description = "某个流无人观看时,触发hook.on_stream_none_reader事件的最大等待时间,单位毫秒") - private int streamNoneReaderDelayMS; - @Schema(description = "keepalive hook触发间隔,单位秒") private int hookAliveInterval; @@ -119,7 +116,6 @@ public class MediaServerItem{ rtspSSLPort = zlmServerConfig.getRtspSSlport(); autoConfig = true; // 默认值true; secret = zlmServerConfig.getApiSecret(); - streamNoneReaderDelayMS = zlmServerConfig.getGeneralStreamNoneReaderDelayMS(); hookAliveInterval = zlmServerConfig.getHookAliveInterval(); rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口 rtpPortRange = zlmServerConfig.getPortRange().replace("_",","); // 默认使用30000,30500作为级联时发送流的端口号 @@ -240,14 +236,6 @@ public class MediaServerItem{ this.secret = secret; } - public int getStreamNoneReaderDelayMS() { - return streamNoneReaderDelayMS; - } - - public void setStreamNoneReaderDelayMS(int streamNoneReaderDelayMS) { - this.streamNoneReaderDelayMS = streamNoneReaderDelayMS; - } - public boolean isRtpEnable() { return rtpEnable; } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java index f0d08a14..ea0bdcaa 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/StreamProxyItem.java @@ -38,7 +38,7 @@ public class StreamProxyItem extends GbStream { @Schema(description = "是否 无人观看时删除") private boolean enable_remove_none_reader; - @Schema(description = "是否 无人观看时不启用") + @Schema(description = "是否 无人观看时自动停用") private boolean enable_disable_none_reader; @Schema(description = "上级平台国标ID") private String platformGbId; diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index afa2daad..7c5b1499 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -541,7 +541,6 @@ public class MediaServerServiceImpl implements IMediaServerService { param.put("hook.on_record_mp4",""); } param.put("hook.timeoutSec","20"); - param.put("general.streamNoneReaderDelayMS",mediaServerItem.getStreamNoneReaderDelayMS()==-1?"3600000":mediaServerItem.getStreamNoneReaderDelayMS() ); // 推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。 // 置0关闭此特性(推流断开会导致立即断开播放器) // 此参数不应大于播放器超时时间 @@ -606,7 +605,6 @@ public class MediaServerServiceImpl implements IMediaServerService { mediaServerItem.setStreamIp(ip); mediaServerItem.setHookIp(sipConfig.getIp()); mediaServerItem.setSdpIp(ip); - mediaServerItem.setStreamNoneReaderDelayMS(zlmServerConfig.getGeneralStreamNoneReaderDelayMS()); return mediaServerItem; } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java index 0e37bbfa..95b3d150 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java @@ -26,7 +26,6 @@ public interface MediaServerMapper { "rtspSSLPort, " + "autoConfig, " + "secret, " + - "streamNoneReaderDelayMS, " + "rtpEnable, " + "rtpPortRange, " + "sendRtpPortRange, " + @@ -51,7 +50,6 @@ public interface MediaServerMapper { "${rtspSSLPort}, " + "${autoConfig}, " + "'${secret}', " + - "${streamNoneReaderDelayMS}, " + "${rtpEnable}, " + "'${rtpPortRange}', " + "'${sendRtpPortRange}', " + @@ -77,7 +75,6 @@ public interface MediaServerMapper { ", rtspPort=${rtspPort}" + ", rtspSSLPort=${rtspSSLPort}" + ", autoConfig=${autoConfig}" + - ", streamNoneReaderDelayMS=${streamNoneReaderDelayMS}" + ", rtpEnable=${rtpEnable}" + ", rtpPortRange='${rtpPortRange}'" + ", sendRtpPortRange='${sendRtpPortRange}'" + @@ -102,7 +99,6 @@ public interface MediaServerMapper { ", rtspPort=${rtspPort}" + ", rtspSSLPort=${rtspSSLPort}" + ", autoConfig=${autoConfig}" + - ", streamNoneReaderDelayMS=${streamNoneReaderDelayMS}" + ", rtpEnable=${rtpEnable}" + ", rtpPortRange='${rtpPortRange}'" + ", sendRtpPortRange='${sendRtpPortRange}'" + diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java index c05910e3..a9827ad3 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/StreamProxyMapper.java @@ -11,10 +11,10 @@ import java.util.List; public interface StreamProxyMapper { @Insert("INSERT INTO stream_proxy (type, name, app, stream,mediaServerId, url, src_url, dst_url, " + - "timeout_ms, ffmpeg_cmd_key, rtp_type, enable_hls, enable_mp4, enable, status, enable_remove_none_reader, createTime) VALUES" + + "timeout_ms, ffmpeg_cmd_key, rtp_type, enable_hls, enable_mp4, enable, status, enable_remove_none_reader, enable_disable_none_reader, createTime) VALUES" + "('${type}','${name}', '${app}', '${stream}', '${mediaServerId}','${url}', '${src_url}', '${dst_url}', " + "'${timeout_ms}', '${ffmpeg_cmd_key}', '${rtp_type}', ${enable_hls}, ${enable_mp4}, ${enable}, ${status}, " + - "${enable_remove_none_reader}, '${createTime}' )") + "${enable_remove_none_reader}, ${enable_disable_none_reader}, '${createTime}' )") int add(StreamProxyItem streamProxyDto); @Update("UPDATE stream_proxy " + @@ -33,6 +33,7 @@ public interface StreamProxyMapper { "enable=#{enable}, " + "status=#{status}, " + "enable_remove_none_reader=#{enable_remove_none_reader}, " + + "enable_disable_none_reader=#{enable_disable_none_reader}, " + "enable_mp4=#{enable_mp4} " + "WHERE app=#{app} AND stream=#{stream}") int update(StreamProxyItem streamProxyDto); diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml index ed025b9a..49d5aca1 100644 --- a/src/main/resources/all-application.yml +++ b/src/main/resources/all-application.yml @@ -146,8 +146,6 @@ media: auto-config: true # [可选] zlm服务器的hook.admin_params=secret secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc - # [可选] zlm服务器的general.streamNoneReaderDelayMS - stream-none-reader-delay-ms: 18000 # 无人观看多久自动关闭流, -1表示永不自动关闭,即 关闭按需拉流 # 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试 rtp: # [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输 @@ -190,6 +188,8 @@ user-settings: logInDatebase: true # 使用推流状态作为推流通道状态 use-pushing-as-status: true + # 按需拉流, true:有人观看拉流,无人观看释放, false:拉起后不自动释放 + stream-on-demand: true # 关闭在线文档(生产环境建议关闭) springdoc: diff --git a/web_src/src/components/dialog/MediaServerEdit.vue b/web_src/src/components/dialog/MediaServerEdit.vue index 1754461d..24f8c85f 100644 --- a/web_src/src/components/dialog/MediaServerEdit.vue +++ b/web_src/src/components/dialog/MediaServerEdit.vue @@ -41,10 +41,6 @@ - - - - @@ -74,6 +70,10 @@ + + + + @@ -94,9 +94,6 @@ - - - - @@ -172,7 +169,6 @@ export default { hookIp: "", sdpIp: "", streamIp: "", - streamNoneReaderDelayMS: "", secret: "035c73f7-bb6b-4889-a715-d9eb2d1925cc", httpPort: "", httpSSlPort: "", @@ -332,7 +328,6 @@ export default { hookIp: "", sdpIp: "", streamIp: "", - streamNoneReaderDelayMS: "", secret: "035c73f7-bb6b-4889-a715-d9eb2d1925cc", httpPort: "", httpSSlPort: "", diff --git a/web_src/src/components/dialog/StreamProxyEdit.vue b/web_src/src/components/dialog/StreamProxyEdit.vue index 936bc53d..1270999f 100644 --- a/web_src/src/components/dialog/StreamProxyEdit.vue +++ b/web_src/src/components/dialog/StreamProxyEdit.vue @@ -105,7 +105,9 @@ - + + + @@ -170,6 +172,7 @@ export default { enable_hls: true, enable_mp4: false, enable_remove_none_reader: false, + enable_disable_none_reader: true, platformGbId: null, mediaServerId: null, }, @@ -276,6 +279,12 @@ export default { if (this.platform.enable && this.platform.expires == "0") { this.platform.expires = "300"; } + }, + removeNoneReader: function(checked) { + this.proxyParam.enable_disable_none_reader = !checked; + }, + disableNoneReaderHandType: function(checked) { + this.proxyParam.enable_remove_none_reader = !checked; } }, }; diff --git a/web_src/src/components/setting/Media.vue b/web_src/src/components/setting/Media.vue index 19465b96..66426010 100644 --- a/web_src/src/components/setting/Media.vue +++ b/web_src/src/components/setting/Media.vue @@ -42,9 +42,6 @@ - - -