级联语音对讲部分
This commit is contained in:
@@ -287,15 +287,19 @@ public class ZLMHttpHookListener {
|
||||
logger.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
||||
}
|
||||
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
|
||||
JSONObject json = (JSONObject) JSON.toJSON(param);
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(param.getMediaServerId());
|
||||
if (mediaInfo == null) {
|
||||
return ret;
|
||||
}
|
||||
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);
|
||||
}
|
||||
if (subscribe != null ) {
|
||||
subscribe.response(mediaInfo, json);
|
||||
}
|
||||
// 流消失移除redis play
|
||||
List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
|
||||
@@ -343,7 +347,7 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
}else if ("broadcast".equals(param.getApp())){
|
||||
// 语音对讲推流 stream需要满足格式deviceId_channelId
|
||||
// 语音喊话推流 stream需要满足格式deviceId_channelId
|
||||
if (param.isRegist() && param.getStream().indexOf("_") > 0) {
|
||||
String[] streamArray = param.getStream().split("_");
|
||||
if (streamArray.length == 2) {
|
||||
@@ -359,53 +363,38 @@ public class ZLMHttpHookListener {
|
||||
if (sendRtpItem == null) {
|
||||
// TODO 可能数据错误,重新开启语音通道
|
||||
}else {
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
logger.info("rtp/{}开始向上级推流, 目标={}:{},SSRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
Map<String, Object> sendParam = new HashMap<>(12);
|
||||
sendParam.put("vhost","__defaultVhost__");
|
||||
sendParam.put("app",sendRtpItem.getApp());
|
||||
sendParam.put("stream",sendRtpItem.getStreamId());
|
||||
sendParam.put("ssrc", sendRtpItem.getSsrc());
|
||||
sendParam.put("src_port", sendRtpItem.getLocalPort());
|
||||
sendParam.put("pt", sendRtpItem.getPt());
|
||||
sendParam.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
|
||||
sendParam.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
|
||||
|
||||
JSONObject jsonObject;
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, sendParam);
|
||||
} else {
|
||||
sendParam.put("is_udp", is_Udp);
|
||||
sendParam.put("dst_url", sendRtpItem.getIp());
|
||||
sendParam.put("dst_port", sendRtpItem.getPort());
|
||||
jsonObject = zlmrtpServerFactory.startSendRtpStream(mediaInfo, sendParam);
|
||||
}
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[语音对讲] 自动推流成功, device: {}, channel: {}", deviceId, channelId);
|
||||
JSONObject jsonObject = zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem);
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0 ) {
|
||||
logger.info("[语音喊话] 自动推流成功, device: {}, channel: {}", device.getDeviceId(), channelId);
|
||||
}else {
|
||||
logger.info("[语音对讲] 推流失败, 结果: {}", jsonObject);
|
||||
logger.info("[语音喊话] 推流失败, 结果: {}", jsonObject);
|
||||
}
|
||||
|
||||
}
|
||||
}else {
|
||||
// 开启语音对讲通道
|
||||
// 开启语音喊话通道
|
||||
try {
|
||||
playService.audioBroadcastCmd(device, channelId, 60, (msg)->{
|
||||
logger.info("[语音对讲] 通道建立成功, device: {}, channel: {}", deviceId, channelId);
|
||||
playService.audioBroadcastCmd(device, channelId, mediaInfo, param.getApp(), param.getStream(),60, false, (msg)->{
|
||||
logger.info("[语音喊话] 通道建立成功, device: {}, channel: {}", deviceId, channelId);
|
||||
});
|
||||
} catch (InvalidArgumentException | ParseException | SipException e) {
|
||||
logger.error("[命令发送失败] 语音对讲: {}", e.getMessage());
|
||||
logger.error("[命令发送失败] 语音喊话: {}", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}else {
|
||||
logger.info("[语音喊话] 推流指向的·通道{}未找到", channelId);
|
||||
}
|
||||
}else {
|
||||
logger.info("[语音喊话] 推流指向的·设备{}未找到", deviceId);
|
||||
}
|
||||
}else {
|
||||
logger.info("[语音喊话] 推流格式有误, 格式为: broadcast/设备编号_通道编号 ");
|
||||
}
|
||||
}
|
||||
|
||||
}else if ("talk".equals(param.getApp())){
|
||||
// 语音对讲推流 stream需要满足格式deviceId_channelId
|
||||
// 语音喊话推流 stream需要满足格式deviceId_channelId
|
||||
if (param.isRegist() && param.getStream().indexOf("_") > 0) {
|
||||
String[] streamArray = param.getStream().split("_");
|
||||
if (streamArray.length == 2) {
|
||||
@@ -421,33 +410,11 @@ public class ZLMHttpHookListener {
|
||||
if (sendRtpItem == null) {
|
||||
// TODO 可能数据错误,重新开启语音通道
|
||||
}else {
|
||||
MediaServerItem mediaInfo = mediaServerService.getOne(sendRtpItem.getMediaServerId());
|
||||
logger.info("rtp/{}开始向上级推流, 目标={}:{},SSRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
Map<String, Object> sendParam = new HashMap<>(12);
|
||||
sendParam.put("vhost","__defaultVhost__");
|
||||
sendParam.put("app",sendRtpItem.getApp());
|
||||
sendParam.put("stream",sendRtpItem.getStreamId());
|
||||
sendParam.put("ssrc", sendRtpItem.getSsrc());
|
||||
sendParam.put("src_port", sendRtpItem.getLocalPort());
|
||||
sendParam.put("pt", sendRtpItem.getPt());
|
||||
sendParam.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
|
||||
sendParam.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
|
||||
|
||||
JSONObject jsonObject;
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
jsonObject = zlmrtpServerFactory.startSendRtpPassive(mediaInfo, 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);
|
||||
}
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[语音对讲] 自动推流成功, device: {}, channel: {}", deviceId, channelId);
|
||||
}
|
||||
zlmrtpServerFactory.startSendRtp(mediaInfo, sendRtpItem);
|
||||
}
|
||||
}else {
|
||||
// 开启语音对讲通道
|
||||
// 开启语音喊话通道
|
||||
MediaServerItem mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
||||
playService.talk(mediaServerItem, device, channelId, (mediaServer, jsonObject)->{
|
||||
System.out.println("开始推流");
|
||||
@@ -549,9 +516,7 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}
|
||||
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
@@ -348,4 +348,52 @@ public class ZLMRTPServerFactory {
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject startSendRtp(MediaServerItem mediaInfo, SendRtpItem sendRtpItem) {
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
logger.info("rtp/{}开始向上级推流, 目标={}:{},SSRC={}", sendRtpItem.getStreamId(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
Map<String, Object> param = new HashMap<>(12);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
param.put("app",sendRtpItem.getApp());
|
||||
param.put("stream",sendRtpItem.getStreamId());
|
||||
param.put("ssrc", sendRtpItem.getSsrc());
|
||||
param.put("src_port", sendRtpItem.getLocalPort());
|
||||
param.put("pt", sendRtpItem.getPt());
|
||||
param.put("use_ps", sendRtpItem.isUsePs() ? "1" : "0");
|
||||
param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
|
||||
if (!sendRtpItem.isTcp()) {
|
||||
// udp模式下开启rtcp保活
|
||||
param.put("udp_rtcp_timeout", sendRtpItem.isRtcp()? "1":"0");
|
||||
}
|
||||
|
||||
if (mediaInfo == null) {
|
||||
return null;
|
||||
}
|
||||
// 如果是非严格模式,需要关闭端口占用
|
||||
JSONObject startSendRtpStreamResult = null;
|
||||
if (sendRtpItem.getLocalPort() != 0) {
|
||||
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(sendRtpItem.getSsrc(), null, mediaInfo.getId());
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
|
||||
if (releasePort(mediaInfo, sendRtpItem.getSsrc())) {
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
|
||||
System.out.println(JSON.toJSON(param));
|
||||
}else {
|
||||
param.put("is_udp", is_Udp);
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
}
|
||||
}else {
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
|
||||
}else {
|
||||
param.put("is_udp", is_Udp);
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
}
|
||||
return startSendRtpStreamResult;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user