|
@@ -20,6 +20,7 @@ import com.ozs.entity.BaseCameraManagement;
|
|
|
import com.ozs.entity.BaseTerminal;
|
|
|
import com.ozs.entity.BaseTerminalLog;
|
|
|
import com.ozs.entity.MsgHeartbeatAlarmMessage;
|
|
|
+import com.ozs.entity.response.BaseCameraManagementResponse;
|
|
|
import com.ozs.entity.vo.CamerasVo;
|
|
|
import com.ozs.entity.vo.PlaybackVo;
|
|
|
import com.ozs.framework.config.ServerConfig;
|
|
@@ -47,10 +48,12 @@ import java.io.OutputStreamWriter;
|
|
|
import java.io.PrintWriter;
|
|
|
import java.text.ParseException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.time.Duration;
|
|
|
import java.time.Instant;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.OffsetDateTime;
|
|
|
import java.time.ZoneOffset;
|
|
|
+import java.time.ZonedDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Calendar;
|
|
@@ -366,39 +369,33 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
boolean success = false;
|
|
|
JSONArray jsonArray = null;
|
|
|
List<String> pathList = new ArrayList<>();
|
|
|
- String data = null;
|
|
|
- try {
|
|
|
- data = HttpUtils.sendGet(webUrl + "/rtsp/api/list");
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("Exception /rtsp/api/list: " + e.getMessage());
|
|
|
- }
|
|
|
- log.info("data------------------>" + data);
|
|
|
- if (StringUtils.isNotEmpty(data)) {
|
|
|
- while (!success && retryCount < maxRetries) {
|
|
|
- try {
|
|
|
+ while (!success && retryCount < maxRetries) {
|
|
|
+ try {
|
|
|
+ String data = HttpUtils.sendGet(webUrl + "/rtsp/api/list");
|
|
|
+ log.info("data------------------>" + data);
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
jsonArray = JSONArray.parseArray(data);
|
|
|
success = true;
|
|
|
- } catch (Exception e) {
|
|
|
- log.info("Exception caught: " + e.getMessage());
|
|
|
- // 增加重试计数
|
|
|
- retryCount++;
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("Exception caught: " + e.getMessage());
|
|
|
+ // 增加重试计数
|
|
|
+ retryCount++;
|
|
|
}
|
|
|
- log.info("jsonArray------------------>" + jsonArray);
|
|
|
- if (!ObjectUtils.isEmpty(jsonArray)) {
|
|
|
- for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
- JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
- String name = jsonObject.getString("Path");
|
|
|
- pathList.add(name);
|
|
|
- }
|
|
|
- boolean contains = pathList.contains(cameraCode + "/" + channel);
|
|
|
- if (!contains) {
|
|
|
- return null;
|
|
|
- } else {
|
|
|
- return getPlayFlvRtsp(cameraCode, channel, type);
|
|
|
- }
|
|
|
+ }
|
|
|
+ log.info("jsonArray------------------>" + jsonArray);
|
|
|
+ if (!ObjectUtils.isEmpty(jsonArray)) {
|
|
|
+ for (int i = 0; i < jsonArray.size(); i++) {
|
|
|
+ JSONObject jsonObject = jsonArray.getJSONObject(i);
|
|
|
+ String name = jsonObject.getString("Path");
|
|
|
+ pathList.add(name);
|
|
|
+ }
|
|
|
+ boolean contains = pathList.contains(cameraCode + "/" + channel);
|
|
|
+ if (!contains) {
|
|
|
+ return null;
|
|
|
+ } else {
|
|
|
+ return getPlayFlvRtsp(cameraCode, channel, type);
|
|
|
}
|
|
|
- return null;
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
@@ -1154,10 +1151,10 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
String body = JSONObject.toJSONString(camerasVo);
|
|
|
String previewURLs = getPreviewURLs("/api/video/v1/cameras/previewURLs", body);
|
|
|
log.info("-------------------------------->>>>>previewURLs" + previewURLs);
|
|
|
- if (StringUtils.isEmpty(previewURLs)){
|
|
|
+ if (StringUtils.isEmpty(previewURLs)) {
|
|
|
log.info("天网接口异常");
|
|
|
return "天网接口异常";
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
long end = System.currentTimeMillis();
|
|
|
JSONObject outJson = JSONObject.parse(previewURLs);
|
|
|
stringBuilder.append("测试结果:" + ("0".equals(outJson.getString("code")) ? "成功" : "失败"));
|
|
@@ -1352,56 +1349,95 @@ ffmpeg -i "concat:1.ts|2.ts" -c copy output.mp4
|
|
|
System.out.println(DateUtils.parseDateToStr(DateUtils.YYYYMMDDHHMMSS, sdate));
|
|
|
}
|
|
|
|
|
|
- public void heartbeatGetPlayFlv() {
|
|
|
- String data = HttpUtils.sendGet(webUrl + "/api/summary");
|
|
|
- log.info("data------------------>" + data);
|
|
|
- if (StringUtils.isNotEmpty(data)) {
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
- log.info("jsonObject------------------>" + jsonObject);
|
|
|
- JSONArray streamArray = jsonObject.getJSONArray("Streams");
|
|
|
- log.info("streamArray------------------>" + streamArray);
|
|
|
- if (!ObjectUtils.isEmpty(streamArray)) {
|
|
|
- for (int i = 0; i < streamArray.size(); i++) {
|
|
|
- JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
- log.info("subObj------------------>" + subObj);
|
|
|
- String subValue = subObj.getString("Subscribers");
|
|
|
- String pathValue = subObj.getString("Path");
|
|
|
- //从缓存取出预拉的流的集合
|
|
|
- List<String> heartbeat = redisCache.getCacheObject("heartbeat");
|
|
|
- log.info("subValue------------------>" + subValue);
|
|
|
- log.info("pathValue------------------>" + pathValue);
|
|
|
- log.info("heartbeat------------------>" + heartbeat);
|
|
|
- //判断压缩流是否订阅者是0
|
|
|
- if (subValue.equals("0") && pathValue.contains("h264_720") && !pathValue.contains("live")) {
|
|
|
- log.info("----------流程1--判断压缩流是否订阅者是0-------------");
|
|
|
- if (!ObjectUtils.isEmpty(heartbeat)) {
|
|
|
- if (!heartbeat.contains(pathValue)) {
|
|
|
- log.info("执行stopStream---111--------------->");
|
|
|
- String[] parts = pathValue.split("/");
|
|
|
- stopStream(parts[0], parts[1]);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("执行stopStream--------2222---------->");
|
|
|
- String[] parts = pathValue.split("/");
|
|
|
- stopStream(parts[0], parts[1]);
|
|
|
- }
|
|
|
- }
|
|
|
- //判断主码流是否订阅者是2
|
|
|
- if (subValue.equals("2") && !pathValue.contains("h264_720")) {
|
|
|
- log.info("----------流程2--判断主码流是否订阅者是2-------------");
|
|
|
- if (!ObjectUtils.isEmpty(heartbeat)) {
|
|
|
- if (!heartbeat.contains(pathValue)) {
|
|
|
- log.info("hostStopStream---111--------------->");
|
|
|
- hostStopStream(pathValue);
|
|
|
- }
|
|
|
- } else {
|
|
|
- log.info("hostStopStream---222--------------->");
|
|
|
- hostStopStream(pathValue);
|
|
|
- }
|
|
|
- }
|
|
|
+ public List<BaseCameraManagementResponse> heartbeatGetPlayFlv() {
|
|
|
+ int maxRetries = 5;
|
|
|
+ int retryCount = 0;
|
|
|
+ boolean success = false;
|
|
|
+ JSONArray streamArray = null;
|
|
|
+ List<BaseCameraManagementResponse> baseCameraManagementResponseList = new ArrayList<>();
|
|
|
+ while (!success && retryCount < maxRetries) {
|
|
|
+ try {
|
|
|
+ String data = HttpUtils.sendGet(webUrl + "/api/summary");
|
|
|
+ log.info("data------------------>" + data);
|
|
|
+ if (StringUtils.isNotEmpty(data)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(data);
|
|
|
+ streamArray = jsonObject.getJSONArray("Streams");
|
|
|
+ success = true;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("Exception caught: " + e.getMessage());
|
|
|
+ // 增加重试计数
|
|
|
+ retryCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (int i = 0; i < streamArray.size(); i++) {
|
|
|
+ BaseCameraManagementResponse baseCameraManagementResponse = new BaseCameraManagementResponse();
|
|
|
+ JSONObject subObj = streamArray.getJSONObject(i);
|
|
|
+ String subValue = subObj.getString("Subscribers");
|
|
|
+ String PathValue = subObj.getString("Path");
|
|
|
+ String type = subObj.getString("Type");
|
|
|
+ String timestampString = subObj.getString("StartTime");
|
|
|
+ ZonedDateTime givenTime = ZonedDateTime.parse(timestampString);
|
|
|
+ // 当前时间
|
|
|
+ Instant currentTime = Instant.now();
|
|
|
+ // 将给定时间转换为Instant对象
|
|
|
+ Instant givenInstant = givenTime.toInstant();
|
|
|
+ // 计算时间差
|
|
|
+ Duration duration = Duration.between(givenInstant, currentTime);
|
|
|
+ //封装
|
|
|
+ // 获取小时差
|
|
|
+ baseCameraManagementResponse.setStartTime(duration.toHours() + "小时前");
|
|
|
+ baseCameraManagementResponse.setStreamPath(PathValue);
|
|
|
+ baseCameraManagementResponse.setSubscribers(subValue);
|
|
|
+ baseCameraManagementResponse.setType(type);
|
|
|
+ // 寻找第一个斜杠的位置
|
|
|
+ int slashIndex = PathValue.indexOf("/");
|
|
|
+ if (slashIndex != -1) {
|
|
|
+ BaseCameraManagementResponse response = new BaseCameraManagementResponse();
|
|
|
+ String result = PathValue.substring(0, slashIndex);
|
|
|
+ BaseCameraManagement cameraManagement = baseCameraManagementService.getOne(new LambdaQueryWrapper<BaseCameraManagement>()
|
|
|
+ .eq(BaseCameraManagement::getCameraCode, result));
|
|
|
+ if (!ObjectUtils.isEmpty(cameraManagement)) {
|
|
|
+ baseCameraManagementResponse.setCameraCode(cameraManagement.getCameraCode());
|
|
|
+ baseCameraManagementResponse.setInstallMile(cameraManagement.getInstallMile());
|
|
|
}
|
|
|
}
|
|
|
+ //取出AudioTracks
|
|
|
+ JSONArray audioJson = subObj.getJSONArray("AudioTracks");
|
|
|
+ for (int v = 0; v < audioJson.size(); v++) {
|
|
|
+ BaseCameraManagementResponse.AudioTracks audioTracks = new BaseCameraManagementResponse.AudioTracks();
|
|
|
+ JSONObject arrayJSONObject = audioJson.getJSONObject(v);
|
|
|
+ String name = arrayJSONObject.getString("Name");
|
|
|
+ String sampleRate = arrayJSONObject.getString("SampleRate");
|
|
|
+ String channels = arrayJSONObject.getString("Channels");
|
|
|
+ String bps = arrayJSONObject.getString("BPS");
|
|
|
+ audioTracks.setBps(bps);
|
|
|
+ audioTracks.setChannels(channels);
|
|
|
+ audioTracks.setName(name);
|
|
|
+ audioTracks.setSampleRate(sampleRate);
|
|
|
+ baseCameraManagementResponse.setAudioTracks(audioTracks);
|
|
|
+ }
|
|
|
+ //取出VideoTracks
|
|
|
+ JSONArray videoJson = subObj.getJSONArray("VideoTracks");
|
|
|
+ for (int v = 0; v < videoJson.size(); v++) {
|
|
|
+ BaseCameraManagementResponse.VideoTracks videoTracks = new BaseCameraManagementResponse.VideoTracks();
|
|
|
+ JSONObject arrayJSONObject = videoJson.getJSONObject(v);
|
|
|
+ String name = arrayJSONObject.getString("Name");
|
|
|
+ String width = arrayJSONObject.getString("Width");
|
|
|
+ String height = arrayJSONObject.getString("Height");
|
|
|
+ String resolution = width + "*" + height;
|
|
|
+ String gop = arrayJSONObject.getString("GOP");
|
|
|
+ String bps = arrayJSONObject.getString("BPS");
|
|
|
+ videoTracks.setBps(bps);
|
|
|
+ videoTracks.setGop(gop);
|
|
|
+ videoTracks.setName(name);
|
|
|
+ videoTracks.setResolution(resolution);
|
|
|
+ baseCameraManagementResponse.setVideoTracks(videoTracks);
|
|
|
+ }
|
|
|
+ baseCameraManagementResponseList.add(baseCameraManagementResponse);
|
|
|
}
|
|
|
+
|
|
|
+ return baseCameraManagementResponseList;
|
|
|
}
|
|
|
|
|
|
public void removePlayFlv(Integer lineDir, Integer currentMile, Integer visualDistance) {
|