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

View File

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

View File

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

View File

@ -295,24 +295,6 @@ public class ZLMHttpHookListener {
result.setEnable_mp4(true); 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")) { if (param.getApp().equalsIgnoreCase("rtp")) {
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream(); String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream();
OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey); OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey);

View File

@ -81,7 +81,10 @@ public class MediaServerItem{
private boolean defaultServer; private boolean defaultServer;
@Schema(description = "录像存储时长") @Schema(description = "录像存储时长")
private int recordDate; private int recordDay;
@Schema(description = "录像存储路径")
private String recordPath;
public MediaServerItem() { public MediaServerItem() {
} }
@ -300,11 +303,19 @@ public class MediaServerItem{
this.sendRtpPortRange = sendRtpPortRange; this.sendRtpPortRange = sendRtpPortRange;
} }
public int getRecordDate() { public int getRecordDay() {
return recordDate; return recordDay;
} }
public void setRecordDate(int recordDate) { public void setRecordDay(int recordDay) {
this.recordDate = recordDate; 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()) { 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())); setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
} }
final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId(); final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId();
@ -606,10 +595,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-")); param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
} }
if (userSetting.getRecordPath() != null) { if (mediaServerItem.getRecordPath() != null) {
File recordPathFile = new File(userSetting.getRecordPath()); File recordPathFile = new File(mediaServerItem.getRecordPath());
File mp4SavePathFile = recordPathFile.getParentFile().getAbsoluteFile(); param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath());
param.put("protocol.mp4_save_path", mp4SavePathFile.getAbsoluteFile());
param.put("record.appName", recordPathFile.getName()); param.put("record.appName", recordPathFile.getName());
} }

View File

@ -102,8 +102,8 @@ public interface CloudRecordServiceMapper {
@Delete(" <script>" + @Delete(" <script>" +
"delete from wvp_cloud_record where media_server_id=#{mediaServerId} and id in " + "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>") " </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,"+ "rtp_port_range,"+
"send_rtp_port_range,"+ "send_rtp_port_range,"+
"record_assist_port,"+ "record_assist_port,"+
"record_day,"+
"record_path,"+
"default_server,"+ "default_server,"+
"create_time,"+ "create_time,"+
"update_time,"+ "update_time,"+
@ -55,6 +57,8 @@ public interface MediaServerMapper {
"#{rtpPortRange}, " + "#{rtpPortRange}, " +
"#{sendRtpPortRange}, " + "#{sendRtpPortRange}, " +
"#{recordAssistPort}, " + "#{recordAssistPort}, " +
"#{recordDay}, " +
"#{recordPath}, " +
"#{defaultServer}, " + "#{defaultServer}, " +
"#{createTime}, " + "#{createTime}, " +
"#{updateTime}, " + "#{updateTime}, " +
@ -82,6 +86,8 @@ public interface MediaServerMapper {
"<if test=\"secret != null\">, secret=#{secret}</if>" + "<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" + "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
"<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</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}"+ "WHERE id=#{id}"+
" </script>"}) " </script>"})
int update(MediaServerItem mediaServerItem); int update(MediaServerItem mediaServerItem);
@ -105,6 +111,8 @@ public interface MediaServerMapper {
"<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" + "<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" + "<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</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>" + "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
"WHERE ip=#{ip} and http_port=#{httpPort}"+ "WHERE ip=#{ip} and http_port=#{httpPort}"+
" </script>"}) " </script>"})

View File

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