From 100252a253263321873e79d43dff94e19defe353 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期三, 22 二月 2023 18:06:52 +0800
Subject: [PATCH] 完善语音对讲
---
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java | 40 +++++++-------------
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java | 13 +++---
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java | 6 +-
src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java | 3 -
src/main/java/com/genersoft/iot/vmp/gb28181/bean/AudioBroadcastCatch.java | 50 ++++++++++++++++++++++++
src/main/java/com/genersoft/iot/vmp/service/IPlayService.java | 4 -
6 files changed, 74 insertions(+), 42 deletions(-)
diff --git a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java
index 1eca131..2107c32 100644
--- a/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java
+++ b/src/main/java/com/genersoft/iot/vmp/conf/redis/RedisConfig.java
@@ -3,6 +3,7 @@
import com.genersoft.iot.vmp.common.VideoManagerConstants;
import com.genersoft.iot.vmp.service.redisMsg.*;
+import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CachingConfigurerSupport;
import org.springframework.context.annotation.Bean;
@@ -12,8 +13,6 @@
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
-
-import com.genersoft.iot.vmp.utils.redis.FastJsonRedisSerializer;
/**
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AudioBroadcastCatch.java b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AudioBroadcastCatch.java
index 88db807..bcf320d 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AudioBroadcastCatch.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/bean/AudioBroadcastCatch.java
@@ -1,6 +1,7 @@
package com.genersoft.iot.vmp.gb28181.bean;
+import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import gov.nist.javax.sip.message.SIPResponse;
/**
@@ -10,10 +11,18 @@
public class AudioBroadcastCatch {
- public AudioBroadcastCatch(String deviceId, String channelId, AudioBroadcastCatchStatus status) {
+ public AudioBroadcastCatch(String deviceId,
+ String channelId,
+ AudioBroadcastCatchStatus status,
+ MediaServerItem mediaServerItem,
+ String app,
+ String stream) {
this.deviceId = deviceId;
this.channelId = channelId;
this.status = status;
+ this.mediaServerItem = mediaServerItem;
+ this.app = app;
+ this.stream = stream;
}
public AudioBroadcastCatch() {
@@ -28,6 +37,21 @@
* 閫氶亾缂栧彿
*/
private String channelId;
+
+ /**
+ * 浣跨敤鐨勬祦濯掍綋
+ */
+ private MediaServerItem mediaServerItem;
+
+ /**
+ * 寰呮帹閫佺粰璁惧鐨勬祦搴旂敤鍚�
+ */
+ private String app;
+
+ /**
+ * 寰呮帹閫佺粰璁惧鐨勬祦ID
+ */
+ private String stream;
/**
* 璇煶骞挎挱鐘舵��
@@ -68,6 +92,30 @@
return sipTransactionInfo;
}
+ public MediaServerItem getMediaServerItem() {
+ return mediaServerItem;
+ }
+
+ public void setMediaServerItem(MediaServerItem mediaServerItem) {
+ this.mediaServerItem = mediaServerItem;
+ }
+
+ public String getApp() {
+ return app;
+ }
+
+ public void setApp(String app) {
+ this.app = app;
+ }
+
+ public String getStream() {
+ return stream;
+ }
+
+ public void setStream(String stream) {
+ this.stream = stream;
+ }
+
public void setSipTransactionInfo(SipTransactionInfo sipTransactionInfo) {
this.sipTransactionInfo = sipTransactionInfo;
}
diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
index 56cadb3..b35fc30 100644
--- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
+++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
@@ -903,8 +903,8 @@
// 闈炰笂绾у钩鍙拌姹傦紝鏌ヨ鏄惁璁惧璇锋眰锛堥�氬父涓烘帴鏀惰闊冲箍鎾殑璁惧锛�
Device device = redisCatchStorage.getDevice(requesterId);
- AudioBroadcastCatch audioBroadcastCatch = audioBroadcastManager.get(requesterId, channelId);
- if (audioBroadcastCatch == null) {
+ AudioBroadcastCatch broadcastCatch = audioBroadcastManager.get(requesterId, channelId);
+ if (broadcastCatch == null) {
logger.warn("鏉ヨ嚜璁惧鐨処nvite璇锋眰闈炶闊冲箍鎾紝宸插拷鐣ワ紝requesterId锛� {}/{}", requesterId, channelId);
try {
responseAck(request, Response.FORBIDDEN);
@@ -915,13 +915,13 @@
}
if (device != null) {
logger.info("鏀跺埌璁惧" + requesterId + "鐨勮闊冲箍鎾璉nvite璇锋眰");
- String key = VideoManagerConstants.BROADCAST_WAITE_INVITE + device.getDeviceId() + audioBroadcastCatch.getChannelId();
+ String key = VideoManagerConstants.BROADCAST_WAITE_INVITE + device.getDeviceId() + broadcastCatch.getChannelId();
dynamicTask.stop(key);
try {
responseAck(request, Response.TRYING);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite BAD_REQUEST: {}", e.getMessage());
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+ playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId());
return;
}
String contentString = new String(request.getRawContent());
@@ -977,7 +977,7 @@
responseAck(request, Response.UNSUPPORTED_MEDIA_TYPE); // 涓嶆敮鎸佺殑鏍煎紡锛屽彂415
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 涓嶆敮鎸佺殑濯掍綋鏍煎紡: {}", e.getMessage());
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+ playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId());
return;
}
return;
@@ -986,19 +986,9 @@
logger.info("璁惧{}璇锋眰璇煶娴侊紝鍦板潃锛歿}:{}锛宻src锛歿}, {}", requesterId, addressStr, port, ssrc,
mediaTransmissionTCP ? (tcpActive? "TCP涓诲姩":"TCP琚姩") : "UDP");
- MediaServerItem mediaServerItem = playService.getNewMediaServerItem(device);
- if (mediaServerItem == null) {
- logger.warn("鏈壘鍒板彲鐢ㄧ殑zlm");
- try {
- responseAck(request, Response.BUSY_HERE);
- } catch (SipException | InvalidArgumentException | ParseException e) {
- logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈壘鍒板彲鐢ㄧ殑zlm: {}", e.getMessage());
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
- }
- return;
- }
+ MediaServerItem mediaServerItem = broadcastCatch.getMediaServerItem();
SendRtpItem sendRtpItem = zlmrtpServerFactory.createSendRtpItem(mediaServerItem, addressStr, port, ssrc, requesterId,
- device.getDeviceId(), audioBroadcastCatch.getChannelId(),
+ device.getDeviceId(), broadcastCatch.getChannelId(),
mediaTransmissionTCP, false);
if (sendRtpItem == null) {
@@ -1007,22 +997,20 @@
responseAck(request, Response.BUSY_HERE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 invite 鏈嶅姟鍣ㄧ鍙h祫婧愪笉瓒�: {}", e.getMessage());
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+ playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId());
return;
}
return;
}
- String app = "broadcast";
- String stream = device.getDeviceId() + "_" + audioBroadcastCatch.getChannelId();
CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME);
sendRtpItem.setPlayType(InviteStreamType.TALK);
sendRtpItem.setCallId(callIdHeader.getCallId());
sendRtpItem.setPlatformId(requesterId);
sendRtpItem.setStatus(1);
- sendRtpItem.setApp(app);
- sendRtpItem.setStreamId(stream);
+ sendRtpItem.setApp(broadcastCatch.getApp());
+ sendRtpItem.setStreamId(broadcastCatch.getStream());
sendRtpItem.setPt(8);
sendRtpItem.setUsePs(false);
sendRtpItem.setRtcp(false);
@@ -1034,22 +1022,22 @@
redisCatchStorage.updateSendRTPSever(sendRtpItem);
- Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream);
+ Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, broadcastCatch.getApp(), broadcastCatch.getStream());
if (streamReady) {
sendOk(device, sendRtpItem, sdp, request, mediaServerItem, mediaTransmissionTCP, ssrc);
}else {
- logger.warn("[璇煶閫氳瘽]锛� 鏈彂鐜板緟鎺ㄩ�佺殑娴�,app={},stream={}", app, stream);
+ logger.warn("[璇煶閫氳瘽]锛� 鏈彂鐜板緟鎺ㄩ�佺殑娴�,app={},stream={}", broadcastCatch.getApp(), broadcastCatch.getStream());
try {
responseAck(request, Response.GONE);
} catch (SipException | InvalidArgumentException | ParseException e) {
logger.error("[鍛戒护鍙戦�佸け璐 璇煶閫氳瘽 鍥炲410澶辫触锛� {}", e.getMessage());
return;
}
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+ playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId());
}
} catch (SdpException e) {
logger.error("[SDP瑙f瀽寮傚父]", e);
- playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId());
+ playService.stopAudioBroadcast(device.getDeviceId(), broadcastCatch.getChannelId());
}
} else {
logger.warn("鏉ヨ嚜鏃犳晥璁惧/骞冲彴鐨勮姹�");
diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
index dae42c7..8770d0e 100644
--- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
+++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java
@@ -274,18 +274,17 @@
logger.info("[ZLM HOOK] 娴佹敞閿�, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
}
-
+ MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
JSONObject json = (JSONObject) JSON.toJSON(param);
taskExecutor.execute(() -> {
ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_stream_changed, json);
if (subscribe != null) {
- MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
+
if (mediaInfo != null) {
subscribe.response(mediaInfo, json);
}
}
// 娴佹秷澶辩Щ闄edis play
- List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
if (param.isRegist()) {
if (param.getOriginType() == OriginType.RTMP_PUSH.ordinal()
|| param.getOriginType() == OriginType.RTSP_PUSH.ordinal()
@@ -343,7 +342,7 @@
}
// 寮�鍚闊冲璁查�氶亾
try {
- playService.audioBroadcastCmd(device, channelId, 60, (msg)->{
+ playService.audioBroadcastCmd(device, channelId, 60, mediaInfo, param.getApp(), param.getStream(), (msg)->{
logger.info("[璇煶瀵硅] 閫氶亾寤虹珛鎴愬姛, device: {}, channel: {}", deviceId, channelId);
});
} catch (InvalidArgumentException | ParseException | SipException e) {
@@ -375,7 +374,7 @@
if (sendRtpItem == null) {
// TODO 鍙兘鏁版嵁閿欒锛岄噸鏂板紑鍚闊抽�氶亾
}else {
- MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
+ MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
logger.info("rtp/{}寮�濮嬪悜涓婄骇鎺ㄦ祦, 鐩爣={}:{}锛孲SRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
Map<String, Object> sendParam = new HashMap<>(12);
sendParam.put("vhost","__defaultVhost__");
@@ -389,12 +388,12 @@
JSONObject jsonObject;
if (sendRtpItem.isTcpActive()) {
- jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, sendParam);
+ jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaServerItem, sendParam);
} else {
sendParam.put("is_udp", sendRtpItem.isTcp() ? "0" : "1");
sendParam.put("dst_url", sendRtpItem.getIp());
sendParam.put("dst_port", sendRtpItem.getPort());
- jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, sendParam);
+ jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaServerItem, sendParam);
}
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
logger.info("[璇煶瀵硅] 鑷姩鎺ㄦ祦鎴愬姛, device: {}, channel: {}", deviceId, channelId);
diff --git a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
index ffdaef3..6d11afa 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/IPlayService.java
@@ -12,9 +12,7 @@
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.vmanager.bean.AudioBroadcastResult;
import com.genersoft.iot.vmp.vmanager.gb28181.play.bean.AudioBroadcastEvent;
-import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
import gov.nist.javax.sip.message.SIPResponse;
-import org.springframework.web.context.request.async.DeferredResult;
import javax.sip.InvalidArgumentException;
import javax.sip.SipException;
@@ -62,7 +60,7 @@
AudioBroadcastResult audioBroadcast(Device device, String channelId);
void stopAudioBroadcast(String deviceId, String channelId);
- void audioBroadcastCmd(Device device, String channelId, int timeout, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException;
+ void audioBroadcastCmd(Device device, String channelId, int timeout, MediaServerItem mediaServerItem, String sourceApp, String sourceStream, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException;
void pauseRtp(String streamId) throws ServiceException, InvalidArgumentException, ParseException, SipException;
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 56efa72..4336664 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
@@ -1011,7 +1011,7 @@
}
@Override
- public void audioBroadcastCmd(Device device, String channelId, int timeout, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException {
+ public void audioBroadcastCmd(Device device, String channelId, int timeout, MediaServerItem mediaServerItem, String sourceApp, String sourceStream, AudioBroadcastEvent event) throws InvalidArgumentException, ParseException, SipException {
if (device == null || channelId == null) {
return;
}
@@ -1027,7 +1027,6 @@
SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(device.getDeviceId(), channelId, null, null);
if (sendRtpItem != null && sendRtpItem.isOnlyAudio()) {
// 鏌ヨ娴佹槸鍚﹀瓨鍦紝涓嶅瓨鍦ㄥ垯璁や负鏄紓甯哥姸鎬�
- MediaServerItem mediaServerItem = mediaServerService.getOne(sendRtpItem.getMediaServerId());
Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, sendRtpItem.getApp(), sendRtpItem.getStreamId());
if (streamReady) {
logger.warn("璇煶骞挎挱宸茬粡寮�鍚細 {}", channelId);
@@ -1042,7 +1041,8 @@
// 鍙戦�侀�氱煡
cmder.audioBroadcastCmd(device, channelId, eventResultForOk -> {
// 鍙戦�佹垚鍔�
- AudioBroadcastCatch audioBroadcastCatch = new AudioBroadcastCatch(device.getDeviceId(), channelId, AudioBroadcastCatchStatus.Ready);
+ AudioBroadcastCatch audioBroadcastCatch = new AudioBroadcastCatch(device.getDeviceId(), channelId,
+ AudioBroadcastCatchStatus.Ready, mediaServerItem, sourceApp, sourceStream);
audioBroadcastManager.update(audioBroadcastCatch);
}, eventResultForError -> {
// 鍙戦�佸け璐�
--
Gitblit v1.8.0