From c25a99d60bef3d3bbd59fee895bd658928fd00db Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 10 一月 2024 16:17:29 +0800
Subject: [PATCH] 修复空指针异常

---
 src/main/java/com/genersoft/iot/vmp/vmanager/gb28181/play/PlayController.java |   25 +++++++++++++++++++------
 1 files changed, 19 insertions(+), 6 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
old mode 100644
new mode 100755
index b9e778e..6db7e4b
--- 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
@@ -40,6 +40,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.sip.InvalidArgumentException;
 import javax.sip.SipException;
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.text.ParseException;
 import java.util.List;
 import java.util.UUID;
@@ -92,6 +94,7 @@
 	public DeferredResult<WVPResult<StreamContent>> play(HttpServletRequest request, @PathVariable String deviceId,
 														 @PathVariable String channelId) {
 
+		logger.info("[寮�濮嬬偣鎾璢 deviceId锛歿}, channelId锛歿}, ", deviceId, channelId);
 		// 鑾峰彇鍙敤鐨剒lm
 		Device device = storager.queryVideoDevice(deviceId);
 		MediaServerItem newMediaServerItem = playService.getNewMediaServerItem(device);
@@ -104,19 +107,21 @@
 		DeferredResult<WVPResult<StreamContent>> result = new DeferredResult<>(userSetting.getPlayTimeout().longValue());
 
 		result.onTimeout(()->{
-			logger.info("鐐规挱鎺ュ彛绛夊緟瓒呮椂");
+			logger.info("[鐐规挱绛夊緟瓒呮椂] deviceId锛歿}, channelId锛歿}, ", deviceId, channelId);
 			// 閲婃斁rtpserver
 			WVPResult<StreamInfo> wvpResult = new WVPResult<>();
 			wvpResult.setCode(ErrorCode.ERROR100.getCode());
 			wvpResult.setMsg("鐐规挱瓒呮椂");
 			requestMessage.setData(wvpResult);
-			resultHolder.invokeResult(requestMessage);
+			resultHolder.invokeAllResult(requestMessage);
+			inviteStreamService.removeInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+			storager.stopPlay(deviceId, channelId);
 		});
 
 		// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
 		resultHolder.put(key, uuid, result);
 
-		playService.play(newMediaServerItem, deviceId, channelId, (code, msg, data) -> {
+		playService.play(newMediaServerItem, deviceId, channelId, null, (code, msg, data) -> {
 			WVPResult<StreamContent> wvpResult = new WVPResult<>();
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
 				wvpResult.setCode(ErrorCode.SUCCESS.getCode());
@@ -125,7 +130,15 @@
 				if (data != null) {
 					StreamInfo streamInfo = (StreamInfo)data;
 					if (userSetting.getUseSourceIpAsStreamIp()) {
-						streamInfo.channgeStreamIp(request.getLocalName());
+						streamInfo=streamInfo.clone();//娣辨嫹璐�
+						String host;
+						try {
+							URL url=new URL(request.getRequestURL().toString());
+							host=url.getHost();
+						} catch (MalformedURLException e) {
+							host=request.getLocalAddr();
+						}
+						streamInfo.channgeStreamIp(host);
 					}
 					wvpResult.setData(new StreamContent(streamInfo));
 				}
@@ -163,7 +176,7 @@
 		}
 		if (InviteSessionStatus.ok == inviteInfo.getStatus()) {
 			try {
-				logger.warn("[鍋滄鐐规挱] {}/{}", device.getDeviceId(), channelId);
+				logger.info("[鍋滄鐐规挱] {}/{}", device.getDeviceId(), channelId);
 				cmder.streamByeCmd(device, channelId, inviteInfo.getStream(), null, null);
 			} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
 				logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱锛� 鍙戦�丅YE: {}", e.getMessage());
@@ -359,7 +372,7 @@
 		message.setKey(key);
 		message.setId(uuid);
 
-		String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + "jpg";
+		String fileName = deviceId + "_" + channelId + "_" + DateUtil.getNowForUrl() + ".jpg";
 		playService.getSnap(deviceId, channelId, fileName, (code, msg, data) -> {
 			if (code == InviteErrorCode.SUCCESS.getCode()) {
 				message.setData(data);

--
Gitblit v1.8.0