|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | // 如果有父设备,更新父设备内子节点数 | 
|---|
|  |  |  | String parentId = channel.getParentId(); | 
|---|
|  |  |  | if (!StringUtils.isEmpty(parentId)) { | 
|---|
|  |  |  | if (!StringUtils.isEmpty(parentId) && !parentId.equals(deviceId)) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (channelMap.get(parentId) == null) { | 
|---|
|  |  |  | channelMap.put(parentId, new HashSet<String>()); | 
|---|
|  |  |  | 
|---|
|  |  |  | DeviceChannel deviceChannel = queryChannel(deviceId, parentId); | 
|---|
|  |  |  | if (deviceChannel != null) { | 
|---|
|  |  |  | deviceChannel.setSubCount(channelMap.get(parentId).size()); | 
|---|
|  |  |  | //            redis.set(VideoManagerConstants.CACHEKEY_PREFIX+deviceId + "_" + deviceChannel.getChannelId(), | 
|---|
|  |  |  | //                  deviceChannel); | 
|---|
|  |  |  | redis.set(VideoManagerConstants.CACHEKEY_PREFIX + deviceId + | 
|---|
|  |  |  | "_" + deviceChannel.getChannelId() + | 
|---|
|  |  |  | "_" + (deviceChannel.getStatus() == 1 ? "on":"off") + | 
|---|
|  |  |  | 
|---|
|  |  |  | PageResult pageResult = new PageResult<Device>(); | 
|---|
|  |  |  | pageResult.setPage(page); | 
|---|
|  |  |  | pageResult.setCount(count); | 
|---|
|  |  |  | Device device = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (deviceIds == null || deviceIds.length == 0) { | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | pageResult.setTotal(deviceIdList.size()); | 
|---|
|  |  |  | int maxCount = (page + 1)* count; | 
|---|
|  |  |  | for (int i = page * count; i < (pageResult.getTotal() > maxCount ? maxCount : pageResult.getTotal() ); i++) { | 
|---|
|  |  |  | devices.add((Device)redis.get((String)deviceIdList.get(i))); | 
|---|
|  |  |  | // devices.add((Device)redis.get((String)deviceIdList.get(i))); | 
|---|
|  |  |  | device =(Device)redis.get((String)deviceIdList.get(i)); | 
|---|
|  |  |  | if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | 
|---|
|  |  |  | // outline(device.getDeviceId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | devices.add(device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | for (int i = 0; i < deviceIds.length; i++) { | 
|---|
|  |  |  | devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | 
|---|
|  |  |  | // devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | 
|---|
|  |  |  | device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | 
|---|
|  |  |  | if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | 
|---|
|  |  |  | // outline(device.getDeviceId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | devices.add(device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | pageResult.setData(devices); | 
|---|
|  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Device> queryVideoDeviceList(String[] deviceIds) { | 
|---|
|  |  |  | List<Device> devices = new ArrayList<>(); | 
|---|
|  |  |  | Device device = null; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | if (deviceIds == null || deviceIds.length == 0) { | 
|---|
|  |  |  | //         List<Object> deviceIdList = redis.keys(VideoManagerConstants.DEVICE_PREFIX+"*"); | 
|---|
|  |  |  | List<Object> deviceIdList = redis.scan(VideoManagerConstants.DEVICE_PREFIX+"*"); | 
|---|
|  |  |  | for (int i = 0; i < deviceIdList.size(); i++) { | 
|---|
|  |  |  | devices.add((Device)redis.get((String)deviceIdList.get(i))); | 
|---|
|  |  |  | device =(Device)redis.get((String)deviceIdList.get(i)); | 
|---|
|  |  |  | if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | 
|---|
|  |  |  | outline(device.getDeviceId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | devices.add(device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } else { | 
|---|
|  |  |  | for (int i = 0; i < deviceIds.length; i++) { | 
|---|
|  |  |  | devices.add((Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i])); | 
|---|
|  |  |  | device = (Device)redis.get(VideoManagerConstants.DEVICE_PREFIX+deviceIds[i]); | 
|---|
|  |  |  | if (redis.scan(VideoManagerConstants.KEEPLIVEKEY_PREFIX+device.getDeviceId()).size() == 0){ | 
|---|
|  |  |  | outline(device.getDeviceId()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | devices.add(device); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return devices; | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlaybackBySSRC(String ssrc) { | 
|---|
|  |  |  | //      List<Object> playLeys = redis.keys(String.format("%S_%s_*", VideoManagerConstants.PLAYER_PREFIX, ssrc)); | 
|---|
|  |  |  | List<Object> playLeys = redis.scan(String.format("%S_%s_*", VideoManagerConstants.PLAY_BLACK_PREFIX, ssrc)); | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) return null; | 
|---|
|  |  |  | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlayByDevice(String deviceId, String code) { | 
|---|
|  |  |  | //      List<Object> playLeys = redis.keys(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAYER_PREFIX, | 
|---|
|  |  |  | 
|---|
|  |  |  | for (Device device : devices) { | 
|---|
|  |  |  | // 更新设备下的通道 | 
|---|
|  |  |  | HashMap<String, HashSet<String>> channelMap = new HashMap<String, HashSet<String>>(); | 
|---|
|  |  |  | //         List<Object> deviceChannelList = redis.keys(VideoManagerConstants.CACHEKEY_PREFIX + | 
|---|
|  |  |  | List<Object> deviceChannelList = redis.scan(VideoManagerConstants.CACHEKEY_PREFIX + | 
|---|
|  |  |  | device.getDeviceId() + "_" + "*"); | 
|---|
|  |  |  | if (deviceChannelList != null && deviceChannelList.size() > 0 ) { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | deviceMap.put(device.getDeviceId(),channelMap); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | System.out.println(); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean startPlayback(StreamInfo stream) { | 
|---|
|  |  |  | return redis.set(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, stream.getSsrc(),stream.getDeviceID(), stream.getCahnnelId()), | 
|---|
|  |  |  | stream); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public boolean stopPlayback(StreamInfo streamInfo) { | 
|---|
|  |  |  | if (streamInfo == null) return false; | 
|---|
|  |  |  | DeviceChannel deviceChannel = queryChannel(streamInfo.getDeviceID(), streamInfo.getCahnnelId()); | 
|---|
|  |  |  | if (deviceChannel != null) { | 
|---|
|  |  |  | deviceChannel.setSsrc(null); | 
|---|
|  |  |  | deviceChannel.setPlay(false); | 
|---|
|  |  |  | updateChannel(streamInfo.getDeviceID(), deviceChannel); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return redis.del(String.format("%S_%s_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | streamInfo.getSsrc(), | 
|---|
|  |  |  | streamInfo.getDeviceID(), | 
|---|
|  |  |  | streamInfo.getCahnnelId())); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamInfo queryPlaybackByDevice(String deviceId, String code) { | 
|---|
|  |  |  | String format = String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | code); | 
|---|
|  |  |  | List<Object> playLeys = redis.scan(String.format("%S_*_%s_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | deviceId, | 
|---|
|  |  |  | code)); | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) { | 
|---|
|  |  |  | playLeys = redis.scan(String.format("%S_*_*_%s", VideoManagerConstants.PLAY_BLACK_PREFIX, | 
|---|
|  |  |  | deviceId)); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (playLeys == null || playLeys.size() == 0) return null; | 
|---|
|  |  |  | return (StreamInfo)redis.get(playLeys.get(0).toString()); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|