From 4ee8924bd9dbd36046d922d9480de310ee16b6ac Mon Sep 17 00:00:00 2001
From: zx <zuoxue@qq.com>
Date: 星期五, 19 八月 2022 21:55:59 +0800
Subject: [PATCH] fix PlatformKeepaliveExpireEvent typo

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |  148 +++++++++++++++++++++++++------------------------
 1 files changed, 76 insertions(+), 72 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 8ea84dc..233e1de 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
@@ -15,10 +15,10 @@
 import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.PlayResult;
 import com.genersoft.iot.vmp.service.IMediaService;
 import com.genersoft.iot.vmp.service.IPlayService;
-import io.swagger.annotations.Api;
-import io.swagger.annotations.ApiImplicitParam;
-import io.swagger.annotations.ApiImplicitParams;
-import io.swagger.annotations.ApiOperation;
+
+import io.swagger.v3.oas.annotations.Operation;
+import io.swagger.v3.oas.annotations.Parameter;
+import io.swagger.v3.oas.annotations.tags.Tag;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -33,15 +33,13 @@
 
 import com.alibaba.fastjson.JSONObject;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
-import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
+import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
 import org.springframework.web.context.request.async.DeferredResult;
 
 import java.util.List;
 import java.util.UUID;
 
-import javax.sip.message.Response;
-
-@Api(tags = "鍥芥爣璁惧鐐规挱")
+@Tag(name  = "鍥芥爣璁惧鐐规挱")
 @CrossOrigin
 @RestController
 @RequestMapping("/api/play")
@@ -56,7 +54,7 @@
 	private VideoStreamSessionManager streamSession;
 
 	@Autowired
-	private IVideoManagerStorager storager;
+	private IVideoManagerStorage storager;
 
 	@Autowired
 	private IRedisCatchStorage redisCatchStorage;
@@ -76,11 +74,9 @@
 	@Autowired
 	private IMediaServerService mediaServerService;
 
-	@ApiOperation("寮�濮嬬偣鎾�")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class),
-			@ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class),
-	})
+	@Operation(summary = "寮�濮嬬偣鎾�")
+	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
+	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
 	@GetMapping("/start/{deviceId}/{channelId}")
 	public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId,
 													   @PathVariable String channelId) {
@@ -88,45 +84,44 @@
 		// 鑾峰彇鍙敤鐨剒lm
 		Device device = storager.queryVideoDevice(deviceId);
 		MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
-		PlayResult playResult = playService.play(newMediaServerItem, deviceId, channelId, null, null);
+		PlayResult playResult = playService.play(newMediaServerItem, deviceId, channelId, null, null, null);
 
 		return playResult.getResult();
 	}
 
-	@ApiOperation("鍋滄鐐规挱")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class),
-			@ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class),
-	})
+
+	@Operation(summary = "鍋滄鐐规挱")
+	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
+	@Parameter(name = "channelId", description = "閫氶亾鍥芥爣缂栧彿", required = true)
 	@GetMapping("/stop/{deviceId}/{channelId}")
 	public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
 
-		logger.debug(String.format("璁惧棰勮/鍥炴斁鍋滄API璋冪敤锛宻treamId锛�%s/%s", deviceId, channelId ));
+		logger.debug(String.format("璁惧棰勮/鍥炴斁鍋滄API璋冪敤锛宻treamId锛�%s_%s", deviceId, channelId ));
 
-		UUID uuid = UUID.randomUUID();
+		String uuid = UUID.randomUUID().toString();
 		DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
 
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
-		resultHolder.put(DeferredResultHolder.CALLBACK_CMD_STOP + uuid, result);
-		Device device = storager.queryVideoDevice(deviceId);
-		cmder.streamByeCmd(deviceId, channelId, (event) -> {
-			StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
-			if (streamInfo == null) {
-				RequestMessage msg = new RequestMessage();
-				msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
-				msg.setData("鐐规挱鏈壘鍒�");
-				resultHolder.invokeResult(msg);
-				storager.stopPlay(deviceId, channelId);
-			}else {
-				redisCatchStorage.stopPlay(streamInfo);
-				storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
-				RequestMessage msg = new RequestMessage();
-				msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
-				//Response response = event.getResponse();
-				msg.setData(String.format("success"));
-				resultHolder.invokeResult(msg);
-			}
-			mediaServerService.closeRTPServer(device, channelId);
+		String key = DeferredResultHolder.CALLBACK_CMD_STOP + deviceId + channelId;
+		resultHolder.put(key, uuid, result);
+		StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
+		if (streamInfo == null) {
+			RequestMessage msg = new RequestMessage();
+			msg.setId(uuid);
+			msg.setKey(key);
+			msg.setData("鐐规挱鏈壘鍒�");
+			resultHolder.invokeAllResult(msg);
+			storager.stopPlay(deviceId, channelId);
+			return result;
+		}
+		cmder.streamByeCmd(deviceId, channelId, streamInfo.getStream(), null, eventResult -> {
+			redisCatchStorage.stopPlay(streamInfo);
+			storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
+			RequestMessage msgForSuccess = new RequestMessage();
+			msgForSuccess.setId(uuid);
+			msgForSuccess.setKey(key);
+			msgForSuccess.setData(String.format("success"));
+			resultHolder.invokeAllResult(msgForSuccess);
 		});
 
 		if (deviceId != null || channelId != null) {
@@ -134,24 +129,29 @@
 			json.put("deviceId", deviceId);
 			json.put("channelId", channelId);
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
+			msg.setId(uuid);
+			msg.setKey(key);
 			msg.setData(json.toString());
-			resultHolder.invokeResult(msg);
+			resultHolder.invokeAllResult(msg);
 		} else {
 			logger.warn("璁惧棰勮/鍥炴斁鍋滄API璋冪敤澶辫触锛�");
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
+			msg.setId(uuid);
+			msg.setKey(key);
 			msg.setData("streamId null");
-			resultHolder.invokeResult(msg);
+			resultHolder.invokeAllResult(msg);
 		}
 
 		// 瓒呮椂澶勭悊
 		result.onTimeout(()->{
-			logger.warn(String.format("璁惧棰勮/鍥炴斁鍋滄瓒呮椂锛宒eviceId/channelId锛�%s/%s ", deviceId, channelId));
+			logger.warn(String.format("璁惧棰勮/鍥炴斁鍋滄瓒呮椂锛宒eviceId/channelId锛�%s_%s ", deviceId, channelId));
+			redisCatchStorage.stopPlay(streamInfo);
+			storager.stopPlay(streamInfo.getDeviceID(), streamInfo.getChannelId());
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
+			msg.setId(uuid);
+			msg.setKey(key);
 			msg.setData("Timeout");
-			resultHolder.invokeResult(msg);
+			resultHolder.invokeAllResult(msg);
 		});
 		return result;
 	}
@@ -161,15 +161,13 @@
 	 * @param streamId 娴両D
 	 * @return
 	 */
-	@ApiOperation("灏嗕笉鏄痟264鐨勮棰戦�氳繃ffmpeg 杞爜涓篽264 + aac")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "streamId", value = "瑙嗛娴両D", dataTypeClass = String.class),
-	})
+	@Operation(summary = "灏嗕笉鏄痟264鐨勮棰戦�氳繃ffmpeg 杞爜涓篽264 + aac")
+	@Parameter(name = "streamId", description = "瑙嗛娴両D", required = true)
 	@PostMapping("/convert/{streamId}")
 	public ResponseEntity<String> playConvert(@PathVariable String streamId) {
 		StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
 		if (streamInfo == null) {
-			streamInfo = redisCatchStorage.queryPlaybackByStreamId(streamId);
+			streamInfo = redisCatchStorage.queryPlayback(null, null, streamId, null);
 		}
 		if (streamInfo == null) {
 			logger.warn("瑙嗛杞爜API璋冪敤澶辫触锛�, 瑙嗛娴佸凡缁忓仠姝�!");
@@ -192,7 +190,7 @@
 				JSONObject data = jsonObject.getJSONObject("data");
 				if (data != null) {
 				   	result.put("key", data.getString("key"));
-					StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId, mediaInfo.getId());
+					StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId, mediaInfo.getId(), false);
 					result.put("data", streamInfoResult);
 				}
 			}else {
@@ -208,10 +206,9 @@
 	 * @param key
 	 * @return
 	 */
-	@ApiOperation("缁撴潫杞爜")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "key", value = "瑙嗛娴乲ey", dataTypeClass = String.class),
-	})
+	@Operation(summary = "缁撴潫杞爜")
+	@Parameter(name = "key", description = "瑙嗛娴乲ey", required = true)
+	@Parameter(name = "mediaServerId", description = "娴佸獟浣撴湇鍔D", required = true)
 	@PostMapping("/convertStop/{key}")
 	public ResponseEntity<String> playConvertStop(@PathVariable String key, String mediaServerId) {
 		JSONObject result = new JSONObject();
@@ -247,10 +244,8 @@
 
 	}
 
-	@ApiOperation("璇煶骞挎挱鍛戒护")
-	@ApiImplicitParams({
-			@ApiImplicitParam(name = "deviceId", value = "璁惧Id", dataTypeClass = String.class),
-	})
+	@Operation(summary = "璇煶骞挎挱鍛戒护")
+	@Parameter(name = "deviceId", description = "璁惧鍥芥爣缂栧彿", required = true)
     @GetMapping("/broadcast/{deviceId}")
     @PostMapping("/broadcast/{deviceId}")
     public DeferredResult<ResponseEntity<String>> broadcastApi(@PathVariable String deviceId) {
@@ -259,10 +254,18 @@
         }
         Device device = storager.queryVideoDevice(deviceId);
 		DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(3 * 1000L);
+		String key  = DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId;
+		if (resultHolder.exist(key, null)) {
+			result.setResult(new ResponseEntity<>("璁惧浣跨敤涓�",HttpStatus.OK));
+			return result;
+		}
+		String uuid  = UUID.randomUUID().toString();
         if (device == null) {
-			resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result);
+
+			resultHolder.put(key, key,  result);
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId);
+			msg.setKey(key);
+			msg.setId(uuid);
 			JSONObject json = new JSONObject();
 			json.put("DeviceID", deviceId);
 			json.put("CmdType", "Broadcast");
@@ -273,14 +276,14 @@
 			return result;
 		}
 		cmder.audioBroadcastCmd(device, (event) -> {
-			Response response = event.getResponse();
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId);
+			msg.setKey(key);
+			msg.setId(uuid);
 			JSONObject json = new JSONObject();
 			json.put("DeviceID", deviceId);
 			json.put("CmdType", "Broadcast");
 			json.put("Result", "Failed");
-			json.put("Description", String.format("璇煶骞挎挱鎿嶄綔澶辫触锛岄敊璇爜锛� %s, %s", response.getStatusCode(), response.getReasonPhrase()));
+			json.put("Description", String.format("璇煶骞挎挱鎿嶄綔澶辫触锛岄敊璇爜锛� %s, %s", event.statusCode, event.msg));
 			msg.setData(json);
 			resultHolder.invokeResult(msg);
 		});
@@ -288,7 +291,8 @@
 		result.onTimeout(() -> {
 			logger.warn(String.format("璇煶骞挎挱鎿嶄綔瓒呮椂, 璁惧鏈繑鍥炲簲绛旀寚浠�"));
 			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId);
+			msg.setKey(key);
+			msg.setId(uuid);
 			JSONObject json = new JSONObject();
 			json.put("DeviceID", deviceId);
 			json.put("CmdType", "Broadcast");
@@ -297,11 +301,11 @@
 			msg.setData(json);
 			resultHolder.invokeResult(msg);
 		});
-		resultHolder.put(DeferredResultHolder.CALLBACK_CMD_BROADCAST + deviceId, result);
+		resultHolder.put(key, uuid, result);
 		return result;
 	}
 
-	@ApiOperation("鑾峰彇鎵�鏈夌殑ssrc")
+	@Operation(summary = "鑾峰彇鎵�鏈夌殑ssrc")
 	@GetMapping("/ssrc")
 	public WVPResult<JSONObject> getSSRC() {
 		if (logger.isDebugEnabled()) {
@@ -314,7 +318,7 @@
 			jsonObject.put("deviceId", transaction.getDeviceId());
 			jsonObject.put("channelId", transaction.getChannelId());
 			jsonObject.put("ssrc", transaction.getSsrc());
-			jsonObject.put("streamId", transaction.getStreamId());
+			jsonObject.put("streamId", transaction.getStream());
 			objects.add(jsonObject);
 		}
 

--
Gitblit v1.8.0