|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.gb28181.session; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.SipConfig; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetting; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.StringRedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private SipConfig sipConfig; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public void initMediaServerSSRC(String mediaServerId, Set<String> usedSet) { | 
|---|
|  |  |  | String ssrcPrefix = sipConfig.getDomain().substring(3, 8); | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + mediaServerId; | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + userSetting.getServerId() + "_" + mediaServerId; | 
|---|
|  |  |  | List<String> ssrcList = new ArrayList<>(); | 
|---|
|  |  |  | for (int i = 1; i < MAX_STREAM_COUNT; i++) { | 
|---|
|  |  |  | String ssrc = String.format("%s%04d", ssrcPrefix, i); | 
|---|
|  |  |  | 
|---|
|  |  |  | return; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String sn = ssrc.substring(1); | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + mediaServerId; | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + userSetting.getServerId() + "_" + mediaServerId; | 
|---|
|  |  |  | redisTemplate.opsForSet().add(redisKey, sn); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private String getSN(String mediaServerId) { | 
|---|
|  |  |  | String sn = null; | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + mediaServerId; | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + userSetting.getServerId() + "_" + mediaServerId; | 
|---|
|  |  |  | Long size = redisTemplate.opsForSet().size(redisKey); | 
|---|
|  |  |  | if (size == null || size == 0) { | 
|---|
|  |  |  | throw new RuntimeException("ssrc已经用完"); | 
|---|
|  |  |  | 
|---|
|  |  |  | * @param mediaServerId 流媒体服务ID | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | public boolean hasMediaServerSSRC(String mediaServerId) { | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + mediaServerId; | 
|---|
|  |  |  | String redisKey = SSRC_INFO_KEY + userSetting.getServerId() + "_" + 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|