基于新的云端录像结构实现国标录像
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.genersoft.iot.vmp.service;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam;
|
||||
import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
|
||||
@@ -28,4 +30,14 @@ public interface ICloudRecordService {
|
||||
*/
|
||||
List<String> getDateList(String app, String stream, int year, int month, List<MediaServerItem> mediaServerItems);
|
||||
|
||||
/**
|
||||
* 添加合并任务
|
||||
*/
|
||||
String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost);
|
||||
|
||||
|
||||
/**
|
||||
* 查询合并任务列表
|
||||
*/
|
||||
JSONArray queryTask(String taskId, String mediaServerId, Boolean isEnd);
|
||||
}
|
||||
|
||||
@@ -87,21 +87,10 @@ public interface IMediaServerService {
|
||||
|
||||
void updateMediaServerKeepalive(String mediaServerId, ServerKeepaliveData data);
|
||||
|
||||
boolean checkRtpServer(MediaServerItem mediaServerItem, String rtp, String stream);
|
||||
|
||||
/**
|
||||
* 获取负载信息
|
||||
* @return
|
||||
*/
|
||||
MediaServerLoad getLoad(MediaServerItem mediaServerItem);
|
||||
|
||||
/**
|
||||
* 按时间查找录像文件
|
||||
*/
|
||||
List<RecordFile> getRecords(String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems);
|
||||
|
||||
/**
|
||||
* 查找存在录像文件的时间
|
||||
*/
|
||||
List<String> getRecordDates(String app, String stream, int year, int month, List<MediaServerItem> mediaServerItems);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package com.genersoft.iot.vmp.service.impl;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SsrcTransaction;
|
||||
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
||||
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam;
|
||||
import com.genersoft.iot.vmp.service.ICloudRecordService;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper;
|
||||
@@ -31,9 +37,18 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
|
||||
@Autowired
|
||||
private CloudRecordServiceMapper cloudRecordServiceMapper;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private AssistRESTfulUtils assistRESTfulUtils;
|
||||
|
||||
@Autowired
|
||||
private VideoStreamSessionManager streamSession;
|
||||
|
||||
@Override
|
||||
public PageInfo<CloudRecordItem> getList(int page, int count, String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems) {
|
||||
// 开始时间和结束时间在数据库中都是以秒为单位的
|
||||
@@ -54,7 +69,8 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
|
||||
|
||||
}
|
||||
PageHelper.startPage(page, count);
|
||||
List<CloudRecordItem> all = cloudRecordServiceMapper.getList(app, stream, startTimeStamp, endTimeStamp, mediaServerItems);
|
||||
List<CloudRecordItem> all = cloudRecordServiceMapper.getList(app, stream, startTimeStamp, endTimeStamp,
|
||||
null, mediaServerItems);
|
||||
return new PageInfo<>(all);
|
||||
}
|
||||
|
||||
@@ -69,7 +85,8 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
|
||||
}
|
||||
long startTimeStamp = startDate.atStartOfDay().toInstant(ZoneOffset.ofHours(8)).getEpochSecond();
|
||||
long endTimeStamp = endDate.atStartOfDay().toInstant(ZoneOffset.ofHours(8)).getEpochSecond();
|
||||
List<CloudRecordItem> cloudRecordItemList = cloudRecordServiceMapper.getList(app, stream, startTimeStamp, endTimeStamp, mediaServerItems);
|
||||
List<CloudRecordItem> cloudRecordItemList = cloudRecordServiceMapper.getList(app, stream, startTimeStamp,
|
||||
endTimeStamp, null, mediaServerItems);
|
||||
if (cloudRecordItemList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -83,12 +100,71 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
|
||||
|
||||
@Override
|
||||
public void addRecord(OnRecordMp4HookParam param) {
|
||||
CloudRecordItem cloudRecordItem = CloudRecordItem.getInstance(param);
|
||||
CloudRecordItem cloudRecordItem = CloudRecordItem.getInstance(param);
|
||||
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(param.getApp(), param.getStream());
|
||||
if (streamAuthorityInfo != null) {
|
||||
cloudRecordItem.setCallId(streamAuthorityInfo.getCallId());
|
||||
}
|
||||
logger.info("[添加录像记录] {}/{} 文件大小:{}", param.getApp(), param.getStream(), param.getFile_size());
|
||||
logger.info("[添加录像记录] {}/{} 文件大小:{}, 时长: {}秒", param.getApp(), param.getStream(), param.getFile_size(),param.getTime_len());
|
||||
cloudRecordServiceMapper.add(cloudRecordItem);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String addTask(String app, String stream, String mediaServerId, String startTime, String endTime, String callId, String remoteHost) {
|
||||
// 参数校验
|
||||
assert app != null;
|
||||
assert stream != null;
|
||||
MediaServerItem mediaServerItem = null;
|
||||
if (mediaServerId == null) {
|
||||
mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
}else {
|
||||
mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
}
|
||||
if (mediaServerItem == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");
|
||||
}else {
|
||||
if (remoteHost == null) {
|
||||
remoteHost = "http://" + mediaServerItem.getStreamIp() + ":" + mediaServerItem.getRecordAssistPort();
|
||||
}
|
||||
}
|
||||
Long startTimeStamp = null;
|
||||
Long endTimeStamp = null;
|
||||
if (startTime != null) {
|
||||
startTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime);
|
||||
}
|
||||
if (endTime != null) {
|
||||
endTimeStamp = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime);
|
||||
}
|
||||
|
||||
List<MediaServerItem> mediaServers = new ArrayList<>();
|
||||
mediaServers.add(mediaServerItem);
|
||||
// 检索相关的录像文件
|
||||
List<String> filePathList = cloudRecordServiceMapper.queryRecordFilePathList(app, stream, startTimeStamp, endTimeStamp, callId, mediaServers);
|
||||
if (filePathList == null || filePathList.isEmpty()) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未检索到视频文件");
|
||||
}
|
||||
JSONObject result = assistRESTfulUtils.addTask(mediaServerItem, app, stream, startTime, endTime, callId, filePathList, remoteHost);
|
||||
if (result.getInteger("code") != 0) {
|
||||
throw new ControllerException(result.getInteger("code"), result.getString("msg"));
|
||||
}
|
||||
return result.getString("data");
|
||||
}
|
||||
|
||||
@Override
|
||||
public JSONArray queryTask(String taskId, String mediaServerId, Boolean isEnd) {
|
||||
MediaServerItem mediaServerItem = null;
|
||||
if (mediaServerId == null) {
|
||||
mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
}else {
|
||||
mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
}
|
||||
if (mediaServerItem == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");
|
||||
}
|
||||
JSONObject result = assistRESTfulUtils.queryTaskList(mediaServerItem, taskId, isEnd);
|
||||
if (result.getInteger("code") != 0) {
|
||||
throw new ControllerException(result.getInteger("code"), result.getString("msg"));
|
||||
}
|
||||
return result.getJSONArray("data");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -741,15 +741,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
}
|
||||
}
|
||||
|
||||
@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();
|
||||
@@ -761,90 +752,4 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||
result.setGbSend(redisCatchStorage.getGbSendCount(mediaServerItem.getId()));
|
||||
return result;
|
||||
}
|
||||
|
||||
@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<>());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,13 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnStreamChangedHookParam;
|
||||
import com.genersoft.iot.vmp.service.*;
|
||||
import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
|
||||
import com.genersoft.iot.vmp.service.bean.ErrorCallback;
|
||||
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
||||
import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import gov.nist.javax.sip.message.SIPResponse;
|
||||
@@ -107,6 +109,9 @@ public class PlayServiceImpl implements IPlayService {
|
||||
@Autowired
|
||||
private ZlmHttpHookSubscribe subscribe;
|
||||
|
||||
@Autowired
|
||||
private CloudRecordServiceMapper cloudRecordServiceMapper;
|
||||
|
||||
|
||||
@Override
|
||||
public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, String ssrc, ErrorCallback<Object> callback) {
|
||||
@@ -749,31 +754,43 @@ public class PlayServiceImpl implements IPlayService {
|
||||
logger.warn("查询录像信息时发现节点已离线");
|
||||
return null;
|
||||
}
|
||||
if (mediaServerItem.getRecordAssistPort() > 0) {
|
||||
JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream(), null);
|
||||
if (jsonObject == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接Assist服务失败");
|
||||
}
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
long duration = jsonObject.getLong("data");
|
||||
|
||||
if (duration == 0) {
|
||||
inviteInfo.getStreamInfo().setProgress(0);
|
||||
} else {
|
||||
String startTime = inviteInfo.getStreamInfo().getStartTime();
|
||||
String endTime = inviteInfo.getStreamInfo().getEndTime();
|
||||
long start = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime);
|
||||
long end = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime);
|
||||
|
||||
BigDecimal currentCount = new BigDecimal(duration / 1000);
|
||||
BigDecimal totalCount = new BigDecimal(end - start);
|
||||
BigDecimal divide = currentCount.divide(totalCount, 2, RoundingMode.HALF_UP);
|
||||
double process = divide.doubleValue();
|
||||
inviteInfo.getStreamInfo().setProgress(process);
|
||||
}
|
||||
inviteStreamService.updateInviteInfo(inviteInfo);
|
||||
}
|
||||
if (mediaServerItem.getRecordAssistPort() == 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未配置Assist服务,无法完成录像下载");
|
||||
}
|
||||
SsrcTransaction ssrcTransaction = streamSession.getSsrcTransaction(deviceId, channelId, null, stream);
|
||||
|
||||
if (ssrcTransaction == null) {
|
||||
logger.warn("[获取下载进度],未找到下载事务信息");
|
||||
return null;
|
||||
}
|
||||
|
||||
// 为了支持多个数据库,这里不能使用求和函数来直接获取总数了
|
||||
List<CloudRecordItem> cloudRecordItemList = cloudRecordServiceMapper.getList("rtp", inviteInfo.getStream(), null, null, ssrcTransaction.getCallId(), null);
|
||||
|
||||
if (cloudRecordItemList.isEmpty()) {
|
||||
logger.warn("[获取下载进度],未找到下载视频信息");
|
||||
return null;
|
||||
}
|
||||
long duration = 0;
|
||||
for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
|
||||
duration += cloudRecordItem.getTimeLen();
|
||||
}
|
||||
if (duration == 0) {
|
||||
inviteInfo.getStreamInfo().setProgress(0);
|
||||
} else {
|
||||
String startTime = inviteInfo.getStreamInfo().getStartTime();
|
||||
String endTime = inviteInfo.getStreamInfo().getEndTime();
|
||||
long start = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(startTime);
|
||||
long end = DateUtil.yyyy_MM_dd_HH_mm_ssToTimestamp(endTime);
|
||||
|
||||
BigDecimal currentCount = new BigDecimal(duration);
|
||||
BigDecimal totalCount = new BigDecimal(end - start);
|
||||
BigDecimal divide = currentCount.divide(totalCount, 2, RoundingMode.HALF_UP);
|
||||
double process = divide.doubleValue();
|
||||
inviteInfo.getStreamInfo().setProgress(process);
|
||||
}
|
||||
inviteStreamService.updateInviteInfo(inviteInfo);
|
||||
|
||||
return inviteInfo.getStreamInfo();
|
||||
}
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user