| | |
| | | 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()); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | 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(); |
| | |
| | | hookSubscribe.setStream(stream); |
| | | hookSubscribe.setHookType(hookType); |
| | | hookSubscribe.setMediaServerId(mediaServerId); |
| | | hookSubscribe.setCreateTime(System.currentTimeMillis()); |
| | | hookSubscribe.setExpireTime(System.currentTimeMillis() + 5 * 60 * 1000); |
| | | return hookSubscribe; |
| | | } |
| | | |
| | |
| | | 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() { |
| | |
| | | sendNotify(HookType.on_publish, event); |
| | | } |
| | | /** |
| | | * 推流鉴权事件 |
| | | * 生成录像文件事件 |
| | | */ |
| | | @Async("taskExecutor") |
| | | @EventListener |
| | |
| | | } |
| | | |
| | | 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); |
| | |
| | | */ |
| | | @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()); |
| | | } |
| | |
| | | }; |
| | | 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) { |