Commit 5a152791c0677bd47d4386a1ba54ccf9060849ce
1 parent
57192a49
添加获取截图接口
Showing
11 changed files
with
127 additions
and
27 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/callback/DeferredResultHolder.java
| ... | ... | @@ -51,6 +51,8 @@ public class DeferredResultHolder { |
| 51 | 51 | |
| 52 | 52 | public static final String CALLBACK_CMD_BROADCAST = "CALLBACK_BROADCAST"; |
| 53 | 53 | |
| 54 | + public static final String CALLBACK_CMD_SNAP= "CALLBACK_SNAP"; | |
| 55 | + | |
| 54 | 56 | private Map<String, Map<String, DeferredResultEx>> map = new ConcurrentHashMap<>(); |
| 55 | 57 | |
| 56 | 58 | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -19,7 +19,7 @@ import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | 19 | import com.genersoft.iot.vmp.service.IPlayService; |
| 20 | 20 | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| 21 | 21 | import com.genersoft.iot.vmp.service.IStreamPushService; |
| 22 | -import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; | |
| 22 | +import com.genersoft.iot.vmp.service.bean.ErrorCallback; | |
| 23 | 23 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| 24 | 24 | import com.genersoft.iot.vmp.service.bean.MessageForPushChannel; |
| 25 | 25 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| ... | ... | @@ -377,7 +377,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 377 | 377 | |
| 378 | 378 | Long finalStartTime = startTime; |
| 379 | 379 | Long finalStopTime = stopTime; |
| 380 | - InviteErrorCallback<Object> hookEvent = (code, msg, data) -> { | |
| 380 | + ErrorCallback<Object> hookEvent = (code, msg, data) -> { | |
| 381 | 381 | StreamInfo streamInfo = (StreamInfo)data; |
| 382 | 382 | MediaServerItem mediaServerItemInUSe = mediaServerService.getOne(streamInfo.getMediaServerId()); |
| 383 | 383 | logger.info("[上级Invite]下级已经开始推流。 回复200OK(SDP), {}/{}", streamInfo.getApp(), streamInfo.getStream()); |
| ... | ... | @@ -426,7 +426,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 426 | 426 | logger.error("[命令发送失败] 国标级联 回复SdpAck", e); |
| 427 | 427 | } |
| 428 | 428 | }; |
| 429 | - InviteErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> { | |
| 429 | + ErrorCallback<Object> errorEvent = ((statusCode, msg, data) -> { | |
| 430 | 430 | // 未知错误。直接转发设备点播的错误 |
| 431 | 431 | try { |
| 432 | 432 | if (statusCode > 0) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRESTfulUtils.java
| ... | ... | @@ -154,7 +154,6 @@ public class ZLMRESTfulUtils { |
| 154 | 154 | |
| 155 | 155 | public void sendGetForImg(MediaServerItem mediaServerItem, String api, Map<String, Object> params, String targetPath, String fileName) { |
| 156 | 156 | String url = String.format("http://%s:%s/index/api/%s", mediaServerItem.getIp(), mediaServerItem.getHttpPort(), api); |
| 157 | - logger.debug(url); | |
| 158 | 157 | HttpUrl parseUrl = HttpUrl.parse(url); |
| 159 | 158 | if (parseUrl == null) { |
| 160 | 159 | return; | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IInviteStreamService.java
| ... | ... | @@ -2,7 +2,7 @@ package com.genersoft.iot.vmp.service; |
| 2 | 2 | |
| 3 | 3 | import com.genersoft.iot.vmp.common.InviteInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.common.InviteSessionType; |
| 5 | -import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; | |
| 5 | +import com.genersoft.iot.vmp.service.bean.ErrorCallback; | |
| 6 | 6 | |
| 7 | 7 | /** |
| 8 | 8 | * 记录国标点播的状态,包括实时预览,下载,录像回放 |
| ... | ... | @@ -54,7 +54,7 @@ public interface IInviteStreamService { |
| 54 | 54 | /** |
| 55 | 55 | * 添加一个invite回调 |
| 56 | 56 | */ |
| 57 | - void once(InviteSessionType type, String deviceId, String channelId, String stream, InviteErrorCallback<Object> callback); | |
| 57 | + void once(InviteSessionType type, String deviceId, String channelId, String stream, ErrorCallback<Object> callback); | |
| 58 | 58 | |
| 59 | 59 | /** |
| 60 | 60 | * 调用一个invite回调 | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
| ... | ... | @@ -4,7 +4,7 @@ import com.genersoft.iot.vmp.common.StreamInfo; |
| 4 | 4 | import com.genersoft.iot.vmp.conf.exception.ServiceException; |
| 5 | 5 | import com.genersoft.iot.vmp.gb28181.bean.Device; |
| 6 | 6 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 7 | -import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; | |
| 7 | +import com.genersoft.iot.vmp.service.bean.ErrorCallback; | |
| 8 | 8 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 9 | 9 | |
| 10 | 10 | import javax.sip.InvalidArgumentException; |
| ... | ... | @@ -17,8 +17,8 @@ import java.text.ParseException; |
| 17 | 17 | public interface IPlayService { |
| 18 | 18 | |
| 19 | 19 | void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 20 | - InviteErrorCallback<Object> callback); | |
| 21 | - SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, InviteErrorCallback<Object> callback); | |
| 20 | + ErrorCallback<Object> callback); | |
| 21 | + SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback); | |
| 22 | 22 | |
| 23 | 23 | MediaServerItem getNewMediaServerItem(Device device); |
| 24 | 24 | |
| ... | ... | @@ -27,13 +27,13 @@ public interface IPlayService { |
| 27 | 27 | */ |
| 28 | 28 | MediaServerItem getNewMediaServerItemHasAssist(Device device); |
| 29 | 29 | |
| 30 | - void playBack(String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback); | |
| 31 | - void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, InviteErrorCallback<Object> callback); | |
| 30 | + void playBack(String deviceId, String channelId, String startTime, String endTime, ErrorCallback<Object> callback); | |
| 31 | + void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, ErrorCallback<Object> callback); | |
| 32 | 32 | |
| 33 | 33 | void zlmServerOffline(String mediaServerId); |
| 34 | 34 | |
| 35 | - void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback); | |
| 36 | - void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback); | |
| 35 | + void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback); | |
| 36 | + void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback); | |
| 37 | 37 | |
| 38 | 38 | StreamInfo getDownLoadInfo(String deviceId, String channelId, String stream); |
| 39 | 39 | |
| ... | ... | @@ -42,4 +42,6 @@ public interface IPlayService { |
| 42 | 42 | void pauseRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException; |
| 43 | 43 | |
| 44 | 44 | void resumeRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException; |
| 45 | + | |
| 46 | + void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback); | |
| 45 | 47 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCallback.java renamed to src/main/java/com/genersoft/iot/vmp/service/bean/ErrorCallback.java
src/main/java/com/genersoft/iot/vmp/service/bean/InviteErrorCode.java
src/main/java/com/genersoft/iot/vmp/service/impl/InviteStreamServiceImpl.java
| ... | ... | @@ -6,7 +6,7 @@ import com.genersoft.iot.vmp.common.InviteSessionStatus; |
| 6 | 6 | import com.genersoft.iot.vmp.common.InviteSessionType; |
| 7 | 7 | import com.genersoft.iot.vmp.common.VideoManagerConstants; |
| 8 | 8 | import com.genersoft.iot.vmp.service.IInviteStreamService; |
| 9 | -import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; | |
| 9 | +import com.genersoft.iot.vmp.service.bean.ErrorCallback; | |
| 10 | 10 | import com.genersoft.iot.vmp.utils.redis.RedisUtil; |
| 11 | 11 | import org.slf4j.Logger; |
| 12 | 12 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -24,7 +24,7 @@ public class InviteStreamServiceImpl implements IInviteStreamService { |
| 24 | 24 | |
| 25 | 25 | private final Logger logger = LoggerFactory.getLogger(InviteStreamServiceImpl.class); |
| 26 | 26 | |
| 27 | - private final Map<String, List<InviteErrorCallback<Object>>> inviteErrorCallbackMap = new ConcurrentHashMap<>(); | |
| 27 | + private final Map<String, List<ErrorCallback<Object>>> inviteErrorCallbackMap = new ConcurrentHashMap<>(); | |
| 28 | 28 | |
| 29 | 29 | @Autowired |
| 30 | 30 | private RedisTemplate<Object, Object> redisTemplate; |
| ... | ... | @@ -141,9 +141,9 @@ public class InviteStreamServiceImpl implements IInviteStreamService { |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | @Override |
| 144 | - public void once(InviteSessionType type, String deviceId, String channelId, String stream, InviteErrorCallback<Object> callback) { | |
| 144 | + public void once(InviteSessionType type, String deviceId, String channelId, String stream, ErrorCallback<Object> callback) { | |
| 145 | 145 | String key = buildKey(type, deviceId, channelId, stream); |
| 146 | - List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); | |
| 146 | + List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); | |
| 147 | 147 | if (callbacks == null) { |
| 148 | 148 | callbacks = new CopyOnWriteArrayList<>(); |
| 149 | 149 | inviteErrorCallbackMap.put(key, callbacks); |
| ... | ... | @@ -155,11 +155,11 @@ public class InviteStreamServiceImpl implements IInviteStreamService { |
| 155 | 155 | @Override |
| 156 | 156 | public void call(InviteSessionType type, String deviceId, String channelId, String stream, int code, String msg, Object data) { |
| 157 | 157 | String key = buildKey(type, deviceId, channelId, stream); |
| 158 | - List<InviteErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); | |
| 158 | + List<ErrorCallback<Object>> callbacks = inviteErrorCallbackMap.get(key); | |
| 159 | 159 | if (callbacks == null) { |
| 160 | 160 | return; |
| 161 | 161 | } |
| 162 | - for (InviteErrorCallback<Object> callback : callbacks) { | |
| 162 | + for (ErrorCallback<Object> callback : callbacks) { | |
| 163 | 163 | callback.run(code, msg, data); |
| 164 | 164 | } |
| 165 | 165 | inviteErrorCallbackMap.remove(key); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -26,7 +26,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| 26 | 26 | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| 27 | 27 | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 28 | 28 | import com.genersoft.iot.vmp.service.*; |
| 29 | -import com.genersoft.iot.vmp.service.bean.InviteErrorCallback; | |
| 29 | +import com.genersoft.iot.vmp.service.bean.ErrorCallback; | |
| 30 | 30 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| 31 | 31 | import com.genersoft.iot.vmp.service.bean.SSRCInfo; |
| 32 | 32 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| ... | ... | @@ -44,6 +44,7 @@ import javax.sdp.*; |
| 44 | 44 | import javax.sip.InvalidArgumentException; |
| 45 | 45 | import javax.sip.ResponseEvent; |
| 46 | 46 | import javax.sip.SipException; |
| 47 | +import java.io.File; | |
| 47 | 48 | import java.math.BigDecimal; |
| 48 | 49 | import java.math.RoundingMode; |
| 49 | 50 | import java.text.ParseException; |
| ... | ... | @@ -114,7 +115,7 @@ public class PlayServiceImpl implements IPlayService { |
| 114 | 115 | |
| 115 | 116 | |
| 116 | 117 | @Override |
| 117 | - public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, InviteErrorCallback<Object> callback) { | |
| 118 | + public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback) { | |
| 118 | 119 | if (mediaServerItem == null) { |
| 119 | 120 | throw new ControllerException(ErrorCode.ERROR100.getCode(), "未找到可用的zlm"); |
| 120 | 121 | } |
| ... | ... | @@ -179,7 +180,7 @@ public class PlayServiceImpl implements IPlayService { |
| 179 | 180 | |
| 180 | 181 | @Override |
| 181 | 182 | public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId, |
| 182 | - InviteErrorCallback<Object> callback) { | |
| 183 | + ErrorCallback<Object> callback) { | |
| 183 | 184 | |
| 184 | 185 | if (mediaServerItem == null || ssrcInfo == null) { |
| 185 | 186 | callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), |
| ... | ... | @@ -522,7 +523,7 @@ public class PlayServiceImpl implements IPlayService { |
| 522 | 523 | |
| 523 | 524 | @Override |
| 524 | 525 | public void playBack(String deviceId, String channelId, String startTime, |
| 525 | - String endTime, InviteErrorCallback<Object> callback) { | |
| 526 | + String endTime, ErrorCallback<Object> callback) { | |
| 526 | 527 | Device device = storager.queryVideoDevice(deviceId); |
| 527 | 528 | if (device == null) { |
| 528 | 529 | return; |
| ... | ... | @@ -535,7 +536,7 @@ public class PlayServiceImpl implements IPlayService { |
| 535 | 536 | @Override |
| 536 | 537 | public void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, |
| 537 | 538 | String deviceId, String channelId, String startTime, |
| 538 | - String endTime, InviteErrorCallback<Object> callback) { | |
| 539 | + String endTime, ErrorCallback<Object> callback) { | |
| 539 | 540 | if (mediaServerItem == null || ssrcInfo == null) { |
| 540 | 541 | callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), |
| 541 | 542 | InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), |
| ... | ... | @@ -725,7 +726,7 @@ public class PlayServiceImpl implements IPlayService { |
| 725 | 726 | |
| 726 | 727 | |
| 727 | 728 | @Override |
| 728 | - public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) { | |
| 729 | + public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback) { | |
| 729 | 730 | Device device = storager.queryVideoDevice(deviceId); |
| 730 | 731 | if (device == null) { |
| 731 | 732 | return; |
| ... | ... | @@ -743,7 +744,7 @@ public class PlayServiceImpl implements IPlayService { |
| 743 | 744 | |
| 744 | 745 | |
| 745 | 746 | @Override |
| 746 | - public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) { | |
| 747 | + public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback) { | |
| 747 | 748 | if (mediaServerItem == null || ssrcInfo == null) { |
| 748 | 749 | callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), |
| 749 | 750 | InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), |
| ... | ... | @@ -1127,4 +1128,53 @@ public class PlayServiceImpl implements IPlayService { |
| 1127 | 1128 | Device device = storager.queryVideoDevice(inviteInfo.getDeviceId()); |
| 1128 | 1129 | cmder.playResumeCmd(device, inviteInfo.getStreamInfo()); |
| 1129 | 1130 | } |
| 1131 | + | |
| 1132 | + @Override | |
| 1133 | + public void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback) { | |
| 1134 | + Device device = deviceService.getDevice(deviceId); | |
| 1135 | + if (device == null) { | |
| 1136 | + errorCallback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), null); | |
| 1137 | + return; | |
| 1138 | + } | |
| 1139 | + | |
| 1140 | + InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); | |
| 1141 | + if (inviteInfo != null) { | |
| 1142 | + if (inviteInfo.getStreamInfo() != null) { | |
| 1143 | + // 已存在线直接截图 | |
| 1144 | + MediaServerItem mediaServerItemInuse = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId()); | |
| 1145 | + String streamUrl; | |
| 1146 | + if (mediaServerItemInuse.getRtspPort() != 0) { | |
| 1147 | + streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", inviteInfo.getStreamInfo().getStream()); | |
| 1148 | + }else { | |
| 1149 | + streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", inviteInfo.getStreamInfo().getStream()); | |
| 1150 | + } | |
| 1151 | + String path = "snap"; | |
| 1152 | + // 请求截图 | |
| 1153 | + logger.info("[请求截图]: " + fileName); | |
| 1154 | + zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName); | |
| 1155 | + File snapFile = new File(path + File.separator + fileName); | |
| 1156 | + if (snapFile.exists()) { | |
| 1157 | + errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), snapFile.getAbsoluteFile()); | |
| 1158 | + }else { | |
| 1159 | + errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null); | |
| 1160 | + } | |
| 1161 | + return; | |
| 1162 | + } | |
| 1163 | + } | |
| 1164 | + | |
| 1165 | + MediaServerItem newMediaServerItem = getNewMediaServerItem(device); | |
| 1166 | + play(newMediaServerItem, deviceId, channelId, (code, msg, data)->{ | |
| 1167 | + if (code == InviteErrorCode.SUCCESS.getCode()) { | |
| 1168 | + InviteInfo inviteInfoForPlay = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId); | |
| 1169 | + if (inviteInfoForPlay != null && inviteInfoForPlay.getStreamInfo() != null) { | |
| 1170 | + getSnap(deviceId, channelId, fileName, errorCallback); | |
| 1171 | + }else { | |
| 1172 | + errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null); | |
| 1173 | + } | |
| 1174 | + }else { | |
| 1175 | + errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null); | |
| 1176 | + } | |
| 1177 | + }); | |
| 1178 | + } | |
| 1179 | + | |
| 1130 | 1180 | } | ... | ... |
src/main/java/com/genersoft/iot/vmp/utils/DateUtil.java
| ... | ... | @@ -32,11 +32,17 @@ public class DateUtil { |
| 32 | 32 | */ |
| 33 | 33 | public static final String PATTERN = "yyyy-MM-dd HH:mm:ss"; |
| 34 | 34 | |
| 35 | + /** | |
| 36 | + * wvp内部统一时间格式 | |
| 37 | + */ | |
| 38 | + public static final String URL_PATTERN = "yyyyMMddHHmmss"; | |
| 39 | + | |
| 35 | 40 | public static final String zoneStr = "Asia/Shanghai"; |
| 36 | 41 | |
| 37 | 42 | public static final DateTimeFormatter formatterCompatibleISO8601 = DateTimeFormatter.ofPattern(ISO8601_COMPATIBLE_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| 38 | 43 | public static final DateTimeFormatter formatterISO8601 = DateTimeFormatter.ofPattern(ISO8601_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| 39 | 44 | public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern(PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); |
| 45 | + public static final DateTimeFormatter urlFormatter = DateTimeFormatter.ofPattern(URL_PATTERN, Locale.getDefault()).withZone(ZoneId.of(zoneStr)); | |
| 40 | 46 | |
| 41 | 47 | public static String yyyy_MM_dd_HH_mm_ssToISO8601(String formatTime) { |
| 42 | 48 | |
| ... | ... | @@ -68,6 +74,15 @@ public class DateUtil { |
| 68 | 74 | } |
| 69 | 75 | |
| 70 | 76 | /** |
| 77 | + * 获取当前时间 | |
| 78 | + * @return | |
| 79 | + */ | |
| 80 | + public static String getNowForUrl() { | |
| 81 | + LocalDateTime nowDateTime = LocalDateTime.now(); | |
| 82 | + return urlFormatter.format(nowDateTime); | |
| 83 | + } | |
| 84 | + | |
| 85 | + /** | |
| 71 | 86 | * 格式校验 |
| 72 | 87 | * @param timeStr 时间字符串 |
| 73 | 88 | * @param dateTimeFormatter 待校验的格式 | ... | ... |
src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
| ... | ... | @@ -24,6 +24,7 @@ import com.genersoft.iot.vmp.service.IPlayService; |
| 24 | 24 | import com.genersoft.iot.vmp.service.bean.InviteErrorCode; |
| 25 | 25 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 26 | 26 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 27 | +import com.genersoft.iot.vmp.utils.DateUtil; | |
| 27 | 28 | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| 28 | 29 | import com.genersoft.iot.vmp.vmanager.bean.StreamContent; |
| 29 | 30 | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| ... | ... | @@ -337,5 +338,35 @@ public class PlayController { |
| 337 | 338 | return jsonObject; |
| 338 | 339 | } |
| 339 | 340 | |
| 341 | + @Operation(summary = "获取截图") | |
| 342 | + @Parameter(name = "deviceId", description = "设备国标编号", required = true) | |
| 343 | + @Parameter(name = "channelId", description = "通道国标编号", required = true) | |
| 344 | + @GetMapping("/snap") | |
| 345 | + public DeferredResult<String> getSnap(String deviceId, String channelId) { | |
| 346 | + if (logger.isDebugEnabled()) { | |
| 347 | + logger.debug("获取截图: {}/{}", deviceId, channelId); | |
| 348 | + } | |
| 349 | + | |
| 350 | + DeferredResult<String> result = new DeferredResult<>(3 * 1000L); | |
| 351 | + String key = DeferredResultHolder.CALLBACK_CMD_SNAP + deviceId; | |
| 352 | + String uuid = UUID.randomUUID().toString(); | |
| 353 | + resultHolder.put(key, uuid, result); | |
| 354 | + | |
| 355 | + RequestMessage message = new RequestMessage(); | |
| 356 | + message.setKey(key); | |
| 357 | + message.setId(uuid); | |
| 358 | + | |
| 359 | + String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + "jpg"; | |
| 360 | + playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> { | |
| 361 | + if (code == InviteErrorCode.SUCCESS.getCode()) { | |
| 362 | + message.setData(data); | |
| 363 | + }else { | |
| 364 | + message.setData(WVPResult.fail(code, msg)); | |
| 365 | + } | |
| 366 | + resultHolder.invokeResult(message); | |
| 367 | + }); | |
| 368 | + return result; | |
| 369 | + } | |
| 370 | + | |
| 340 | 371 | } |
| 341 | 372 | ... | ... |