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

pull/1414/head
648540858 2024-04-11 22:25:57 +08:00
parent 8750f0f3dd
commit 5c0183a422
4 changed files with 16 additions and 17 deletions

View File

@ -37,15 +37,14 @@ public class RecordEndEventListener implements ApplicationListener<RecordEndEven
event.getRecordInfo().getChannelId(), count,sumNum);
if (!handlerMap.isEmpty()) {
RecordEndEventHandler handler = handlerMap.get(deviceId + channelId);
logger.info("录像查询完成事件触发, 发送订阅deviceId{}, channelId: {}",
event.getRecordInfo().getDeviceId(), event.getRecordInfo().getChannelId());
if (handler !=null){
handler.handler(event.getRecordInfo());
if (count ==sumNum){
handlerMap.remove(deviceId + channelId);
}
}
}else {
logger.info("录像查询完成事件触发, 但是订阅为空取消发送deviceId{}, channelId: {}",
event.getRecordInfo().getDeviceId(), event.getRecordInfo().getChannelId());
}
}

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());
}

View File

@ -1044,9 +1044,7 @@ public class PlayServiceImpl implements IPlayService {
};
Hook hook = Hook.getInstance(HookType.on_record_mp4, "rtp", ssrcInfo.getStream(), mediaServerItem.getId());
// 设置过期时间,下载失败时自动处理订阅数据
// long difference = DateUtil.getDifference(startTime, endTime)/1000;
// Instant expiresInstant = Instant.now().plusSeconds(TimeUnit.MINUTES.toSeconds(difference * 2));
// hookSubscribe.setExpires(expiresInstant);
hook.setExpireTime(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
subscribe.addSubscribe(hook, hookEventForRecord);
});
} catch (InvalidArgumentException | SipException | ParseException e) {