Browse Source

feat:视频预览,预置位操作,云台控制,抓拍,录像下载

yanyuan
wangguangyuan 1 month ago
parent
commit
57c6724f4d
11 changed files with 277 additions and 4 deletions
  1. +25
    -0
      inspect-base/inspect-base-core/src/main/java/com/inspect/base/core/utils/HttpClientUtils.java
  2. +9
    -0
      inspect-ivs/src/main/java/com/inspect/ivs/constant/IvsConst.java
  3. +27
    -1
      inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java
  4. +22
    -1
      inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java
  5. +14
    -1
      inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsRecordController.java
  6. +28
    -1
      inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsStreamController.java
  7. +33
    -0
      inspect-ivs/src/main/java/com/inspect/ivs/service/HlsPlaybackComponent.java
  8. +10
    -0
      inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/contants/AccessApiConstant.java
  9. +37
    -0
      inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/PatrolPresetPosController.java
  10. +25
    -0
      inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/PatrolVideotapeController.java
  11. +47
    -0
      inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/VideoController.java

+ 25
- 0
inspect-base/inspect-base-core/src/main/java/com/inspect/base/core/utils/HttpClientUtils.java View File

@ -75,6 +75,31 @@ public class HttpClientUtils {
return connection.getInputStream();
}
public static InputStream getStream(String url) throws Exception {
URL realUrl = new URL(url);
URLConnection connection = realUrl.openConnection();
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.connect();
return connection.getInputStream();
}
public static InputStream postStream(String url, String jsonParam) throws Exception {
URL realUrl = new URL(url);
HttpURLConnection connection = (HttpURLConnection) realUrl.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setDoOutput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream(), "utf-8");
writer.write(jsonParam);
writer.flush();
writer.close();
return connection.getInputStream();
}
public static URLConnection getConnection(String url, String param) throws Exception {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);


+ 9
- 0
inspect-ivs/src/main/java/com/inspect/ivs/constant/IvsConst.java View File

@ -26,6 +26,15 @@ public class IvsConst {
public static final String URI_HLS_SESSION_CONTROL = "/hik/nvr/playback/hls/sessions/%s/controls";
public static final String URI_HLS_UI_SESSIONS = "/hik/nvr/playback/hls/ui/sessions";
public static final String URI_HLS_UI_SESSION_CONTROL = "/hik/nvr/playback/hls/ui/sessions/%s/controls";
public static final String URI_UI_CONFIG = "/hik/nvr/playback/hls/ui/config";
public static final String URI_LIVE_START = "/hik/nvr/playback/hls/ui/actions/live/start";
public static final String URI_LIVE_STOP = "/hik/nvr/playback/hls/ui/actions/live/stop";
public static final String URI_LIVE_STATUS = "/hik/nvr/playback/hls/ui/actions/live/status";
public static final String URI_PRESET_LIST_PAGE = "/device/ptzpresetlist/%s/%s";
public static final String URI_PRESET_CREATE = "/hik/nvr/playback/hls/ui/actions/preset/create";
public static final String URI_SNAPSHOT_TASK = "/platform/platformSnapshot/%s/%s";
public static final String URI_SNAPSHOT_DOWNLOAD = "/platform/snapshot/%s";
public static final String URI_CLIP_DOWNLOAD = "/hik/nvr/playback/clips/download";
public static final String URI_PRESET_REMOVE = "/ptz/presetposition/{cameraCode}/{domainCode}/{presetIndex}/v1.0";
public static final String URI_PRESET_LIST = "/device/ptzpresetlist/{cameraCode}/{domainCode}";
public static final String IVS_TOKEN = "IVS_TOKEN";


+ 27
- 1
inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsControlController.java View File

@ -6,6 +6,7 @@ import com.inspect.base.core.utils.StringUtils;
import com.inspect.base.redis.service.RedisService;
import com.inspect.ivs.base.feign.domain.IvsResult;
import com.inspect.ivs.constant.IvsConst;
import com.inspect.ivs.service.HlsPlaybackComponent;
import com.inspect.ivs.service.IvsCommonService;
import com.inspect.ivs.service.IvsResourceRetryableDelegate;
import com.inspect.ivs.util.UriUtils;
@ -19,8 +20,12 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.http.ResponseEntity;
import java.io.IOException;
@ -32,15 +37,18 @@ public class IvsControlController {
private final RedisService redisService;
private final IvsCommonService ivsCommonService;
private final IvsResourceRetryableDelegate ivsResourceRetryableDelegate;
private final HlsPlaybackComponent hlsPlaybackComponent;
@Value("${ivs.version:3800}")
private String version;
public IvsControlController(
RedisService redisService,
IvsCommonService ivsCommonService, IvsResourceRetryableDelegate ivsResourceRetryableDelegate) {
IvsCommonService ivsCommonService, IvsResourceRetryableDelegate ivsResourceRetryableDelegate,
HlsPlaybackComponent hlsPlaybackComponent) {
this.redisService = redisService;
this.ivsCommonService = ivsCommonService;
this.ivsResourceRetryableDelegate = ivsResourceRetryableDelegate;
this.hlsPlaybackComponent = hlsPlaybackComponent;
}
@GetMapping({"ptz"})
@ -155,4 +163,22 @@ public class IvsControlController {
log.debug("[IVS] END");
return ivsPresetListView;
}
@PostMapping({"ptzControl"})
public ResponseEntity<JSONObject> ptzControl(@RequestBody JSONObject request) {
log.debug("[IVS] ptz control page param:{}", request);
return this.hlsPlaybackComponent.post(IvsConst.URI_PTZ_CONTROL, request);
}
@GetMapping({"presetList/{deviceCode}/{domainCode}"})
public ResponseEntity<JSONObject> presetListPage(@PathVariable String deviceCode, @PathVariable String domainCode) {
log.debug("[IVS] preset list page deviceCode:{}, domainCode:{}", deviceCode, domainCode);
return this.hlsPlaybackComponent.get(String.format(IvsConst.URI_PRESET_LIST_PAGE, deviceCode, domainCode));
}
@PostMapping({"presetCreate"})
public ResponseEntity<JSONObject> presetCreate(@RequestBody JSONObject request) {
log.debug("[IVS] preset create param:{}", request);
return this.hlsPlaybackComponent.post(IvsConst.URI_PRESET_CREATE, request);
}
}

+ 22
- 1
inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsDeviceController.java View File

@ -9,6 +9,7 @@ import com.inspect.ivs.base.feign.view.SipbDeviceListView;
import com.inspect.ivs.constant.IvsConst;
import com.inspect.ivs.domain.Temp;
import com.inspect.ivs.domain.TempConfiguration;
import com.inspect.ivs.service.HlsPlaybackComponent;
import com.inspect.ivs.service.IvsCommonService;
import com.inspect.ivs.service.IvsResourceRetryableDelegate;
import com.inspect.ivs.util.UriUtils;
@ -47,12 +48,14 @@ public class IvsDeviceController {
private boolean testMode;
private final IvsCommonService ivsCommonService;
private final HlsPlaybackComponent hlsPlaybackComponent;
@Resource
private IvsResourceRetryableDelegate ivsResourceRetryableDelegate;
public IvsDeviceController(IvsCommonService ivsCommonService) {
public IvsDeviceController(IvsCommonService ivsCommonService, HlsPlaybackComponent hlsPlaybackComponent) {
this.ivsCommonService = ivsCommonService;
this.hlsPlaybackComponent = hlsPlaybackComponent;
}
@ -471,6 +474,24 @@ public class IvsDeviceController {
return ivsCommonService.getResultJson(ivsResourceRetryableDelegate.getLabel(), UriUtils.parse(IvsConst.URI_DEVICE_LIST, ivsDevChanListVo));
}
@GetMapping({"hls/config"})
public ResponseEntity<JSONObject> hlsConfig() {
log.debug("[DEVICE] hls config");
return this.hlsPlaybackComponent.get(IvsConst.URI_UI_CONFIG);
}
@GetMapping({"platformSnapshot/{deviceCode}/{domainCode}"})
public ResponseEntity<JSONObject> createSnapshotTask(@PathVariable String deviceCode, @PathVariable String domainCode) {
log.debug("[DEVICE] create snapshot task deviceCode:{}, domainCode:{}", deviceCode, domainCode);
return this.hlsPlaybackComponent.get(String.format(IvsConst.URI_SNAPSHOT_TASK, deviceCode, domainCode));
}
@GetMapping({"snapshot/{taskId}"})
public ResponseEntity<byte[]> downloadSnapshot(@PathVariable String taskId) {
log.debug("[DEVICE] download snapshot taskId:{}", taskId);
return this.hlsPlaybackComponent.getBinary(String.format(IvsConst.URI_SNAPSHOT_DOWNLOAD, taskId));
}
private static int calculateSum(int n) {
int sum = 0;
for (int i = 1; i <= n; i++) {


+ 14
- 1
inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsRecordController.java View File

@ -1,10 +1,12 @@
package com.inspect.ivs.controller;
import com.alibaba.fastjson.JSONObject;
import com.inspect.base.core.domain.Response;
import com.inspect.base.core.utils.DateUtils;
import com.inspect.base.core.utils.StringUtils;
import com.inspect.base.redis.service.RedisService;
import com.inspect.ivs.constant.IvsConst;
import com.inspect.ivs.service.HlsPlaybackComponent;
import com.inspect.ivs.service.IvsCommonService;
import com.inspect.ivs.service.ZlMediaComponent;
import com.inspect.ivs.util.UriUtils;
@ -22,7 +24,10 @@ import java.util.concurrent.TimeUnit;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@ -33,11 +38,13 @@ public class IvsRecordController {
private final IvsCommonService ivsCommonService;
private final RedisService redisService;
private final ZlMediaComponent zlmediaComponent;
private final HlsPlaybackComponent hlsPlaybackComponent;
public IvsRecordController(IvsCommonService ivsCommonService, RedisService redisService, ZlMediaComponent zlmediaComponent) {
public IvsRecordController(IvsCommonService ivsCommonService, RedisService redisService, ZlMediaComponent zlmediaComponent, HlsPlaybackComponent hlsPlaybackComponent) {
this.ivsCommonService = ivsCommonService;
this.redisService = redisService;
this.zlmediaComponent = zlmediaComponent;
this.hlsPlaybackComponent = hlsPlaybackComponent;
}
@GetMapping({"start"})
@ -83,6 +90,12 @@ public class IvsRecordController {
return ivsRecStopView;
}
@PostMapping({"clipDownload"})
public ResponseEntity<byte[]> clipDownload(@RequestBody JSONObject request) {
log.debug("[RECORD] clip download param:{}", request);
return this.hlsPlaybackComponent.postBinary(IvsConst.URI_CLIP_DOWNLOAD, request);
}
public String getLabel() {
return UUID.randomUUID().toString().trim().replaceAll(StringUtils.DASH, StringUtils.EMPTY);
}


+ 28
- 1
inspect-ivs/src/main/java/com/inspect/ivs/controller/IvsStreamController.java View File

@ -1,11 +1,13 @@
package com.inspect.ivs.controller;
import com.alibaba.fastjson.JSONObject;
import com.inspect.base.core.domain.Response;
import com.inspect.base.core.utils.StringUtils;
import com.inspect.base.core.utils.uuid.UUID;
import com.inspect.base.redis.service.RedisService;
import com.inspect.ivs.constant.IvsConst;
import com.inspect.ivs.enums.RtspType;
import com.inspect.ivs.service.HlsPlaybackComponent;
import com.inspect.ivs.service.IvsCommonService;
import com.inspect.ivs.service.XinTongComponent;
import com.inspect.ivs.service.ZlMediaComponent;
@ -16,12 +18,16 @@ import com.inspect.ivs.vo.IvsVideoRtspVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.net.URLEncoder;
@RestController
@RequestMapping({"/api/v1/stream"})
@ -30,6 +36,7 @@ public class IvsStreamController {
private final IvsCommonService ivsCommonService;
private final ZlMediaComponent zlMediaComponent;
private final XinTongComponent xinTongComponent;
private final HlsPlaybackComponent hlsPlaybackComponent;
@Value("${ivs.test:false}")
private Boolean bIvsTestMode;
@Value("${rtsp.type:xintong}")
@ -37,10 +44,11 @@ public class IvsStreamController {
@Resource
private RedisService redisService;
public IvsStreamController(IvsCommonService ivsCommonService, ZlMediaComponent zlMediaComponent, XinTongComponent xinTongComponent) {
public IvsStreamController(IvsCommonService ivsCommonService, ZlMediaComponent zlMediaComponent, XinTongComponent xinTongComponent, HlsPlaybackComponent hlsPlaybackComponent) {
this.ivsCommonService = ivsCommonService;
this.zlMediaComponent = zlMediaComponent;
this.xinTongComponent = xinTongComponent;
this.hlsPlaybackComponent = hlsPlaybackComponent;
}
@GetMapping({"start"})
@ -122,4 +130,23 @@ public class IvsStreamController {
return ivsVideoRtspView;
}
@PostMapping({"live/start"})
public ResponseEntity<JSONObject> liveStart(@RequestBody JSONObject request) {
log.debug("[STREAM] live start param:{}", request);
return this.hlsPlaybackComponent.post(IvsConst.URI_LIVE_START, request);
}
@PostMapping({"live/stop"})
public ResponseEntity<JSONObject> liveStop(@RequestBody JSONObject request) {
log.debug("[STREAM] live stop param:{}", request);
return this.hlsPlaybackComponent.post(IvsConst.URI_LIVE_STOP, request);
}
@GetMapping({"live/status"})
public ResponseEntity<JSONObject> liveStatus(@RequestParam("cameraCode") String cameraCode) throws Exception {
log.debug("[STREAM] live status cameraCode:{}", cameraCode);
String uri = IvsConst.URI_LIVE_STATUS + "?cameraCode=" + URLEncoder.encode(cameraCode, "UTF-8");
return this.hlsPlaybackComponent.get(uri);
}
}

+ 33
- 0
inspect-ivs/src/main/java/com/inspect/ivs/service/HlsPlaybackComponent.java View File

@ -39,6 +39,18 @@ public class HlsPlaybackComponent {
return exchange(webClient.delete().uri(url.concat(uri)));
}
public ResponseEntity<byte[]> getBinary(String uri) {
log.info("[NVR HLS] GET binary url: {}", url.concat(uri));
return exchangeBinary(webClient.get().uri(url.concat(uri)));
}
public ResponseEntity<byte[]> postBinary(String uri, Object body) {
log.info("[NVR HLS] POST binary url: {}, body: {}", url.concat(uri), JSONObject.toJSONString(body));
return exchangeBinary(webClient.post().uri(url.concat(uri))
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(body));
}
private ResponseEntity<JSONObject> exchange(WebClient.RequestHeadersSpec<?> spec) {
assert webClient != null;
try {
@ -66,4 +78,25 @@ public class HlsPlaybackComponent {
return ResponseEntity.status(HttpStatus.BAD_GATEWAY).body(error);
}
}
private ResponseEntity<byte[]> exchangeBinary(WebClient.RequestHeadersSpec<?> spec) {
assert webClient != null;
try {
return spec.exchangeToMono(response ->
response.bodyToMono(byte[].class)
.defaultIfEmpty(new byte[0])
.map(bytes -> {
MediaType mediaType = response.headers().contentType().orElse(MediaType.APPLICATION_OCTET_STREAM);
return ResponseEntity.status(response.statusCode().value())
.contentType(mediaType)
.body(bytes);
}))
.block();
} catch (WebClientException e) {
log.error("[NVR HLS] request failed, url: {}", url, e);
return ResponseEntity.status(HttpStatus.BAD_GATEWAY)
.contentType(MediaType.APPLICATION_JSON)
.body(new byte[0]);
}
}
}

+ 10
- 0
inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/contants/AccessApiConstant.java View File

@ -19,5 +19,15 @@ public class AccessApiConstant {
public static final String HLS_SESSION_CONTROL = "/api/v1/playback/hls/sessions/%s/controls";
public static final String HLS_UI_SESSION_CREATE = "/api/v1/playback/hls/ui/sessions";
public static final String HLS_UI_SESSION_CONTROL = "/api/v1/playback/hls/ui/sessions/%s/controls";
public static final String HLS_CONFIG = "/api/v1/device/hls/config";
public static final String LIVE_START = "/api/v1/stream/live/start";
public static final String LIVE_STOP = "/api/v1/stream/live/stop";
public static final String LIVE_STATUS = "/api/v1/stream/live/status";
public static final String PTZ_CONTROL_PAGE = "/api/v1/control/ptzControl";
public static final String PRESET_LIST_PAGE = "/api/v1/control/presetList/%s/%s";
public static final String PRESET_CREATE = "/api/v1/control/presetCreate";
public static final String SNAPSHOT_TASK = "/api/v1/device/platformSnapshot/%s/%s";
public static final String SNAPSHOT_DOWNLOAD = "/api/v1/device/snapshot/%s";
public static final String CLIP_DOWNLOAD = "/api/v1/record/clipDownload";
public static final String PTZ_LIST = "/api/v1/control/presetList";
}

+ 37
- 0
inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/PatrolPresetPosController.java View File

@ -796,4 +796,41 @@ public class PatrolPresetPosController extends BaseController {
}
}
@PostMapping({"/ptzControl"})
public AjaxResult ptzControl(@RequestBody JSONObject request) throws Exception {
logger.info("[PRESET] ptz control param: {}", request);
String result = HttpClientUtils.postJson(this.deviceUrl + AccessApiConstant.PTZ_CONTROL_PAGE, request.toJSONString(), "");
return parsePresetPageResult(result);
}
@GetMapping({"/presetList/{deviceCode}/{domainCode}"})
public AjaxResult presetListPage(@PathVariable String deviceCode, @PathVariable String domainCode) throws Exception {
logger.info("[PRESET] preset list deviceCode: {}, domainCode: {}", deviceCode, domainCode);
String result = HttpClientUtils.get(this.deviceUrl + String.format(AccessApiConstant.PRESET_LIST_PAGE, deviceCode, domainCode));
return parsePresetPageResult(result);
}
@PostMapping({"/presetCreate"})
public AjaxResult presetCreate(@RequestBody JSONObject request) throws Exception {
logger.info("[PRESET] preset create param: {}", request);
String result = HttpClientUtils.postJson(this.deviceUrl + AccessApiConstant.PRESET_CREATE, request.toJSONString(), "");
return parsePresetPageResult(result);
}
private AjaxResult parsePresetPageResult(String result) {
if (result == null || result.trim().isEmpty()) {
return AjaxResult.error("接入层返回异常");
}
try {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.containsKey("code") && !Constants.SUCCESS.equals(jsonObject.getInteger("code"))) {
return AjaxResult.error(jsonObject.getString("message"));
}
return AjaxResult.success(jsonObject);
} catch (Exception e) {
logger.error("preset page response parse error, result: {}", result, e);
return AjaxResult.error("接入层返回异常");
}
}
}

+ 25
- 0
inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/PatrolVideotapeController.java View File

@ -26,12 +26,16 @@ import com.inspect.patrol.service.impl.DeviceIntoService;
import com.inspect.patrol.service.impl.Video2NvrComponent;
import java.util.Date;
import java.io.InputStream;
import java.util.Objects;
import javax.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -211,6 +215,27 @@ public class PatrolVideotapeController extends BaseController {
return parseHlsResult(result);
}
@GetMapping({"/snapshot/task/{deviceCode}/{domainCode}"})
public AjaxResult createSnapshotTask(@PathVariable String deviceCode, @PathVariable String domainCode) throws Exception {
log.info("snapshot task deviceCode: {}, domainCode: {}", deviceCode, domainCode);
String result = HttpClientUtils.get(this.deviceUrl + String.format(AccessApiConstant.SNAPSHOT_TASK, deviceCode, domainCode));
return parseHlsResult(result);
}
@GetMapping({"/snapshot/{taskId}"})
public ResponseEntity<InputStreamResource> downloadSnapshot(@PathVariable String taskId) throws Exception {
log.info("download snapshot taskId: {}", taskId);
InputStream inputStream = HttpClientUtils.getStream(this.deviceUrl + String.format(AccessApiConstant.SNAPSHOT_DOWNLOAD, taskId));
return ResponseEntity.ok().contentType(MediaType.IMAGE_JPEG).body(new InputStreamResource(inputStream));
}
@PostMapping({"/clip/download"})
public ResponseEntity<InputStreamResource> downloadClip(@RequestBody JSONObject request) throws Exception {
log.info("clip download param: {}", request);
InputStream inputStream = HttpClientUtils.postStream(this.deviceUrl + AccessApiConstant.CLIP_DOWNLOAD, request.toJSONString());
return ResponseEntity.ok().contentType(MediaType.parseMediaType("video/mp4")).body(new InputStreamResource(inputStream));
}
private AjaxResult parseHlsResult(String result) {
if (result == null || result.trim().isEmpty()) {
return AjaxResult.error("接入层返回异常");


+ 47
- 0
inspect-main/inspect-main-video/src/main/java/com/inspect/patrol/controller/VideoController.java View File

@ -1,6 +1,7 @@
package com.inspect.patrol.controller;
import com.alibaba.fastjson.JSONObject;
import com.inspect.base.core.constant.Constants;
import com.inspect.base.core.utils.HttpClientUtils;
import com.inspect.base.core.web.controller.BaseController;
import com.inspect.base.core.web.domain.AjaxResult;
@ -15,6 +16,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
@ -70,4 +73,48 @@ public class VideoController extends BaseController {
}
return AjaxResult.success(JSONObject.parseObject(result));
}
@GetMapping({"/config"})
public AjaxResult config() throws Exception {
log.info("[VIDEO] load device tree config");
String result = HttpClientUtils.get(this.deviceUrl + AccessApiConstant.HLS_CONFIG);
return parsePageResult(result);
}
@PostMapping({"/realtime/start"})
public AjaxResult realtimeStart(@RequestBody JSONObject request) throws Exception {
log.info("[VIDEO] realtime start param:{}", request);
String result = HttpClientUtils.postJson(this.deviceUrl + AccessApiConstant.LIVE_START, request.toJSONString(), "");
return parsePageResult(result);
}
@PostMapping({"/realtime/stop"})
public AjaxResult realtimeStop(@RequestBody JSONObject request) throws Exception {
log.info("[VIDEO] realtime stop param:{}", request);
String result = HttpClientUtils.postJson(this.deviceUrl + AccessApiConstant.LIVE_STOP, request.toJSONString(), "");
return parsePageResult(result);
}
@GetMapping({"/realtime/status"})
public AjaxResult realtimeStatus(@RequestParam("cameraCode") String cameraCode) throws Exception {
log.info("[VIDEO] realtime status cameraCode:{}", cameraCode);
String result = HttpClientUtils.get(this.deviceUrl + AccessApiConstant.LIVE_STATUS, "cameraCode=" + cameraCode);
return parsePageResult(result);
}
private AjaxResult parsePageResult(String result) {
if (result == null || result.trim().isEmpty()) {
return AjaxResult.error("接入层返回异常");
}
try {
JSONObject jsonObject = JSONObject.parseObject(result);
if (jsonObject.containsKey("code") && !Constants.SUCCESS.equals(jsonObject.getInteger("code"))) {
return AjaxResult.error(jsonObject.getString("message"));
}
return AjaxResult.success(jsonObject);
} catch (Exception e) {
log.error("video page response parse error, result: {}", result, e);
return AjaxResult.error("接入层返回异常");
}
}
}

Loading…
Cancel
Save