From 64b6a3560399cfe742d998209c3ff315c4856b9e Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期四, 04 一月 2024 11:33:29 +0800
Subject: [PATCH] Merge branch '2.6.9' into wvp-28181-2.0
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 68 +++++++++++++---------------------
1 files changed, 26 insertions(+), 42 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 7ca07ee..2376942 100755
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -1,6 +1,5 @@
package com.genersoft.iot.vmp.service.impl;
-import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.genersoft.iot.vmp.common.InviteInfo;
@@ -15,11 +14,9 @@
import com.genersoft.iot.vmp.gb28181.bean.*;
import com.genersoft.iot.vmp.gb28181.event.SipSubscribe;
import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
-import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
-import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe;
@@ -32,6 +29,7 @@
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
import com.genersoft.iot.vmp.storager.dao.CloudRecordServiceMapper;
+import com.genersoft.iot.vmp.utils.CloudRecordUtils;
import com.genersoft.iot.vmp.utils.DateUtil;
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
import gov.nist.javax.sip.message.SIPResponse;
@@ -49,11 +47,9 @@
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
-import java.time.Instant;
import java.util.List;
import java.util.UUID;
import java.util.Vector;
-import java.util.concurrent.TimeUnit;
@SuppressWarnings(value = {"rawtypes", "unchecked"})
@Service
@@ -232,6 +228,15 @@
HookSubscribeForStreamChange hookSubscribe = HookSubscribeFactory.on_stream_changed("rtp", ssrcInfo.getStream(), true, "rtsp", mediaServerItem.getId());
subscribe.removeSubscribe(hookSubscribe);
}
+ }else {
+ logger.info("[鐐规挱瓒呮椂] 鏀舵祦瓒呮椂 deviceId: {}, channelId: {},鐮佹祦绫诲瀷锛歿}锛岀鍙o細{}, SSRC: {}",
+ device.getDeviceId(), channelId, device.isSwitchPrimarySubStream() ? "杈呯爜娴�" : "涓荤爜娴�",
+ ssrcInfo.getPort(), ssrcInfo.getSsrc());
+
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
+
+ mediaServerService.closeRTPServer(mediaServerItem.getId(), ssrcInfo.getStream());
+ streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
}
}, userSetting.getPlayTimeout());
@@ -262,6 +267,7 @@
InviteOKHandler(eventResult, ssrcInfo, mediaServerItem, device, channelId,
timeOutTaskKey, callback, inviteInfo, InviteSessionType.PLAY);
}, (event) -> {
+ logger.info("[鐐规挱澶辫触] deviceId: {}, channelId:{}, {}: {}", device.getDeviceId(), channelId, event.statusCode, event.msg);
dynamicTask.stop(timeOutTaskKey);
mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream());
// 閲婃斁ssrc
@@ -303,7 +309,13 @@
if (!device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
return;
}
- String substring = contentString.substring(0, contentString.indexOf("y="));
+
+ String substring;
+ if (contentString.indexOf("y=") > 0) {
+ substring = contentString.substring(0, contentString.indexOf("y="));
+ }else {
+ substring = contentString;
+ }
try {
SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
int port = -1;
@@ -393,7 +405,7 @@
deviceChannel.setStreamId(streamInfo.getStream());
storager.startPlay(deviceId, channelId, streamInfo.getStream());
}
- InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAYBACK, deviceId, channelId);
+ InviteInfo inviteInfo = inviteStreamService.getInviteInfoByStream(InviteSessionType.PLAYBACK, ((OnStreamChangedHookParam) param).getStream());
if (inviteInfo != null) {
inviteInfo.setStatus(InviteSessionStatus.ok);
@@ -418,23 +430,6 @@
}
if (mediaServerItem == null) {
logger.warn("鐐规挱鏃舵湭鎵惧埌鍙娇鐢ㄧ殑ZLM...");
- }
- return mediaServerItem;
- }
-
- @Override
- public MediaServerItem getNewMediaServerItemHasAssist(Device device) {
- if (device == null) {
- return null;
- }
- MediaServerItem mediaServerItem;
- if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) {
- mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(true);
- } else {
- mediaServerItem = mediaServerService.getOne(device.getMediaServerId());
- }
- if (mediaServerItem == null) {
- logger.warn("[鑾峰彇鍙敤鐨刏LM鑺傜偣]鏈壘鍒板彲浣跨敤鐨刏LM...");
}
return mediaServerItem;
}
@@ -536,7 +531,6 @@
// 澶勭悊鏀跺埌200ok鍚庣殑TCP涓诲姩杩炴帴浠ュ強SSRC涓嶄竴鑷寸殑闂
InviteOKHandler(eventResult, ssrcInfo, mediaServerItem, device, channelId,
playBackTimeOutTaskKey, callback, inviteInfo, InviteSessionType.PLAYBACK);
-
}, errorEvent);
} catch (InvalidArgumentException | SipException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 褰曞儚鍥炴斁: {}", e.getMessage());
@@ -557,6 +551,10 @@
ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
String contentString = new String(responseEvent.getResponse().getRawContent());
String ssrcInResponse = SipUtils.getSsrcFromSdp(contentString);
+ // 鍏煎鍥炲鐨勬秷鎭腑缂哄皯ssrc(y瀛楁)鐨勬儏鍐�
+ if (ssrcInResponse == null) {
+ ssrcInResponse = ssrcInfo.getSsrc();
+ }
if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
// ssrc 涓�鑷�
if (mediaServerItem.isRtpEnable()) {
@@ -635,13 +633,14 @@
+
@Override
public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback) {
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
}
- MediaServerItem newMediaServerItem = getNewMediaServerItemHasAssist(device);
+ MediaServerItem newMediaServerItem = this.getNewMediaServerItem(device);
if (newMediaServerItem == null) {
callback.run(InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getCode(),
InviteErrorCode.ERROR_FOR_ASSIST_NOT_READY.getMsg(),
@@ -728,7 +727,7 @@
logger.info("[褰曞儚涓嬭浇] 鏀跺埌褰曞儚鍐欏叆纾佺洏娑堟伅鍐呭锛� " + hookParam);
OnRecordMp4HookParam recordMp4HookParam = (OnRecordMp4HookParam)hookParam;
String filePath = recordMp4HookParam.getFile_path();
- DownloadFileInfo downloadFileInfo = getDownloadFilePath(mediaServerItem, filePath);
+ DownloadFileInfo downloadFileInfo = CloudRecordUtils.getDownloadFilePath(mediaServerItem, filePath);
InviteInfo inviteInfoForNew = inviteStreamService.getInviteInfo(inviteInfo.getType(), inviteInfo.getDeviceId()
, inviteInfo.getChannelId(), inviteInfo.getStream());
inviteInfoForNew.getStreamInfo().setDownLoadFilePath(downloadFileInfo);
@@ -822,21 +821,6 @@
}
inviteStreamService.updateInviteInfo(inviteInfo);
return inviteInfo.getStreamInfo();
- }
-
- private DownloadFileInfo getDownloadFilePath(MediaServerItem mediaServerItem, String filePath) {
- DownloadFileInfo downloadFileInfo = new DownloadFileInfo();
-
- String pathTemplate = "%s://%s:%s/index/api/downloadFile?file_path=" + filePath;
-
- downloadFileInfo.setHttpPath(String.format(pathTemplate, "http", mediaServerItem.getStreamIp(),
- mediaServerItem.getHttpPort()));
-
- if (mediaServerItem.getHttpSSlPort() > 0) {
- downloadFileInfo.setHttpsPath(String.format(pathTemplate, "https", mediaServerItem.getStreamIp(),
- mediaServerItem.getHttpSSlPort()));
- }
- return downloadFileInfo;
}
private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, HookParam hookParam, String deviceId, String channelId, String startTime, String endTime) {
--
Gitblit v1.8.0