From 8f7016878d4e4c835d9d62d94ada4e8277da2f05 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 31 Dec 2024 10:17:49 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=8B=89=E6=B5=81=E4=BB=A3=E7=90=86]=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=8D=95=E7=8B=AC=E7=9A=84=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E6=AF=8F=E6=AC=A1=E6=8B=89=E6=B5=81=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/streamProxy/bean/StreamProxy.java | 5 +++- .../streamProxy/bean/StreamProxyParam.java | 2 +- .../controller/StreamProxyController.java | 8 ++++--- .../streamProxy/dao/StreamProxyMapper.java | 23 +++++++++++-------- .../impl/StreamProxyPlayServiceImpl.java | 12 +++------- .../service/impl/StreamProxyServiceImpl.java | 7 +++--- web_src/src/components/StreamProxyEdit.vue | 2 +- 数据库/2.7.3/更新-mysql-2.7.3.sql | 7 +++++- 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxy.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxy.java index 0ca72a60..7a531469 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxy.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxy.java @@ -30,9 +30,12 @@ public class StreamProxy extends CommonGBChannel { @Schema(description = "流ID") private String stream; - @Schema(description = "流媒体服务ID") + @Schema(description = "当前拉流使用的流媒体服务ID") private String mediaServerId; + @Schema(description = "固定选择的流媒体服务ID") + private String relatesMediaServerId; + @Schema(description = "拉流地址") private String srcUrl; diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxyParam.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxyParam.java index 632ca998..0497d233 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxyParam.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/bean/StreamProxyParam.java @@ -57,7 +57,7 @@ public class StreamProxyParam { StreamProxy streamProxy = new StreamProxy(); streamProxy.setApp(app); streamProxy.setStream(stream); - streamProxy.setMediaServerId(mediaServerId); + streamProxy.setRelatesMediaServerId(mediaServerId); streamProxy.setSrcUrl(url); streamProxy.setTimeout(timeoutMs/1000); streamProxy.setRtspType(rtpType); diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java index 54304385..4cf966a5 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/controller/StreamProxyController.java @@ -19,7 +19,6 @@ import io.swagger.v3.oas.annotations.security.SecurityRequirement; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; import org.springframework.util.ObjectUtils; import org.springframework.web.bind.annotation.*; @@ -112,8 +111,8 @@ public class StreamProxyController { @ResponseBody public StreamProxy add(@RequestBody StreamProxy param){ log.info("添加代理: " + JSONObject.toJSONString(param)); - if (ObjectUtils.isEmpty(param.getMediaServerId())) { - param.setMediaServerId(null); + if (ObjectUtils.isEmpty(param.getRelatesMediaServerId())) { + param.setRelatesMediaServerId(null); } if (ObjectUtils.isEmpty(param.getType())) { param.setType("default"); @@ -135,6 +134,9 @@ public class StreamProxyController { if (param.getId() == 0) { throw new ControllerException(ErrorCode.ERROR400.getCode(), "缺少代理信息的ID"); } + if (ObjectUtils.isEmpty(param.getRelatesMediaServerId())) { + param.setRelatesMediaServerId(null); + } if (ObjectUtils.isEmpty(param.getGbId())) { param.setGbDeviceId(null); } diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java index 82d48e21..f43f1096 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/dao/StreamProxyMapper.java @@ -11,11 +11,11 @@ import java.util.List; @Repository public interface StreamProxyMapper { - @Insert("INSERT INTO wvp_stream_proxy (type, app, stream,media_server_id, src_url, " + - "timeout, ffmpeg_cmd_key, rtsp_type, enable_audio, enable_mp4, enable, pulling, stream_key, " + + @Insert("INSERT INTO wvp_stream_proxy (type, app, stream,relates_media_server_id, src_url, " + + "timeout, ffmpeg_cmd_key, rtsp_type, enable_audio, enable_mp4, enable, pulling, " + "enable_remove_none_reader, enable_disable_none_reader, create_time) VALUES" + - "(#{type}, #{app}, #{stream}, #{mediaServerId}, #{srcUrl}, " + - "#{timeout}, #{ffmpegCmdKey}, #{rtspType}, #{enableAudio}, #{enableMp4}, #{enable}, #{pulling}, #{streamKey}, " + + "(#{type}, #{app}, #{stream}, #{relatesMediaServerId}, #{srcUrl}, " + + "#{timeout}, #{ffmpegCmdKey}, #{rtspType}, #{enableAudio}, #{enableMp4}, #{enable}, #{pulling}, " + "#{enableRemoveNoneReader}, #{enableDisableNoneReader}, #{createTime} )") @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id") int add(StreamProxy streamProxyDto); @@ -24,7 +24,7 @@ public interface StreamProxyMapper { "SET type=#{type}, " + "app=#{app}," + "stream=#{stream}," + - "media_server_id=#{mediaServerId}, " + + "relates_media_server_id=#{relatesMediaServerId}, " + "src_url=#{srcUrl}," + "timeout=#{timeout}, " + "ffmpeg_cmd_key=#{ffmpegCmdKey}, " + @@ -32,7 +32,6 @@ public interface StreamProxyMapper { "enable_audio=#{enableAudio}, " + "enable=#{enable}, " + "pulling=#{pulling}, " + - "stream_key=#{streamKey}, " + "enable_remove_none_reader=#{enableRemoveNoneReader}, " + "enable_disable_none_reader=#{enableDisableNoneReader}, " + "enable_mp4=#{enableMp4} " + @@ -84,8 +83,14 @@ public interface StreamProxyMapper { StreamProxy select(@Param("id") int id); @Update("UPDATE wvp_stream_proxy " + - "SET pulling=false, " + - "stream_key = null " + - "WHERE id=#{id}") + " SET pulling=false, media_server_id = null," + + " stream_key = null " + + " WHERE id=#{id}") void removeStream(@Param("id")int id); + + @Update("UPDATE wvp_stream_proxy " + + " SET pulling=#{pulling}, media_server_id = #{mediaServerId}, " + + " stream_key = #{streamKey} " + + " WHERE id=#{id}") + void addStream(StreamProxy streamProxy); } diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java index 170ed6fd..4cdbcd33 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyPlayServiceImpl.java @@ -44,22 +44,19 @@ public class StreamProxyPlayServiceImpl implements IStreamProxyPlayService { return null; } MediaServer mediaServer; - String mediaServerId = streamProxy.getMediaServerId(); + String mediaServerId = streamProxy.getRelatesMediaServerId(); if (mediaServerId == null) { mediaServer = mediaServerService.getMediaServerForMinimumLoad(null); }else { mediaServer = mediaServerService.getOne(mediaServerId); - if (mediaServer == null) { - mediaServer = mediaServerService.getMediaServerForMinimumLoad(null); - } } if (mediaServer == null) { - throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的媒体节点"); + throw new ControllerException(ErrorCode.ERROR100.getCode(), mediaServerId == null?"未找到可用的媒体节点":"未找到节点" + mediaServerId); } StreamInfo streamInfo = mediaServerService.startProxy(mediaServer, streamProxy); if (mediaServerId == null || !mediaServerId.equals(mediaServer.getId())) { streamProxy.setMediaServerId(mediaServer.getId()); - streamProxyMapper.update(streamProxy); + streamProxyMapper.addStream(streamProxy); } return streamInfo; } @@ -88,9 +85,6 @@ public class StreamProxyPlayServiceImpl implements IStreamProxyPlayService { }else { mediaServerService.stopProxy(mediaServer, streamProxy.getStreamKey()); } - streamProxy.setMediaServerId(mediaServer.getId()); - streamProxy.setStreamKey(null); - streamProxy.setPulling(false); streamProxyMapper.removeStream(streamProxy.getId()); } diff --git a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java index 38751123..612180e1 100755 --- a/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/streamProxy/service/impl/StreamProxyServiceImpl.java @@ -406,11 +406,10 @@ public class StreamProxyServiceImpl implements IStreamProxyService { return; } streamProxy.setPulling(status); - if (!mediaServerId.equals(streamProxy.getMediaServerId())) { - streamProxy.setMediaServerId(mediaServerId); - } + streamProxy.setMediaServerId(mediaServerId); streamProxy.setUpdateTime(DateUtil.getNow()); - streamProxyMapper.update(streamProxy); + streamProxyMapper.addStream(streamProxy); + streamProxy.setGbStatus(status ? "ON" : "OFF"); if (streamProxy.getGbId() > 0) { if (status) { diff --git a/web_src/src/components/StreamProxyEdit.vue b/web_src/src/components/StreamProxyEdit.vue index b4596941..8d854a14 100644 --- a/web_src/src/components/StreamProxyEdit.vue +++ b/web_src/src/components/StreamProxyEdit.vue @@ -39,7 +39,7 @@