合并271分支

pull/1489/head
648540858 2024-05-23 17:47:43 +08:00
parent 2c89fae49a
commit aeeb61d141
7 changed files with 70 additions and 77 deletions

View File

@ -10,6 +10,7 @@ public class RecordInfo {
private String url;
private long startTime;
private double timeLen;
private String params;
public static RecordInfo getInstance(OnRecordMp4HookParam hookParam) {
RecordInfo recordInfo = new RecordInfo();
@ -79,6 +80,14 @@ public class RecordInfo {
this.timeLen = timeLen;
}
public String getParams() {
return params;
}
public void setParams(String params) {
this.params = params;
}
@Override
public String toString() {
return "RecordInfo{" +
@ -87,6 +96,7 @@ public class RecordInfo {
", 文件大小=" + fileSize +
", 开始时间=" + startTime +
", 时长=" + timeLen +
", params=" + params +
'}';
}
}

View File

@ -24,12 +24,7 @@ import com.genersoft.iot.vmp.service.*;
import com.genersoft.iot.vmp.service.redisMsg.IRedisRpcService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.utils.MediaServerUtils;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import com.genersoft.iot.vmp.vmanager.bean.OtherPsSendInfo;
import com.genersoft.iot.vmp.vmanager.bean.OtherRtpSendInfo;
import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@ -41,11 +36,6 @@ import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
import java.text.ParseException;
import java.util.List;
import java.util.Map;
/**
@ -159,7 +149,7 @@ public class ZLMHttpHookListener {
@PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8")
public HookResult onPlay(@RequestBody OnPlayHookParam param) {
Map<String, String> paramMap = urlParamToMap(param.getParams());
Map<String, String> paramMap = MediaServerUtils.urlParamToMap(param.getParams());
// 对于播放流进行鉴权
boolean authenticateResult = mediaService.authenticatePlay(param.getApp(), param.getStream(), paramMap.get("callId"));
if (!authenticateResult) {
@ -215,7 +205,7 @@ public class ZLMHttpHookListener {
if (!ObjectUtils.isEmpty(mediaServer.getTranscodeSuffix())
&& !"null".equalsIgnoreCase(mediaServer.getTranscodeSuffix())
&& param.getStream().endsWith(mediaServer.getTranscodeSuffix()) ) {
return;
return HookResult.SUCCESS();
}
if (param.getSchema().equalsIgnoreCase("rtsp")) {
if (param.isRegist()) {
@ -242,7 +232,7 @@ public class ZLMHttpHookListener {
logger.info("[ZLM HOOK]流无人观看:{}->{}->{}/{}", param.getMediaServerId(), param.getSchema(),
param.getApp(), param.getStream());
MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
MediaServer mediaInfo = mediaServerService.getOne(param.getMediaServerId());
if (mediaInfo == null) {
JSONObject ret = new JSONObject();
ret.put("code", 0);

View File

@ -19,11 +19,6 @@ public interface ICloudRecordService {
*/
PageInfo<CloudRecordItem> getList(int page, int count, String query, String app, String stream, String startTime, String endTime, List<MediaServer> mediaServerItems, String callId);
/**
* hook
*/
void addRecord(OnRecordMp4HookParam param);
/**
*
*/
@ -56,5 +51,5 @@ public interface ICloudRecordService {
*/
DownloadFileInfo getPlayUrlPath(Integer recordId);
List<CloudRecordItem> getAllList(String query, String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems, String callId, List<Integer> ids);
List<CloudRecordItem> getAllList(String query, String app, String stream, String startTime, String endTime, List<MediaServer> mediaServerItems, String callId, List<Integer> ids);
}

View File

@ -1,7 +1,6 @@
package com.genersoft.iot.vmp.service.bean;
import com.genersoft.iot.vmp.media.event.media.MediaRecordMp4Event;
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRecordMp4HookParam;
import com.genersoft.iot.vmp.utils.MediaServerUtils;
import java.util.Map;
@ -92,7 +91,7 @@ public class CloudRecordItem {
cloudRecordItem.setMediaServerId(param.getMediaServer().getId());
cloudRecordItem.setTimeLen((long) param.getRecordInfo().getTimeLen() * 1000);
cloudRecordItem.setEndTime((param.getRecordInfo().getStartTime() + (long)param.getRecordInfo().getTimeLen()) * 1000);
Map<String, String> paramsMap = MediaServerUtils.urlParamToMap(param.getParams());
Map<String, String> paramsMap = MediaServerUtils.urlParamToMap(param.getRecordInfo().getParams());
if (paramsMap.get("callId") != null) {
cloudRecordItem.setCallId(paramsMap.get("callId"));
}

View File

@ -5,14 +5,12 @@ import com.alibaba.fastjson2.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.genersoft.iot.vmp.conf.exception.ControllerException;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
import com.genersoft.iot.vmp.media.event.media.MediaRecordMp4Event;
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
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.ICloudRecordService;
import com.genersoft.iot.vmp.media.event.media.MediaRecordMp4Event;
import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.dto.StreamAuthorityInfo;
import com.genersoft.iot.vmp.service.ICloudRecordService;
import com.genersoft.iot.vmp.service.bean.CloudRecordItem;
import com.genersoft.iot.vmp.service.bean.DownloadFileInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@ -41,6 +39,7 @@ import java.util.Set;
@DS("share")
public class CloudRecordServiceImpl implements ICloudRecordService {
private final static Logger logger = LoggerFactory.getLogger(CloudRecordServiceImpl.class);
@Autowired
@ -59,7 +58,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
private VideoStreamSessionManager streamSession;
@Override
public PageInfo<CloudRecordItem> getList(int page, int count, String query, String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems, String callId) {
public PageInfo<CloudRecordItem> getList(int page, int count, String query, String app, String stream, String startTime, String endTime, List<MediaServer> mediaServerItems, String callId) {
// 开始时间和结束时间在数据库中都是以秒为单位的
Long startTimeStamp = null;
Long endTimeStamp = null;
@ -111,7 +110,13 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
@EventListener
public void onApplicationEvent(MediaRecordMp4Event event) {
CloudRecordItem cloudRecordItem = CloudRecordItem.getInstance(event);
logger.info("[添加录像记录] {}/{} 内容:{}", event.getApp(), event.getStream(), event.getRecordInfo());
if (ObjectUtils.isEmpty(cloudRecordItem.getCallId())) {
StreamAuthorityInfo streamAuthorityInfo = redisCatchStorage.getStreamAuthorityInfo(event.getApp(), event.getStream());
if (streamAuthorityInfo != null) {
cloudRecordItem.setCallId(streamAuthorityInfo.getCallId());
}
}
logger.info("[添加录像记录] {}/{}, callId: {}, 内容:{}", event.getApp(), event.getStream(), cloudRecordItem.getCallId(), event.getRecordInfo());
cloudRecordServiceMapper.add(cloudRecordItem);
}
@ -239,7 +244,7 @@ public class CloudRecordServiceImpl implements ICloudRecordService {
}
@Override
public List<CloudRecordItem> getAllList(String query, String app, String stream, String startTime, String endTime, List<MediaServerItem> mediaServerItems, String callId, List<Integer> ids) {
public List<CloudRecordItem> getAllList(String query, String app, String stream, String startTime, String endTime, List<MediaServer> mediaServerItems, String callId, List<Integer> ids) {
// 开始时间和结束时间在数据库中都是以秒为单位的
Long startTimeStamp = null;
Long endTimeStamp = null;

View File

@ -12,12 +12,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform;
import com.genersoft.iot.vmp.media.bean.MediaServer;
import com.genersoft.iot.vmp.media.bean.ResultForOnPublish;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.StreamInfo;
import com.genersoft.iot.vmp.conf.MediaConfig;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
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.StreamProxyItem;
import com.genersoft.iot.vmp.service.*;

View File

@ -75,22 +75,22 @@ public class CloudRecordController {
if (ObjectUtils.isEmpty(month)) {
month = calendar.get(Calendar.MONTH) + 1;
}
List<MediaServer> mediaServerItems;
List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) {
mediaServerItems = new ArrayList<>();
MediaServer mediaServerItem = mediaServerService.getOne(mediaServerId);
if (mediaServerItem == null) {
mediaServers = new ArrayList<>();
MediaServer mediaServer = mediaServerService.getOne(mediaServerId);
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId);
}
mediaServerItems.add(mediaServerItem);
mediaServers.add(mediaServer);
} else {
mediaServerItems = mediaServerService.getAllOnlineList();
mediaServers = mediaServerService.getAllOnlineList();
}
if (mediaServerItems.isEmpty()) {
if (mediaServers.isEmpty()) {
return new ArrayList<>();
}
return cloudRecordService.getDateList(app, stream, year, month, mediaServerItems);
return cloudRecordService.getDateList(app, stream, year, month, mediaServers);
}
@ResponseBody
@ -120,18 +120,18 @@ public class CloudRecordController {
logger.info("[云端录像] 查询 app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}",
app, stream, mediaServerId, page, count, startTime, endTime, callId);
List<MediaServer> mediaServerItems;
List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) {
mediaServerItems = new ArrayList<>();
MediaServer mediaServerItem = mediaServerService.getOne(mediaServerId);
if (mediaServerItem == null) {
mediaServers = new ArrayList<>();
MediaServer mediaServer = mediaServerService.getOne(mediaServerId);
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId);
}
mediaServerItems.add(mediaServerItem);
mediaServers.add(mediaServer);
} else {
mediaServerItems = mediaServerService.getAllOnlineList();
mediaServers = mediaServerService.getAllOnlineList();
}
if (mediaServerItems.isEmpty()) {
if (mediaServers.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "当前无流媒体");
}
if (query != null && ObjectUtils.isEmpty(query.trim())) {
@ -152,7 +152,7 @@ public class CloudRecordController {
if (callId != null && ObjectUtils.isEmpty(callId.trim())) {
callId = null;
}
return cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServerItems, callId);
return cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServers, callId);
}
@ResponseBody
@ -175,20 +175,20 @@ public class CloudRecordController {
@RequestParam(required = false) String callId,
@RequestParam(required = false) String remoteHost
){
MediaServer mediaServerItem;
MediaServer mediaServer;
if (mediaServerId == null) {
mediaServerItem = mediaServerService.getDefaultMediaServer();
mediaServer = mediaServerService.getDefaultMediaServer();
}else {
mediaServerItem = mediaServerService.getOne(mediaServerId);
mediaServer = mediaServerService.getOne(mediaServerId);
}
if (mediaServerItem == null) {
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的流媒体");
}else {
if (remoteHost == null) {
remoteHost = request.getScheme() + "://" + mediaServerItem.getIp() + ":" + mediaServerItem.getRecordAssistPort();
remoteHost = request.getScheme() + "://" + mediaServer.getIp() + ":" + mediaServer.getRecordAssistPort();
}
}
return cloudRecordService.addTask(app, stream, mediaServerItem, startTime, endTime, callId, remoteHost, mediaServerId != null);
return cloudRecordService.addTask(app, stream, mediaServer, startTime, endTime, callId, remoteHost, mediaServerId != null);
}
@ResponseBody
@ -309,18 +309,18 @@ public class CloudRecordController {
logger.info("[下载指定录像文件的压缩包] 查询 app->{}, stream->{}, mediaServerId->{}, startTime->{}, endTime->{}, callId->{}",
app, stream, mediaServerId, startTime, endTime, callId);
List<MediaServerItem> mediaServerItems;
List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) {
mediaServerItems = new ArrayList<>();
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
if (mediaServerItem == null) {
mediaServers = new ArrayList<>();
MediaServer mediaServer = mediaServerService.getOne(mediaServerId);
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId);
}
mediaServerItems.add(mediaServerItem);
mediaServers.add(mediaServer);
} else {
mediaServerItems = mediaServerService.getAll();
mediaServers = mediaServerService.getAll();
}
if (mediaServerItems.isEmpty()) {
if (mediaServers.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "当前无流媒体");
}
if (query != null && ObjectUtils.isEmpty(query.trim())) {
@ -344,7 +344,7 @@ public class CloudRecordController {
if (stream != null && callId != null) {
response.addHeader( "Content-Disposition", "attachment;filename=" + stream + "_" + callId + ".zip" );
}
List<CloudRecordItem> cloudRecordItemList = cloudRecordService.getAllList(query, app, stream, startTime, endTime, mediaServerItems, callId, ids);
List<CloudRecordItem> cloudRecordItemList = cloudRecordService.getAllList(query, app, stream, startTime, endTime, mediaServers, callId, ids);
if (ObjectUtils.isEmpty(cloudRecordItemList)) {
return;
}
@ -412,18 +412,18 @@ public class CloudRecordController {
logger.info("[云端录像] 查询URL app->{}, stream->{}, mediaServerId->{}, page->{}, count->{}, startTime->{}, endTime->{}, callId->{}",
app, stream, mediaServerId, page, count, startTime, endTime, callId);
List<MediaServerItem> mediaServerItems;
List<MediaServer> mediaServers;
if (!ObjectUtils.isEmpty(mediaServerId)) {
mediaServerItems = new ArrayList<>();
MediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
if (mediaServerItem == null) {
mediaServers = new ArrayList<>();
MediaServer mediaServer = mediaServerService.getOne(mediaServerId);
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体: " + mediaServerId);
}
mediaServerItems.add(mediaServerItem);
mediaServers.add(mediaServer);
} else {
mediaServerItems = mediaServerService.getAll();
mediaServers = mediaServerService.getAll();
}
if (mediaServerItems.isEmpty()) {
if (mediaServers.isEmpty()) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "当前无流媒体");
}
if (query != null && ObjectUtils.isEmpty(query.trim())) {
@ -444,15 +444,15 @@ public class CloudRecordController {
if (callId != null && ObjectUtils.isEmpty(callId.trim())) {
callId = null;
}
MediaServerItem mediaServerItem = mediaServerService.getDefaultMediaServer();
if (mediaServerItem == null) {
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
if (mediaServer == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到流媒体节点");
}
if (remoteHost == null) {
remoteHost = request.getScheme() + "://" + request.getLocalAddr() + ":" +
(request.getScheme().equals("https")? mediaServerItem.getHttpSSlPort() : mediaServerItem.getHttpPort());
(request.getScheme().equals("https")? mediaServer.getHttpSSlPort() : mediaServer.getHttpPort());
}
PageInfo<CloudRecordItem> cloudRecordItemPageInfo = cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServerItems, callId);
PageInfo<CloudRecordItem> cloudRecordItemPageInfo = cloudRecordService.getList(page, count, query, app, stream, startTime, endTime, mediaServers, callId);
PageInfo<CloudRecordUrl> cloudRecordUrlPageInfo = new PageInfo<>();
if (!ObjectUtils.isEmpty(cloudRecordItemPageInfo)) {
cloudRecordUrlPageInfo.setPageNum(cloudRecordItemPageInfo.getPageNum());