|
@@ -1,12 +1,15 @@
|
|
|
package com.zhiqiyun.open.router.apis;
|
|
package com.zhiqiyun.open.router.apis;
|
|
|
|
|
|
|
|
import cn.hutool.crypto.SecureUtil;
|
|
import cn.hutool.crypto.SecureUtil;
|
|
|
|
|
+import cn.hutool.http.HttpRequest;
|
|
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.dliyun.oap.framework.annotation.ServiceMethod;
|
|
import com.dliyun.oap.framework.annotation.ServiceMethod;
|
|
|
import com.dliyun.oap.framework.annotation.ServiceMethodBean;
|
|
import com.dliyun.oap.framework.annotation.ServiceMethodBean;
|
|
|
import com.dliyun.oap.framework.response.OapResponse;
|
|
import com.dliyun.oap.framework.response.OapResponse;
|
|
|
import com.google.common.collect.Maps;
|
|
import com.google.common.collect.Maps;
|
|
|
|
|
+import com.zhiqiyun.open.camera.config.CameraConfig;
|
|
|
import com.zhiqiyun.open.camera.rtsp.RtspPushSrs;
|
|
import com.zhiqiyun.open.camera.rtsp.RtspPushSrs;
|
|
|
import com.zhiqiyun.open.camera.rtsp.RtspTransfer;
|
|
import com.zhiqiyun.open.camera.rtsp.RtspTransfer;
|
|
|
import com.zhiqiyun.open.core.models.hwVideo.DeviceList;
|
|
import com.zhiqiyun.open.core.models.hwVideo.DeviceList;
|
|
@@ -22,6 +25,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
|
|
+import java.net.URLDecoder;
|
|
|
|
|
+import java.net.URLEncoder;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
|
@@ -49,7 +54,7 @@ public class HwVideoApi {
|
|
|
params.put("toIndex", String.valueOf(request.getPage() * request.getLimit()));
|
|
params.put("toIndex", String.valueOf(request.getPage() * request.getLimit()));
|
|
|
JSONObject jsonObject = request.getLoadType().compareTo(1) == 0 ? videoDockingService.loadDeviceList(params)
|
|
JSONObject jsonObject = request.getLoadType().compareTo(1) == 0 ? videoDockingService.loadDeviceList(params)
|
|
|
: videoDockingUrbanService.loadDeviceList(params);
|
|
: videoDockingUrbanService.loadDeviceList(params);
|
|
|
- log.info("设备信息:{}", jsonObject.toJSONString());
|
|
|
|
|
|
|
+// log.info("设备信息:{}", jsonObject.toJSONString());
|
|
|
JSONObject cameraBriefExInfos = jsonObject.getJSONObject("cameraBriefExInfos");
|
|
JSONObject cameraBriefExInfos = jsonObject.getJSONObject("cameraBriefExInfos");
|
|
|
int total = cameraBriefExInfos.getIntValue("total");
|
|
int total = cameraBriefExInfos.getIntValue("total");
|
|
|
JSONObject cameraBriefInfoExList = cameraBriefExInfos.getJSONObject("cameraBriefInfoExList");
|
|
JSONObject cameraBriefInfoExList = cameraBriefExInfos.getJSONObject("cameraBriefInfoExList");
|
|
@@ -63,42 +68,97 @@ public class HwVideoApi {
|
|
|
return OapResponse.success();
|
|
return OapResponse.success();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private final static String SRS_API = "https://10.35.5.111:8090";
|
|
|
|
|
+
|
|
|
@ServiceMethod(method = "hw.video.url.find", title = "获取视频URL信息")
|
|
@ServiceMethod(method = "hw.video.url.find", title = "获取视频URL信息")
|
|
|
public OapResponse loadVideoRtspUrl(@Valid VideoRtsUrlRequest request) throws Exception {
|
|
public OapResponse loadVideoRtspUrl(@Valid VideoRtsUrlRequest request) throws Exception {
|
|
|
- VideoRtsUrlResponse response = new VideoRtsUrlResponse();
|
|
|
|
|
|
|
+
|
|
|
JSONObject jsonObject = request.getLoadType().compareTo(1) == 0 ? videoDockingService.loadVideoRtspUrl(request.getCameraCode())
|
|
JSONObject jsonObject = request.getLoadType().compareTo(1) == 0 ? videoDockingService.loadVideoRtspUrl(request.getCameraCode())
|
|
|
: videoDockingUrbanService.loadVideoRtspUrl(request.getCameraCode());
|
|
: videoDockingUrbanService.loadVideoRtspUrl(request.getCameraCode());
|
|
|
String rtspUri = jsonObject.getString("rtspURL");
|
|
String rtspUri = jsonObject.getString("rtspURL");
|
|
|
log.info("获取到监控rtspURI:{}", rtspUri);
|
|
log.info("获取到监控rtspURI:{}", rtspUri);
|
|
|
- if (StringUtils.isBlank(rtspUri)) return OapResponse.fail("ERROR", "视频流地址获取失败");
|
|
|
|
|
|
|
+ rtspUri = CameraConfig.replaceUri(rtspUri);
|
|
|
|
|
+ log.info("获取到监控rtspURI:{}", rtspUri);
|
|
|
|
|
+ if (StringUtils.isBlank(rtspUri)) {
|
|
|
|
|
+ return OapResponse.fail("ERROR", "视频流地址获取失败");
|
|
|
|
|
+ }
|
|
|
String rtspId = request.getCameraCode().split("#")[0];
|
|
String rtspId = request.getCameraCode().split("#")[0];
|
|
|
- RtspTransfer.createRtspId(rtspUri, rtspId);
|
|
|
|
|
- response.setRtspId(rtspId);
|
|
|
|
|
- log.info("RtspTransfer.STREAM_MAP:{}", RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
- if (StringUtils.isNotBlank(RtspTransfer.STREAM_MAP.get(rtspId))) {
|
|
|
|
|
- response.setRtspUri(RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
- } else {
|
|
|
|
|
- rtspUri = String.format(RtspPushSrs.SRS_PUSH_ADDRESS, SecureUtil.md5(rtspId));
|
|
|
|
|
- log.info("重新进行流推送:{}", rtspUri);
|
|
|
|
|
- taskExecutor.execute(() -> {
|
|
|
|
|
- try {
|
|
|
|
|
- //停顿1秒在进行推流,已缓解频繁开启或关闭推流造成的问题
|
|
|
|
|
- Thread.sleep(1000);
|
|
|
|
|
- RtspTransfer.startPushRtmp(rtspId);
|
|
|
|
|
- } catch (Exception e) {
|
|
|
|
|
- log.info("============停止推流=======================");
|
|
|
|
|
- RtspTransfer.removeRtsp(rtspId);
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- RtspTransfer.STREAM_MAP.put(rtspId, rtspUri);
|
|
|
|
|
- response.setRtspUri(rtspUri);
|
|
|
|
|
|
|
+ String body = HttpRequest.get(SRS_API + "/api/v1/srs/push")
|
|
|
|
|
+ .form("rtspId", rtspId)
|
|
|
|
|
+ .form("rtspUri", URLEncoder.encode(rtspUri, "utf-8"))
|
|
|
|
|
+ .execute().body();
|
|
|
|
|
+ log.info("推流返回信息:{}", body);
|
|
|
|
|
+ JSONObject obJson = JSONObject.parseObject(body);
|
|
|
|
|
+ if (0 != obJson.getIntValue("code")) {
|
|
|
|
|
+ return OapResponse.fail("ERROR", "视频流地址获取失败");
|
|
|
}
|
|
}
|
|
|
|
|
+ VideoRtsUrlResponse response = obJson.getJSONObject("data").toJavaObject(VideoRtsUrlResponse.class);
|
|
|
|
|
+// RtspTransfer.createRtspId(rtspUri, rtspId);
|
|
|
|
|
+// response.setRtspId(rtspId);
|
|
|
|
|
+// log.info("RtspTransfer.STREAM_MAP:{}", RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
+// if (StringUtils.isNotBlank(RtspTransfer.STREAM_MAP.get(rtspId))) {
|
|
|
|
|
+// response.setRtspUri(RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
+// } else {
|
|
|
|
|
+// rtspUri = String.format(RtspPushSrs.SRS_PUSH_ADDRESS, SecureUtil.md5(rtspId));
|
|
|
|
|
+// log.info("重新进行流推送:{}", rtspUri);
|
|
|
|
|
+// taskExecutor.execute(() -> {
|
|
|
|
|
+// try {
|
|
|
|
|
+// //停顿1秒在进行推流,已缓解频繁开启或关闭推流造成的问题
|
|
|
|
|
+// Thread.sleep(1000);
|
|
|
|
|
+// RtspTransfer.startPushRtmp(rtspId);
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// log.info("============停止推流=======================");
|
|
|
|
|
+// RtspTransfer.removeRtsp(rtspId);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+// RtspTransfer.STREAM_MAP.put(rtspId, rtspUri);
|
|
|
|
|
+// response.setRtspUri(rtspUri);
|
|
|
|
|
+// }
|
|
|
return OapResponse.success().setBody(response);
|
|
return OapResponse.success().setBody(response);
|
|
|
}
|
|
}
|
|
|
|
|
+// @ServiceMethod(method = "hw.video.url.find", title = "获取视频URL信息")
|
|
|
|
|
+// public OapResponse loadVideoRtspUrl(@Valid VideoRtsUrlRequest request) throws Exception {
|
|
|
|
|
+// VideoRtsUrlResponse response = new VideoRtsUrlResponse();
|
|
|
|
|
+// JSONObject jsonObject = request.getLoadType().compareTo(1) == 0 ? videoDockingService.loadVideoRtspUrl(request.getCameraCode())
|
|
|
|
|
+// : videoDockingUrbanService.loadVideoRtspUrl(request.getCameraCode());
|
|
|
|
|
+// String rtspUri = jsonObject.getString("rtspURL");
|
|
|
|
|
+// log.info("获取到监控rtspURI:{}", rtspUri);
|
|
|
|
|
+// rtspUri = CameraConfig.replaceUri(rtspUri);
|
|
|
|
|
+// log.info("获取到监控rtspURI:{}", rtspUri);
|
|
|
|
|
+// if (StringUtils.isBlank(rtspUri)) return OapResponse.fail("ERROR", "视频流地址获取失败");
|
|
|
|
|
+// String rtspId = request.getCameraCode().split("#")[0];
|
|
|
|
|
+// RtspTransfer.createRtspId(rtspUri, rtspId);
|
|
|
|
|
+// response.setRtspId(rtspId);
|
|
|
|
|
+// log.info("RtspTransfer.STREAM_MAP:{}", RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
+// if (StringUtils.isNotBlank(RtspTransfer.STREAM_MAP.get(rtspId))) {
|
|
|
|
|
+// response.setRtspUri(RtspTransfer.STREAM_MAP.get(rtspId));
|
|
|
|
|
+// } else {
|
|
|
|
|
+// rtspUri = String.format(RtspPushSrs.SRS_PUSH_ADDRESS, SecureUtil.md5(rtspId));
|
|
|
|
|
+// log.info("重新进行流推送:{}", rtspUri);
|
|
|
|
|
+// taskExecutor.execute(() -> {
|
|
|
|
|
+// try {
|
|
|
|
|
+// //停顿1秒在进行推流,已缓解频繁开启或关闭推流造成的问题
|
|
|
|
|
+// Thread.sleep(1000);
|
|
|
|
|
+// RtspTransfer.startPushRtmp(rtspId);
|
|
|
|
|
+// } catch (Exception e) {
|
|
|
|
|
+// log.info("============停止推流=======================");
|
|
|
|
|
+// RtspTransfer.removeRtsp(rtspId);
|
|
|
|
|
+// }
|
|
|
|
|
+// });
|
|
|
|
|
+// RtspTransfer.STREAM_MAP.put(rtspId, rtspUri);
|
|
|
|
|
+// response.setRtspUri(rtspUri);
|
|
|
|
|
+// }
|
|
|
|
|
+// return OapResponse.success().setBody(response);
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
@ServiceMethod(method = "hw.video.live.stop", title = "停止视频推流工作")
|
|
@ServiceMethod(method = "hw.video.live.stop", title = "停止视频推流工作")
|
|
|
public OapResponse videoStopPush(VideoStopPushRequest request) throws Exception {
|
|
public OapResponse videoStopPush(VideoStopPushRequest request) throws Exception {
|
|
|
- RtspTransfer.removeRtsp(request.getRtspId());
|
|
|
|
|
|
|
+ log.info("============停止推流=======================:{}", JSONUtil.toJsonStr(request));
|
|
|
|
|
+ String body = HttpRequest.get(SRS_API + "/api/v1/srs/stop")
|
|
|
|
|
+ .form("rtspId", request.getRtspId())
|
|
|
|
|
+ .execute().body();
|
|
|
|
|
+ log.info("============停止推流=======================:{}", body);
|
|
|
|
|
+// RtspTransfer.removeRtsp(request.getRtspId());
|
|
|
return OapResponse.success();
|
|
return OapResponse.success();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|