修复无法下载较长时间时间录像的BUG

This commit is contained in:
648540858
2024-04-11 22:25:57 +08:00
parent 8750f0f3dd
commit 5c0183a422
4 changed files with 16 additions and 17 deletions

View File

@@ -14,7 +14,8 @@ public class Hook {
private String mediaServerId;
private Long createTime;
private Long expireTime;
public static Hook getInstance(HookType hookType, String app, String stream, String mediaServerId) {
Hook hookSubscribe = new Hook();
@@ -22,7 +23,7 @@ public class Hook {
hookSubscribe.setStream(stream);
hookSubscribe.setHookType(hookType);
hookSubscribe.setMediaServerId(mediaServerId);
hookSubscribe.setCreateTime(System.currentTimeMillis());
hookSubscribe.setExpireTime(System.currentTimeMillis() + 5 * 60 * 1000);
return hookSubscribe;
}
@@ -50,12 +51,13 @@ public class Hook {
this.stream = stream;
}
public Long getCreateTime() {
return createTime;
public Long getExpireTime() {
return expireTime;
}
public void setCreateTime(Long createTime) {
this.createTime = createTime;
public void setExpireTime(Long expireTime) {
this.expireTime = expireTime;
}
public String getMediaServerId() {

View File

@@ -58,7 +58,7 @@ public class HookSubscribe {
sendNotify(HookType.on_publish, event);
}
/**
* 推流鉴权事件
* 生成录像文件事件
*/
@Async("taskExecutor")
@EventListener
@@ -79,8 +79,8 @@ public class HookSubscribe {
}
public void addSubscribe(Hook hook, HookSubscribe.Event event) {
if (hook.getCreateTime() == null) {
hook.setCreateTime(System.currentTimeMillis());
if (hook.getExpireTime() == null) {
hook.setExpireTime(System.currentTimeMillis() + subscribeExpire);
}
allSubscribes.put(hook.toString(), event);
allHook.put(hook.toString(), hook);
@@ -96,9 +96,9 @@ public class HookSubscribe {
*/
@Scheduled(fixedRate=subscribeExpire) //每5分钟执行一次
public void execute(){
long expireTime = System.currentTimeMillis() - subscribeExpire;
long expireTime = System.currentTimeMillis();
for (Hook hook : allHook.values()) {
if (hook.getCreateTime() < expireTime) {
if (hook.getExpireTime() < expireTime) {
allSubscribes.remove(hook.toString());
allHook.remove(hook.toString());
}