修复无法下载较长时间时间录像的BUG
parent
8750f0f3dd
commit
5c0183a422
|
@ -37,15 +37,14 @@ public class RecordEndEventListener implements ApplicationListener<RecordEndEven
|
||||||
event.getRecordInfo().getChannelId(), count,sumNum);
|
event.getRecordInfo().getChannelId(), count,sumNum);
|
||||||
if (!handlerMap.isEmpty()) {
|
if (!handlerMap.isEmpty()) {
|
||||||
RecordEndEventHandler handler = handlerMap.get(deviceId + channelId);
|
RecordEndEventHandler handler = handlerMap.get(deviceId + channelId);
|
||||||
|
logger.info("录像查询完成事件触发, 发送订阅,deviceId:{}, channelId: {}",
|
||||||
|
event.getRecordInfo().getDeviceId(), event.getRecordInfo().getChannelId());
|
||||||
if (handler !=null){
|
if (handler !=null){
|
||||||
handler.handler(event.getRecordInfo());
|
handler.handler(event.getRecordInfo());
|
||||||
if (count ==sumNum){
|
if (count ==sumNum){
|
||||||
handlerMap.remove(deviceId + channelId);
|
handlerMap.remove(deviceId + channelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
logger.info("录像查询完成事件触发, 但是订阅为空,取消发送,deviceId:{}, channelId: {}",
|
|
||||||
event.getRecordInfo().getDeviceId(), event.getRecordInfo().getChannelId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,8 @@ public class Hook {
|
||||||
|
|
||||||
private String mediaServerId;
|
private String mediaServerId;
|
||||||
|
|
||||||
private Long createTime;
|
private Long expireTime;
|
||||||
|
|
||||||
|
|
||||||
public static Hook getInstance(HookType hookType, String app, String stream, String mediaServerId) {
|
public static Hook getInstance(HookType hookType, String app, String stream, String mediaServerId) {
|
||||||
Hook hookSubscribe = new Hook();
|
Hook hookSubscribe = new Hook();
|
||||||
|
@ -22,7 +23,7 @@ public class Hook {
|
||||||
hookSubscribe.setStream(stream);
|
hookSubscribe.setStream(stream);
|
||||||
hookSubscribe.setHookType(hookType);
|
hookSubscribe.setHookType(hookType);
|
||||||
hookSubscribe.setMediaServerId(mediaServerId);
|
hookSubscribe.setMediaServerId(mediaServerId);
|
||||||
hookSubscribe.setCreateTime(System.currentTimeMillis());
|
hookSubscribe.setExpireTime(System.currentTimeMillis() + 5 * 60 * 1000);
|
||||||
return hookSubscribe;
|
return hookSubscribe;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -50,12 +51,13 @@ public class Hook {
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getCreateTime() {
|
|
||||||
return createTime;
|
public Long getExpireTime() {
|
||||||
|
return expireTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreateTime(Long createTime) {
|
public void setExpireTime(Long expireTime) {
|
||||||
this.createTime = createTime;
|
this.expireTime = expireTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMediaServerId() {
|
public String getMediaServerId() {
|
||||||
|
|
|
@ -58,7 +58,7 @@ public class HookSubscribe {
|
||||||
sendNotify(HookType.on_publish, event);
|
sendNotify(HookType.on_publish, event);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 推流鉴权事件
|
* 生成录像文件事件
|
||||||
*/
|
*/
|
||||||
@Async("taskExecutor")
|
@Async("taskExecutor")
|
||||||
@EventListener
|
@EventListener
|
||||||
|
@ -79,8 +79,8 @@ public class HookSubscribe {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSubscribe(Hook hook, HookSubscribe.Event event) {
|
public void addSubscribe(Hook hook, HookSubscribe.Event event) {
|
||||||
if (hook.getCreateTime() == null) {
|
if (hook.getExpireTime() == null) {
|
||||||
hook.setCreateTime(System.currentTimeMillis());
|
hook.setExpireTime(System.currentTimeMillis() + subscribeExpire);
|
||||||
}
|
}
|
||||||
allSubscribes.put(hook.toString(), event);
|
allSubscribes.put(hook.toString(), event);
|
||||||
allHook.put(hook.toString(), hook);
|
allHook.put(hook.toString(), hook);
|
||||||
|
@ -96,9 +96,9 @@ public class HookSubscribe {
|
||||||
*/
|
*/
|
||||||
@Scheduled(fixedRate=subscribeExpire) //每5分钟执行一次
|
@Scheduled(fixedRate=subscribeExpire) //每5分钟执行一次
|
||||||
public void execute(){
|
public void execute(){
|
||||||
long expireTime = System.currentTimeMillis() - subscribeExpire;
|
long expireTime = System.currentTimeMillis();
|
||||||
for (Hook hook : allHook.values()) {
|
for (Hook hook : allHook.values()) {
|
||||||
if (hook.getCreateTime() < expireTime) {
|
if (hook.getExpireTime() < expireTime) {
|
||||||
allSubscribes.remove(hook.toString());
|
allSubscribes.remove(hook.toString());
|
||||||
allHook.remove(hook.toString());
|
allHook.remove(hook.toString());
|
||||||
}
|
}
|
||||||
|
|
|
@ -1044,9 +1044,7 @@ public class PlayServiceImpl implements IPlayService {
|
||||||
};
|
};
|
||||||
Hook hook = Hook.getInstance(HookType.on_record_mp4, "rtp", ssrcInfo.getStream(), mediaServerItem.getId());
|
Hook hook = Hook.getInstance(HookType.on_record_mp4, "rtp", ssrcInfo.getStream(), mediaServerItem.getId());
|
||||||
// 设置过期时间,下载失败时自动处理订阅数据
|
// 设置过期时间,下载失败时自动处理订阅数据
|
||||||
// long difference = DateUtil.getDifference(startTime, endTime)/1000;
|
hook.setExpireTime(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
|
||||||
// Instant expiresInstant = Instant.now().plusSeconds(TimeUnit.MINUTES.toSeconds(difference * 2));
|
|
||||||
// hookSubscribe.setExpires(expiresInstant);
|
|
||||||
subscribe.addSubscribe(hook, hookEventForRecord);
|
subscribe.addSubscribe(hook, hookEventForRecord);
|
||||||
});
|
});
|
||||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||||
|
|
Loading…
Reference in New Issue