From b1c92cf4e88447fc59a2b0b8b78c0e2c41282141 Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Tue, 23 Nov 2021 14:51:37 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9C=A8redis=E4=B8=AD=E6=B7=BB=E5=8A=A0wvp?= =?UTF-8?q?=E5=AD=98=E6=B4=BB=E4=BE=9D=E6=8D=AE=EF=BC=8C=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=8E=A8=E6=B5=81=E5=8F=98=E5=8C=96=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/common/VideoManagerConstants.java | 7 +++++- .../com/genersoft/iot/vmp/conf/UserSetup.java | 10 ++++++++ .../iot/vmp/conf/VManagerConfig.java | 25 ------------------- .../genersoft/iot/vmp/conf/WVPTimerTask.java | 24 +++++++++++++----- .../callback/DeferredResultHolder.java | 2 -- .../vmp/media/zlm/ZLMHttpHookListener.java | 16 ++++++++++++ .../service/impl/MediaServerServiceImpl.java | 2 +- .../iot/vmp/storager/IRedisCatchStorage.java | 25 ++++++++++++++++++- .../storager/impl/RedisCatchStorageImpl.java | 21 +++++++++++++++- .../iot/vmp/utils/redis/RedisUtil.java | 6 +++++ .../ApiCompatibleController.java | 2 +- .../{ => gb28181}/ApiControlController.java | 2 +- .../vmp/web/{ => gb28181}/ApiController.java | 2 +- .../{ => gb28181}/ApiDeviceController.java | 2 +- .../{ => gb28181}/ApiStreamController.java | 2 +- .../vmp/web/{ => gb28181}/AuthController.java | 2 +- 16 files changed, 107 insertions(+), 43 deletions(-) delete mode 100644 src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/ApiCompatibleController.java (96%) rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/ApiControlController.java (98%) rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/ApiController.java (98%) rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/ApiDeviceController.java (99%) rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/ApiStreamController.java (99%) rename src/main/java/com/genersoft/iot/vmp/web/{ => gb28181}/AuthController.java (93%) diff --git a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java index 5fd9c772..560d69a0 100644 --- a/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java +++ b/src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java @@ -8,7 +8,9 @@ package com.genersoft.iot.vmp.common; */ public class VideoManagerConstants { - public static final String WVP_SERVER_PREFIX = "VMP_wvp_server"; + public static final String WVP_SERVER_PREFIX = "VMP_SIGNALLING_SERVER_INFO_"; + + public static final String WVP_SERVER_STREAM_PUSH_PREFIX = "VMP_SIGNALLING_STREAM_PUSH_"; public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; @@ -51,4 +53,7 @@ public class VideoManagerConstants { public static final String MEDIA_SSRC_USED_PREFIX = "VMP_media_used_ssrc_"; public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_media_transaction_"; + + //************************** redis 消息********************************* + public static final String WVP_MSG_STREAM_PUSH_CHANGE_PREFIX = "WVP_msg_stream_push_change"; } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java index 8b1b5b0f..13831b45 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java @@ -27,6 +27,8 @@ public class UserSetup { private Boolean logInDatebase = Boolean.TRUE; + private String serverId = "000000"; + private List interfaceAuthenticationExcludes = new ArrayList<>(); public Boolean getSavePositionHistory() { @@ -104,4 +106,12 @@ public class UserSetup { public void setLogInDatebase(Boolean logInDatebase) { this.logInDatebase = logInDatebase; } + + public String getServerId() { + return serverId; + } + + public void setServerId(String serverId) { + this.serverId = serverId; + } } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java deleted file mode 100644 index 85c158c0..00000000 --- a/src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.genersoft.iot.vmp.conf; - -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Configuration; - -/** - * @description: 获取数据库配置 - * @author: swwheihei - * @date: 2020年5月6日 下午2:46:00 - */ -@Configuration("vmConfig") -public class VManagerConfig { - - @Value("${spring.application.database:redis}") - private String database; - - - public String getDatabase() { - return database; - } - - public void setDatabase(String database) { - this.database = database; - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java b/src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java index 72f0db6c..3e72e29e 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java @@ -1,7 +1,10 @@ package com.genersoft.iot.vmp.conf; +import com.alibaba.fastjson.JSONObject; +import com.genersoft.iot.vmp.service.IMediaServerService; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; @@ -12,13 +15,22 @@ public class WVPTimerTask { private IRedisCatchStorage redisCatchStorage; @Autowired - private SipConfig sipConfig; + private IMediaServerService mediaServerService; @Autowired - private MediaConfig mediaConfig; + private UserSetup userSetup; + + @Value("${server.port}") + private int serverPort; + + @Autowired + private SipConfig sipConfig; -// @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 -// public void execute(){ -//// redisCatchStorage.updateWVPInfo(); -// } + @Scheduled(fixedRate = 2 * 1000) //每3秒执行一次 + public void execute(){ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("ip", sipConfig.getIp()); + jsonObject.put("port", serverPort); + redisCatchStorage.updateWVPInfo(userSetup.getServerId(), jsonObject, 3); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java index 51d03b46..255ded1d 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java @@ -37,8 +37,6 @@ public class DeferredResultHolder { public static final String CALLBACK_CMD_STOP = "CALLBACK_STOP"; - public static final String CALLBACK_ONVIF = "CALLBACK_ONVIF"; - public static final String CALLBACK_CMD_MOBILEPOSITION = "CALLBACK_MOBILEPOSITION"; public static final String CALLBACK_CMD_PRESETQUERY = "CALLBACK_PRESETQUERY"; 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 f74dcfa7..e35f0592 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 @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.UserSetup; import com.genersoft.iot.vmp.gb28181.bean.Device; import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.service.IMediaServerService; +import com.genersoft.iot.vmp.service.IMediaService; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.IVideoManagerStorager; @@ -56,6 +57,9 @@ public class ZLMHttpHookListener { @Autowired private IMediaServerService mediaServerService; + @Autowired + private IMediaService mediaService; + @Autowired private ZLMRESTfulUtils zlmresTfulUtils; @@ -295,11 +299,23 @@ public class ZLMHttpHookListener { } }else { if (!"rtp".equals(app) ){ + // 发送流变化redis消息 + JSONObject jsonObject = new JSONObject(); + jsonObject.put("serverId", userSetup.getServerId()); + jsonObject.put("app", app); + jsonObject.put("stream", streamId); + jsonObject.put("register", regist); + jsonObject.put("mediaServerId", mediaServerId); + redisCatchStorage.sendStreamChangeMsg(jsonObject); + MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); if (regist) { zlmMediaListManager.addMedia(mediaServerItem, app, streamId); + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks); + redisCatchStorage.addStream(mediaServerItem, app, streamId, streamInfo); }else { zlmMediaListManager.removeMedia( app, streamId); + redisCatchStorage.removeStream(mediaServerItem, app, streamId); } } } 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 1c2190a9..51f99d92 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 @@ -47,7 +47,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR private boolean sslEnabled; @Value("${server.port}") - private String serverPort; + private Integer serverPort; @Autowired private MediaConfig mediaConfig; diff --git a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java index e4313d90..69bcd84a 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import java.util.List; import java.util.Map; @@ -120,5 +121,27 @@ public interface IRedisCatchStorage { /** * 在redis添加wvp的信息 */ - void updateWVPInfo(JSONObject jsonObject); + void updateWVPInfo(String id, JSONObject jsonObject, int time); + + /** + * 发送推流生成与推流消失消息 + * @param jsonObject 消息内容 + */ + void sendStreamChangeMsg(JSONObject jsonObject); + + /** + * 添加流信息到redis + * @param mediaServerItem + * @param app + * @param streamId + */ + void addStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo); + + /** + * 移除流信息从redis + * @param mediaServerItem + * @param app + * @param streamId + */ + void removeStream(MediaServerItem mediaServerItem, String app, String streamId); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java index e5b1269d..0d0ede7d 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.common.VideoManagerConstants; import com.genersoft.iot.vmp.gb28181.bean.*; +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; import com.genersoft.iot.vmp.storager.IRedisCatchStorage; import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; import com.genersoft.iot.vmp.utils.redis.RedisUtil; @@ -295,8 +296,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { } @Override - public void updateWVPInfo(JSONObject jsonObject) { + public void updateWVPInfo(String id, JSONObject jsonObject, int time) { + String key = VideoManagerConstants.WVP_SERVER_PREFIX + id; + redis.set(key, jsonObject, time); + } + + @Override + public void sendStreamChangeMsg(JSONObject jsonObject) { + String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX; + redis.convertAndSend(key, jsonObject.toJSONString()); + } + @Override + public void addStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo) { + String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId(); + redis.set(key, streamInfo); } + @Override + public void removeStream(MediaServerItem mediaServerItem, String app, String streamId) { + String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId(); + redis.del(key); + } } diff --git a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java index 35da6788..f89b30df 100644 --- a/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java +++ b/src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java @@ -729,4 +729,10 @@ public class RedisUtil { return new ArrayList<>(keys); } + // ============================== 消息发送与订阅 ============================== + public void convertAndSend(String channel, String msg) { + redisTemplate.convertAndSend(channel, msg); + + } + } diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiCompatibleController.java similarity index 96% rename from src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiCompatibleController.java index c2a26b16..5080bb03 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiCompatibleController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.genersoft.iot.vmp.common.StreamInfo; import com.genersoft.iot.vmp.service.IMediaService; diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiControlController.java similarity index 98% rename from src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiControlController.java index a8e0de4f..f784d3e6 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiControlController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.gb28181.bean.Device; diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiController.java similarity index 98% rename from src/main/java/com/genersoft/iot/vmp/web/ApiController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiController.java index cafa40cf..faf873e3 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.conf.SipConfig; diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java similarity index 99% rename from src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java index ef839763..30942839 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; diff --git a/src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java similarity index 99% rename from src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java index ae7e9212..8ebd8edf 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/src/main/java/com/genersoft/iot/vmp/web/AuthController.java b/src/main/java/com/genersoft/iot/vmp/web/gb28181/AuthController.java similarity index 93% rename from src/main/java/com/genersoft/iot/vmp/web/AuthController.java rename to src/main/java/com/genersoft/iot/vmp/web/gb28181/AuthController.java index f4a2af86..abefa42b 100644 --- a/src/main/java/com/genersoft/iot/vmp/web/AuthController.java +++ b/src/main/java/com/genersoft/iot/vmp/web/gb28181/AuthController.java @@ -1,4 +1,4 @@ -package com.genersoft.iot.vmp.web; +package com.genersoft.iot.vmp.web.gb28181; import com.genersoft.iot.vmp.service.IUserService; import com.genersoft.iot.vmp.storager.dao.dto.User;