From fa62ab9a0143433a5d058ab3229a37e4a9a0f696 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期二, 20 六月 2023 14:16:46 +0800
Subject: [PATCH] Merge pull request #893 from sxh-netizen/wvp-28181-2.0

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |   45 ++++++++++++++++++++++++++-------------------
 1 files changed, 26 insertions(+), 19 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 200a7d9..0cf4874 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
@@ -26,7 +26,6 @@
 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;
@@ -41,7 +40,6 @@
 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;
@@ -90,16 +88,17 @@
 	@Operation(summary = "寮�濮嬬偣鎾�")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
+	@Parameter(name = "isSubStream", description = "鏄惁瀛愮爜娴侊紙true-瀛愮爜娴侊紝false-涓荤爜娴侊級锛岄粯璁や负false", required = true)
 	@GetMapping("/start/{deviceId}/{channelId}")
 	public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId,
-														 @PathVariable String channelId) {
+														 @PathVariable String channelId,boolean isSubStream) {
 
 		// 鑾峰彇鍙敤鐨剒lm
 		Device device = storager.queryVideoDevice(deviceId);
 		MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
 
 		RequestMessage requestMessage = new RequestMessage();
-		String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
+		String key = DeferredResultHolder.getPlayKey(deviceId,channelId,device.isSwitchPrimarySubStream(),isSubStream);
 		requestMessage.setKey(key);
 		String uuid = UUID.randomUUID().toString();
 		requestMessage.setId(uuid);
@@ -118,7 +117,7 @@
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
 		resultHolder.put(key, uuid, result);
 
-		playService.play(newMediaServerItem, deviceId, channelId, (code, msg, data) -> {
+		playService.play(newMediaServerItem, deviceId, channelId,isSubStream, (code, msg, data) -> {
 			WVPResult<StreamContent> wvpResult = new WVPResult<>();
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
 				wvpResult.setCode(ErrorCode.SUCCESS.getCode());
@@ -144,8 +143,9 @@
 	@Operation(summary = "鍋滄鐐规挱")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
+	@Parameter(name = "isSubStream", description = "鏄惁瀛愮爜娴侊紙true-瀛愮爜娴侊紝false-涓荤爜娴侊級锛岄粯璁や负false", required = true)
 	@GetMapping("/stop/{deviceId}/{channelId}")
-	public JSONObject playStop(@PathVariable String deviceId, @PathVariable String channelId) {
+	public JSONObject playStop(@PathVariable String deviceId, @PathVariable String channelId,boolean isSubStream) {
 
 		logger.debug(String.format("璁惧棰勮/鍥炴斁鍋滄API璋冪敤锛宻treamId锛�%s_%s", deviceId, channelId ));
 
@@ -158,7 +158,12 @@
 			throw new ControllerException(ErrorCode.ERROR100.getCode(), "璁惧[" + deviceId + "]涓嶅瓨鍦�");
 		}
 
-		InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+		InviteInfo inviteInfo =null;
+		if(device.isSwitchPrimarySubStream()){
+			inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);
+		}else {
+			inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+		}
 		if (inviteInfo == null) {
 			throw new ControllerException(ErrorCode.ERROR100.getCode(), "鐐规挱鏈壘鍒�");
 		}
@@ -171,12 +176,17 @@
 				throw new ControllerException(ErrorCode.ERROR100.getCode(), "鍛戒护鍙戦�佸け璐�: " + e.getMessage());
 			}
 		}
-		inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+		if(device.isSwitchPrimarySubStream()){
+			inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId,isSubStream);
+		}else {
+			inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+			storager.stopPlay(deviceId, channelId);
+		}
 
-		storager.stopPlay(deviceId, channelId);
 		JSONObject json = new JSONObject();
 		json.put("deviceId", deviceId);
 		json.put("channelId", channelId);
+		json.put("isSubStream", isSubStream);
 		return json;
 	}
 
@@ -343,30 +353,27 @@
 	@Operation(summary = "鑾峰彇鎴浘")
 	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
 	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
+	@Parameter(name = "isSubStream", description = "鏄惁瀛愮爜娴侊紙true-瀛愮爜娴侊紝false-涓荤爜娴侊級锛岄粯璁や负false", required = true)
 	@GetMapping("/snap")
-	public DeferredResult<String> getSnap(HttpServletRequest request, String deviceId, String channelId) {
+	public DeferredResult<String> getSnap(String deviceId, String channelId,boolean isSubStream) {
 		if (logger.isDebugEnabled()) {
 			logger.debug("鑾峰彇鎴浘: {}/{}", deviceId, channelId);
 		}
 
+		Device device = storager.queryVideoDevice(deviceId);
 		DeferredResult<String> result = new DeferredResult<>(3 * 1000L);
-		String key  = DeferredResultHolder.CALLBACK_CMD_SNAP + deviceId;
+		String key = DeferredResultHolder.getSnapKey(deviceId,channelId,device.isSwitchPrimarySubStream(),isSubStream);
 		String uuid  = UUID.randomUUID().toString();
 		resultHolder.put(key, uuid,  result);
 
 		RequestMessage message = new RequestMessage();
 		message.setKey(key);
 		message.setId(uuid);
-		String nowForUrl = DateUtil.getNowForUrl();
-		String fileName = deviceId + "_" + channelId + "_" + nowForUrl + ".jpg";
 
-		playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
+		String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + "jpg";
+		playService.getSnap(deviceId, channelId, fileName,isSubStream, (code, msg, data) -> {
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
-				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);
+				message.setData(data);
 			}else {
 				message.setData(WVPResult.fail(code, msg));
 			}

--
Gitblit v1.8.0