diff --git a/sql/初始化-mysql-2.6.9.sql b/sql/初始化-mysql-2.6.9.sql index bd8a4f57..9dab2a45 100644 --- a/sql/初始化-mysql-2.6.9.sql +++ b/sql/初始化-mysql-2.6.9.sql @@ -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) ); diff --git a/sql/初始化-postgresql-kingbase-2.6.9.sql b/sql/初始化-postgresql-kingbase-2.6.9.sql index 701fd763..ed239c38 100644 --- a/sql/初始化-postgresql-kingbase-2.6.9.sql +++ b/sql/初始化-postgresql-kingbase-2.6.9.sql @@ -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) ); diff --git a/sql/更新-mysql-2.6.9.sql b/sql/更新-mysql-2.6.9.sql index 00de8b2c..c994d5b6 100644 --- a/sql/更新-mysql-2.6.9.sql +++ b/sql/更新-mysql-2.6.9.sql @@ -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; diff --git a/sql/更新-postgresql-kingbase-2.6.9.sql b/sql/更新-postgresql-kingbase-2.6.9.sql index 550d9b2b..711f5b6f 100644 --- a/sql/更新-postgresql-kingbase-2.6.9.sql +++ b/sql/更新-postgresql-kingbase-2.6.9.sql @@ -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; + diff --git a/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java b/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java index 7e11833f..a58fe6de 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java @@ -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 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); diff --git a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java index 20ed8cb1..3acc795e 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java @@ -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; } diff --git a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java index aaeff0a2..0d11df82 100644 --- a/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java +++ b/src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java @@ -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; } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 9bff21f0..885126c1 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -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); diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java index 365f1540..cebfec3b 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java @@ -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; } } diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java index 889909a7..56f2a0c0 100755 --- a/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java +++ b/src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java @@ -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()); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java index 775fe295..594bceef 100644 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java @@ -102,8 +102,8 @@ public interface CloudRecordServiceMapper { @Delete(" ") - int deleteList(List cloudRecordItemIdList, @Param("mediaServerId") String mediaServerId); + int deleteList(List cloudRecordItemIdList); } diff --git a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java index 77f4f192..46785911 100755 --- a/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java +++ b/src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java @@ -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 { ", secret=#{secret}" + ", record_assist_port=#{recordAssistPort}" + ", hook_alive_interval=#{hookAliveInterval}" + + ", record_day=#{recordDay}" + + ", record_path=#{recordPath}" + "WHERE id=#{id}"+ " "}) int update(MediaServerItem mediaServerItem); @@ -105,6 +111,8 @@ public interface MediaServerMapper { ", send_rtp_port_range=#{sendRtpPortRange}" + ", secret=#{secret}" + ", record_assist_port=#{recordAssistPort}" + + ", record_day=#{recordDay}" + + ", record_path=#{recordPath}" + ", hook_alive_interval=#{hookAliveInterval}" + "WHERE ip=#{ip} and http_port=#{httpPort}"+ " "}) diff --git a/src/main/resources/all-application.yml b/src/main/resources/all-application.yml index 7a70c9ec..59dac15d 100644 --- a/src/main/resources/all-application.yml +++ b/src/main/resources/all-application.yml @@ -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范围内选择端口用于媒体流传输