From 341ea7110a954bf72493990e02eef5048504c3d4 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期五, 05 十一月 2021 10:04:45 +0800
Subject: [PATCH] 添加注释
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 62 +++++++++++++++----------------
1 files changed, 30 insertions(+), 32 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index 3e34646..d7b8ffe 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -34,6 +34,10 @@
import org.springframework.util.ResourceUtils;
import org.springframework.web.context.request.async.DeferredResult;
+import javax.sip.DialogTerminatedEvent;
+import javax.sip.ResponseEvent;
+import javax.sip.TimeoutEvent;
+import javax.sip.TransactionTerminatedEvent;
import javax.sip.message.Response;
import java.io.FileNotFoundException;
import java.util.UUID;
@@ -78,9 +82,11 @@
@Override
public PlayResult play(MediaServerItem mediaServerItem, String deviceId, String channelId, ZLMHttpHookSubscribe.Event hookEvent, SipSubscribe.Event errorEvent) {
PlayResult playResult = new PlayResult();
+ RequestMessage msg = new RequestMessage();
+ String key = DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId;
+ msg.setKey(key);
+ msg.setId(playResult.getUuid());
if (mediaServerItem == null) {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + playResult.getUuid());
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(-1);
wvpResult.setMsg("鏈壘鍒板彲鐢ㄧ殑zlm");
@@ -88,20 +94,19 @@
resultHolder.invokeResult(msg);
return playResult;
}
+
Device device = storager.queryVideoDevice(deviceId);
StreamInfo streamInfo = redisCatchStorage.queryPlayByDevice(deviceId, channelId);
playResult.setDevice(device);
- UUID uuid = UUID.randomUUID();
- playResult.setUuid(uuid.toString());
+ String uuid = UUID.randomUUID().toString();
+ playResult.setUuid(uuid);
DeferredResult<ResponseEntity<String>> result = new DeferredResult<ResponseEntity<String>>(userSetup.getPlayTimeout());
playResult.setResult(result);
// 褰曞儚鏌ヨ浠hannelId浣滀负deviceId鏌ヨ
- resultHolder.put(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid, result);
+ resultHolder.put(key, uuid, result);
// 瓒呮椂澶勭悊
result.onTimeout(()->{
logger.warn(String.format("璁惧鐐规挱瓒呮椂锛宒eviceId锛�%s 锛宑hannelId锛�%s", deviceId, channelId));
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + playResult.getUuid());
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(-1);
SIPDialog dialog = streamSession.getDialog(deviceId, channelId);
@@ -115,7 +120,8 @@
cmder.streamByeCmd(device.getDeviceId(), channelId);
// 閲婃斁rtpserver
mediaServerService.closeRTPServer(playResult.getDevice(), channelId);
- resultHolder.invokeResult(msg);
+ // 鍥炲涔嬪墠鎵�鏈夌殑鐐规挱璇锋眰
+ resultHolder.invokeAllResult(msg);
});
result.onCompletion(()->{
// 鐐规挱缁撴潫鏃惰皟鐢ㄦ埅鍥炬帴鍙�
@@ -168,31 +174,27 @@
hookEvent.response(mediaServerItem, response);
}
}, (event) -> {
- // 鐐规挱杩斿洖sip閿欒
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
- Response response = event.getResponse();
- mediaServerService.closeRTPServer(playResult.getDevice(), channelId);
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(-1);
- wvpResult.setMsg(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", response.getStatusCode(), response.getReasonPhrase()));
+ // 鐐规挱杩斿洖sip閿欒
+ mediaServerService.closeRTPServer(playResult.getDevice(), channelId);
+ wvpResult.setMsg(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg));
msg.setData(wvpResult);
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
if (errorEvent != null) {
errorEvent.response(event);
}
+
});
} else {
String streamId = streamInfo.getStreamId();
if (streamId == null) {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(-1);
wvpResult.setMsg(String.format("鐐规挱澶辫触锛� redis缂撳瓨streamId绛変簬null"));
msg.setData(wvpResult);
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
return playResult;
}
String mediaServerId = streamInfo.getMediaServerId();
@@ -200,8 +202,6 @@
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(mediaInfo, streamId);
if (rtpInfo != null && rtpInfo.getBoolean("exist")) {
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(0);
@@ -209,7 +209,7 @@
wvpResult.setData(streamInfo);
msg.setData(wvpResult);
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
if (hookEvent != null) {
hookEvent.response(mediaServerItem, JSONObject.parseObject(JSON.toJSONString(streamInfo)));
}
@@ -229,15 +229,11 @@
onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString());
}, (event) -> {
mediaServerService.closeRTPServer(playResult.getDevice(), channelId);
- RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
- Response response = event.getResponse();
-
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(-1);
- wvpResult.setMsg(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", response.getStatusCode(), response.getReasonPhrase()));
+ wvpResult.setMsg(String.format("鐐规挱澶辫触锛� 閿欒鐮侊細 %s, %s", event.statusCode, event.msg));
msg.setData(wvpResult);
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
});
}
}
@@ -248,7 +244,8 @@
@Override
public void onPublishHandlerForPlay(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
+ msg.setId(uuid);
+ msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId);
StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid);
if (streamInfo != null) {
DeviceChannel deviceChannel = storager.queryChannel(deviceId, channelId);
@@ -261,15 +258,15 @@
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(0);
- wvpResult.setMsg("sucess");
+ wvpResult.setMsg("success");
wvpResult.setData(streamInfo);
msg.setData(wvpResult);
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
} else {
logger.warn("璁惧棰勮API璋冪敤澶辫触锛�");
msg.setData("璁惧棰勮API璋冪敤澶辫触锛�");
- resultHolder.invokeResult(msg);
+ resultHolder.invokeAllResult(msg);
}
}
@@ -292,7 +289,8 @@
@Override
public void onPublishHandlerForPlayBack(MediaServerItem mediaServerItem, JSONObject resonse, String deviceId, String channelId, String uuid) {
RequestMessage msg = new RequestMessage();
- msg.setId(DeferredResultHolder.CALLBACK_CMD_PlAY + uuid);
+ msg.setKey(DeferredResultHolder.CALLBACK_CMD_PLAY + deviceId + channelId);
+ msg.setId(uuid);
StreamInfo streamInfo = onPublishHandler(mediaServerItem, resonse, deviceId, channelId, uuid);
if (streamInfo != null) {
redisCatchStorage.startPlayback(streamInfo);
--
Gitblit v1.8.0