Commit b1c92cf4e88447fc59a2b0b8b78c0e2c41282141
1 parent
6282c81b
在redis中添加wvp存活依据,添加推流变化消息
Showing
16 changed files
with
107 additions
and
43 deletions
src/main/java/com/genersoft/iot/vmp/common/VideoManagerConstants.java
| @@ -8,7 +8,9 @@ package com.genersoft.iot.vmp.common; | @@ -8,7 +8,9 @@ package com.genersoft.iot.vmp.common; | ||
| 8 | */ | 8 | */ |
| 9 | public class VideoManagerConstants { | 9 | public class VideoManagerConstants { |
| 10 | 10 | ||
| 11 | - public static final String WVP_SERVER_PREFIX = "VMP_wvp_server"; | 11 | + public static final String WVP_SERVER_PREFIX = "VMP_SIGNALLING_SERVER_INFO_"; |
| 12 | + | ||
| 13 | + public static final String WVP_SERVER_STREAM_PUSH_PREFIX = "VMP_SIGNALLING_STREAM_PUSH_"; | ||
| 12 | 14 | ||
| 13 | public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; | 15 | public static final String MEDIA_SERVER_PREFIX = "VMP_MEDIA_SERVER_"; |
| 14 | 16 | ||
| @@ -51,4 +53,7 @@ public class VideoManagerConstants { | @@ -51,4 +53,7 @@ public class VideoManagerConstants { | ||
| 51 | public static final String MEDIA_SSRC_USED_PREFIX = "VMP_media_used_ssrc_"; | 53 | public static final String MEDIA_SSRC_USED_PREFIX = "VMP_media_used_ssrc_"; |
| 52 | 54 | ||
| 53 | public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_media_transaction_"; | 55 | public static final String MEDIA_TRANSACTION_USED_PREFIX = "VMP_media_transaction_"; |
| 56 | + | ||
| 57 | + //************************** redis 消息********************************* | ||
| 58 | + public static final String WVP_MSG_STREAM_PUSH_CHANGE_PREFIX = "WVP_msg_stream_push_change"; | ||
| 54 | } | 59 | } |
src/main/java/com/genersoft/iot/vmp/conf/UserSetup.java
| @@ -27,6 +27,8 @@ public class UserSetup { | @@ -27,6 +27,8 @@ public class UserSetup { | ||
| 27 | 27 | ||
| 28 | private Boolean logInDatebase = Boolean.TRUE; | 28 | private Boolean logInDatebase = Boolean.TRUE; |
| 29 | 29 | ||
| 30 | + private String serverId = "000000"; | ||
| 31 | + | ||
| 30 | private List<String> interfaceAuthenticationExcludes = new ArrayList<>(); | 32 | private List<String> interfaceAuthenticationExcludes = new ArrayList<>(); |
| 31 | 33 | ||
| 32 | public Boolean getSavePositionHistory() { | 34 | public Boolean getSavePositionHistory() { |
| @@ -104,4 +106,12 @@ public class UserSetup { | @@ -104,4 +106,12 @@ public class UserSetup { | ||
| 104 | public void setLogInDatebase(Boolean logInDatebase) { | 106 | public void setLogInDatebase(Boolean logInDatebase) { |
| 105 | this.logInDatebase = logInDatebase; | 107 | this.logInDatebase = logInDatebase; |
| 106 | } | 108 | } |
| 109 | + | ||
| 110 | + public String getServerId() { | ||
| 111 | + return serverId; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setServerId(String serverId) { | ||
| 115 | + this.serverId = serverId; | ||
| 116 | + } | ||
| 107 | } | 117 | } |
src/main/java/com/genersoft/iot/vmp/conf/VManagerConfig.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.conf; | ||
| 2 | - | ||
| 3 | -import org.springframework.beans.factory.annotation.Value; | ||
| 4 | -import org.springframework.context.annotation.Configuration; | ||
| 5 | - | ||
| 6 | -/** | ||
| 7 | - * @description: 获取数据库配置 | ||
| 8 | - * @author: swwheihei | ||
| 9 | - * @date: 2020年5月6日 下午2:46:00 | ||
| 10 | - */ | ||
| 11 | -@Configuration("vmConfig") | ||
| 12 | -public class VManagerConfig { | ||
| 13 | - | ||
| 14 | - @Value("${spring.application.database:redis}") | ||
| 15 | - private String database; | ||
| 16 | - | ||
| 17 | - | ||
| 18 | - public String getDatabase() { | ||
| 19 | - return database; | ||
| 20 | - } | ||
| 21 | - | ||
| 22 | - public void setDatabase(String database) { | ||
| 23 | - this.database = database; | ||
| 24 | - } | ||
| 25 | -} |
src/main/java/com/genersoft/iot/vmp/conf/WVPTimerTask.java
| 1 | package com.genersoft.iot.vmp.conf; | 1 | package com.genersoft.iot.vmp.conf; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 4 | +import com.genersoft.iot.vmp.service.IMediaServerService; | ||
| 3 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 5 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 4 | import org.springframework.beans.factory.annotation.Autowired; | 6 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | +import org.springframework.beans.factory.annotation.Value; | ||
| 5 | import org.springframework.scheduling.annotation.Scheduled; | 8 | import org.springframework.scheduling.annotation.Scheduled; |
| 6 | import org.springframework.stereotype.Component; | 9 | import org.springframework.stereotype.Component; |
| 7 | 10 | ||
| @@ -12,13 +15,22 @@ public class WVPTimerTask { | @@ -12,13 +15,22 @@ public class WVPTimerTask { | ||
| 12 | private IRedisCatchStorage redisCatchStorage; | 15 | private IRedisCatchStorage redisCatchStorage; |
| 13 | 16 | ||
| 14 | @Autowired | 17 | @Autowired |
| 15 | - private SipConfig sipConfig; | 18 | + private IMediaServerService mediaServerService; |
| 16 | 19 | ||
| 17 | @Autowired | 20 | @Autowired |
| 18 | - private MediaConfig mediaConfig; | 21 | + private UserSetup userSetup; |
| 22 | + | ||
| 23 | + @Value("${server.port}") | ||
| 24 | + private int serverPort; | ||
| 25 | + | ||
| 26 | + @Autowired | ||
| 27 | + private SipConfig sipConfig; | ||
| 19 | 28 | ||
| 20 | -// @Scheduled(cron="0/2 * * * * ? ") //每3秒执行一次 | ||
| 21 | -// public void execute(){ | ||
| 22 | -//// redisCatchStorage.updateWVPInfo(); | ||
| 23 | -// } | 29 | + @Scheduled(fixedRate = 2 * 1000) //每3秒执行一次 |
| 30 | + public void execute(){ | ||
| 31 | + JSONObject jsonObject = new JSONObject(); | ||
| 32 | + jsonObject.put("ip", sipConfig.getIp()); | ||
| 33 | + jsonObject.put("port", serverPort); | ||
| 34 | + redisCatchStorage.updateWVPInfo(userSetup.getServerId(), jsonObject, 3); | ||
| 35 | + } | ||
| 24 | } | 36 | } |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| @@ -37,8 +37,6 @@ public class DeferredResultHolder { | @@ -37,8 +37,6 @@ public class DeferredResultHolder { | ||
| 37 | 37 | ||
| 38 | public static final String CALLBACK_CMD_STOP = "CALLBACK_STOP"; | 38 | public static final String CALLBACK_CMD_STOP = "CALLBACK_STOP"; |
| 39 | 39 | ||
| 40 | - public static final String CALLBACK_ONVIF = "CALLBACK_ONVIF"; | ||
| 41 | - | ||
| 42 | public static final String CALLBACK_CMD_MOBILEPOSITION = "CALLBACK_MOBILEPOSITION"; | 40 | public static final String CALLBACK_CMD_MOBILEPOSITION = "CALLBACK_MOBILEPOSITION"; |
| 43 | 41 | ||
| 44 | public static final String CALLBACK_CMD_PRESETQUERY = "CALLBACK_PRESETQUERY"; | 42 | public static final String CALLBACK_CMD_PRESETQUERY = "CALLBACK_PRESETQUERY"; |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
| @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.UserSetup; | @@ -10,6 +10,7 @@ import com.genersoft.iot.vmp.conf.UserSetup; | ||
| 10 | import com.genersoft.iot.vmp.gb28181.bean.Device; | 10 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 11 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 12 | import com.genersoft.iot.vmp.service.IMediaServerService; | 12 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 13 | +import com.genersoft.iot.vmp.service.IMediaService; | ||
| 13 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; | 14 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 14 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 15 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 15 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 16 | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; |
| @@ -57,6 +58,9 @@ public class ZLMHttpHookListener { | @@ -57,6 +58,9 @@ public class ZLMHttpHookListener { | ||
| 57 | private IMediaServerService mediaServerService; | 58 | private IMediaServerService mediaServerService; |
| 58 | 59 | ||
| 59 | @Autowired | 60 | @Autowired |
| 61 | + private IMediaService mediaService; | ||
| 62 | + | ||
| 63 | + @Autowired | ||
| 60 | private ZLMRESTfulUtils zlmresTfulUtils; | 64 | private ZLMRESTfulUtils zlmresTfulUtils; |
| 61 | 65 | ||
| 62 | @Autowired | 66 | @Autowired |
| @@ -295,11 +299,23 @@ public class ZLMHttpHookListener { | @@ -295,11 +299,23 @@ public class ZLMHttpHookListener { | ||
| 295 | } | 299 | } |
| 296 | }else { | 300 | }else { |
| 297 | if (!"rtp".equals(app) ){ | 301 | if (!"rtp".equals(app) ){ |
| 302 | + // 发送流变化redis消息 | ||
| 303 | + JSONObject jsonObject = new JSONObject(); | ||
| 304 | + jsonObject.put("serverId", userSetup.getServerId()); | ||
| 305 | + jsonObject.put("app", app); | ||
| 306 | + jsonObject.put("stream", streamId); | ||
| 307 | + jsonObject.put("register", regist); | ||
| 308 | + jsonObject.put("mediaServerId", mediaServerId); | ||
| 309 | + redisCatchStorage.sendStreamChangeMsg(jsonObject); | ||
| 310 | + | ||
| 298 | MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); | 311 | MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId); |
| 299 | if (regist) { | 312 | if (regist) { |
| 300 | zlmMediaListManager.addMedia(mediaServerItem, app, streamId); | 313 | zlmMediaListManager.addMedia(mediaServerItem, app, streamId); |
| 314 | + StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(mediaServerItem, app, streamId, tracks); | ||
| 315 | + redisCatchStorage.addStream(mediaServerItem, app, streamId, streamInfo); | ||
| 301 | }else { | 316 | }else { |
| 302 | zlmMediaListManager.removeMedia( app, streamId); | 317 | zlmMediaListManager.removeMedia( app, streamId); |
| 318 | + redisCatchStorage.removeStream(mediaServerItem, app, streamId); | ||
| 303 | } | 319 | } |
| 304 | } | 320 | } |
| 305 | } | 321 | } |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| @@ -47,7 +47,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | @@ -47,7 +47,7 @@ public class MediaServerServiceImpl implements IMediaServerService, CommandLineR | ||
| 47 | private boolean sslEnabled; | 47 | private boolean sslEnabled; |
| 48 | 48 | ||
| 49 | @Value("${server.port}") | 49 | @Value("${server.port}") |
| 50 | - private String serverPort; | 50 | + private Integer serverPort; |
| 51 | 51 | ||
| 52 | @Autowired | 52 | @Autowired |
| 53 | private MediaConfig mediaConfig; | 53 | private MediaConfig mediaConfig; |
src/main/java/com/genersoft/iot/vmp/storager/IRedisCatchStorage.java
| @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; | @@ -5,6 +5,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; | ||
| 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; | 5 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatform; |
| 6 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; | 6 | import com.genersoft.iot.vmp.gb28181.bean.ParentPlatformCatch; |
| 7 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; | 7 | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| 8 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 8 | 9 | ||
| 9 | import java.util.List; | 10 | import java.util.List; |
| 10 | import java.util.Map; | 11 | import java.util.Map; |
| @@ -120,5 +121,27 @@ public interface IRedisCatchStorage { | @@ -120,5 +121,27 @@ public interface IRedisCatchStorage { | ||
| 120 | /** | 121 | /** |
| 121 | * 在redis添加wvp的信息 | 122 | * 在redis添加wvp的信息 |
| 122 | */ | 123 | */ |
| 123 | - void updateWVPInfo(JSONObject jsonObject); | 124 | + void updateWVPInfo(String id, JSONObject jsonObject, int time); |
| 125 | + | ||
| 126 | + /** | ||
| 127 | + * 发送推流生成与推流消失消息 | ||
| 128 | + * @param jsonObject 消息内容 | ||
| 129 | + */ | ||
| 130 | + void sendStreamChangeMsg(JSONObject jsonObject); | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 添加流信息到redis | ||
| 134 | + * @param mediaServerItem | ||
| 135 | + * @param app | ||
| 136 | + * @param streamId | ||
| 137 | + */ | ||
| 138 | + void addStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo); | ||
| 139 | + | ||
| 140 | + /** | ||
| 141 | + * 移除流信息从redis | ||
| 142 | + * @param mediaServerItem | ||
| 143 | + * @param app | ||
| 144 | + * @param streamId | ||
| 145 | + */ | ||
| 146 | + void removeStream(MediaServerItem mediaServerItem, String app, String streamId); | ||
| 124 | } | 147 | } |
src/main/java/com/genersoft/iot/vmp/storager/impl/RedisCatchStorageImpl.java
| @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; | @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSONObject; | ||
| 4 | import com.genersoft.iot.vmp.common.StreamInfo; | 4 | import com.genersoft.iot.vmp.common.StreamInfo; |
| 5 | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 5 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 6 | import com.genersoft.iot.vmp.gb28181.bean.*; | 6 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 7 | +import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 7 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 8 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 8 | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; | 9 | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; |
| 9 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; | 10 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| @@ -295,8 +296,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | @@ -295,8 +296,26 @@ public class RedisCatchStorageImpl implements IRedisCatchStorage { | ||
| 295 | } | 296 | } |
| 296 | 297 | ||
| 297 | @Override | 298 | @Override |
| 298 | - public void updateWVPInfo(JSONObject jsonObject) { | 299 | + public void updateWVPInfo(String id, JSONObject jsonObject, int time) { |
| 300 | + String key = VideoManagerConstants.WVP_SERVER_PREFIX + id; | ||
| 301 | + redis.set(key, jsonObject, time); | ||
| 302 | + } | ||
| 303 | + | ||
| 304 | + @Override | ||
| 305 | + public void sendStreamChangeMsg(JSONObject jsonObject) { | ||
| 306 | + String key = VideoManagerConstants.WVP_MSG_STREAM_PUSH_CHANGE_PREFIX; | ||
| 307 | + redis.convertAndSend(key, jsonObject.toJSONString()); | ||
| 308 | + } | ||
| 299 | 309 | ||
| 310 | + @Override | ||
| 311 | + public void addStream(MediaServerItem mediaServerItem, String app, String streamId, StreamInfo streamInfo) { | ||
| 312 | + String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId(); | ||
| 313 | + redis.set(key, streamInfo); | ||
| 300 | } | 314 | } |
| 301 | 315 | ||
| 316 | + @Override | ||
| 317 | + public void removeStream(MediaServerItem mediaServerItem, String app, String streamId) { | ||
| 318 | + String key = VideoManagerConstants.WVP_SERVER_STREAM_PUSH_PREFIX + app + "_" + streamId + "_" + mediaServerItem.getId(); | ||
| 319 | + redis.del(key); | ||
| 320 | + } | ||
| 302 | } | 321 | } |
src/main/java/com/genersoft/iot/vmp/utils/redis/RedisUtil.java
| @@ -729,4 +729,10 @@ public class RedisUtil { | @@ -729,4 +729,10 @@ public class RedisUtil { | ||
| 729 | return new ArrayList<>(keys); | 729 | return new ArrayList<>(keys); |
| 730 | } | 730 | } |
| 731 | 731 | ||
| 732 | + // ============================== 消息发送与订阅 ============================== | ||
| 733 | + public void convertAndSend(String channel, String msg) { | ||
| 734 | + redisTemplate.convertAndSend(channel, msg); | ||
| 735 | + | ||
| 736 | + } | ||
| 737 | + | ||
| 732 | } | 738 | } |
src/main/java/com/genersoft/iot/vmp/web/ApiCompatibleController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiCompatibleController.java
src/main/java/com/genersoft/iot/vmp/web/ApiControlController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiControlController.java
src/main/java/com/genersoft/iot/vmp/web/ApiController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiController.java
src/main/java/com/genersoft/iot/vmp/web/ApiDeviceController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiDeviceController.java
src/main/java/com/genersoft/iot/vmp/web/ApiStreamController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/ApiStreamController.java
src/main/java/com/genersoft/iot/vmp/web/AuthController.java renamed to src/main/java/com/genersoft/iot/vmp/web/gb28181/AuthController.java
| 1 | -package com.genersoft.iot.vmp.web; | 1 | +package com.genersoft.iot.vmp.web.gb28181; |
| 2 | 2 | ||
| 3 | import com.genersoft.iot.vmp.service.IUserService; | 3 | import com.genersoft.iot.vmp.service.IUserService; |
| 4 | import com.genersoft.iot.vmp.storager.dao.dto.User; | 4 | import com.genersoft.iot.vmp.storager.dao.dto.User; |