| | |
| | | // 请求截图 |
| | | logger.info("[请求截图]: " + fileName); |
| | | zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName); |
| | | String filePath = path + File.separator + fileName; |
| | | File snapFile = new File(path + File.separator + fileName); |
| | | if (snapFile.exists()) { |
| | | errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), snapFile.getAbsoluteFile()); |
| | | errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), filePath); |
| | | }else { |
| | | errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null); |
| | | } |
| | |
| | | public enum ErrorCode { |
| | | SUCCESS(0, "成功"), |
| | | ERROR100(100, "失败"), |
| | | ERROR400(400, "参数不全或者错误"), |
| | | ERROR400(400, "参数或方法错误"), |
| | | ERROR404(404, "资源未找到"), |
| | | ERROR403(403, "无权限操作"), |
| | | ERROR401(401, "请登录后重新请求"), |
New file |
| | |
| | | package com.genersoft.iot.vmp.vmanager.bean; |
| | | |
| | | import io.swagger.v3.oas.annotations.media.Schema; |
| | | |
| | | @Schema(description = "截图地址信息") |
| | | public class SnapPath { |
| | | |
| | | @Schema(description = "相对地址") |
| | | private String path; |
| | | |
| | | @Schema(description = "绝对地址") |
| | | private String absoluteFilePath; |
| | | |
| | | @Schema(description = "请求地址") |
| | | private String url; |
| | | |
| | | |
| | | public static SnapPath getInstance(String path, String absoluteFilePath, String url) { |
| | | SnapPath snapPath = new SnapPath(); |
| | | snapPath.setPath(path); |
| | | snapPath.setAbsoluteFilePath(absoluteFilePath); |
| | | snapPath.setUrl(url); |
| | | return snapPath; |
| | | } |
| | | |
| | | |
| | | public String getPath() { |
| | | return path; |
| | | } |
| | | |
| | | public void setPath(String path) { |
| | | this.path = path; |
| | | } |
| | | |
| | | public String getAbsoluteFilePath() { |
| | | return absoluteFilePath; |
| | | } |
| | | |
| | | public void setAbsoluteFilePath(String absoluteFilePath) { |
| | | this.absoluteFilePath = absoluteFilePath; |
| | | } |
| | | |
| | | public String getUrl() { |
| | | return url; |
| | | } |
| | | |
| | | public void setUrl(String url) { |
| | | this.url = url; |
| | | } |
| | | } |
| | |
| | | @Operation(summary = "请求截图") |
| | | @Parameter(name = "deviceId", description = "设备国标编号", required = true) |
| | | @Parameter(name = "channelId", description = "通道国标编号", required = true) |
| | | public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId) { |
| | | @Parameter(name = "mark", description = "标识", required = false) |
| | | public void getSnap(HttpServletResponse resp, @PathVariable String deviceId, @PathVariable String channelId, @RequestParam(required = false) String mark) { |
| | | |
| | | try { |
| | | final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + ".jpg").toPath()); |
| | | |
| | | final InputStream in = Files.newInputStream(new File("snap" + File.separator + deviceId + "_" + channelId + (mark == null? ".jpg": ("_" + mark + ".jpg"))).toPath()); |
| | | resp.setContentType(MediaType.IMAGE_PNG_VALUE); |
| | | IOUtils.copy(in, resp.getOutputStream()); |
| | | } catch (IOException e) { |
| | |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | | import com.genersoft.iot.vmp.utils.DateUtil; |
| | | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode; |
| | | import com.genersoft.iot.vmp.vmanager.bean.SnapPath; |
| | | import com.genersoft.iot.vmp.vmanager.bean.StreamContent; |
| | | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; |
| | | import io.swagger.v3.oas.annotations.Operation; |
| | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.sip.InvalidArgumentException; |
| | | import javax.sip.SipException; |
| | | import java.io.File; |
| | | import java.text.ParseException; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | |
| | | @Parameter(name = "deviceId", description = "设备国标编号", required = true) |
| | | @Parameter(name = "channelId", description = "通道国标编号", required = true) |
| | | @GetMapping("/snap") |
| | | public DeferredResult<String> getSnap(String deviceId, String channelId) { |
| | | public DeferredResult<String> getSnap(HttpServletRequest request, String deviceId, String channelId) { |
| | | if (logger.isDebugEnabled()) { |
| | | logger.debug("获取截图: {}/{}", deviceId, channelId); |
| | | } |
| | |
| | | RequestMessage message = new RequestMessage(); |
| | | message.setKey(key); |
| | | message.setId(uuid); |
| | | String nowForUrl = DateUtil.getNowForUrl(); |
| | | String fileName = deviceId + "_" + channelId + "_" + nowForUrl + ".jpg"; |
| | | |
| | | String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg"; |
| | | playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> { |
| | | if (code == InviteErrorCode.SUCCESS.getCode()) { |
| | | message.setData(data); |
| | | File snapFile = new File((String)data); |
| | | String fileNameForUrl = deviceId + "/" + channelId + "?mark=" + nowForUrl; |
| | | String uri = request.getRequestURL().toString().replace(request.getRequestURI(), "/api/device/query/snap/" + fileNameForUrl); |
| | | SnapPath snapPath = SnapPath.getInstance((String) data, snapFile.getAbsolutePath(), uri); |
| | | message.setData(snapPath); |
| | | }else { |
| | | message.setData(WVPResult.fail(code, msg)); |
| | | } |