From a2d93fce811acc83ad5ff0b4a93403db22795a10 Mon Sep 17 00:00:00 2001
From: winfed <chinesezwf@gmail.com>
Date: 星期五, 09 六月 2023 15:19:18 +0800
Subject: [PATCH] fix:修复拉流代理配置展示问题:音频、录制、无人观看
---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 135 ++++++++++++++++++++++++++++-----------------
1 files changed, 84 insertions(+), 51 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 879e9ca..efba170 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
@@ -26,7 +26,7 @@
import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.*;
-import com.genersoft.iot.vmp.service.bean.InviteErrorCallback;
+import com.genersoft.iot.vmp.service.bean.ErrorCallback;
import com.genersoft.iot.vmp.service.bean.InviteErrorCode;
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
@@ -44,6 +44,7 @@
import javax.sip.InvalidArgumentException;
import javax.sip.ResponseEvent;
import javax.sip.SipException;
+import java.io.File;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.ParseException;
@@ -114,7 +115,7 @@
@Override
- public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, InviteErrorCallback<Object> callback) {
+ public SSRCInfo play(MediaServerItem mediaServerItem, String deviceId, String channelId, ErrorCallback<Object> callback) {
if (mediaServerItem == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "鏈壘鍒板彲鐢ㄧ殑zlm");
}
@@ -179,7 +180,7 @@
@Override
public void play(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, Device device, String channelId,
- InviteErrorCallback<Object> callback) {
+ ErrorCallback<Object> callback) {
if (mediaServerItem == null || ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
@@ -187,7 +188,20 @@
null);
return;
}
- logger.info("[鐐规挱寮�濮媇 deviceId: {}, channelId: {},鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
+ logger.info("\r\n" +
+ " [鐐规挱寮�濮媇 \r\n" +
+ "deviceId : {}, \r\n" +
+ "channelId : {},\r\n" +
+ "鏀舵祦绔彛 : {}, \r\n" +
+ "鏀舵祦妯″紡 : {}, \r\n" +
+ "SSRC : {}, \r\n" +
+ "SSRC鏍¢獙 锛歿}",
+ device.getDeviceId(),
+ channelId,
+ ssrcInfo.getPort(),
+ device.getStreamMode(),
+ ssrcInfo.getSsrc(),
+ device.isSsrcCheck());
//绔彛鑾峰彇澶辫触鐨剆srcInfo 娌℃湁蹇呰鍙戦�佺偣鎾寚浠�
if (ssrcInfo.getPort() <= 0) {
@@ -328,23 +342,13 @@
return;
}
logger.info("[鐐规挱娑堟伅] 鏀跺埌invite 200, 鍙戠幇涓嬬骇鑷畾涔変簡ssrc: {}", ssrcInResponse);
+
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
logger.info("[鐐规挱娑堟伅] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
- if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
- // ssrc 涓嶅彲鐢�
- logger.info("[鐐规挱娑堟伅] SSRC淇鏃跺彂鐜皊src涓嶅彲浣跨敤 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
- // 閲婃斁ssrc
- ssrcFactory.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
- streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
- callback.run(InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
- InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
- inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
- InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
- InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
+ // 閲婃斁ssrc
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
- return;
- }
// 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄噸鏂拌缃洃鍚嵆鍙�
if (!mediaServerItem.isRtpEnable()) {
// 娣诲姞璁㈤槄
@@ -367,7 +371,7 @@
return;
}
callback.run(InviteErrorCode.SUCCESS.getCode(),
- InviteErrorCode.SUCCESS.getMsg(), null);
+ InviteErrorCode.SUCCESS.getMsg(), streamInfo);
inviteStreamService.call(InviteSessionType.PLAY, device.getDeviceId(), channelId, null,
InviteErrorCode.SUCCESS.getCode(),
InviteErrorCode.SUCCESS.getMsg(),
@@ -387,8 +391,6 @@
}
dynamicTask.stop(timeOutTaskKey);
- // 閲婃斁ssrc
- mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
@@ -522,7 +524,7 @@
@Override
public void playBack(String deviceId, String channelId, String startTime,
- String endTime, InviteErrorCallback<Object> callback) {
+ String endTime, ErrorCallback<Object> callback) {
Device device = storager.queryVideoDevice(deviceId);
if (device == null) {
return;
@@ -535,7 +537,7 @@
@Override
public void playBack(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo,
String deviceId, String channelId, String startTime,
- String endTime, InviteErrorCallback<Object> callback) {
+ String endTime, ErrorCallback<Object> callback) {
if (mediaServerItem == null || ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(),
@@ -653,17 +655,8 @@
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
logger.info("[褰曞儚鍥炴斁] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
- if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
- // ssrc 涓嶅彲鐢�
- logger.info("[褰曞儚鍥炴斁] SSRC淇鏃跺彂鐜皊src涓嶅彲浣跨敤 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
- // 閲婃斁ssrc
- dynamicTask.stop(playBackTimeOutTaskKey);
- mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
- streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
- callback.run(InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
- InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
- return;
- }
+ // 閲婃斁ssrc
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
// 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
if (!mediaServerItem.isRtpEnable()) {
@@ -692,8 +685,6 @@
}
dynamicTask.stop(playBackTimeOutTaskKey);
- // 閲婃斁ssrc
- mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
@@ -725,7 +716,7 @@
@Override
- public void download(String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) {
+ 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;
@@ -743,7 +734,7 @@
@Override
- public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, InviteErrorCallback<Object> callback) {
+ public void download(MediaServerItem mediaServerItem, SSRCInfo ssrcInfo, String deviceId, String channelId, String startTime, String endTime, int downloadSpeed, ErrorCallback<Object> callback) {
if (mediaServerItem == null || ssrcInfo == null) {
callback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(),
InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(),
@@ -757,7 +748,7 @@
null);
return;
}
- logger.info("[褰曞儚涓嬭浇] deviceId: {}, channelId: {},鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
+ logger.info("[褰曞儚涓嬭浇] deviceId: {}, channelId: {}, 涓嬭浇閫熷害锛歿}, 鏀舵祦绔彛锛歿}, 鏀舵祦妯″紡锛歿}, SSRC: {}, SSRC鏍¢獙锛歿}", device.getDeviceId(), channelId, downloadSpeed, ssrcInfo.getPort(), device.getStreamMode(), ssrcInfo.getSsrc(), device.isSsrcCheck());
// 鍒濆鍖杛edis涓殑invite娑堟伅鐘舵��
InviteInfo inviteInfo = InviteInfo.getinviteInfo(device.getDeviceId(), channelId, ssrcInfo.getStream(), ssrcInfo,
mediaServerItem.getSdpIp(), ssrcInfo.getPort(), device.getStreamMode(), InviteSessionType.DOWNLOAD,
@@ -857,15 +848,8 @@
if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) {
logger.info("[褰曞儚涓嬭浇] SSRC淇 {}->{}", ssrcInfo.getSsrc(), ssrcInResponse);
- if (!ssrcFactory.checkSsrc(mediaServerItem.getId(),ssrcInResponse)) {
- // ssrc 涓嶅彲鐢�
- // 閲婃斁ssrc
- mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
- streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
- callback.run(InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getCode(),
- InviteErrorCode.ERROR_FOR_SSRC_UNAVAILABLE.getMsg(), null);
- return;
- }
+ // 閲婃斁ssrc
+ mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
// 鍗曠鍙fā寮弒treamId涔熸湁鍙樺寲锛岄渶瑕侀噸鏂拌缃洃鍚�
if (!mediaServerItem.isRtpEnable()) {
@@ -888,12 +872,9 @@
cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
} catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
logger.error("[鍛戒护鍙戦�佸け璐 鍋滄鐐规挱锛� 鍙戦�丅YE: {}", e.getMessage());
-
}
dynamicTask.stop(downLoadTimeOutTaskKey);
- // 閲婃斁ssrc
- mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
@@ -970,10 +951,12 @@
private StreamInfo onPublishHandlerForDownload(MediaServerItem mediaServerItemInuse, JSONObject response, String deviceId, String channelId, String startTime, String endTime) {
StreamInfo streamInfo = onPublishHandler(mediaServerItemInuse, response, deviceId, channelId);
if (streamInfo != null) {
+ streamInfo.setProgress(0);
streamInfo.setStartTime(startTime);
streamInfo.setEndTime(endTime);
- InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.DOWNLOAD, deviceId, channelId);
+ InviteInfo inviteInfo = inviteStreamService.getInviteInfo(InviteSessionType.DOWNLOAD, deviceId, channelId, streamInfo.getStream());
if (inviteInfo != null) {
+ logger.info("[褰曞儚涓嬭浇] 鏇存柊invite娑堟伅涓殑stream淇℃伅");
inviteInfo.setStatus(InviteSessionStatus.ok);
inviteInfo.setStreamInfo(streamInfo);
inviteStreamService.updateInviteInfo(inviteInfo);
@@ -1126,4 +1109,54 @@
Device device = storager.queryVideoDevice(inviteInfo.getDeviceId());
cmder.playResumeCmd(device, inviteInfo.getStreamInfo());
}
+
+ @Override
+ public void getSnap(String deviceId, String channelId, String fileName, ErrorCallback errorCallback) {
+ Device device = deviceService.getDevice(deviceId);
+ if (device == null) {
+ errorCallback.run(InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getCode(), InviteErrorCode.ERROR_FOR_PARAMETER_ERROR.getMsg(), null);
+ return;
+ }
+
+ InviteInfo inviteInfo = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+ if (inviteInfo != null) {
+ if (inviteInfo.getStreamInfo() != null) {
+ // 宸插瓨鍦ㄧ嚎鐩存帴鎴浘
+ MediaServerItem mediaServerItemInuse = mediaServerService.getOne(inviteInfo.getStreamInfo().getMediaServerId());
+ String streamUrl;
+ if (mediaServerItemInuse.getRtspPort() != 0) {
+ streamUrl = String.format("rtsp://127.0.0.1:%s/%s/%s", mediaServerItemInuse.getRtspPort(), "rtp", inviteInfo.getStreamInfo().getStream());
+ }else {
+ streamUrl = String.format("http://127.0.0.1:%s/%s/%s.live.mp4", mediaServerItemInuse.getHttpPort(), "rtp", inviteInfo.getStreamInfo().getStream());
+ }
+ String path = "snap";
+ // 璇锋眰鎴浘
+ logger.info("[璇锋眰鎴浘]: " + fileName);
+ zlmresTfulUtils.getSnap(mediaServerItemInuse, streamUrl, 15, 1, path, fileName);
+ String filePath = path + File.separator + fileName;
+ File snapFile = new File(path + File.separator + fileName);
+ if (snapFile.exists()) {
+ errorCallback.run(InviteErrorCode.SUCCESS.getCode(), InviteErrorCode.SUCCESS.getMsg(), filePath);
+ }else {
+ errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null);
+ }
+ return;
+ }
+ }
+
+ MediaServerItem newMediaServerItem = getNewMediaServerItem(device);
+ play(newMediaServerItem, deviceId, channelId, (code, msg, data)->{
+ if (code == InviteErrorCode.SUCCESS.getCode()) {
+ InviteInfo inviteInfoForPlay = inviteStreamService.getInviteInfoByDeviceAndChannel(InviteSessionType.PLAY, deviceId, channelId);
+ if (inviteInfoForPlay != null && inviteInfoForPlay.getStreamInfo() != null) {
+ getSnap(deviceId, channelId, fileName, errorCallback);
+ }else {
+ errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null);
+ }
+ }else {
+ errorCallback.run(InviteErrorCode.FAIL.getCode(), InviteErrorCode.FAIL.getMsg(), null);
+ }
+ });
+ }
+
}
--
Gitblit v1.8.0