将录像存储路径迁移至wvp中配置,assist以有在需要视频合成的时候才会用

pull/1242/head
648540858 2023-11-01 14:07:32 +08:00
parent 75fccfaf17
commit 5d3f307b44
13 changed files with 69 additions and 66 deletions

View File

@ -165,7 +165,7 @@ create table wvp_media_server (
update_time character varying(50),
hook_alive_interval integer,
record_path character varying(255),
record_date integer default 7,
record_day integer default 7,
constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
);

View File

@ -165,7 +165,7 @@ create table wvp_media_server (
update_time character varying(50),
hook_alive_interval integer,
record_path character varying(255),
record_date integer default 7,
record_day integer default 7,
constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
);

View File

@ -496,6 +496,6 @@ alter table wvp_media_server
add record_path character varying(255);
alter table wvp_media_server
add record_date integer default 7;
add record_day integer default 7;

View File

@ -496,6 +496,7 @@ alter table wvp_media_server
add record_path character varying(255);
alter table wvp_media_server
add record_date integer default 7;
add record_day integer default 7;

View File

@ -41,8 +41,8 @@ public class CloudRecordTimer {
/**
*
*/
// @Scheduled(fixedRate = 5000) //每五秒执行一次,方便测试
@Scheduled(cron = "0 0 0 * * ?") //每天的0点执行
// @Scheduled(fixedRate = 5000)
public void execute(){
logger.info("[录像文件定时清理] 开始清理过期录像文件");
// 获取配置了assist的流媒体节点
@ -54,10 +54,10 @@ public class CloudRecordTimer {
for (MediaServerItem mediaServerItem : mediaServerItemList) {
Calendar lastCalendar = Calendar.getInstance();
if (mediaServerItem.getRecordDate() > 0) {
if (mediaServerItem.getRecordDay() > 0) {
lastCalendar.setTime(new Date());
// 获取保存的最后截至日期,因为每个节点都有一个日期,也就是支持每个节点设置不同的保存日期,
lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDate());
lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDay());
Long lastDate = lastCalendar.getTimeInMillis();
// 获取到截至日期之前的录像文件列表,文件列表满足未被收藏和保持的。这两个字段目前共能一致,
@ -66,22 +66,16 @@ public class CloudRecordTimer {
if (cloudRecordItemList.isEmpty()) {
continue;
}
List<Integer> cloudRecordItemIdList = new ArrayList<>();
for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
String date = new File(cloudRecordItem.getFilePath()).getParentFile().getName();
JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServerItem, cloudRecordItem.getApp(),
cloudRecordItem.getStream(), date, cloudRecordItem.getFileName());
if (jsonObject.getInteger("code") == 0) {
cloudRecordItemIdList.add(cloudRecordItem.getId());
}else {
logger.warn("[录像文件定时清理] 删除磁盘文件错误: {}", jsonObject);
logger.warn("[录像文件定时清理] 删除磁盘文件错误: {}:{}", cloudRecordItem.getFilePath(), jsonObject);
}
}
if (cloudRecordItemIdList.isEmpty()) {
continue;
}
cloudRecordServiceMapper.deleteList(cloudRecordItemIdList, mediaServerItem.getId());
result += cloudRecordItemIdList.size();
result += cloudRecordServiceMapper.deleteList(cloudRecordItemList);
}
}
logger.info("[录像文件定时清理] 共清理{}个过期录像文件", result);

View File

@ -81,6 +81,12 @@ public class MediaConfig{
@Value("${media.record-assist-port:0}")
private Integer recordAssistPort = 0;
@Value("${media.record-date:7}")
private Integer recordDay = 7;
@Value("${media.record-path}")
private String recordPath;
public String getId() {
return id;
}
@ -212,13 +218,32 @@ public class MediaConfig{
mediaServerItem.setSendRtpPortRange(rtpSendPortRange);
mediaServerItem.setRecordAssistPort(recordAssistPort);
mediaServerItem.setHookAliveInterval(30.00f);
mediaServerItem.setRecordDay(recordDay);
if (recordPath != null) {
mediaServerItem.setRecordPath(recordPath);
}
mediaServerItem.setCreateTime(DateUtil.getNow());
mediaServerItem.setUpdateTime(DateUtil.getNow());
return mediaServerItem;
}
public Integer getRecordDay() {
return recordDay;
}
public void setRecordDay(Integer recordDay) {
this.recordDay = recordDay;
}
public String getRecordPath() {
return recordPath;
}
public void setRecordPath(String recordPath) {
this.recordPath = recordPath;
}
public String getRtpSendPortRange() {
return rtpSendPortRange;
}

View File

@ -56,8 +56,6 @@ public class UserSetting {
private String serverId = "000000";
private String recordPath = null;
private String thirdPartyGBIdReg = "[\\s\\S]*";
private String civilCodeFile = "classpath:civilCode.csv";
@ -252,14 +250,6 @@ public class UserSetting {
this.refuseChannelStatusChannelFormNotify = refuseChannelStatusChannelFormNotify;
}
public String getRecordPath() {
return recordPath;
}
public void setRecordPath(String recordPath) {
this.recordPath = recordPath;
}
public int getMaxNotifyCountQueue() {
return maxNotifyCountQueue;
}

View File

@ -295,24 +295,6 @@ public class ZLMHttpHookListener {
result.setEnable_mp4(true);
}
}
if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
logger.info("推流时发现尚未设置录像路径从assist服务中读取");
JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, 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);
result.setMp4_save_path(recordPath);
// 修改zlm中的录像路径
if (mediaInfo.isAutoConfig()) {
taskExecutor.execute(() -> {
mediaServerService.setZLMConfig(mediaInfo, false);
});
}
}
}
}
if (param.getApp().equalsIgnoreCase("rtp")) {
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream();
OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey);

View File

@ -81,7 +81,10 @@ public class MediaServerItem{
private boolean defaultServer;
@Schema(description = "录像存储时长")
private int recordDate;
private int recordDay;
@Schema(description = "录像存储路径")
private String recordPath;
public MediaServerItem() {
}
@ -300,11 +303,19 @@ public class MediaServerItem{
this.sendRtpPortRange = sendRtpPortRange;
}
public int getRecordDate() {
return recordDate;
public int getRecordDay() {
return recordDay;
}
public void setRecordDate(int recordDate) {
this.recordDate = recordDate;
public void setRecordDay(int recordDay) {
this.recordDay = recordDay;
}
public String getRecordPath() {
return recordPath;
}
public void setRecordPath(String recordPath) {
this.recordPath = recordPath;
}
}

View File

@ -419,17 +419,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
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();
@ -606,10 +595,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
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());
}

View File

@ -102,8 +102,8 @@ public interface CloudRecordServiceMapper {
@Delete(" <script>" +
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} and id in " +
" <foreach collection='cloudRecordItemIdList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
" <foreach collection='cloudRecordItemIdList' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
" </script>")
int deleteList(List<Integer> cloudRecordItemIdList, @Param("mediaServerId") String mediaServerId);
int deleteList(List<CloudRecordItem> cloudRecordItemIdList);
}

View File

@ -31,6 +31,8 @@ public interface MediaServerMapper {
"rtp_port_range,"+
"send_rtp_port_range,"+
"record_assist_port,"+
"record_day,"+
"record_path,"+
"default_server,"+
"create_time,"+
"update_time,"+
@ -55,6 +57,8 @@ public interface MediaServerMapper {
"#{rtpPortRange}, " +
"#{sendRtpPortRange}, " +
"#{recordAssistPort}, " +
"#{recordDay}, " +
"#{recordPath}, " +
"#{defaultServer}, " +
"#{createTime}, " +
"#{updateTime}, " +
@ -82,6 +86,8 @@ public interface MediaServerMapper {
"<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
"<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
"<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
"<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
"WHERE id=#{id}"+
" </script>"})
int update(MediaServerItem mediaServerItem);
@ -105,6 +111,8 @@ public interface MediaServerMapper {
"<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
"<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
"<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
"<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
"WHERE ip=#{ip} and http_port=#{httpPort}"+
" </script>"})

View File

@ -139,6 +139,10 @@ media:
auto-config: true
# [可选] zlm服务器的hook.admin_params=secret
secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
# 录像路径
record-path: ./www/record
# 录像保存时长
record-date: 7
# 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分 点播超时建议使用多端口测试
rtp:
# [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输