Commit 8c4922cbe14b126c5c04a23b0c1968676e597eb7
Merge branch '2.6.7' into wvp-28181-2.0
# Conflicts: # src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java # src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java # src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
Showing
11 changed files
with
216 additions
and
240 deletions
src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java
| ... | ... | @@ -9,6 +9,9 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; |
| 9 | 9 | import org.springframework.data.redis.core.RedisTemplate; |
| 10 | 10 | import org.springframework.data.redis.serializer.StringRedisSerializer; |
| 11 | 11 | |
| 12 | +import org.springframework.data.redis.listener.PatternTopic; | |
| 13 | +import org.springframework.data.redis.listener.RedisMessageListenerContainer; | |
| 14 | + | |
| 12 | 15 | |
| 13 | 16 | /** |
| 14 | 17 | * Redis中间件配置类,使用spring-data-redis集成,自动从application.yml中加载redis配置 | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/redis/RedisTemplateConfig.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.conf.redis; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; | |
| 4 | +import org.springframework.context.annotation.Bean; | |
| 5 | +import org.springframework.context.annotation.Configuration; | |
| 6 | +import org.springframework.data.redis.connection.RedisConnectionFactory; | |
| 7 | +import org.springframework.data.redis.core.RedisTemplate; | |
| 8 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | |
| 9 | + | |
| 10 | +@Configuration | |
| 11 | +public class RedisTemplateConfig { | |
| 12 | + | |
| 13 | + @Bean | |
| 14 | + public RedisTemplate<Object, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | |
| 15 | + RedisTemplate<Object, Object> redisTemplate = new RedisTemplate<>(); | |
| 16 | + // 使用fastJson序列化 | |
| 17 | + FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class); | |
| 18 | + // value值的序列化采用fastJsonRedisSerializer | |
| 19 | + redisTemplate.setValueSerializer(fastJsonRedisSerializer); | |
| 20 | + redisTemplate.setHashValueSerializer(fastJsonRedisSerializer); | |
| 21 | + | |
| 22 | + // key的序列化采用StringRedisSerializer | |
| 23 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | |
| 24 | + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); | |
| 25 | + redisTemplate.setConnectionFactory(redisConnectionFactory); | |
| 26 | + return redisTemplate; | |
| 27 | + } | |
| 28 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java
| ... | ... | @@ -38,7 +38,6 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { |
| 38 | 38 | return; |
| 39 | 39 | } |
| 40 | 40 | if (!userSetting.isInterfaceAuthentication()) { |
| 41 | - // 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录 | |
| 42 | 41 | UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(null, null, new ArrayList<>() ); |
| 43 | 42 | SecurityContextHolder.getContext().setAuthentication(token); |
| 44 | 43 | chain.doFilter(request, response); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/session/SSRCFactory.java
0 → 100644
| 1 | +package com.genersoft.iot.vmp.gb28181.session; | |
| 2 | + | |
| 3 | +import com.genersoft.iot.vmp.conf.SipConfig; | |
| 4 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 5 | +import org.springframework.data.redis.core.StringRedisTemplate; | |
| 6 | +import org.springframework.stereotype.Component; | |
| 7 | + | |
| 8 | +import java.util.ArrayList; | |
| 9 | +import java.util.List; | |
| 10 | +import java.util.Set; | |
| 11 | + | |
| 12 | +/** | |
| 13 | + * ssrc使用 | |
| 14 | + */ | |
| 15 | +@Component | |
| 16 | +public class SSRCFactory { | |
| 17 | + | |
| 18 | + /** | |
| 19 | + * 播流最大并发个数 | |
| 20 | + */ | |
| 21 | + private static final Integer MAX_STREAM_COUNT = 10000; | |
| 22 | + | |
| 23 | + /** | |
| 24 | + * 播流最大并发个数 | |
| 25 | + */ | |
| 26 | + private static final String SSRC_INFO_KEY = "VMP_SSRC_INFO_"; | |
| 27 | + | |
| 28 | + @Autowired | |
| 29 | + private StringRedisTemplate redisTemplate; | |
| 30 | + | |
| 31 | + @Autowired | |
| 32 | + private SipConfig sipConfig; | |
| 33 | + | |
| 34 | + | |
| 35 | + public void initMediaServerSSRC(String mediaServerId, Set<String> usedSet) { | |
| 36 | + String ssrcPrefix = sipConfig.getDomain().substring(3, 8); | |
| 37 | + String redisKey = SSRC_INFO_KEY + mediaServerId; | |
| 38 | + List<String> ssrcList = new ArrayList<>(); | |
| 39 | + for (int i = 1; i < MAX_STREAM_COUNT; i++) { | |
| 40 | + String ssrc = String.format("%s%04d", ssrcPrefix, i); | |
| 41 | + | |
| 42 | + if (null == usedSet || !usedSet.contains(ssrc)) { | |
| 43 | + ssrcList.add(ssrc); | |
| 44 | + | |
| 45 | + } | |
| 46 | + } | |
| 47 | + if (redisTemplate.opsForSet().size(redisKey) != null) { | |
| 48 | + redisTemplate.delete(redisKey); | |
| 49 | + } | |
| 50 | + redisTemplate.opsForSet().add(redisKey, ssrcList.toArray(new String[0])); | |
| 51 | + } | |
| 52 | + | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * 获取视频预览的SSRC值,第一位固定为0 | |
| 56 | + * | |
| 57 | + * @return ssrc | |
| 58 | + */ | |
| 59 | + public String getPlaySsrc(String mediaServerId) { | |
| 60 | + return "0" + getSN(mediaServerId); | |
| 61 | + } | |
| 62 | + | |
| 63 | + /** | |
| 64 | + * 获取录像回放的SSRC值,第一位固定为1 | |
| 65 | + */ | |
| 66 | + public String getPlayBackSsrc(String mediaServerId) { | |
| 67 | + return "1" + getSN(mediaServerId); | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * 释放ssrc,主要用完的ssrc一定要释放,否则会耗尽 | |
| 72 | + * | |
| 73 | + * @param ssrc 需要重置的ssrc | |
| 74 | + */ | |
| 75 | + public void releaseSsrc(String mediaServerId, String ssrc) { | |
| 76 | + if (ssrc == null) { | |
| 77 | + return; | |
| 78 | + } | |
| 79 | + String sn = ssrc.substring(1); | |
| 80 | + String redisKey = SSRC_INFO_KEY + mediaServerId; | |
| 81 | + redisTemplate.opsForSet().add(redisKey, sn); | |
| 82 | + } | |
| 83 | + | |
| 84 | + /** | |
| 85 | + * 获取后四位数SN,随机数 | |
| 86 | + */ | |
| 87 | + private String getSN(String mediaServerId) { | |
| 88 | + String sn = null; | |
| 89 | + String redisKey = SSRC_INFO_KEY + mediaServerId; | |
| 90 | + Long size = redisTemplate.opsForSet().size(redisKey); | |
| 91 | + if (size == null || size == 0) { | |
| 92 | + throw new RuntimeException("ssrc已经用完"); | |
| 93 | + } else { | |
| 94 | + // 在集合中移除并返回一个随机成员。 | |
| 95 | + sn = (String) redisTemplate.opsForSet().pop(redisKey); | |
| 96 | + redisTemplate.opsForSet().remove(redisKey, sn); | |
| 97 | + } | |
| 98 | + return sn; | |
| 99 | + } | |
| 100 | + | |
| 101 | + /** | |
| 102 | + * 重置一个流媒体服务的所有ssrc | |
| 103 | + * | |
| 104 | + * @param mediaServerId 流媒体服务ID | |
| 105 | + */ | |
| 106 | + public void reset(String mediaServerId) { | |
| 107 | + this.initMediaServerSSRC(mediaServerId, null); | |
| 108 | + } | |
| 109 | + | |
| 110 | + /** | |
| 111 | + * 是否已经存在了某个MediaServer的SSRC信息 | |
| 112 | + * | |
| 113 | + * @param mediaServerId 流媒体服务ID | |
| 114 | + */ | |
| 115 | + public boolean hasMediaServerSSRC(String mediaServerId) { | |
| 116 | + String redisKey = SSRC_INFO_KEY + mediaServerId; | |
| 117 | + return redisTemplate.opsForSet().members(redisKey) != null; | |
| 118 | + } | |
| 119 | + | |
| 120 | + /** | |
| 121 | + * 查询ssrc是否可用 | |
| 122 | + * | |
| 123 | + * @param mediaServerId | |
| 124 | + * @param ssrc | |
| 125 | + * @return | |
| 126 | + */ | |
| 127 | + public boolean checkSsrc(String mediaServerId, String ssrc) { | |
| 128 | + String sn = ssrc.substring(1); | |
| 129 | + String redisKey = SSRC_INFO_KEY + mediaServerId; | |
| 130 | + return redisTemplate.opsForSet().isMember(redisKey, sn) != null; | |
| 131 | + } | |
| 132 | +} | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java deleted
100644 → 0
| 1 | -package com.genersoft.iot.vmp.gb28181.session; | |
| 2 | - | |
| 3 | -import com.genersoft.iot.vmp.utils.ConfigConst; | |
| 4 | -import io.swagger.v3.oas.annotations.media.Schema; | |
| 5 | - | |
| 6 | -import java.util.ArrayList; | |
| 7 | -import java.util.List; | |
| 8 | -import java.util.Random; | |
| 9 | -import java.util.Set; | |
| 10 | - | |
| 11 | -@Schema(description = "ssrc信息") | |
| 12 | -public class SsrcConfig { | |
| 13 | - | |
| 14 | - /** | |
| 15 | - * zlm流媒体服务器Id | |
| 16 | - */ | |
| 17 | - @Schema(description = "流媒体服务器Id") | |
| 18 | - private String mediaServerId; | |
| 19 | - | |
| 20 | - @Schema(description = "SSRC前缀") | |
| 21 | - private String ssrcPrefix; | |
| 22 | - | |
| 23 | - /** | |
| 24 | - * zlm流媒体服务器已用会话句柄 | |
| 25 | - */ | |
| 26 | - @Schema(description = "zlm流媒体服务器已用会话句柄") | |
| 27 | - private List<String> isUsed; | |
| 28 | - | |
| 29 | - /** | |
| 30 | - * zlm流媒体服务器可用会话句柄 | |
| 31 | - */ | |
| 32 | - @Schema(description = "zlm流媒体服务器可用会话句柄") | |
| 33 | - private List<String> notUsed; | |
| 34 | - | |
| 35 | - public SsrcConfig() { | |
| 36 | - } | |
| 37 | - | |
| 38 | - public SsrcConfig(String mediaServerId, Set<String> usedSet, String sipDomain) { | |
| 39 | - this.mediaServerId = mediaServerId; | |
| 40 | - this.isUsed = new ArrayList<>(); | |
| 41 | - this.ssrcPrefix = sipDomain.substring(3, 8); | |
| 42 | - this.notUsed = new ArrayList<>(); | |
| 43 | - for (int i = 1; i < ConfigConst.MAX_STRTEAM_COUNT; i++) { | |
| 44 | - String ssrc; | |
| 45 | - if (i < 10) { | |
| 46 | - ssrc = "000" + i; | |
| 47 | - } else if (i < 100) { | |
| 48 | - ssrc = "00" + i; | |
| 49 | - } else if (i < 1000) { | |
| 50 | - ssrc = "0" + i; | |
| 51 | - } else { | |
| 52 | - ssrc = String.valueOf(i); | |
| 53 | - } | |
| 54 | - if (null == usedSet || !usedSet.contains(ssrc)) { | |
| 55 | - this.notUsed.add(ssrc); | |
| 56 | - } else { | |
| 57 | - this.isUsed.add(ssrc); | |
| 58 | - } | |
| 59 | - } | |
| 60 | - } | |
| 61 | - | |
| 62 | - | |
| 63 | - /** | |
| 64 | - * 获取视频预览的SSRC值,第一位固定为0 | |
| 65 | - * @return ssrc | |
| 66 | - */ | |
| 67 | - public String getPlaySsrc() { | |
| 68 | - return "0" + getSsrcPrefix() + getSN(); | |
| 69 | - } | |
| 70 | - | |
| 71 | - /** | |
| 72 | - * 获取录像回放的SSRC值,第一位固定为1 | |
| 73 | - * | |
| 74 | - */ | |
| 75 | - public String getPlayBackSsrc() { | |
| 76 | - return "1" + getSsrcPrefix() + getSN(); | |
| 77 | - } | |
| 78 | - | |
| 79 | - /** | |
| 80 | - * 释放ssrc,主要用完的ssrc一定要释放,否则会耗尽 | |
| 81 | - * @param ssrc 需要重置的ssrc | |
| 82 | - */ | |
| 83 | - public void releaseSsrc(String ssrc) { | |
| 84 | - if (ssrc == null) { | |
| 85 | - return; | |
| 86 | - } | |
| 87 | - String sn = ssrc.substring(6); | |
| 88 | - try { | |
| 89 | - isUsed.remove(sn); | |
| 90 | - notUsed.add(sn); | |
| 91 | - }catch (NullPointerException e){ | |
| 92 | - } | |
| 93 | - } | |
| 94 | - | |
| 95 | - /** | |
| 96 | - * 获取后四位数SN,随机数 | |
| 97 | - * | |
| 98 | - */ | |
| 99 | - private String getSN() { | |
| 100 | - String sn = null; | |
| 101 | - int index = 0; | |
| 102 | - if (notUsed.size() == 0) { | |
| 103 | - throw new RuntimeException("ssrc已经用完"); | |
| 104 | - } else if (notUsed.size() == 1) { | |
| 105 | - sn = notUsed.get(0); | |
| 106 | - } else { | |
| 107 | - index = new Random().nextInt(notUsed.size() - 1); | |
| 108 | - sn = notUsed.get(index); | |
| 109 | - } | |
| 110 | - notUsed.remove(index); | |
| 111 | - isUsed.add(sn); | |
| 112 | - return sn; | |
| 113 | - } | |
| 114 | - | |
| 115 | - public String getSsrcPrefix() { | |
| 116 | - return ssrcPrefix; | |
| 117 | - } | |
| 118 | - | |
| 119 | - public String getMediaServerId() { | |
| 120 | - return mediaServerId; | |
| 121 | - } | |
| 122 | - | |
| 123 | - public void setMediaServerId(String mediaServerId) { | |
| 124 | - this.mediaServerId = mediaServerId; | |
| 125 | - } | |
| 126 | - | |
| 127 | - public void setSsrcPrefix(String ssrcPrefix) { | |
| 128 | - this.ssrcPrefix = ssrcPrefix; | |
| 129 | - } | |
| 130 | - | |
| 131 | - public List<String> getIsUsed() { | |
| 132 | - return isUsed; | |
| 133 | - } | |
| 134 | - | |
| 135 | - public void setIsUsed(List<String> isUsed) { | |
| 136 | - this.isUsed = isUsed; | |
| 137 | - } | |
| 138 | - | |
| 139 | - public List<String> getNotUsed() { | |
| 140 | - return notUsed; | |
| 141 | - } | |
| 142 | - | |
| 143 | - public void setNotUsed(List<String> notUsed) { | |
| 144 | - this.notUsed = notUsed; | |
| 145 | - } | |
| 146 | - | |
| 147 | - public boolean checkSsrc(String ssrcInResponse) { | |
| 148 | - return !isUsed.contains(ssrcInResponse); | |
| 149 | - } | |
| 150 | -} |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -5,7 +5,7 @@ import com.genersoft.iot.vmp.conf.DynamicTask; |
| 5 | 5 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 6 | 6 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 7 | 7 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 8 | -import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; | |
| 8 | +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; | |
| 9 | 9 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 10 | 10 | import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; |
| 11 | 11 | import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; |
| ... | ... | @@ -75,6 +75,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 75 | 75 | private IRedisCatchStorage redisCatchStorage; |
| 76 | 76 | |
| 77 | 77 | @Autowired |
| 78 | + private SSRCFactory ssrcFactory; | |
| 79 | + | |
| 80 | + @Autowired | |
| 78 | 81 | private DynamicTask dynamicTask; |
| 79 | 82 | |
| 80 | 83 | @Autowired |
| ... | ... | @@ -491,12 +494,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 491 | 494 | } else if (gbStream != null) { |
| 492 | 495 | if(ssrc.equals(ssrcDefault)) |
| 493 | 496 | { |
| 494 | - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); | |
| 495 | - if(ssrcConfig != null) | |
| 496 | - { | |
| 497 | - ssrc = ssrcConfig.getPlaySsrc(); | |
| 498 | - ssrcConfig.releaseSsrc(ssrc); | |
| 499 | - } | |
| 497 | + ssrc = ssrcFactory.getPlaySsrc(mediaServerItem.getId()); | |
| 498 | + ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrc); | |
| 500 | 499 | } |
| 501 | 500 | if("push".equals(gbStream.getStreamType())) { |
| 502 | 501 | if (streamPushItem != null && streamPushItem.isPushIng()) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
| 1 | 1 | package com.genersoft.iot.vmp.media.zlm.dto; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | -import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; | |
| 4 | +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; | |
| 5 | 5 | import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; |
| 6 | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | 7 | import org.springframework.util.ObjectUtils; |
| ... | ... | @@ -80,8 +80,8 @@ public class MediaServerItem{ |
| 80 | 80 | @Schema(description = "是否是默认ZLM") |
| 81 | 81 | private boolean defaultServer; |
| 82 | 82 | |
| 83 | - @Schema(description = "SSRC信息") | |
| 84 | - private SsrcConfig ssrcConfig; | |
| 83 | +// @Schema(description = "SSRC信息") | |
| 84 | +// private SsrcConfig ssrcConfig; | |
| 85 | 85 | |
| 86 | 86 | @Schema(description = "当前使用到的端口") |
| 87 | 87 | private int currentPort; |
| ... | ... | @@ -92,7 +92,7 @@ public class MediaServerItem{ |
| 92 | 92 | * 在ApplicationCheckRunner里对mediaServerSsrcMap进行初始化 |
| 93 | 93 | */ |
| 94 | 94 | @Schema(description = "ID") |
| 95 | - private HashMap<String, SsrcConfig> mediaServerSsrcMap; | |
| 95 | + private HashMap<String, SSRCFactory> mediaServerSsrcMap; | |
| 96 | 96 | |
| 97 | 97 | public MediaServerItem() { |
| 98 | 98 | } |
| ... | ... | @@ -279,22 +279,14 @@ public class MediaServerItem{ |
| 279 | 279 | this.updateTime = updateTime; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - public HashMap<String, SsrcConfig> getMediaServerSsrcMap() { | |
| 282 | + public HashMap<String, SSRCFactory> getMediaServerSsrcMap() { | |
| 283 | 283 | return mediaServerSsrcMap; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - public void setMediaServerSsrcMap(HashMap<String, SsrcConfig> mediaServerSsrcMap) { | |
| 286 | + public void setMediaServerSsrcMap(HashMap<String, SSRCFactory> mediaServerSsrcMap) { | |
| 287 | 287 | this.mediaServerSsrcMap = mediaServerSsrcMap; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - public SsrcConfig getSsrcConfig() { | |
| 291 | - return ssrcConfig; | |
| 292 | - } | |
| 293 | - | |
| 294 | - public void setSsrcConfig(SsrcConfig ssrcConfig) { | |
| 295 | - this.ssrcConfig = ssrcConfig; | |
| 296 | - } | |
| 297 | - | |
| 298 | 290 | public int getCurrentPort() { |
| 299 | 291 | return currentPort; |
| 300 | 292 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java
| ... | ... | @@ -45,6 +45,8 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { |
| 45 | 45 | device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); |
| 46 | 46 | } |
| 47 | 47 | |
| 48 | + | |
| 49 | + | |
| 48 | 50 | if ("WGS84".equals(device.getGeoCoordSys())) { |
| 49 | 51 | deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); |
| 50 | 52 | deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
| ... | ... | @@ -9,6 +9,8 @@ import com.genersoft.iot.vmp.conf.SipConfig; |
| 9 | 9 | import com.genersoft.iot.vmp.conf.UserSetting; |
| 10 | 10 | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| 11 | 11 | import com.genersoft.iot.vmp.gb28181.event.EventPublisher; |
| 12 | +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; | |
| 13 | +import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; | |
| 12 | 14 | import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; |
| 13 | 15 | import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils; |
| 14 | 16 | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; |
| ... | ... | @@ -56,6 +58,9 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 56 | 58 | @Autowired |
| 57 | 59 | private SipConfig sipConfig; |
| 58 | 60 | |
| 61 | + @Autowired | |
| 62 | + private SSRCFactory ssrcFactory; | |
| 63 | + | |
| 59 | 64 | @Value("${server.ssl.enabled:false}") |
| 60 | 65 | private boolean sslEnabled; |
| 61 | 66 | |
| ... | ... | @@ -96,6 +101,7 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 96 | 101 | @Autowired |
| 97 | 102 | private RedisTemplate<Object, Object> redisTemplate; |
| 98 | 103 | |
| 104 | + | |
| 99 | 105 | /** |
| 100 | 106 | * 初始化 |
| 101 | 107 | */ |
| ... | ... | @@ -107,10 +113,8 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 107 | 113 | continue; |
| 108 | 114 | } |
| 109 | 115 | // 更新 |
| 110 | - if (mediaServerItem.getSsrcConfig() == null) { | |
| 111 | - SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); | |
| 112 | - mediaServerItem.setSsrcConfig(ssrcConfig); | |
| 113 | - redisTemplate.opsForValue().set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(), mediaServerItem); | |
| 116 | + if (ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) { | |
| 117 | + ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); | |
| 114 | 118 | } |
| 115 | 119 | // 查询redis是否存在此mediaServer |
| 116 | 120 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); |
| ... | ... | @@ -134,36 +138,27 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 134 | 138 | return null; |
| 135 | 139 | } |
| 136 | 140 | // 获取mediaServer可用的ssrc |
| 137 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); | |
| 138 | - | |
| 139 | - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); | |
| 140 | - if (ssrcConfig == null) { | |
| 141 | - logger.info("media server [ {} ] ssrcConfig is null", mediaServerItem.getId()); | |
| 142 | - return null; | |
| 141 | + String ssrc; | |
| 142 | + if (presetSsrc != null) { | |
| 143 | + ssrc = presetSsrc; | |
| 143 | 144 | }else { |
| 144 | - String ssrc; | |
| 145 | - if (presetSsrc != null) { | |
| 146 | - ssrc = presetSsrc; | |
| 145 | + if (isPlayback) { | |
| 146 | + ssrc = ssrcFactory.getPlayBackSsrc(mediaServerItem.getId()); | |
| 147 | 147 | }else { |
| 148 | - if (isPlayback) { | |
| 149 | - ssrc = ssrcConfig.getPlayBackSsrc(); | |
| 150 | - }else { | |
| 151 | - ssrc = ssrcConfig.getPlaySsrc(); | |
| 152 | - } | |
| 148 | + ssrc = ssrcFactory.getPlaySsrc(mediaServerItem.getId()); | |
| 153 | 149 | } |
| 150 | + } | |
| 154 | 151 | |
| 155 | - if (streamId == null) { | |
| 156 | - streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); | |
| 157 | - } | |
| 158 | - int rtpServerPort; | |
| 159 | - if (mediaServerItem.isRtpEnable()) { | |
| 160 | - rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); | |
| 161 | - } else { | |
| 162 | - rtpServerPort = mediaServerItem.getRtpProxyPort(); | |
| 163 | - } | |
| 164 | - redisTemplate.opsForValue().set(key, mediaServerItem); | |
| 165 | - return new SSRCInfo(rtpServerPort, ssrc, streamId); | |
| 152 | + if (streamId == null) { | |
| 153 | + streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); | |
| 154 | + } | |
| 155 | + int rtpServerPort; | |
| 156 | + if (mediaServerItem.isRtpEnable()) { | |
| 157 | + rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); | |
| 158 | + } else { | |
| 159 | + rtpServerPort = mediaServerItem.getRtpProxyPort(); | |
| 166 | 160 | } |
| 161 | + return new SSRCInfo(rtpServerPort, ssrc, streamId); | |
| 167 | 162 | } |
| 168 | 163 | |
| 169 | 164 | @Override |
| ... | ... | @@ -191,11 +186,7 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 191 | 186 | if (mediaServerItem == null || ssrc == null) { |
| 192 | 187 | return; |
| 193 | 188 | } |
| 194 | - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); | |
| 195 | - ssrcConfig.releaseSsrc(ssrc); | |
| 196 | - mediaServerItem.setSsrcConfig(ssrcConfig); | |
| 197 | - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); | |
| 198 | - redisTemplate.opsForValue().set(key, mediaServerItem); | |
| 189 | + ssrcFactory.releaseSsrc(mediaServerItemId, ssrc); | |
| 199 | 190 | } |
| 200 | 191 | |
| 201 | 192 | /** |
| ... | ... | @@ -203,8 +194,7 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 203 | 194 | */ |
| 204 | 195 | @Override |
| 205 | 196 | public void clearRTPServer(MediaServerItem mediaServerItem) { |
| 206 | - mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); | |
| 207 | - redisTemplate.opsForZSet().add(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(), mediaServerItem.getId(), 0); | |
| 197 | + ssrcFactory.reset(mediaServerItem.getId()); | |
| 208 | 198 | |
| 209 | 199 | } |
| 210 | 200 | |
| ... | ... | @@ -214,16 +204,8 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 214 | 204 | mediaServerMapper.update(mediaSerItem); |
| 215 | 205 | MediaServerItem mediaServerItemInRedis = getOne(mediaSerItem.getId()); |
| 216 | 206 | MediaServerItem mediaServerItemInDataBase = mediaServerMapper.queryOne(mediaSerItem.getId()); |
| 217 | - if (mediaServerItemInRedis != null && mediaServerItemInRedis.getSsrcConfig() != null) { | |
| 218 | - mediaServerItemInDataBase.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); | |
| 219 | - }else { | |
| 220 | - mediaServerItemInDataBase.setSsrcConfig( | |
| 221 | - new SsrcConfig( | |
| 222 | - mediaServerItemInDataBase.getId(), | |
| 223 | - null, | |
| 224 | - sipConfig.getDomain() | |
| 225 | - ) | |
| 226 | - ); | |
| 207 | + if (mediaServerItemInRedis == null || ssrcFactory.hasMediaServerSSRC(mediaSerItem.getId())) { | |
| 208 | + ssrcFactory.initMediaServerSSRC(mediaServerItemInDataBase.getId(),null); | |
| 227 | 209 | } |
| 228 | 210 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItemInDataBase.getId(); |
| 229 | 211 | redisTemplate.opsForValue().set(key, mediaServerItemInDataBase); |
| ... | ... | @@ -404,14 +386,8 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 404 | 386 | } |
| 405 | 387 | mediaServerMapper.update(serverItem); |
| 406 | 388 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + zlmServerConfig.getGeneralMediaServerId(); |
| 407 | - if (redisTemplate.opsForValue().get(key) == null) { | |
| 408 | - SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain()); | |
| 409 | - serverItem.setSsrcConfig(ssrcConfig); | |
| 410 | - }else { | |
| 411 | - MediaServerItem mediaServerItemInRedis = JsonUtil.redisJsonToObject(redisTemplate, key, MediaServerItem.class); | |
| 412 | - if (Objects.nonNull(mediaServerItemInRedis)) { | |
| 413 | - serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); | |
| 414 | - } | |
| 389 | + if (ssrcFactory.hasMediaServerSSRC(serverItem.getId())) { | |
| 390 | + ssrcFactory.initMediaServerSSRC(zlmServerConfig.getGeneralMediaServerId(), null); | |
| 415 | 391 | } |
| 416 | 392 | redisTemplate.opsForValue().set(key, serverItem); |
| 417 | 393 | resetOnlineServerItem(serverItem); |
| ... | ... | @@ -709,8 +685,7 @@ public class MediaServerServiceImpl implements IMediaServerService { |
| 709 | 685 | } |
| 710 | 686 | // zlm连接重试 |
| 711 | 687 | logger.warn("[更新ZLM 保活信息]尝试链接zml id {}", mediaServerId); |
| 712 | - SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); | |
| 713 | - mediaServerItem.setSsrcConfig(ssrcConfig); | |
| 688 | + ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); | |
| 714 | 689 | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); |
| 715 | 690 | redisTemplate.opsForValue().set(key, mediaServerItem); |
| 716 | 691 | clearRTPServer(mediaServerItem); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.conf.exception.ServiceException; |
| 11 | 11 | import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; |
| 12 | 12 | import com.genersoft.iot.vmp.gb28181.bean.*; |
| 13 | 13 | import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; |
| 14 | +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; | |
| 14 | 15 | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; |
| 15 | 16 | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; |
| 16 | 17 | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; |
| ... | ... | @@ -101,6 +102,9 @@ public class PlayServiceImpl implements IPlayService { |
| 101 | 102 | private ZlmHttpHookSubscribe subscribe; |
| 102 | 103 | |
| 103 | 104 | @Autowired |
| 105 | + private SSRCFactory ssrcFactory; | |
| 106 | + | |
| 107 | + @Autowired | |
| 104 | 108 | private RedisTemplate<Object, Object> redisTemplate; |
| 105 | 109 | |
| 106 | 110 | |
| ... | ... | @@ -298,10 +302,10 @@ public class PlayServiceImpl implements IPlayService { |
| 298 | 302 | if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { |
| 299 | 303 | logger.info("[点播消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); |
| 300 | 304 | |
| 301 | - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { | |
| 305 | + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { | |
| 302 | 306 | // ssrc 不可用 |
| 303 | 307 | // 释放ssrc |
| 304 | - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 308 | + ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | |
| 305 | 309 | streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); |
| 306 | 310 | event.msg = "下级自定义了ssrc,但是此ssrc不可用"; |
| 307 | 311 | event.statusCode = 400; |
| ... | ... | @@ -539,7 +543,7 @@ public class PlayServiceImpl implements IPlayService { |
| 539 | 543 | if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { |
| 540 | 544 | logger.info("[回放消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); |
| 541 | 545 | |
| 542 | - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { | |
| 546 | + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { | |
| 543 | 547 | // ssrc 不可用 |
| 544 | 548 | // 释放ssrc |
| 545 | 549 | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); |
| ... | ... | @@ -678,7 +682,7 @@ public class PlayServiceImpl implements IPlayService { |
| 678 | 682 | if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { |
| 679 | 683 | logger.info("[回放消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); |
| 680 | 684 | |
| 681 | - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { | |
| 685 | + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { | |
| 682 | 686 | // ssrc 不可用 |
| 683 | 687 | // 释放ssrc |
| 684 | 688 | mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); | ... | ... |