| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 开始播放时将流存入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) { |