From 3dfbc843adf2d4b6affd3d1d14684941a09561fb Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Mon, 3 Apr 2023 10:53:54 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E9=89=B4=E6=9D=83=E6=97=B6=EF=BC=8C=E5=A4=84?= =?UTF-8?q?=E4=BA=8E=E5=BF=BD=E7=95=A5=E5=9C=B0=E5=9D=80=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E4=B8=8D=E5=8F=AF=E7=94=A8=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../security/JwtAuthenticationFilter.java | 1 - .../vmp/conf/security/WebSecurityConfig.java | 32 ++++++++++--------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java index e50a8b0e..27151eee 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/JwtAuthenticationFilter.java @@ -38,7 +38,6 @@ public class JwtAuthenticationFilter extends OncePerRequestFilter { return; } if (!userSetting.isInterfaceAuthentication()) { - // 构建UsernamePasswordAuthenticationToken,这里密码为null,是因为提供了正确的JWT,实现自动登录 UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(null, null, new ArrayList<>() ); SecurityContextHolder.getContext().setAuthentication(token); chain.doFilter(request, response); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java index c9a1233b..cea19f81 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/security/WebSecurityConfig.java @@ -72,21 +72,23 @@ public class WebSecurityConfig extends WebSecurityConfigurerAdapter { **/ @Override public void configure(WebSecurity web) { - - ArrayList matchers = new ArrayList<>(); - matchers.add("/"); - matchers.add("/#/**"); - matchers.add("/static/**"); - matchers.add("/index.html"); - matchers.add("/doc.html"); - matchers.add("/webjars/**"); - matchers.add("/swagger-resources/**"); - matchers.add("/v3/api-docs/**"); - matchers.add("/js/**"); - matchers.add("/api/device/query/snap/**"); - matchers.addAll(userSetting.getInterfaceAuthenticationExcludes()); - // 可以直接访问的静态数据 - web.ignoring().antMatchers(matchers.toArray(new String[0])); + if (userSetting.isInterfaceAuthentication()) { + ArrayList matchers = new ArrayList<>(); + matchers.add("/"); + matchers.add("/#/**"); + matchers.add("/static/**"); + matchers.add("/index.html"); + matchers.add("/doc.html"); + matchers.add("/webjars/**"); + matchers.add("/swagger-resources/**"); + matchers.add("/v3/api-docs/**"); + matchers.add("/js/**"); + matchers.add("/api/device/query/snap/**"); + matchers.add("/record_proxy/*/**"); + matchers.addAll(userSetting.getInterfaceAuthenticationExcludes()); + // 可以直接访问的静态数据 + web.ignoring().antMatchers(matchers.toArray(new String[0])); + } } /** From 0858f7995b8236d79c6e39a5974cb7a13bcb4e3e Mon Sep 17 00:00:00 2001 From: 648540858 <648540858@qq.com> Date: Sat, 8 Apr 2023 15:22:18 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96ssrc=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E7=BB=93=E6=9E=84=EF=BC=8C=E9=81=BF=E5=85=8D=E5=9B=A0=E4=B8=BA?= =?UTF-8?q?=E5=A4=A7=E9=87=8Fssrc=E5=AD=98=E5=9C=A8MediaServer=E4=B8=AD?= =?UTF-8?q?=E5=AF=BC=E8=87=B4redis=E8=AF=BB=E5=8F=96=E8=B6=85=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../iot/vmp/conf/redis/RedisConfig.java | 18 --- .../vmp/conf/redis/RedisTemplateConfig.java | 28 ++++ .../iot/vmp/gb28181/session/SSRCFactory.java | 132 +++++++++++++++ .../iot/vmp/gb28181/session/SsrcConfig.java | 150 ------------------ .../request/impl/InviteRequestProcessor.java | 13 +- .../vmp/media/zlm/dto/MediaServerItem.java | 20 +-- .../impl/DeviceChannelServiceImpl.java | 2 + .../service/impl/MediaServerServiceImpl.java | 88 ++++------ .../iot/vmp/service/impl/PlayServiceImpl.java | 12 +- .../genersoft/iot/vmp/utils/ConfigConst.java | 8 - 10 files changed, 213 insertions(+), 258 deletions(-) create mode 100644 src/main/java/com/genersoft/iot/vmp/conf/redis/RedisTemplateConfig.java create mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/session/SSRCFactory.java delete mode 100644 src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java delete mode 100644 src/main/java/com/genersoft/iot/vmp/utils/ConfigConst.java diff --git a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java index a2dca631..87b4d53d 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java @@ -9,12 +9,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.annotation.Order; import org.springframework.data.redis.connection.RedisConnectionFactory; -import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.PatternTopic; import org.springframework.data.redis.listener.RedisMessageListenerContainer; -import org.springframework.data.redis.serializer.StringRedisSerializer; - -import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; /** @@ -48,21 +44,7 @@ public class RedisConfig extends CachingConfigurerSupport { @Autowired private RedisPushStreamResponseListener redisPushStreamResponseListener; - @Bean - public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { - RedisTemplate redisTemplate = new RedisTemplate<>(); - // 使用fastJson序列化 - FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class); - // value值的序列化采用fastJsonRedisSerializer - redisTemplate.setValueSerializer(fastJsonRedisSerializer); - redisTemplate.setHashValueSerializer(fastJsonRedisSerializer); - // key的序列化采用StringRedisSerializer - redisTemplate.setKeySerializer(new StringRedisSerializer()); - redisTemplate.setHashKeySerializer(new StringRedisSerializer()); - redisTemplate.setConnectionFactory(redisConnectionFactory); - return redisTemplate; - } /** diff --git a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisTemplateConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisTemplateConfig.java new file mode 100644 index 00000000..1868a5d4 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisTemplateConfig.java @@ -0,0 +1,28 @@ +package com.genersoft.iot.vmp.conf.redis; + +import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.data.redis.connection.RedisConnectionFactory; +import org.springframework.data.redis.core.RedisTemplate; +import org.springframework.data.redis.serializer.StringRedisSerializer; + +@Configuration +public class RedisTemplateConfig { + + @Bean + public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { + RedisTemplate redisTemplate = new RedisTemplate<>(); + // 使用fastJson序列化 + FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer(Object.class); + // value值的序列化采用fastJsonRedisSerializer + redisTemplate.setValueSerializer(fastJsonRedisSerializer); + redisTemplate.setHashValueSerializer(fastJsonRedisSerializer); + + // key的序列化采用StringRedisSerializer + redisTemplate.setKeySerializer(new StringRedisSerializer()); + redisTemplate.setHashKeySerializer(new StringRedisSerializer()); + redisTemplate.setConnectionFactory(redisConnectionFactory); + return redisTemplate; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SSRCFactory.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SSRCFactory.java new file mode 100644 index 00000000..ec8e0ba6 --- /dev/null +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SSRCFactory.java @@ -0,0 +1,132 @@ +package com.genersoft.iot.vmp.gb28181.session; + +import com.genersoft.iot.vmp.conf.SipConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.StringRedisTemplate; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +/** + * ssrc使用 + */ +@Component +public class SSRCFactory { + + /** + * 播流最大并发个数 + */ + private static final Integer MAX_STREAM_COUNT = 10000; + + /** + * 播流最大并发个数 + */ + private static final String SSRC_INFO_KEY = "VMP_SSRC_INFO_"; + + @Autowired + private StringRedisTemplate redisTemplate; + + @Autowired + private SipConfig sipConfig; + + + public void initMediaServerSSRC(String mediaServerId, Set usedSet) { + String ssrcPrefix = sipConfig.getDomain().substring(3, 8); + String redisKey = SSRC_INFO_KEY + mediaServerId; + List ssrcList = new ArrayList<>(); + for (int i = 1; i < MAX_STREAM_COUNT; i++) { + String ssrc = String.format("%s%04d", ssrcPrefix, i); + + if (null == usedSet || !usedSet.contains(ssrc)) { + ssrcList.add(ssrc); + + } + } + if (redisTemplate.opsForSet().size(redisKey) != null) { + redisTemplate.delete(redisKey); + } + redisTemplate.opsForSet().add(redisKey, ssrcList.toArray(new String[0])); + } + + + /** + * 获取视频预览的SSRC值,第一位固定为0 + * + * @return ssrc + */ + public String getPlaySsrc(String mediaServerId) { + return "0" + getSN(mediaServerId); + } + + /** + * 获取录像回放的SSRC值,第一位固定为1 + */ + public String getPlayBackSsrc(String mediaServerId) { + return "1" + getSN(mediaServerId); + } + + /** + * 释放ssrc,主要用完的ssrc一定要释放,否则会耗尽 + * + * @param ssrc 需要重置的ssrc + */ + public void releaseSsrc(String mediaServerId, String ssrc) { + if (ssrc == null) { + return; + } + String sn = ssrc.substring(1); + String redisKey = SSRC_INFO_KEY + mediaServerId; + redisTemplate.opsForSet().add(redisKey, sn); + } + + /** + * 获取后四位数SN,随机数 + */ + private String getSN(String mediaServerId) { + String sn = null; + String redisKey = SSRC_INFO_KEY + mediaServerId; + Long size = redisTemplate.opsForSet().size(redisKey); + if (size == null || size == 0) { + throw new RuntimeException("ssrc已经用完"); + } else { + // 在集合中移除并返回一个随机成员。 + sn = (String) redisTemplate.opsForSet().pop(redisKey); + redisTemplate.opsForSet().remove(redisKey, sn); + } + return sn; + } + + /** + * 重置一个流媒体服务的所有ssrc + * + * @param mediaServerId 流媒体服务ID + */ + public void reset(String mediaServerId) { + this.initMediaServerSSRC(mediaServerId, null); + } + + /** + * 是否已经存在了某个MediaServer的SSRC信息 + * + * @param mediaServerId 流媒体服务ID + */ + public boolean hasMediaServerSSRC(String mediaServerId) { + String redisKey = SSRC_INFO_KEY + mediaServerId; + return redisTemplate.opsForSet().members(redisKey) != null; + } + + /** + * 查询ssrc是否可用 + * + * @param mediaServerId + * @param ssrc + * @return + */ + public boolean checkSsrc(String mediaServerId, String ssrc) { + String sn = ssrc.substring(1); + String redisKey = SSRC_INFO_KEY + mediaServerId; + return redisTemplate.opsForSet().isMember(redisKey, sn) != null; + } +} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java b/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java deleted file mode 100644 index cc303c8b..00000000 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/session/SsrcConfig.java +++ /dev/null @@ -1,150 +0,0 @@ -package com.genersoft.iot.vmp.gb28181.session; - -import com.genersoft.iot.vmp.utils.ConfigConst; -import io.swagger.v3.oas.annotations.media.Schema; - -import java.util.ArrayList; -import java.util.List; -import java.util.Random; -import java.util.Set; - -@Schema(description = "ssrc信息") -public class SsrcConfig { - - /** - * zlm流媒体服务器Id - */ - @Schema(description = "流媒体服务器Id") - private String mediaServerId; - - @Schema(description = "SSRC前缀") - private String ssrcPrefix; - - /** - * zlm流媒体服务器已用会话句柄 - */ - @Schema(description = "zlm流媒体服务器已用会话句柄") - private List isUsed; - - /** - * zlm流媒体服务器可用会话句柄 - */ - @Schema(description = "zlm流媒体服务器可用会话句柄") - private List notUsed; - - public SsrcConfig() { - } - - public SsrcConfig(String mediaServerId, Set usedSet, String sipDomain) { - this.mediaServerId = mediaServerId; - this.isUsed = new ArrayList<>(); - this.ssrcPrefix = sipDomain.substring(3, 8); - this.notUsed = new ArrayList<>(); - for (int i = 1; i < ConfigConst.MAX_STRTEAM_COUNT; i++) { - String ssrc; - if (i < 10) { - ssrc = "000" + i; - } else if (i < 100) { - ssrc = "00" + i; - } else if (i < 1000) { - ssrc = "0" + i; - } else { - ssrc = String.valueOf(i); - } - if (null == usedSet || !usedSet.contains(ssrc)) { - this.notUsed.add(ssrc); - } else { - this.isUsed.add(ssrc); - } - } - } - - - /** - * 获取视频预览的SSRC值,第一位固定为0 - * @return ssrc - */ - public String getPlaySsrc() { - return "0" + getSsrcPrefix() + getSN(); - } - - /** - * 获取录像回放的SSRC值,第一位固定为1 - * - */ - public String getPlayBackSsrc() { - return "1" + getSsrcPrefix() + getSN(); - } - - /** - * 释放ssrc,主要用完的ssrc一定要释放,否则会耗尽 - * @param ssrc 需要重置的ssrc - */ - public void releaseSsrc(String ssrc) { - if (ssrc == null) { - return; - } - String sn = ssrc.substring(6); - try { - isUsed.remove(sn); - notUsed.add(sn); - }catch (NullPointerException e){ - } - } - - /** - * 获取后四位数SN,随机数 - * - */ - private String getSN() { - String sn = null; - int index = 0; - if (notUsed.size() == 0) { - throw new RuntimeException("ssrc已经用完"); - } else if (notUsed.size() == 1) { - sn = notUsed.get(0); - } else { - index = new Random().nextInt(notUsed.size() - 1); - sn = notUsed.get(index); - } - notUsed.remove(index); - isUsed.add(sn); - return sn; - } - - public String getSsrcPrefix() { - return ssrcPrefix; - } - - public String getMediaServerId() { - return mediaServerId; - } - - public void setMediaServerId(String mediaServerId) { - this.mediaServerId = mediaServerId; - } - - public void setSsrcPrefix(String ssrcPrefix) { - this.ssrcPrefix = ssrcPrefix; - } - - public List getIsUsed() { - return isUsed; - } - - public void setIsUsed(List isUsed) { - this.isUsed = isUsed; - } - - public List getNotUsed() { - return notUsed; - } - - public void setNotUsed(List notUsed) { - this.notUsed = notUsed; - } - - public boolean checkSsrc(String ssrcInResponse) { - return !isUsed.contains(ssrcInResponse); - } -} diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java index 1a6358b0..80734177 100644 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java +++ b/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; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; -import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.SIPProcessorObserver; import com.genersoft.iot.vmp.gb28181.transmit.SIPSender; @@ -74,6 +74,9 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements @Autowired private IRedisCatchStorage redisCatchStorage; + @Autowired + private SSRCFactory ssrcFactory; + @Autowired private DynamicTask dynamicTask; @@ -491,12 +494,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements } else if (gbStream != null) { if(ssrc.equals(ssrcDefault)) { - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); - if(ssrcConfig != null) - { - ssrc = ssrcConfig.getPlaySsrc(); - ssrcConfig.releaseSsrc(ssrc); - } + ssrc = ssrcFactory.getPlaySsrc(mediaServerItem.getId()); + ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrc); } if("push".equals(gbStream.getStreamType())) { if (streamPushItem != null && streamPushItem.isPushIng()) { 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 f3eb3d67..ea248fde 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 @@ -1,7 +1,7 @@ package com.genersoft.iot.vmp.media.zlm.dto; -import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig; import io.swagger.v3.oas.annotations.media.Schema; import org.springframework.util.ObjectUtils; @@ -80,8 +80,8 @@ public class MediaServerItem{ @Schema(description = "是否是默认ZLM") private boolean defaultServer; - @Schema(description = "SSRC信息") - private SsrcConfig ssrcConfig; +// @Schema(description = "SSRC信息") +// private SsrcConfig ssrcConfig; @Schema(description = "当前使用到的端口") private int currentPort; @@ -92,7 +92,7 @@ public class MediaServerItem{ * 在ApplicationCheckRunner里对mediaServerSsrcMap进行初始化 */ @Schema(description = "ID") - private HashMap mediaServerSsrcMap; + private HashMap mediaServerSsrcMap; public MediaServerItem() { } @@ -279,22 +279,14 @@ public class MediaServerItem{ this.updateTime = updateTime; } - public HashMap getMediaServerSsrcMap() { + public HashMap getMediaServerSsrcMap() { return mediaServerSsrcMap; } - public void setMediaServerSsrcMap(HashMap mediaServerSsrcMap) { + public void setMediaServerSsrcMap(HashMap mediaServerSsrcMap) { this.mediaServerSsrcMap = mediaServerSsrcMap; } - public SsrcConfig getSsrcConfig() { - return ssrcConfig; - } - - public void setSsrcConfig(SsrcConfig ssrcConfig) { - this.ssrcConfig = ssrcConfig; - } - public int getCurrentPort() { return currentPort; } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java index 336082f5..9223ced0 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/DeviceChannelServiceImpl.java @@ -45,6 +45,8 @@ public class DeviceChannelServiceImpl implements IDeviceChannelService { device = deviceMapper.getDeviceByDeviceId(deviceChannel.getDeviceId()); } + + if ("WGS84".equals(device.getGeoCoordSys())) { deviceChannel.setLongitudeWgs84(deviceChannel.getLongitude()); deviceChannel.setLatitudeWgs84(deviceChannel.getLatitude()); 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 eab8edb3..9bd64f1e 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 @@ -9,7 +9,7 @@ import com.genersoft.iot.vmp.conf.SipConfig; import com.genersoft.iot.vmp.conf.UserSetting; import com.genersoft.iot.vmp.conf.exception.ControllerException; import com.genersoft.iot.vmp.gb28181.event.EventPublisher; -import com.genersoft.iot.vmp.gb28181.session.SsrcConfig; +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory; @@ -54,6 +54,9 @@ public class MediaServerServiceImpl implements IMediaServerService { @Autowired private SipConfig sipConfig; + @Autowired + private SSRCFactory ssrcFactory; + @Value("${server.ssl.enabled:false}") private boolean sslEnabled; @@ -90,6 +93,7 @@ public class MediaServerServiceImpl implements IMediaServerService { @Autowired private IRedisCatchStorage redisCatchStorage; + /** * 初始化 */ @@ -101,9 +105,8 @@ public class MediaServerServiceImpl implements IMediaServerService { continue; } // 更新 - if (mediaServerItem.getSsrcConfig() == null) { - SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); - mediaServerItem.setSsrcConfig(ssrcConfig); + if (ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) { + ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); RedisUtil.set(VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(), mediaServerItem); } // 查询redis是否存在此mediaServer @@ -127,36 +130,27 @@ public class MediaServerServiceImpl implements IMediaServerService { return null; } // 获取mediaServer可用的ssrc - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); - - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); - if (ssrcConfig == null) { - logger.info("media server [ {} ] ssrcConfig is null", mediaServerItem.getId()); - return null; + String ssrc; + if (presetSsrc != null) { + ssrc = presetSsrc; }else { - String ssrc; - if (presetSsrc != null) { - ssrc = presetSsrc; + if (isPlayback) { + ssrc = ssrcFactory.getPlayBackSsrc(mediaServerItem.getId()); }else { - if (isPlayback) { - ssrc = ssrcConfig.getPlayBackSsrc(); - }else { - ssrc = ssrcConfig.getPlaySsrc(); - } + ssrc = ssrcFactory.getPlaySsrc(mediaServerItem.getId()); } - - if (streamId == null) { - streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); - } - int rtpServerPort; - if (mediaServerItem.isRtpEnable()) { - rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); - } else { - rtpServerPort = mediaServerItem.getRtpProxyPort(); - } - RedisUtil.set(key, mediaServerItem); - return new SSRCInfo(rtpServerPort, ssrc, streamId); } + + if (streamId == null) { + streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase(); + } + int rtpServerPort; + if (mediaServerItem.isRtpEnable()) { + rtpServerPort = zlmrtpServerFactory.createRTPServer(mediaServerItem, streamId, ssrcCheck?Integer.parseInt(ssrc):0, port); + } else { + rtpServerPort = mediaServerItem.getRtpProxyPort(); + } + return new SSRCInfo(rtpServerPort, ssrc, streamId); } @Override @@ -184,11 +178,7 @@ public class MediaServerServiceImpl implements IMediaServerService { if (mediaServerItem == null || ssrc == null) { return; } - SsrcConfig ssrcConfig = mediaServerItem.getSsrcConfig(); - ssrcConfig.releaseSsrc(ssrc); - mediaServerItem.setSsrcConfig(ssrcConfig); - String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); - RedisUtil.set(key, mediaServerItem); + ssrcFactory.releaseSsrc(mediaServerItemId, ssrc); } /** @@ -196,8 +186,7 @@ public class MediaServerServiceImpl implements IMediaServerService { */ @Override public void clearRTPServer(MediaServerItem mediaServerItem) { - mediaServerItem.setSsrcConfig(new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain())); - RedisUtil.zAdd(VideoManagerConstants.MEDIA_SERVERS_ONLINE_PREFIX + userSetting.getServerId(), mediaServerItem.getId(), 0); + ssrcFactory.reset(mediaServerItem.getId()); } @@ -207,16 +196,8 @@ public class MediaServerServiceImpl implements IMediaServerService { mediaServerMapper.update(mediaSerItem); MediaServerItem mediaServerItemInRedis = getOne(mediaSerItem.getId()); MediaServerItem mediaServerItemInDataBase = mediaServerMapper.queryOne(mediaSerItem.getId()); - if (mediaServerItemInRedis != null && mediaServerItemInRedis.getSsrcConfig() != null) { - mediaServerItemInDataBase.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); - }else { - mediaServerItemInDataBase.setSsrcConfig( - new SsrcConfig( - mediaServerItemInDataBase.getId(), - null, - sipConfig.getDomain() - ) - ); + if (mediaServerItemInRedis == null || ssrcFactory.hasMediaServerSSRC(mediaSerItem.getId())) { + ssrcFactory.initMediaServerSSRC(mediaServerItemInDataBase.getId(),null); } String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItemInDataBase.getId(); RedisUtil.set(key, mediaServerItemInDataBase); @@ -396,14 +377,8 @@ public class MediaServerServiceImpl implements IMediaServerService { } mediaServerMapper.update(serverItem); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + zlmServerConfig.getGeneralMediaServerId(); - if (RedisUtil.get(key) == null) { - SsrcConfig ssrcConfig = new SsrcConfig(zlmServerConfig.getGeneralMediaServerId(), null, sipConfig.getDomain()); - serverItem.setSsrcConfig(ssrcConfig); - }else { - MediaServerItem mediaServerItemInRedis = JsonUtil.redisJsonToObject(key, MediaServerItem.class); - if (Objects.nonNull(mediaServerItemInRedis)) { - serverItem.setSsrcConfig(mediaServerItemInRedis.getSsrcConfig()); - } + if (ssrcFactory.hasMediaServerSSRC(serverItem.getId())) { + ssrcFactory.initMediaServerSSRC(zlmServerConfig.getGeneralMediaServerId(), null); } RedisUtil.set(key, serverItem); resetOnlineServerItem(serverItem); @@ -682,8 +657,7 @@ public class MediaServerServiceImpl implements IMediaServerService { } // zlm连接重试 logger.warn("[更新ZLM 保活信息]尝试链接zml id {}", mediaServerId); - SsrcConfig ssrcConfig = new SsrcConfig(mediaServerItem.getId(), null, sipConfig.getDomain()); - mediaServerItem.setSsrcConfig(ssrcConfig); + ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItem.getId(); RedisUtil.set(key, mediaServerItem); clearRTPServer(mediaServerItem); diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java index 0c9243ef..a072e8af 100644 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java @@ -11,6 +11,7 @@ import com.genersoft.iot.vmp.conf.exception.ServiceException; import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException; import com.genersoft.iot.vmp.gb28181.bean.*; import com.genersoft.iot.vmp.gb28181.event.SipSubscribe; +import com.genersoft.iot.vmp.gb28181.session.SSRCFactory; import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager; import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder; import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage; @@ -100,6 +101,9 @@ public class PlayServiceImpl implements IPlayService { @Autowired private ZlmHttpHookSubscribe subscribe; + @Autowired + private SSRCFactory ssrcFactory; + @Override public void play(MediaServerItem mediaServerItem, String deviceId, String channelId, @@ -295,10 +299,10 @@ public class PlayServiceImpl implements IPlayService { if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { logger.info("[点播消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { // ssrc 不可用 // 释放ssrc - mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); + ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream()); event.msg = "下级自定义了ssrc,但是此ssrc不可用"; event.statusCode = 400; @@ -536,7 +540,7 @@ public class PlayServiceImpl implements IPlayService { if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { logger.info("[回放消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { // ssrc 不可用 // 释放ssrc mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); @@ -675,7 +679,7 @@ public class PlayServiceImpl implements IPlayService { if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { logger.info("[回放消息] SSRC修正 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse); - if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { + if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) { // ssrc 不可用 // 释放ssrc mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc()); diff --git a/src/main/java/com/genersoft/iot/vmp/utils/ConfigConst.java b/src/main/java/com/genersoft/iot/vmp/utils/ConfigConst.java deleted file mode 100644 index 125d8180..00000000 --- a/src/main/java/com/genersoft/iot/vmp/utils/ConfigConst.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.genersoft.iot.vmp.utils; - -public class ConfigConst { - /** - * 播流最大并发个数 - */ - public static final Integer MAX_STRTEAM_COUNT = 10000; -}