Commit 5d3f307b44aa8df32c9d893764fb8525d51eda5c

Authored by 648540858
1 parent 75fccfaf

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

sql/初始化-mysql-2.6.9.sql
... ... @@ -165,7 +165,7 @@ create table wvp_media_server (
165 165 update_time character varying(50),
166 166 hook_alive_interval integer,
167 167 record_path character varying(255),
168   - record_date integer default 7,
  168 + record_day integer default 7,
169 169 constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
170 170 );
171 171  
... ...
sql/初始化-postgresql-kingbase-2.6.9.sql
... ... @@ -165,7 +165,7 @@ create table wvp_media_server (
165 165 update_time character varying(50),
166 166 hook_alive_interval integer,
167 167 record_path character varying(255),
168   - record_date integer default 7,
  168 + record_day integer default 7,
169 169 constraint uk_media_server_unique_ip_http_port unique (ip, http_port)
170 170 );
171 171  
... ...
sql/更新-mysql-2.6.9.sql
... ... @@ -496,6 +496,6 @@ alter table wvp_media_server
496 496 add record_path character varying(255);
497 497  
498 498 alter table wvp_media_server
499   - add record_date integer default 7;
  499 + add record_day integer default 7;
500 500  
501 501  
... ...
sql/更新-postgresql-kingbase-2.6.9.sql
... ... @@ -496,6 +496,7 @@ alter table wvp_media_server
496 496 add record_path character varying(255);
497 497  
498 498 alter table wvp_media_server
499   - add record_date integer default 7;
  499 + add record_day integer default 7;
  500 +
500 501  
501 502  
... ...
src/main/java/com/genersoft/iot/vmp/conf/CloudRecordTimer.java
... ... @@ -41,8 +41,8 @@ public class CloudRecordTimer {
41 41 /**
42 42 * 定时查询待删除的录像文件
43 43 */
  44 +// @Scheduled(fixedRate = 5000) //每五秒执行一次,方便测试
44 45 @Scheduled(cron = "0 0 0 * * ?") //每天的0点执行
45   -// @Scheduled(fixedRate = 5000)
46 46 public void execute(){
47 47 logger.info("[录像文件定时清理] 开始清理过期录像文件");
48 48 // 获取配置了assist的流媒体节点
... ... @@ -54,10 +54,10 @@ public class CloudRecordTimer {
54 54 for (MediaServerItem mediaServerItem : mediaServerItemList) {
55 55  
56 56 Calendar lastCalendar = Calendar.getInstance();
57   - if (mediaServerItem.getRecordDate() > 0) {
  57 + if (mediaServerItem.getRecordDay() > 0) {
58 58 lastCalendar.setTime(new Date());
59 59 // 获取保存的最后截至日期,因为每个节点都有一个日期,也就是支持每个节点设置不同的保存日期,
60   - lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDate());
  60 + lastCalendar.add(Calendar.DAY_OF_MONTH, -mediaServerItem.getRecordDay());
61 61 Long lastDate = lastCalendar.getTimeInMillis();
62 62  
63 63 // 获取到截至日期之前的录像文件列表,文件列表满足未被收藏和保持的。这两个字段目前共能一致,
... ... @@ -66,22 +66,16 @@ public class CloudRecordTimer {
66 66 if (cloudRecordItemList.isEmpty()) {
67 67 continue;
68 68 }
69   - List<Integer> cloudRecordItemIdList = new ArrayList<>();
70 69 for (CloudRecordItem cloudRecordItem : cloudRecordItemList) {
71 70 String date = new File(cloudRecordItem.getFilePath()).getParentFile().getName();
72 71 JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServerItem, cloudRecordItem.getApp(),
73 72 cloudRecordItem.getStream(), date, cloudRecordItem.getFileName());
74 73 if (jsonObject.getInteger("code") == 0) {
75   - cloudRecordItemIdList.add(cloudRecordItem.getId());
76 74 }else {
77   - logger.warn("[录像文件定时清理] 删除磁盘文件错误: {}", jsonObject);
  75 + logger.warn("[录像文件定时清理] 删除磁盘文件错误: {}:{}", cloudRecordItem.getFilePath(), jsonObject);
78 76 }
79 77 }
80   - if (cloudRecordItemIdList.isEmpty()) {
81   - continue;
82   - }
83   - cloudRecordServiceMapper.deleteList(cloudRecordItemIdList, mediaServerItem.getId());
84   - result += cloudRecordItemIdList.size();
  78 + result += cloudRecordServiceMapper.deleteList(cloudRecordItemList);
85 79 }
86 80 }
87 81 logger.info("[录像文件定时清理] 共清理{}个过期录像文件", result);
... ...
src/main/java/com/genersoft/iot/vmp/conf/MediaConfig.java
... ... @@ -81,6 +81,12 @@ public class MediaConfig{
81 81 @Value("${media.record-assist-port:0}")
82 82 private Integer recordAssistPort = 0;
83 83  
  84 + @Value("${media.record-date:7}")
  85 + private Integer recordDay = 7;
  86 +
  87 + @Value("${media.record-path}")
  88 + private String recordPath;
  89 +
84 90 public String getId() {
85 91 return id;
86 92 }
... ... @@ -212,13 +218,32 @@ public class MediaConfig{
212 218 mediaServerItem.setSendRtpPortRange(rtpSendPortRange);
213 219 mediaServerItem.setRecordAssistPort(recordAssistPort);
214 220 mediaServerItem.setHookAliveInterval(30.00f);
215   -
  221 + mediaServerItem.setRecordDay(recordDay);
  222 + if (recordPath != null) {
  223 + mediaServerItem.setRecordPath(recordPath);
  224 + }
216 225 mediaServerItem.setCreateTime(DateUtil.getNow());
217 226 mediaServerItem.setUpdateTime(DateUtil.getNow());
218 227  
219 228 return mediaServerItem;
220 229 }
221 230  
  231 + public Integer getRecordDay() {
  232 + return recordDay;
  233 + }
  234 +
  235 + public void setRecordDay(Integer recordDay) {
  236 + this.recordDay = recordDay;
  237 + }
  238 +
  239 + public String getRecordPath() {
  240 + return recordPath;
  241 + }
  242 +
  243 + public void setRecordPath(String recordPath) {
  244 + this.recordPath = recordPath;
  245 + }
  246 +
222 247 public String getRtpSendPortRange() {
223 248 return rtpSendPortRange;
224 249 }
... ...
src/main/java/com/genersoft/iot/vmp/conf/UserSetting.java
... ... @@ -56,8 +56,6 @@ public class UserSetting {
56 56  
57 57 private String serverId = "000000";
58 58  
59   - private String recordPath = null;
60   -
61 59 private String thirdPartyGBIdReg = "[\\s\\S]*";
62 60  
63 61 private String civilCodeFile = "classpath:civilCode.csv";
... ... @@ -252,14 +250,6 @@ public class UserSetting {
252 250 this.refuseChannelStatusChannelFormNotify = refuseChannelStatusChannelFormNotify;
253 251 }
254 252  
255   - public String getRecordPath() {
256   - return recordPath;
257   - }
258   -
259   - public void setRecordPath(String recordPath) {
260   - this.recordPath = recordPath;
261   - }
262   -
263 253 public int getMaxNotifyCountQueue() {
264 254 return maxNotifyCountQueue;
265 255 }
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
... ... @@ -295,24 +295,6 @@ public class ZLMHttpHookListener {
295 295 result.setEnable_mp4(true);
296 296 }
297 297 }
298   - if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
299   - logger.info("推流时发现尚未设置录像路径,从assist服务中读取");
300   - JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null);
301   - if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
302   - JSONObject dataJson = info.getJSONObject("data");
303   - if (dataJson != null) {
304   - String recordPath = dataJson.getString("record");
305   - userSetting.setRecordPath(recordPath);
306   - result.setMp4_save_path(recordPath);
307   - // 修改zlm中的录像路径
308   - if (mediaInfo.isAutoConfig()) {
309   - taskExecutor.execute(() -> {
310   - mediaServerService.setZLMConfig(mediaInfo, false);
311   - });
312   - }
313   - }
314   - }
315   - }
316 298 if (param.getApp().equalsIgnoreCase("rtp")) {
317 299 String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + param.getStream();
318 300 OtherRtpSendInfo otherRtpSendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(receiveKey);
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/dto/MediaServerItem.java
... ... @@ -81,7 +81,10 @@ public class MediaServerItem{
81 81 private boolean defaultServer;
82 82  
83 83 @Schema(description = "录像存储时长")
84   - private int recordDate;
  84 + private int recordDay;
  85 +
  86 + @Schema(description = "录像存储路径")
  87 + private String recordPath;
85 88  
86 89 public MediaServerItem() {
87 90 }
... ... @@ -300,11 +303,19 @@ public class MediaServerItem{
300 303 this.sendRtpPortRange = sendRtpPortRange;
301 304 }
302 305  
303   - public int getRecordDate() {
304   - return recordDate;
  306 + public int getRecordDay() {
  307 + return recordDay;
  308 + }
  309 +
  310 + public void setRecordDay(int recordDay) {
  311 + this.recordDay = recordDay;
  312 + }
  313 +
  314 + public String getRecordPath() {
  315 + return recordPath;
305 316 }
306 317  
307   - public void setRecordDate(int recordDate) {
308   - this.recordDate = recordDate;
  318 + public void setRecordPath(String recordPath) {
  319 + this.recordPath = recordPath;
309 320 }
310 321 }
... ...
src/main/java/com/genersoft/iot/vmp/service/impl/MediaServerServiceImpl.java
... ... @@ -419,17 +419,6 @@ public class MediaServerServiceImpl implements IMediaServerService {
419 419  
420 420  
421 421 if (serverItem.isAutoConfig()) {
422   - // 查看assist服务的录像路径配置
423   - if (serverItem.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) {
424   - JSONObject info = assistRESTfulUtils.getInfo(serverItem, null);
425   - if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
426   - JSONObject dataJson = info.getJSONObject("data");
427   - if (dataJson != null) {
428   - String recordPath = dataJson.getString("record");
429   - userSetting.setRecordPath(recordPath);
430   - }
431   - }
432   - }
433 422 setZLMConfig(serverItem, "0".equals(zlmServerConfig.getHookEnable()));
434 423 }
435 424 final String zlmKeepaliveKey = zlmKeepaliveKeyPrefix + serverItem.getId();
... ... @@ -606,10 +595,9 @@ public class MediaServerServiceImpl implements IMediaServerService {
606 595 param.put("rtp_proxy.port_range", mediaServerItem.getRtpPortRange().replace(",", "-"));
607 596 }
608 597  
609   - if (userSetting.getRecordPath() != null) {
610   - File recordPathFile = new File(userSetting.getRecordPath());
611   - File mp4SavePathFile = recordPathFile.getParentFile().getAbsoluteFile();
612   - param.put("protocol.mp4_save_path", mp4SavePathFile.getAbsoluteFile());
  598 + if (mediaServerItem.getRecordPath() != null) {
  599 + File recordPathFile = new File(mediaServerItem.getRecordPath());
  600 + param.put("protocol.mp4_save_path", recordPathFile.getParentFile().getPath());
613 601 param.put("record.appName", recordPathFile.getName());
614 602 }
615 603  
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/CloudRecordServiceMapper.java
... ... @@ -102,8 +102,8 @@ public interface CloudRecordServiceMapper {
102 102  
103 103 @Delete(" <script>" +
104 104 "delete from wvp_cloud_record where media_server_id=#{mediaServerId} and id in " +
105   - " <foreach collection='cloudRecordItemIdList' item='item' open='(' separator=',' close=')' > #{item}</foreach>" +
  105 + " <foreach collection='cloudRecordItemIdList' item='item' open='(' separator=',' close=')' > #{item.id}</foreach>" +
106 106 " </script>")
107   - int deleteList(List<Integer> cloudRecordItemIdList, @Param("mediaServerId") String mediaServerId);
  107 + int deleteList(List<CloudRecordItem> cloudRecordItemIdList);
108 108  
109 109 }
... ...
src/main/java/com/genersoft/iot/vmp/storager/dao/MediaServerMapper.java
... ... @@ -31,6 +31,8 @@ public interface MediaServerMapper {
31 31 "rtp_port_range,"+
32 32 "send_rtp_port_range,"+
33 33 "record_assist_port,"+
  34 + "record_day,"+
  35 + "record_path,"+
34 36 "default_server,"+
35 37 "create_time,"+
36 38 "update_time,"+
... ... @@ -55,6 +57,8 @@ public interface MediaServerMapper {
55 57 "#{rtpPortRange}, " +
56 58 "#{sendRtpPortRange}, " +
57 59 "#{recordAssistPort}, " +
  60 + "#{recordDay}, " +
  61 + "#{recordPath}, " +
58 62 "#{defaultServer}, " +
59 63 "#{createTime}, " +
60 64 "#{updateTime}, " +
... ... @@ -82,6 +86,8 @@ public interface MediaServerMapper {
82 86 "<if test=\"secret != null\">, secret=#{secret}</if>" +
83 87 "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
84 88 "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
  89 + "<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
  90 + "<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
85 91 "WHERE id=#{id}"+
86 92 " </script>"})
87 93 int update(MediaServerItem mediaServerItem);
... ... @@ -105,6 +111,8 @@ public interface MediaServerMapper {
105 111 "<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
106 112 "<if test=\"secret != null\">, secret=#{secret}</if>" +
107 113 "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
  114 + "<if test=\"recordDay != null\">, record_day=#{recordDay}</if>" +
  115 + "<if test=\"recordPath != null\">, record_path=#{recordPath}</if>" +
108 116 "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
109 117 "WHERE ip=#{ip} and http_port=#{httpPort}"+
110 118 " </script>"})
... ...
src/main/resources/all-application.yml
... ... @@ -139,6 +139,10 @@ media:
139 139 auto-config: true
140 140 # [可选] zlm服务器的hook.admin_params=secret
141 141 secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
  142 + # 录像路径
  143 + record-path: ./www/record
  144 + # 录像保存时长
  145 + record-date: 7
142 146 # 启用多端口模式, 多端口模式使用端口区分每路流,兼容性更好。 单端口使用流的ssrc区分, 点播超时建议使用多端口测试
143 147 rtp:
144 148 # [可选] 是否启用多端口模式, 开启后会在portRange范围内选择端口用于媒体流传输
... ...