调整录像下载
parent
3e9def7aac
commit
62ae1ee978
|
@ -95,7 +95,7 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i
|
|||
if (ssrcTransaction != null) {
|
||||
logger.info("[录像流]推送完毕,关流通知, device: {}, channelId: {}", ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId());
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, ssrcTransaction.getDeviceId(), ssrcTransaction.getChannelId(), ssrcTransaction.getStream());
|
||||
if (inviteInfo.getStreamInfo() != null) {
|
||||
if (inviteInfo != null && inviteInfo.getStreamInfo() != null) {
|
||||
inviteInfo.getStreamInfo().setProgress(1);
|
||||
inviteStreamService.updateInviteInfo(inviteInfo);
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ import com.genersoft.iot.vmp.media.abl.bean.hook.OnStreamArriveABLHookParam;
|
|||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent;
|
||||
import com.genersoft.iot.vmp.media.event.media.MediaRecordMp4Event;
|
||||
import com.genersoft.iot.vmp.media.event.media.MediaRecordProcessEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.service.IInviteStreamService;
|
||||
|
@ -297,16 +298,15 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
|
|||
CloudRecordItem cloudRecordItem = cloudRecordServiceMapper.getListByFileName(event.getApp(), event.getStream(), event.getFileName());
|
||||
if (cloudRecordItem == null) {
|
||||
cloudRecordItem = CloudRecordItem.getInstance(event);
|
||||
cloudRecordItem.setStartTime(System.currentTimeMillis() - event.getCurrentFileDuration() * 1000);
|
||||
cloudRecordItem.setEndTime(System.currentTimeMillis());
|
||||
cloudRecordItem.setStartTime(event.getStartTime());
|
||||
cloudRecordItem.setEndTime(event.getEndTime());
|
||||
cloudRecordServiceMapper.add(cloudRecordItem);
|
||||
}else {
|
||||
cloudRecordServiceMapper.updateTimeLen(cloudRecordItem.getId(), (long)event.getCurrentFileDuration() * 1000, System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
// 收流结束
|
||||
@EventListener
|
||||
public void onApplicationEvent(MediaDepartureEvent event) {
|
||||
public void onApplicationEvent(MediaRecordMp4Event event) {
|
||||
InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, null, null, event.getStream());
|
||||
if (inviteInfo == null || inviteInfo.getStreamInfo() == null) {
|
||||
return;
|
||||
|
@ -319,6 +319,7 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
|
|||
long endTime = cloudRecordItemList.get(0).getEndTime();
|
||||
JSONObject jsonObject = ablresTfulUtils.queryRecordList(event.getMediaServer(), event.getApp(), event.getStream(), DateUtil.timestampMsToUrlToyyyy_MM_dd_HH_mm_ss(startTime),
|
||||
DateUtil.timestampMsToUrlToyyyy_MM_dd_HH_mm_ss(endTime));
|
||||
System.err.println(jsonObject);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
|
||||
return;
|
||||
}
|
||||
|
@ -326,11 +327,12 @@ public class ABLMediaNodeServerService implements IMediaNodeServerService {
|
|||
if (urlJson == null) {
|
||||
return;
|
||||
}
|
||||
String download = urlJson.getString("download");
|
||||
String download = urlJson.getString("http-mp4") + "?download_speed=6";
|
||||
DownloadFileInfo downloadFileInfo = new DownloadFileInfo();
|
||||
downloadFileInfo.setHttpPath(download);
|
||||
downloadFileInfo.setHttpsPath(download);
|
||||
inviteInfo.getStreamInfo().setDownLoadFilePath(downloadFileInfo);
|
||||
inviteStreamService.updateInviteInfo(inviteInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -379,6 +379,8 @@ public class ABLRESTfulUtils {
|
|||
param.put("stream", stream);
|
||||
param.put("starttime", startTime);
|
||||
param.put("endtime", endTime);
|
||||
System.out.println("starttime: "+ startTime);
|
||||
System.out.println("endtime: "+ endTime);
|
||||
return sendPost(mediaServer,"queryRecordList", param, null);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.media.abl.bean.hook;
|
|||
public class OnRecordProgressABLHookParam extends OnRecordMp4ABLHookParam{
|
||||
private Integer currentFileDuration;
|
||||
private Integer TotalVideoDuration;
|
||||
private String startTime;
|
||||
private String endTime;
|
||||
|
||||
public Integer getCurrentFileDuration() {
|
||||
return currentFileDuration;
|
||||
|
@ -19,4 +21,20 @@ public class OnRecordProgressABLHookParam extends OnRecordMp4ABLHookParam{
|
|||
public void setTotalVideoDuration(Integer totalVideoDuration) {
|
||||
TotalVideoDuration = totalVideoDuration;
|
||||
}
|
||||
|
||||
public String getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(String startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public String getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(String endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,9 @@ package com.genersoft.iot.vmp.media.event.media;
|
|||
import com.genersoft.iot.vmp.media.abl.ABLHttpHookListener;
|
||||
import com.genersoft.iot.vmp.media.abl.bean.hook.OnRecordProgressABLHookParam;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 录像文件进度通知事件
|
||||
|
@ -12,6 +15,8 @@ public class MediaRecordProcessEvent extends MediaEvent {
|
|||
private Integer currentFileDuration;
|
||||
private Integer TotalVideoDuration;
|
||||
private String fileName;
|
||||
private long startTime;
|
||||
private long endTime;
|
||||
|
||||
public MediaRecordProcessEvent(Object source) {
|
||||
super(source);
|
||||
|
@ -25,6 +30,8 @@ public class MediaRecordProcessEvent extends MediaEvent {
|
|||
mediaRecordMp4Event.setTotalVideoDuration(hookParam.getTotalVideoDuration());
|
||||
mediaRecordMp4Event.setMediaServer(mediaServer);
|
||||
mediaRecordMp4Event.setFileName(hookParam.getFileName());
|
||||
mediaRecordMp4Event.setStartTime(DateUtil.urlToTimestampMs(hookParam.getStartTime()));
|
||||
mediaRecordMp4Event.setEndTime(DateUtil.urlToTimestampMs(hookParam.getEndTime()));
|
||||
return mediaRecordMp4Event;
|
||||
}
|
||||
|
||||
|
@ -51,4 +58,20 @@ public class MediaRecordProcessEvent extends MediaEvent {
|
|||
public void setFileName(String fileName) {
|
||||
this.fileName = fileName;
|
||||
}
|
||||
|
||||
public long getStartTime() {
|
||||
return startTime;
|
||||
}
|
||||
|
||||
public void setStartTime(long startTime) {
|
||||
this.startTime = startTime;
|
||||
}
|
||||
|
||||
public long getEndTime() {
|
||||
return endTime;
|
||||
}
|
||||
|
||||
public void setEndTime(long endTime) {
|
||||
this.endTime = endTime;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1025,24 +1025,25 @@ public class PlayServiceImpl implements IPlayService {
|
|||
// 处理收到200ok后的TCP主动连接以及SSRC不一致的问题
|
||||
InviteOKHandler(eventResult, ssrcInfo, mediaServerItem, device, channelId,
|
||||
downLoadTimeOutTaskKey, callback, inviteInfo, InviteSessionType.DOWNLOAD);
|
||||
|
||||
// 注册录像回调事件,录像下载结束后写入下载地址
|
||||
HookSubscribe.Event hookEventForRecord = (hookData) -> {
|
||||
logger.info("[录像下载] 收到录像写入磁盘消息: , {}/{}-{}",
|
||||
inviteInfo.getDeviceId(), inviteInfo.getChannelId(), ssrcInfo.getStream());
|
||||
logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookData);
|
||||
RecordInfo recordInfo = hookData.getRecordInfo();
|
||||
String filePath = recordInfo.getFilePath();
|
||||
DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath);
|
||||
InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId()
|
||||
, inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo);
|
||||
inviteStreamService.updateInviteInfo(inviteInfoForNew);
|
||||
};
|
||||
Hook hook = Hook.getInstance(HookType.on_record_mp4, "rtp", ssrcInfo.getStream(), mediaServerItem.getId());
|
||||
// 设置过期时间,下载失败时自动处理订阅数据
|
||||
hook.setExpireTime(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
|
||||
subscribe.addSubscribe(hook, hookEventForRecord);
|
||||
if (mediaServerItem.getType().equals("zlm")) {
|
||||
// 注册录像回调事件,录像下载结束后写入下载地址
|
||||
HookSubscribe.Event hookEventForRecord = (hookData) -> {
|
||||
logger.info("[录像下载] 收到录像写入磁盘消息: , {}/{}-{}",
|
||||
inviteInfo.getDeviceId(), inviteInfo.getChannelId(), ssrcInfo.getStream());
|
||||
logger.info("[录像下载] 收到录像写入磁盘消息内容: " + hookData);
|
||||
RecordInfo recordInfo = hookData.getRecordInfo();
|
||||
String filePath = recordInfo.getFilePath();
|
||||
DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath);
|
||||
InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId()
|
||||
, inviteInfo.getChannelId(), inviteInfo.getStream());
|
||||
inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo);
|
||||
inviteStreamService.updateInviteInfo(inviteInfoForNew);
|
||||
};
|
||||
Hook hook = Hook.getInstance(HookType.on_record_mp4, "rtp", ssrcInfo.getStream(), mediaServerItem.getId());
|
||||
// 设置过期时间,下载失败时自动处理订阅数据
|
||||
hook.setExpireTime(System.currentTimeMillis() + 24 * 60 * 60 * 1000);
|
||||
subscribe.addSubscribe(hook, hookEventForRecord);
|
||||
}
|
||||
});
|
||||
} catch (InvalidArgumentException | SipException | ParseException e) {
|
||||
logger.error("[命令发送失败] 录像下载: {}", e.getMessage());
|
||||
|
|
|
@ -134,6 +134,18 @@ public class DateUtil {
|
|||
return formatter.format(LocalDateTime.ofInstant(instant, ZoneId.of(zoneStr)));
|
||||
}
|
||||
|
||||
/**
|
||||
* yyyy_MM_dd_HH_mm_ss 转时间戳(毫秒)
|
||||
*
|
||||
* @param formatTime
|
||||
* @return
|
||||
*/
|
||||
public static long urlToTimestampMs(String formatTime) {
|
||||
TemporalAccessor temporalAccessor = urlFormatter.parse(formatTime);
|
||||
Instant instant = Instant.from(temporalAccessor);
|
||||
return instant.toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间戳 转 yyyy_MM_dd
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue