From 131ea7766924113f6d0b8d8d4c288084ae635a31 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 06 十二月 2022 10:33:43 +0800
Subject: [PATCH] 接口使用旧的stream信息,支持使用远程ip端口做为回复的地址而不是使用sip中的地址

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |   62 ++++++++++++++++---------------
 1 files changed, 32 insertions(+), 30 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
index 87e203a..46aa63c 100644
--- a/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
+++ b/src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java
@@ -21,6 +21,7 @@
 import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import com.genersoft.iot.vmp.vmanager.bean.DeferredResultEx;
 import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
+import com.genersoft.iot.vmp.vmanager.bean.StreamContent;
 import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
 import io.swagger.v3.oas.annotations.Operation;
 import io.swagger.v3.oas.annotations.Parameter;
@@ -80,23 +81,9 @@
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
 	@GetMapping("/start/{deviceId}/{channelId}")
-	public DeferredResult<WVPResult<StreamInfo>> play(HttpServletRequest request, @PathVariable String deviceId,
-													  @PathVariable String channelId) {
+	public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId,
+														 @PathVariable String channelId) {
 
-		String localAddr = request.getLocalAddr();
-		String localName = request.getLocalName();
-		String remoteHost = request.getRemoteHost();
-		String remoteAddr = request.getRemoteAddr();
-		String remoteUser = request.getRemoteUser();
-		String requestURI = request.getRequestURI();
-		System.out.println(3333333);
-		System.out.println(localAddr);
-		System.out.println(localName);
-		System.out.println(remoteHost);
-		System.out.println(remoteAddr);
-		System.out.println(remoteUser);
-		System.out.println(requestURI);
-		System.out.println(4444444);
 		// 鑾峰彇鍙敤鐨剒lm
 		Device device = storager.queryVideoDevice(deviceId);
 		MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
@@ -107,20 +94,37 @@
 		msg.setKey(key);
 		String uuid = UUID.randomUUID().toString();
 		msg.setId(uuid);
-		DeferredResult<WVPResult<StreamInfo>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
-		DeferredResultEx<WVPResult<StreamInfo>> deferredResultEx = new DeferredResultEx<>(result);
+		DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
+		DeferredResultEx<WVPResult<StreamContent>> deferredResultEx = new DeferredResultEx<>(result);
 
-		deferredResultEx.setFilter(result1 -> {
-			System.out.println(1111);
-			System.out.println(request.getLocalName());
-			WVPResult<StreamInfo> wvpResult = (WVPResult<StreamInfo>)result1;
-			if (wvpResult.getCode() == ErrorCode.SUCCESS.getCode()) {
-				StreamInfo data = wvpResult.getData();
-				data.channgeStreamIp(request.getLocalName());
-				((WVPResult<StreamInfo>)result1).setData(data);
-			}
-			return result1;
+		result.onTimeout(()->{
+			logger.info("鐐规挱鎺ュ彛绛夊緟瓒呮椂");
+			// 閲婃斁rtpserver
+			WVPResult<StreamInfo> wvpResult = new WVPResult<>();
+			wvpResult.setCode(ErrorCode.ERROR100.getCode());
+			wvpResult.setMsg("鐐规挱瓒呮椂");
+			msg.setData(wvpResult);
+			resultHolder.invokeResult(msg);
 		});
+
+
+			// TODO 鍦ㄧ偣鎾湭鎴愬姛鐨勬儏鍐典笅鍦ㄦ璋冪敤鎺ュ彛鐐规挱浼氬鑷磋繑鍥炵殑娴佸湴鍧�ip閿欒
+			deferredResultEx.setFilter(result1 -> {
+				WVPResult<StreamInfo> wvpResult1 = (WVPResult<StreamInfo>)result1;
+				WVPResult<StreamContent> resultStream = null;
+				if (wvpResult1.getCode() == ErrorCode.SUCCESS.getCode()) {
+					StreamInfo data = wvpResult1.getData().clone();
+					if (userSetting.getUseSourceIpAsStreamIp()) {
+						data.channgeStreamIp(request.getLocalName());
+					}
+					resultStream = new WVPResult<>();
+					resultStream.setCode(wvpResult1.getCode());
+					resultStream.setMsg(wvpResult1.getMsg());
+					resultStream.setData(new StreamContent(wvpResult1.getData()));
+				}
+				return resultStream;
+			});
+
 
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
 		resultHolder.put(key, uuid, deferredResultEx);
@@ -130,7 +134,6 @@
 		}
 		return result;
 	}
-
 
 	@Operation(summary = "鍋滄鐐规挱")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
@@ -168,7 +171,6 @@
 		json.put("deviceId", deviceId);
 		json.put("channelId", channelId);
 		return json;
-
 	}
 
 	/**

--
Gitblit v1.8.0