From fc77b3f819b3143387b90a4d631725e7c6513ecd Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 01 十二月 2023 15:49:18 +0800
Subject: [PATCH] 支持重新接入zlm的时候检查拉流代理数据是否异常,异常数据自动移除
---
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java | 145 ++++++------------------------------------------
1 files changed, 19 insertions(+), 126 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
index f8c1ba1..7c4965e 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
@@ -128,7 +128,7 @@
continue;
}
// 鏇存柊
- if (ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) {
+ if (!ssrcFactory.hasMediaServerSSRC(mediaServerItem.getId())) {
ssrcFactory.initMediaServerSSRC(mediaServerItem.getId(), null);
}
// 鏌ヨredis鏄惁瀛樺湪姝ediaServer
@@ -229,7 +229,7 @@
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();
@@ -411,7 +411,7 @@
}
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);
@@ -419,17 +419,6 @@
if (serverItem.isAutoConfig()) {
- // 鏌ョ湅assist鏈嶅姟鐨勫綍鍍忚矾寰勯厤缃�
- if (serverItem.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
- JSONObject info = assistRESTfulUtils.getInfo(serverItem, null);
- if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
- JSONObject dataJson = info.getJSONObject("data");
- if (dataJson != null) {
- String recordPath = dataJson.getString("record");
- userSetting.setRecordPath(recordPath);
- }
- }
- }
setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
}
final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId();
@@ -564,7 +553,7 @@
logger.info("[ZLM] 姝e湪璁剧疆 锛歿} -> {}:{}",
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
String protocol = sslEnabled ? "https" : "http";
- String hookPrex = String.format("%s://%s:%s/index/hook", protocol, mediaServerItem.getHookIp(), serverPort);
+ String hookPrefix = String.format("%s://%s:%s/index/hook", protocol, mediaServerItem.getHookIp(), serverPort);
Map<String, Object> param = new HashMap<>();
param.put("api.secret",mediaServerItem.getSecret()); // -profile:v Baseline
@@ -573,25 +562,21 @@
}
param.put("hook.enable","1");
param.put("hook.on_flow_report","");
- param.put("hook.on_play",String.format("%s/on_play", hookPrex));
+ param.put("hook.on_play",String.format("%s/on_play", hookPrefix));
param.put("hook.on_http_access","");
- param.put("hook.on_publish", String.format("%s/on_publish", hookPrex));
+ param.put("hook.on_publish", String.format("%s/on_publish", hookPrefix));
param.put("hook.on_record_ts","");
param.put("hook.on_rtsp_auth","");
param.put("hook.on_rtsp_realm","");
- param.put("hook.on_server_started",String.format("%s/on_server_started", hookPrex));
+ param.put("hook.on_server_started",String.format("%s/on_server_started", hookPrefix));
param.put("hook.on_shell_login","");
- param.put("hook.on_stream_changed",String.format("%s/on_stream_changed", hookPrex));
- param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrex));
- param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrex));
- 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_stream_changed",String.format("%s/on_stream_changed", hookPrefix));
+ param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrefix));
+ param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrefix));
+ param.put("hook.on_server_keepalive",String.format("%s/on_server_keepalive", hookPrefix));
+ param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrefix));
+ param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrefix));
+ param.put("hook.on_record_mp4",String.format("%s/on_record_mp4", hookPrefix));
param.put("hook.timeoutSec","20");
// 鎺ㄦ祦鏂紑鍚庡彲浠ュ湪瓒呮椂鏃堕棿鍐呴噸鏂拌繛鎺ヤ笂缁х画鎺ㄦ祦锛岃繖鏍锋挱鏀惧櫒浼氭帴鐫�鎾斁銆�
// 缃�0鍏抽棴姝ょ壒鎬�(鎺ㄦ祦鏂紑浼氬鑷寸珛鍗虫柇寮�鎾斁鍣�)
@@ -600,15 +585,13 @@
param.put("protocol.continue_push_ms", "3000" );
// 鏈�澶氱瓑寰呮湭鍒濆鍖栫殑Track鏃堕棿锛屽崟浣嶆绉掞紝瓒呮椂涔嬪悗浼氬拷鐣ユ湭鍒濆鍖栫殑Track, 璁剧疆姝ら�夐」浼樺寲閭d簺闊抽閿欒鐨勪笉瑙勮寖娴侊紝
// 绛墇lm鏀寔缁欐瘡涓猺tpServer璁剧疆鍏抽棴闊抽鐨勬椂鍊欏彲浠ヤ笉璁剧疆姝ら�夐」
-// param.put("general.wait_track_ready_ms", "3000" );
if (mediaServerItem.isRtpEnable() && !ObjectUtils.isEmpty(mediaServerItem.getRtpPortRange())) {
param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
}
- if (userSetting.getRecordPath() != null) {
- File recordPathFile = new File(userSetting.getRecordPath());
- File mp4SavePathFile = recordPathFile.getParentFile().getAbsoluteFile();
- param.put("protocol.mp4_save_path", mp4SavePathFile.getAbsoluteFile());
+ if (mediaServerItem.getRecordPath() != null) {
+ File recordPathFile = new File(mediaServerItem.getRecordPath());
+ param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath());
param.put("record.appName", recordPathFile.getName());
}
@@ -741,15 +724,6 @@
}
@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());
@@ -762,88 +736,7 @@
}
@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();
}
}
--
Gitblit v1.8.0