old mode 100644
new mode 100755
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSON; | 
|---|
|  |  |  | import com.alibaba.fastjson2.JSONObject; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.StreamInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.SystemAllInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.VideoManagerConstants; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.conf.UserSetting; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.*; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.AlarmChannelMessage; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.Device; | 
|---|
|  |  |  | 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 com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.bean.GPSMsgInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.bean.ThirdPartyGB; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.DeviceChannelMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.DeviceMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.dto.PlatformRegisterInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.DateUtil; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.utils.JsonUtil; | 
|---|
|  |  |  | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
|---|
|  |  |  | import org.springframework.data.redis.core.RedisTemplate; | 
|---|
|  |  |  | import org.springframework.data.redis.core.StringRedisTemplate; | 
|---|
|  |  |  | import org.springframework.stereotype.Component; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import java.time.Duration; | 
|---|
|  |  |  | import java.util.*; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @SuppressWarnings("rawtypes") | 
|---|
|  |  |  | 
|---|
|  |  |  | private DeviceChannelMapper deviceChannelMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private DeviceMapper deviceMapper; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private UserSetting userSetting; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private RedisTemplate<Object, Object> redisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private StringRedisTemplate stringRedisTemplate; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Long getCSEQ() { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 开始播放时将流存入redis | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean startPlay(StreamInfo stream) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), | 
|---|
|  |  |  | stream.getMediaServerId(), stream.getStream(), stream.getDeviceID(), stream.getChannelId()), | 
|---|
|  |  |  | stream); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 停止播放时从redis删除 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean stopPlay(StreamInfo streamInfo) { | 
|---|
|  |  |  | if (streamInfo == null) { | 
|---|
|  |  |  | return false; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | Boolean result = redisTemplate.delete(String.format("%S_%s_%s_%s_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | streamInfo.getMediaServerId(), | 
|---|
|  |  |  | streamInfo.getStream(), | 
|---|
|  |  |  | streamInfo.getDeviceID(), | 
|---|
|  |  |  | streamInfo.getChannelId())); | 
|---|
|  |  |  | return result != null && result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * 查询播放列表 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlay(StreamInfo streamInfo) { | 
|---|
|  |  |  | return (StreamInfo)redisTemplate.opsForValue().get(String.format("%S_%s_%s_%s_%s_%s", | 
|---|
|  |  |  | VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | streamInfo.getMediaServerId(), | 
|---|
|  |  |  | streamInfo.getStream(), | 
|---|
|  |  |  | streamInfo.getDeviceID(), | 
|---|
|  |  |  | streamInfo.getChannelId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlayByStreamId(String streamId) { | 
|---|
|  |  |  | List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(), streamId)); | 
|---|
|  |  |  | if (playLeys.size() == 0) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlayByDevice(String deviceId, String channelId) { | 
|---|
|  |  |  | List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId)); | 
|---|
|  |  |  | if (playLeys.size() == 0) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return (StreamInfo)redisTemplate.opsForValue().get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Map<String, StreamInfo> queryPlayByDeviceId(String deviceId) { | 
|---|
|  |  |  | Map<String, StreamInfo> streamInfos = new HashMap<>(); | 
|---|
|  |  |  | List<Object> players = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, userSetting.getServerId(),deviceId)); | 
|---|
|  |  |  | if (players.size() == 0) { | 
|---|
|  |  |  | return streamInfos; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | for (Object player : players) { | 
|---|
|  |  |  | String key = (String) player; | 
|---|
|  |  |  | StreamInfo streamInfo = JsonUtil.redisJsonToObject(redisTemplate, key, StreamInfo.class); | 
|---|
|  |  |  | if (Objects.isNull(streamInfo)) { | 
|---|
|  |  |  | continue; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | streamInfos.put(streamInfo.getDeviceID() + "_" + streamInfo.getChannelId(), streamInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return streamInfos; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean startPlayback(StreamInfo stream, String callId) { | 
|---|
|  |  |  | redisTemplate.opsForValue().set(String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId), stream); | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean startDownload(StreamInfo stream, String callId) { | 
|---|
|  |  |  | String key=String.format("%S_%s_%s_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), stream.getMediaServerId(), stream.getDeviceID(), stream.getChannelId(), stream.getStream(), callId); | 
|---|
|  |  |  | if (stream.getProgress() == 1) { | 
|---|
|  |  |  | logger.debug("添加下载缓存==已完成下载=》{}",key); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, stream); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | logger.debug("添加下载缓存==未完成下载=》{}",key); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, stream, 60*60); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean stopDownload(String deviceId, String channelId, String stream, String callId) { | 
|---|
|  |  |  | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); | 
|---|
|  |  |  | if (deviceChannel != null) { | 
|---|
|  |  |  | deviceChannel.setStreamId(null); | 
|---|
|  |  |  | deviceChannel.setDeviceId(deviceId); | 
|---|
|  |  |  | deviceChannelMapper.update(deviceChannel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId, | 
|---|
|  |  |  | stream, | 
|---|
|  |  |  | callId | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Object> scan = RedisUtil.scan(redisTemplate, key); | 
|---|
|  |  |  | if (scan.size() > 0) { | 
|---|
|  |  |  | for (Object keyObj : scan) { | 
|---|
|  |  |  | redisTemplate.delete(keyObj); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean stopPlayback(String deviceId, String channelId, String stream, String callId) { | 
|---|
|  |  |  | DeviceChannel deviceChannel = deviceChannelMapper.queryChannel(deviceId, channelId); | 
|---|
|  |  |  | if (deviceChannel != null) { | 
|---|
|  |  |  | deviceChannel.setStreamId(null); | 
|---|
|  |  |  | deviceChannel.setDeviceId(deviceId); | 
|---|
|  |  |  | deviceChannelMapper.update(deviceChannel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId, | 
|---|
|  |  |  | stream, | 
|---|
|  |  |  | callId | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Object> scan = RedisUtil.scan(redisTemplate, key); | 
|---|
|  |  |  | if (scan.size() > 0) { | 
|---|
|  |  |  | for (Object keyObj : scan) { | 
|---|
|  |  |  | redisTemplate.delete(keyObj); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return true; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlayback(String deviceId, String channelId, String stream, String callId) { | 
|---|
|  |  |  | if (stream == null && callId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId, | 
|---|
|  |  |  | stream, | 
|---|
|  |  |  | callId | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key); | 
|---|
|  |  |  | if (streamInfoScan.size() > 0) { | 
|---|
|  |  |  | return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0)); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public String queryPlaybackForKey(String deviceId, String channelId, String stream, String callId) { | 
|---|
|  |  |  | if (stream == null && callId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId, | 
|---|
|  |  |  | stream, | 
|---|
|  |  |  | callId | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key); | 
|---|
|  |  |  | return (String) streamInfoScan.get(0); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updatePlatformCatchInfo(ParentPlatformCatch parentPlatformCatch) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_CATCH_PREFIX  + userSetting.getServerId() + "_" +  parentPlatformCatch.getId(); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updatePlatformRegisterInfo(String callId, PlatformRegisterInfo platformRegisterInfo) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId; | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, platformRegisterInfo, 30); | 
|---|
|  |  |  | Duration duration = Duration.ofSeconds(30L); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, platformRegisterInfo, duration); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void delPlatformRegisterInfo(String callId) { | 
|---|
|  |  |  | redisTemplate.delete(VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + callId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void cleanPlatformRegisterInfos() { | 
|---|
|  |  |  | List regInfos = RedisUtil.scan(redisTemplate, VideoManagerConstants.PLATFORM_REGISTER_INFO_PREFIX + userSetting.getServerId() + "_" + "*"); | 
|---|
|  |  |  | for (Object key : regInfos) { | 
|---|
|  |  |  | redisTemplate.delete(key.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<SendRtpItem> querySendRTPServerByChnnelId(String channelId) { | 
|---|
|  |  |  | public List<SendRtpItem> querySendRTPServerByChannelId(String channelId) { | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void clearCatchByDeviceId(String deviceId) { | 
|---|
|  |  |  | List<Object> playLeys = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId)); | 
|---|
|  |  |  | if (playLeys.size() > 0) { | 
|---|
|  |  |  | for (Object key : playLeys) { | 
|---|
|  |  |  | redisTemplate.delete(key.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Object> playBackers = RedisUtil.scan(redisTemplate, String.format("%S_%s_*_%s_*_*_*", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId)); | 
|---|
|  |  |  | if (playBackers.size() > 0) { | 
|---|
|  |  |  | for (Object key : playBackers) { | 
|---|
|  |  |  | redisTemplate.delete(key.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | List<Object> deviceCache = RedisUtil.scan(redisTemplate, String.format("%S%s_%s", VideoManagerConstants.DEVICE_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId)); | 
|---|
|  |  |  | if (deviceCache.size() > 0) { | 
|---|
|  |  |  | for (Object key : deviceCache) { | 
|---|
|  |  |  | redisTemplate.delete(key.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateWVPInfo(JSONObject jsonObject, int time) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_SERVER_PREFIX + userSetting.getServerId(); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, jsonObject, time); | 
|---|
|  |  |  | Duration duration = Duration.ofSeconds(time); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, jsonObject, duration); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendStreamChangeMsg(String type, JSONObject jsonObject) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_MSG_STREAM_CHANGE_PREFIX + type; | 
|---|
|  |  |  | logger.info("[redis 流变化事件] {}: {}", key, jsonObject.toString()); | 
|---|
|  |  |  | logger.info("[redis 流变化事件] 发送 {}: {}", key, jsonObject.toString()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, jsonObject); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public void removeStream(String mediaServerId, String type, String app, String streamId) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_SERVER_STREAM_PREFIX + userSetting.getServerId() + "_" + type + "_"  + app + "_" + streamId + "_" + mediaServerId; | 
|---|
|  |  |  | redisTemplate.delete(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryDownload(String deviceId, String channelId, String stream, String callId) { | 
|---|
|  |  |  | if (stream == null && callId == null) { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (deviceId == null) { | 
|---|
|  |  |  | deviceId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (channelId == null) { | 
|---|
|  |  |  | channelId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (stream == null) { | 
|---|
|  |  |  | stream = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (callId == null) { | 
|---|
|  |  |  | callId = "*"; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String key = String.format("%S_%s_*_%s_%s_%s_%s", VideoManagerConstants.DOWNLOAD_PREFIX, | 
|---|
|  |  |  | userSetting.getServerId(), | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | channelId, | 
|---|
|  |  |  | stream, | 
|---|
|  |  |  | callId | 
|---|
|  |  |  | ); | 
|---|
|  |  |  | List<Object> streamInfoScan = RedisUtil.scan(redisTemplate, key); | 
|---|
|  |  |  | if (streamInfoScan.size() > 0) { | 
|---|
|  |  |  | return (StreamInfo) redisTemplate.opsForValue().get(streamInfoScan.get(0)); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | return null; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public ThirdPartyGB queryMemberNoGBId(String queryKey) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_STREAM_GB_ID_PREFIX + queryKey; | 
|---|
|  |  |  | return JsonUtil.redisJsonToObject(redisTemplate, key, ThirdPartyGB.class); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | for (Object o : keys) { | 
|---|
|  |  |  | String key = (String) o; | 
|---|
|  |  |  | Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); | 
|---|
|  |  |  | if (Objects.nonNull(device)) { // 只取没有存过得 | 
|---|
|  |  |  | if (Objects.nonNull(device)) { | 
|---|
|  |  |  | // 只取没有存过得 | 
|---|
|  |  |  | result.add(JsonUtil.redisJsonToObject(redisTemplate, key, Device.class)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public Device getDevice(String deviceId) { | 
|---|
|  |  |  | String key = VideoManagerConstants.DEVICE_PREFIX + userSetting.getServerId() + "_" + deviceId; | 
|---|
|  |  |  | return JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); | 
|---|
|  |  |  | Device device = JsonUtil.redisJsonToObject(redisTemplate, key, Device.class); | 
|---|
|  |  |  | if (device == null){ | 
|---|
|  |  |  | device = deviceMapper.getDeviceByDeviceId(deviceId); | 
|---|
|  |  |  | if (device != null) { | 
|---|
|  |  |  | updateDevice(device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return device; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void updateGpsMsgInfo(GPSMsgInfo gpsMsgInfo) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WVP_STREAM_GPS_MSG_PREFIX + userSetting.getServerId() + "_" + gpsMsgInfo.getId(); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, gpsMsgInfo, 60); // 默认GPS消息保存1分钟 | 
|---|
|  |  |  | Duration duration = Duration.ofSeconds(60L); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, gpsMsgInfo, duration); | 
|---|
|  |  |  | // 默认GPS消息保存1分钟 | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendMobilePositionMsg(JSONObject jsonObject) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_MOBILE_POSITION; | 
|---|
|  |  |  | logger.info("[redis发送通知] 移动位置 {}: {}", key, jsonObject.toString()); | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 移动位置 {}: {}", key, jsonObject.toString()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, jsonObject); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendStreamPushRequestedMsg(MessageForPushChannel msg) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_REQUESTED; | 
|---|
|  |  |  | logger.info("[redis发送通知] 推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream()); | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 推流被请求 {}: {}/{}", key, msg.getApp(), msg.getStream()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | public void sendAlarmMsg(AlarmChannelMessage msg) { | 
|---|
|  |  |  | // 此消息用于对接第三方服务下级来的消息内容 | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_ALARM; | 
|---|
|  |  |  | logger.info("[redis发送通知] 报警{}: {}", key, JSON.toJSON(msg)); | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 报警{}: {}", key, JSON.toJSON(msg)); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean deviceIsOnline(String deviceId) { | 
|---|
|  |  |  | return getDevice(deviceId).getOnline() == 1; | 
|---|
|  |  |  | return getDevice(deviceId).isOnLine(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendStreamPushRequestedMsgForStatus() { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_GET_ALL_ONLINE_REQUESTED; | 
|---|
|  |  |  | logger.info("[redis通知]获取所有推流设备的状态"); | 
|---|
|  |  |  | logger.info("[redis通知] 发送 获取所有推流设备的状态"); | 
|---|
|  |  |  | JSONObject jsonObject = new JSONObject(); | 
|---|
|  |  |  | jsonObject.put(key, key); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, jsonObject); | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int getGbReceiveCount(String id) { | 
|---|
|  |  |  | String playKey = VideoManagerConstants.PLAYER_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*"; | 
|---|
|  |  |  | String playBackKey = VideoManagerConstants.PLAY_BLACK_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*"; | 
|---|
|  |  |  | String downloadKey = VideoManagerConstants.DOWNLOAD_PREFIX + "_" + userSetting.getServerId() + "_" + id + "_*"; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return RedisUtil.scan(redisTemplate, playKey).size() + RedisUtil.scan(redisTemplate, playBackKey).size() + RedisUtil.scan(redisTemplate, downloadKey).size(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public int getGbSendCount(String id) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PLATFORM_SEND_RTP_INFO_PREFIX | 
|---|
|  |  |  | + userSetting.getServerId() + "_*_" + id + "_*"; | 
|---|
|  |  |  | return RedisUtil.scan(redisTemplate, key).size(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendDeviceOrChannelStatus(String deviceId, String channelId, boolean online) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS; | 
|---|
|  |  |  | StringBuilder msg = new StringBuilder(); | 
|---|
|  |  |  | msg.append(deviceId); | 
|---|
|  |  |  | if (channelId != null) { | 
|---|
|  |  |  | msg.append(":").append(channelId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | msg.append(" ").append(online? "ON":"OFF"); | 
|---|
|  |  |  | logger.info("[redis通知] 推送设备/通道状态-> {} ", msg); | 
|---|
|  |  |  | // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号 | 
|---|
|  |  |  | stringRedisTemplate.convertAndSend(key, msg.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendChannelAddOrDelete(String deviceId, String channelId, boolean add) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_SUBSCRIBE_DEVICE_STATUS; | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | StringBuilder msg = new StringBuilder(); | 
|---|
|  |  |  | msg.append(deviceId); | 
|---|
|  |  |  | if (channelId != null) { | 
|---|
|  |  |  | msg.append(":").append(channelId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | msg.append(" ").append(add? "ADD":"DELETE"); | 
|---|
|  |  |  | logger.info("[redis通知] 推送通道-> {}", msg); | 
|---|
|  |  |  | // 使用 RedisTemplate<Object, Object> 发送字符串消息会导致发送的消息多带了双引号 | 
|---|
|  |  |  | stringRedisTemplate.convertAndSend(key, msg.toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendPlatformStartPlayMsg(MessageForPushChannel msg) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_STREAM_START_PLAY_NOTIFY; | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 推流被上级平台观看 {}: {}/{}->{}", key, msg.getApp(), msg.getStream(), msg.getPlatFormId()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendPlatformStopPlayMsg(MessageForPushChannel msg) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_STREAM_STOP_PLAY_NOTIFY; | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 上级平台停止观看 {}: {}/{}->{}", key, msg.getApp(), msg.getStream(), msg.getPlatFormId()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addPushListItem(String app, String stream, OnStreamChangedHookParam param) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PUSH_STREAM_LIST + app + "_" + stream; | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, param); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public OnStreamChangedHookParam getPushListItem(String app, String stream) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PUSH_STREAM_LIST + app + "_" + stream; | 
|---|
|  |  |  | return (OnStreamChangedHookParam)redisTemplate.opsForValue().get(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void removePushListItem(String app, String stream, String mediaServerId) { | 
|---|
|  |  |  | String key = VideoManagerConstants.PUSH_STREAM_LIST + app + "_" + stream; | 
|---|
|  |  |  | OnStreamChangedHookParam param = (OnStreamChangedHookParam)redisTemplate.opsForValue().get(key); | 
|---|
|  |  |  | if (param != null && param.getMediaServerId().equalsIgnoreCase(mediaServerId)) { | 
|---|
|  |  |  | redisTemplate.delete(key); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendPushStreamClose(MessageForPushChannel msg) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_CLOSE_REQUESTED; | 
|---|
|  |  |  | logger.info("[redis发送通知] 发送 停止向上级推流 {}: {}/{}->{}", key, msg.getApp(), msg.getStream(), msg.getPlatFormId()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(msg)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void addWaiteSendRtpItem(SendRtpItem sendRtpItem, int platformPlayTimeout) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WAITE_SEND_PUSH_STREAM + sendRtpItem.getApp() + "_" + sendRtpItem.getStream(); | 
|---|
|  |  |  | redisTemplate.opsForValue().set(key, sendRtpItem); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public SendRtpItem getWaiteSendRtpItem(String app, String stream) { | 
|---|
|  |  |  | String key = VideoManagerConstants.WAITE_SEND_PUSH_STREAM + app + "_" + stream; | 
|---|
|  |  |  | return JsonUtil.redisJsonToObject(redisTemplate, key, SendRtpItem.class); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendStartSendRtp(SendRtpItem sendRtpItem) { | 
|---|
|  |  |  | String key = VideoManagerConstants.START_SEND_PUSH_STREAM + sendRtpItem.getApp() + "_" + sendRtpItem.getStream(); | 
|---|
|  |  |  | logger.info("[redis发送通知] 通知其他WVP推流 {}: {}/{}->{}", key, sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getPlatformId()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(sendRtpItem)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public void sendPushStreamOnline(SendRtpItem sendRtpItem) { | 
|---|
|  |  |  | String key = VideoManagerConstants.VM_MSG_STREAM_PUSH_CLOSE_REQUESTED; | 
|---|
|  |  |  | logger.info("[redis发送通知] 流上线 {}: {}/{}->{}", key, sendRtpItem.getApp(), sendRtpItem.getStream(), sendRtpItem.getPlatformId()); | 
|---|
|  |  |  | redisTemplate.convertAndSend(key, JSON.toJSON(sendRtpItem)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|