From 0acf13445a2e3120f3d3599238401c9f2885d711 Mon Sep 17 00:00:00 2001
From: lawrencehj <1934378145@qq.com>
Date: 星期三, 23 六月 2021 16:21:12 +0800
Subject: [PATCH] 改为fmp4截图

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |   51 ++++++++++++++++++++++-----------------------------
 1 files changed, 22 insertions(+), 29 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 1af7e6e..0f35945 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
@@ -1,7 +1,7 @@
 package com.genersoft.iot.vmp.vmanager.gb28181.play;
 
 import com.genersoft.iot.vmp.common.StreamInfo;
-import com.genersoft.iot.vmp.conf.MediaServerConfig;
+import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
 import com.genersoft.iot.vmp.gb28181.bean.Device;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
@@ -73,30 +73,21 @@
 	public DeferredResult<ResponseEntity<String>> play(@PathVariable String deviceId,
 													   @PathVariable String channelId) {
 
-
 		PlayResult playResult = playService.play(deviceId, channelId, null, null);
 
-		// 瓒呮椂澶勭悊
-		playResult.getResult().onTimeout(()->{
-			logger.warn(String.format("璁惧鐐规挱瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
-			// 閲婃斁rtpserver
-			cmder.closeRTPServer(playResult.getDevice(), channelId);
-			RequestMessage msg = new RequestMessage();
-			msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + playResult.getUuid());
-			msg.setData("Timeout");
-			resultHolder.invokeResult(msg);
-		});
+
 		return playResult.getResult();
 	}
 
 	@ApiOperation("鍋滄鐐规挱")
 	@ApiImplicitParams({
-			@ApiImplicitParam(name = "streamId", value = "瑙嗛娴両D", dataTypeClass = String.class),
+			@ApiImplicitParam(name = "deviceId", value = "璁惧ID", dataTypeClass = String.class),
+			@ApiImplicitParam(name = "channelId", value = "閫氶亾ID", dataTypeClass = String.class),
 	})
-	@PostMapping("/stop/{streamId}")
-	public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String streamId) {
+	@GetMapping("/stop/{deviceId}/{channelId}")
+	public DeferredResult<ResponseEntity<String>> playStop(@PathVariable String deviceId, @PathVariable String channelId) {
 
-		logger.debug(String.format("璁惧棰勮/鍥炴斁鍋滄API璋冪敤锛宻treamId锛�%s", streamId));
+		logger.debug(String.format("璁惧棰勮/鍥炴斁鍋滄API璋冪敤锛宻treamId锛�%s/$s", deviceId, channelId ));
 
 		UUID uuid = UUID.randomUUID();
 		DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>();
@@ -104,13 +95,14 @@
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
 		resultHolder.put(DeferredResultHolder.CALLBACK_CMD_STOP + uuid, result);
 
-		cmder.streamByeCmd(streamId, event -> {
-			StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
+		cmder.streamByeCmd(deviceId, channelId, event -> {
+			StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
 			if (streamInfo == null) {
 				RequestMessage msg = new RequestMessage();
-				msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
-				msg.setData("streamId not found");
+				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());
@@ -122,9 +114,10 @@
 			}
 		});
 
-		if (streamId != null) {
+		if (deviceId != null || channelId != null) {
 			JSONObject json = new JSONObject();
-			json.put("streamId", streamId);
+			json.put("deviceId", deviceId);
+			json.put("channelId", channelId);
 			RequestMessage msg = new RequestMessage();
 			msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
 			msg.setData(json.toString());
@@ -139,7 +132,7 @@
 
 		// 瓒呮椂澶勭悊
 		result.onTimeout(()->{
-			logger.warn(String.format("璁惧棰勮/鍥炴斁鍋滄瓒呮椂锛宻treamId锛�%s ", streamId));
+			logger.warn(String.format("璁惧棰勮/鍥炴斁鍋滄瓒呮椂锛宒eviceId/channelId锛�%s/$s ", deviceId, channelId));
 			RequestMessage msg = new RequestMessage();
 			msg.setId(DeferredResultHolder.CALLBACK_CMD_STOP + uuid);
 			msg.setData("Timeout");
@@ -159,7 +152,7 @@
 	})
 	@PostMapping("/convert/{streamId}")
 	public ResponseEntity<String> playConvert(@PathVariable String streamId) {
-		StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
+		StreamInfo streamInfo = streamId.startsWith("gb_play_") ? redisCatchStorage.queryPlayByStreamId(streamId) : redisCatchStorage.queryPlaybackByStreamId(streamId);
 		if (streamInfo == null) {
 			logger.warn("瑙嗛杞爜API璋冪敤澶辫触锛�, 瑙嗛娴佸凡缁忓仠姝�!");
 			return new ResponseEntity<String>("鏈壘鍒拌棰戞祦淇℃伅, 瑙嗛娴佸彲鑳藉凡缁忓仠姝�", HttpStatus.OK);
@@ -169,19 +162,19 @@
 			logger.warn("瑙嗛杞爜API璋冪敤澶辫触锛�, 瑙嗛娴佸凡鍋滄鎺ㄦ祦!");
 			return new ResponseEntity<String>("鎺ㄦ祦淇℃伅鍦ㄦ祦濯掍綋涓笉瀛樺湪, 瑙嗛娴佸彲鑳藉凡鍋滄鎺ㄦ祦", HttpStatus.OK);
 		} else {
-			MediaServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
+			ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
 			String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
 					streamId );
 			String srcUrl = String.format("rtsp://%s:%s/rtp/%s", "127.0.0.1", mediaInfo.getRtspPort(), streamId);
-			JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(srcUrl, dstUrl, "1000000");
-			System.out.println(jsonObject);
+			JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(srcUrl, dstUrl, "1000000", true, false, null);
+			logger.info(jsonObject.toJSONString());
 			JSONObject result = new JSONObject();
 			if (jsonObject != null && jsonObject.getInteger("code") == 0) {
 				   result.put("code", 0);
 				JSONObject data = jsonObject.getJSONObject("data");
 				if (data != null) {
 				   	result.put("key", data.getString("key"));
-					StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStream("convert", streamId);
+					StreamInfo streamInfoResult = mediaService.getStreamInfoByAppAndStreamWithCheck("convert", streamId);
 					result.put("data", streamInfoResult);
 				}
 			}else {
@@ -205,7 +198,7 @@
 	public ResponseEntity<String> playConvertStop(@PathVariable String key) {
 
 		JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(key);
-		System.out.println(jsonObject);
+		logger.info(jsonObject.toJSONString());
 		JSONObject result = new JSONObject();
 		if (jsonObject != null && jsonObject.getInteger("code") == 0) {
 			result.put("code", 0);

--
Gitblit v1.8.0