| | |
| | | continue; |
| | | } |
| | | // 更新 |
| | | if (ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) { |
| | | if (!ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) { |
| | | ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null); |
| | | } |
| | | // 查询redis是否存在此mediaServer |
| | |
| | | mediaServerMapper.update(mediaSerItem); |
| | | MediaServerItem mediaServerItemInRedis = getOne(mediaSerItem.getId()); |
| | | MediaServerItem mediaServerItemInDataBase = mediaServerMapper.queryOne(mediaSerItem.getId()); |
| | | if (mediaServerItemInRedis == null || ssrcFactory.hasMediaServerSSRC(mediaSerItem.getId())) { |
| | | if (mediaServerItemInRedis == null || !ssrcFactory.hasMediaServerSSRC(mediaSerItem.getId())) { |
| | | ssrcFactory.initMediaServerSSRC(mediaServerItemInDataBase.getId(),null); |
| | | } |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + mediaServerItemInDataBase.getId(); |
| | |
| | | } |
| | | mediaServerMapper.update(serverItem); |
| | | String key = VideoManagerConstants.MEDIA_SERVER_PREFIX + userSetting.getServerId() + "_" + zlmServerConfig.getGeneralMediaServerId(); |
| | | if (ssrcFactory.hasMediaServerSSRC(serverItem.getId())) { |
| | | if (!ssrcFactory.hasMediaServerSSRC(serverItem.getId())) { |
| | | ssrcFactory.initMediaServerSSRC(zlmServerConfig.getGeneralMediaServerId(), null); |
| | | } |
| | | redisTemplate.opsForValue().set(key, serverItem); |
| | |
| | | param.put("hook.on_server_keepalive",String.format("%s/on_server_keepalive", hookPrex)); |
| | | param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrex)); |
| | | param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrex)); |
| | | if (mediaServerItem.getRecordAssistPort() > 0) { |
| | | param.put("hook.on_record_mp4",String.format("http://127.0.0.1:%s/api/record/on_record_mp4", mediaServerItem.getRecordAssistPort())); |
| | | }else { |
| | | param.put("hook.on_record_mp4",""); |
| | | } |
| | | param.put("hook.on_record_mp4",String.format("%s/on_record_mp4", hookPrex)); |
| | | // if (mediaServerItem.getRecordAssistPort() > 0) { |
| | | // param.put("hook.on_record_mp4",String.format("http://127.0.0.1:%s/api/record/on_record_mp4", mediaServerItem.getRecordAssistPort())); |
| | | // }else { |
| | | // param.put("hook.on_record_mp4",""); |
| | | // } |
| | | param.put("hook.timeoutSec","20"); |
| | | // 推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。 |
| | | // 置0关闭此特性(推流断开会导致立即断开播放器) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public boolean checkRtpServer(MediaServerItem mediaServerItem, String app, String stream) { |
| | | JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaServerItem, stream); |
| | | if(rtpInfo.getInteger("code") == 0){ |
| | | return rtpInfo.getBoolean("exist"); |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @Override |
| | | public MediaServerLoad getLoad(MediaServerItem mediaServerItem) { |
| | | MediaServerLoad result = new MediaServerLoad(); |
| | | result.setId(mediaServerItem.getId()); |
| | |
| | | } |
| | | |
| | | @Override |
| | | public List<RecordFile> getRecords(String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems) { |
| | | Assert.notNull(app, "app不存在"); |
| | | Assert.notNull(stream, "stream不存在"); |
| | | Assert.notNull(startTime, "startTime不存在"); |
| | | Assert.notNull(endTime, "endTime不存在"); |
| | | Assert.notEmpty(mediaServerItems, "流媒体列表为空"); |
| | | |
| | | CompletableFuture[] completableFutures = new CompletableFuture[mediaServerItems.size()]; |
| | | for (int i = 0; i < mediaServerItems.size(); i++) { |
| | | completableFutures[i] = getRecordFilesForOne(app, stream, startTime, endTime, mediaServerItems.get(i)); |
| | | } |
| | | List<RecordFile> result = new ArrayList<>(); |
| | | for (int i = 0; i < completableFutures.length; i++) { |
| | | try { |
| | | List<RecordFile> list = (List<RecordFile>) completableFutures[i].get(); |
| | | if (!list.isEmpty()) { |
| | | for (int g = 0; g < list.size(); g++) { |
| | | list.get(g).setMediaServerId(mediaServerItems.get(i).getId()); |
| | | } |
| | | result.addAll(list); |
| | | } |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (ExecutionException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | Comparator<RecordFile> comparator = Comparator.comparing(RecordFile::getFileName); |
| | | result.sort(comparator); |
| | | return result; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> getRecordDates(String app, String stream, int year, int month, List<MediaServerItem> mediaServerItems) { |
| | | Assert.notNull(app, "app不存在"); |
| | | Assert.notNull(stream, "stream不存在"); |
| | | Assert.notEmpty(mediaServerItems, "流媒体列表为空"); |
| | | CompletableFuture[] completableFutures = new CompletableFuture[mediaServerItems.size()]; |
| | | |
| | | for (int i = 0; i < mediaServerItems.size(); i++) { |
| | | completableFutures[i] = getRecordDatesForOne(app, stream, year, month, mediaServerItems.get(i)); |
| | | } |
| | | List<String> result = new ArrayList<>(); |
| | | CompletableFuture.allOf(completableFutures).join(); |
| | | for (CompletableFuture completableFuture : completableFutures) { |
| | | try { |
| | | List<String> list = (List<String>) completableFuture.get(); |
| | | result.addAll(list); |
| | | } catch (InterruptedException e) { |
| | | throw new RuntimeException(e); |
| | | } catch (ExecutionException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | Collections.sort(result); |
| | | return result; |
| | | } |
| | | |
| | | @Async |
| | | public CompletableFuture<List<String>> getRecordDatesForOne(String app, String stream, int year, int month, MediaServerItem mediaServerItem) { |
| | | JSONObject fileListJson = assistRESTfulUtils.getDateList(mediaServerItem, app, stream, year, month); |
| | | if (fileListJson != null && !fileListJson.isEmpty()) { |
| | | if (fileListJson.getString("code") != null && fileListJson.getInteger("code") == 0) { |
| | | JSONArray data = fileListJson.getJSONArray("data"); |
| | | return CompletableFuture.completedFuture(data.toJavaList(String.class)); |
| | | } |
| | | } |
| | | return CompletableFuture.completedFuture(new ArrayList<>()); |
| | | } |
| | | |
| | | @Async |
| | | public CompletableFuture<List<RecordFile>> getRecordFilesForOne(String app, String stream, String startTime, String endTime, MediaServerItem mediaServerItem) { |
| | | JSONObject fileListJson = assistRESTfulUtils.getFileList(mediaServerItem, 1, 100000000, app, stream, startTime, endTime); |
| | | if (fileListJson != null && !fileListJson.isEmpty()) { |
| | | if (fileListJson.getString("code") != null && fileListJson.getInteger("code") == 0) { |
| | | JSONObject data = fileListJson.getJSONObject("data"); |
| | | JSONArray list = data.getJSONArray("list"); |
| | | if (list != null) { |
| | | return CompletableFuture.completedFuture(list.toJavaList(RecordFile.class)); |
| | | } |
| | | } |
| | | } |
| | | return CompletableFuture.completedFuture(new ArrayList<>()); |
| | | public List<MediaServerItem> getAllWithAssistPort() { |
| | | return mediaServerMapper.queryAllWithAssistPort(); |
| | | } |
| | | } |