优化代码调用
parent
6c0087db88
commit
f458c9b793
|
@ -141,6 +141,22 @@ public class SendRtpItem {
|
|||
|
||||
}
|
||||
|
||||
public static SendRtpItem getInstance(String app, String stream, String ssrc, String dstIp, Integer dstPort, boolean tcp, int sendLocalPort, Integer pt) {
|
||||
SendRtpItem sendRtpItem = new SendRtpItem();
|
||||
sendRtpItem.setApp(app);
|
||||
sendRtpItem.setStream(stream);
|
||||
sendRtpItem.setSsrc(ssrc);
|
||||
sendRtpItem.setTcp(tcp);
|
||||
sendRtpItem.setLocalPort(sendLocalPort);
|
||||
sendRtpItem.setIp(dstIp);
|
||||
sendRtpItem.setPort(dstPort);
|
||||
if (pt != null) {
|
||||
sendRtpItem.setPt(pt);
|
||||
}
|
||||
|
||||
return sendRtpItem;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
|
|
@ -18,7 +18,6 @@ import com.genersoft.iot.vmp.media.event.hook.Hook;
|
|||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookType;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.utils.DateUtil;
|
||||
|
|
|
@ -353,7 +353,7 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
|||
}
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, param);
|
||||
JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServer, param);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
}
|
||||
|
|
|
@ -152,72 +152,6 @@ public class ZLMServerFactory {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建一个国标推流
|
||||
* @param ip 推流ip
|
||||
* @param port 推流端口
|
||||
* @param ssrc 推流唯一标识
|
||||
* @param platformId 平台id
|
||||
* @param channelId 通道id
|
||||
* @param tcp 是否为tcp
|
||||
* @return SendRtpItem
|
||||
*/
|
||||
public SendRtpItem createSendRtpItem(MediaServer serverItem, String ip, int port, String ssrc, String platformId,
|
||||
String deviceId, String channelId, boolean tcp, boolean rtcp){
|
||||
|
||||
int localPort = sendRtpPortManager.getNextPort(serverItem);
|
||||
if (localPort == 0) {
|
||||
return null;
|
||||
}
|
||||
SendRtpItem sendRtpItem = new SendRtpItem();
|
||||
sendRtpItem.setIp(ip);
|
||||
sendRtpItem.setPort(port);
|
||||
sendRtpItem.setSsrc(ssrc);
|
||||
sendRtpItem.setPlatformId(platformId);
|
||||
sendRtpItem.setDeviceId(deviceId);
|
||||
sendRtpItem.setChannelId(channelId);
|
||||
sendRtpItem.setTcp(tcp);
|
||||
sendRtpItem.setRtcp(rtcp);
|
||||
sendRtpItem.setApp("rtp");
|
||||
sendRtpItem.setLocalPort(localPort);
|
||||
sendRtpItem.setServerId(userSetting.getServerId());
|
||||
sendRtpItem.setMediaServerId(serverItem.getId());
|
||||
return sendRtpItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个直播推流
|
||||
* @param ip 推流ip
|
||||
* @param port 推流端口
|
||||
* @param ssrc 推流唯一标识
|
||||
* @param platformId 平台id
|
||||
* @param channelId 通道id
|
||||
* @param tcp 是否为tcp
|
||||
* @return SendRtpItem
|
||||
*/
|
||||
public SendRtpItem createSendRtpItem(MediaServer serverItem, String ip, int port, String ssrc, String platformId,
|
||||
String app, String stream, String channelId, boolean tcp, boolean rtcp){
|
||||
|
||||
int localPort = sendRtpPortManager.getNextPort(serverItem);
|
||||
if (localPort == 0) {
|
||||
return null;
|
||||
}
|
||||
SendRtpItem sendRtpItem = new SendRtpItem();
|
||||
sendRtpItem.setIp(ip);
|
||||
sendRtpItem.setPort(port);
|
||||
sendRtpItem.setSsrc(ssrc);
|
||||
sendRtpItem.setApp(app);
|
||||
sendRtpItem.setStream(stream);
|
||||
sendRtpItem.setPlatformId(platformId);
|
||||
sendRtpItem.setChannelId(channelId);
|
||||
sendRtpItem.setTcp(tcp);
|
||||
sendRtpItem.setLocalPort(localPort);
|
||||
sendRtpItem.setServerId(userSetting.getServerId());
|
||||
sendRtpItem.setMediaServerId(serverItem.getId());
|
||||
sendRtpItem.setRtcp(rtcp);
|
||||
return sendRtpItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用zlm RESTFUL API —— startSendRtp
|
||||
*/
|
||||
|
@ -236,17 +170,6 @@ public class ZLMServerFactory {
|
|||
return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询待转推的流是否就绪
|
||||
*/
|
||||
public Boolean isRtpReady(MediaServer mediaServerItem, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtsp", streamId);
|
||||
if (mediaInfo.getInteger("code") == -2) {
|
||||
return null;
|
||||
}
|
||||
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询待转推的流是否就绪
|
||||
*/
|
||||
|
@ -282,27 +205,6 @@ public class ZLMServerFactory {
|
|||
return mediaInfo.getInteger("totalReaderCount");
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用zlm RESTful API —— stopSendRtp
|
||||
*/
|
||||
public Boolean stopSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) {
|
||||
if (mediaServerItem == null) {
|
||||
logger.error("[停止RTP推流] 失败: 媒体节点为NULL");
|
||||
return false;
|
||||
}
|
||||
Boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param);
|
||||
if (jsonObject == null) {
|
||||
logger.error("[停止RTP推流] 失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
result= true;
|
||||
logger.info("[停止RTP推流] 成功");
|
||||
} else {
|
||||
logger.warn("[停止RTP推流] 失败: {}, 参数:{}->\r\n{}",jsonObject.getString("msg"), JSON.toJSON(param), jsonObject);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject startSendRtp(MediaServer mediaInfo, SendRtpItem sendRtpItem) {
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
logger.info("rtp/{}开始推流, 目标={}:{},SSRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.genersoft.iot.vmp.conf.DynamicTask;
|
|||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.event.hook.Hook;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookType;
|
||||
import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
|
||||
|
@ -45,9 +46,6 @@ public class PsController {
|
|||
|
||||
private final static Logger logger = LoggerFactory.getLogger(PsController.class);
|
||||
|
||||
@Autowired
|
||||
private ZLMServerFactory zlmServerFactory;
|
||||
|
||||
@Autowired
|
||||
private HookSubscribe hookSubscribe;
|
||||
|
||||
|
@ -209,35 +207,12 @@ public class PsController {
|
|||
sendInfo.setPushApp(app);
|
||||
sendInfo.setPushStream(stream);
|
||||
sendInfo.setPushSSRC(ssrc);
|
||||
|
||||
Map<String, Object> param;
|
||||
|
||||
|
||||
param = new HashMap<>();
|
||||
param.put("vhost","__defaultVhost__");
|
||||
param.put("app",app);
|
||||
param.put("stream",stream);
|
||||
param.put("ssrc", ssrc);
|
||||
|
||||
param.put("dst_url", dstIp);
|
||||
param.put("dst_port", dstPort);
|
||||
String is_Udp = isUdp ? "1" : "0";
|
||||
param.put("is_udp", is_Udp);
|
||||
param.put("src_port", sendInfo.getSendLocalPort());
|
||||
|
||||
|
||||
SendRtpItem sendRtpItem = SendRtpItem.getInstance(app, stream, ssrc, dstIp, dstPort, !isUdp, sendInfo.getSendLocalPort(), null);
|
||||
Boolean streamReady = mediaServerService.isStreamReady(mediaServer, app, stream);
|
||||
if (streamReady) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, param);
|
||||
// mediaServerService.startSendRtp(mediaServer, );
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, param);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[视频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItem);
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, sendRtpItem);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}else {
|
||||
logger.info("[第三方PS服务对接->发送流] 流不存在,等待流上线,callId->{}", callId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
|
@ -260,15 +235,9 @@ public class PsController {
|
|||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, param);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, param);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[视频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItem);
|
||||
logger.info("[第三方PS服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, sendRtpItem);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
});
|
||||
}
|
||||
|
@ -291,7 +260,7 @@ public class PsController {
|
|||
param.put("stream",sendInfo.getPushStream());
|
||||
param.put("ssrc",sendInfo.getPushSSRC());
|
||||
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
Boolean result = zlmServerFactory.stopSendRtpStream(mediaServerItem, param);
|
||||
boolean result = mediaServerService.stopSendRtp(mediaServerItem, sendInfo.getPushApp(), sendInfo.getStream(), sendInfo.getPushSSRC());
|
||||
if (!result) {
|
||||
logger.info("[第三方PS服务对接->关闭发送流] 失败 callId->{}", callId);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "停止发流失败");
|
||||
|
|
|
@ -6,13 +6,14 @@ import com.genersoft.iot.vmp.conf.DynamicTask;
|
|||
import com.genersoft.iot.vmp.conf.UserSetting;
|
||||
import com.genersoft.iot.vmp.conf.exception.ControllerException;
|
||||
import com.genersoft.iot.vmp.conf.security.JwtUtils;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.media.event.hook.Hook;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookType;
|
||||
import com.genersoft.iot.vmp.media.zlm.SendRtpPortManager;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
||||
import com.genersoft.iot.vmp.utils.redis.RedisUtil;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.OtherRtpSendInfo;
|
||||
|
@ -43,9 +44,6 @@ import java.util.concurrent.TimeUnit;
|
|||
@RequestMapping("/api/rtp")
|
||||
public class RtpController {
|
||||
|
||||
@Autowired
|
||||
private ZLMServerFactory zlmServerFactory;
|
||||
|
||||
@Autowired
|
||||
private SendRtpPortManager sendRtpPortManager;
|
||||
|
||||
|
@ -81,8 +79,8 @@ public class RtpController {
|
|||
logger.info("[第三方服务对接->开启收流和获取发流信息] isSend->{}, ssrc->{}, callId->{}, stream->{}, tcpMode->{}, callBack->{}",
|
||||
isSend, ssrc, callId, stream, tcpMode==0?"UDP":"TCP被动", callBack);
|
||||
|
||||
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
if (mediaServerItem == null) {
|
||||
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
||||
if (mediaServer == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(),"没有可用的MediaServer");
|
||||
}
|
||||
if (stream == null) {
|
||||
|
@ -100,14 +98,14 @@ public class RtpController {
|
|||
}
|
||||
}
|
||||
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_" + callId + "_" + stream;
|
||||
int localPortForVideo = zlmServerFactory.createRTPServer(mediaServerItem, stream, ssrcInt, null, false, false, tcpMode);
|
||||
int localPortForAudio = zlmServerFactory.createRTPServer(mediaServerItem, stream + "_a" , ssrcInt, null, false, false, tcpMode);
|
||||
if (localPortForVideo == 0 || localPortForAudio == 0) {
|
||||
SSRCInfo ssrcInfoForVideo = mediaServerService.openRTPServer(mediaServer, stream, ssrcInt + "",false,false, null, false, false, false, tcpMode);
|
||||
SSRCInfo ssrcInfoForAudio = mediaServerService.openRTPServer(mediaServer, stream + "_a", ssrcInt + "", false, false, null, false,false,false, tcpMode);
|
||||
if (ssrcInfoForVideo.getPort() == 0 || ssrcInfoForAudio.getPort() == 0) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取端口失败");
|
||||
}
|
||||
// 注册回调如果rtp收流超时则通过回调发送通知
|
||||
if (callBack != null) {
|
||||
Hook hook = Hook.getInstance(HookType.on_rtp_server_timeout, "rtp", stream, mediaServerItem.getId());
|
||||
Hook hook = Hook.getInstance(HookType.on_rtp_server_timeout, "rtp", stream, mediaServer.getId());
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
hookSubscribe.addSubscribe(hook,
|
||||
(hookData)->{
|
||||
|
@ -128,9 +126,9 @@ public class RtpController {
|
|||
}
|
||||
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + "_" + callId;
|
||||
OtherRtpSendInfo otherRtpSendInfo = new OtherRtpSendInfo();
|
||||
otherRtpSendInfo.setReceiveIp(mediaServerItem.getSdpIp());
|
||||
otherRtpSendInfo.setReceivePortForVideo(localPortForVideo);
|
||||
otherRtpSendInfo.setReceivePortForAudio(localPortForAudio);
|
||||
otherRtpSendInfo.setReceiveIp(mediaServer.getSdpIp());
|
||||
otherRtpSendInfo.setReceivePortForVideo(ssrcInfoForVideo.getPort());
|
||||
otherRtpSendInfo.setReceivePortForAudio(ssrcInfoForAudio.getPort());
|
||||
otherRtpSendInfo.setCallId(callId);
|
||||
otherRtpSendInfo.setStream(stream);
|
||||
|
||||
|
@ -138,10 +136,10 @@ public class RtpController {
|
|||
redisTemplate.opsForValue().set(receiveKey, otherRtpSendInfo);
|
||||
if (isSend != null && isSend) {
|
||||
// 预创建发流信息
|
||||
int portForVideo = sendRtpPortManager.getNextPort(mediaServerItem);
|
||||
int portForAudio = sendRtpPortManager.getNextPort(mediaServerItem);
|
||||
int portForVideo = sendRtpPortManager.getNextPort(mediaServer);
|
||||
int portForAudio = sendRtpPortManager.getNextPort(mediaServer);
|
||||
|
||||
otherRtpSendInfo.setSendLocalIp(mediaServerItem.getSdpIp());
|
||||
otherRtpSendInfo.setSendLocalIp(mediaServer.getSdpIp());
|
||||
otherRtpSendInfo.setSendLocalPortForVideo(portForVideo);
|
||||
otherRtpSendInfo.setSendLocalPortForAudio(portForAudio);
|
||||
// 将信息写入redis中,以备后用
|
||||
|
@ -160,8 +158,8 @@ public class RtpController {
|
|||
public void closeRtpServer(String stream) {
|
||||
logger.info("[第三方服务对接->关闭收流] stream->{}", stream);
|
||||
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
zlmServerFactory.closeRtpServer(mediaServerItem,stream);
|
||||
zlmServerFactory.closeRtpServer(mediaServerItem,stream + "_a");
|
||||
mediaServerService.closeRTPServer(mediaServerItem, stream);
|
||||
mediaServerService.closeRTPServer(mediaServerItem, stream+ "_a");
|
||||
String receiveKey = VideoManagerConstants.WVP_OTHER_RECEIVE_RTP_INFO + userSetting.getServerId() + "_*_" + stream;
|
||||
List<Object> scan = RedisUtil.scan(redisTemplate, receiveKey);
|
||||
if (scan.size() > 0) {
|
||||
|
@ -232,72 +230,31 @@ public class RtpController {
|
|||
sendInfo.setPushStream(stream);
|
||||
sendInfo.setPushSSRC(ssrc);
|
||||
|
||||
Map<String, Object> paramForAudio;
|
||||
Map<String, Object> paramForVideo;
|
||||
|
||||
SendRtpItem sendRtpItemForVideo;
|
||||
SendRtpItem sendRtpItemForAudio;
|
||||
if (!ObjectUtils.isEmpty(dstIpForAudio) && dstPortForAudio > 0) {
|
||||
paramForAudio = new HashMap<>();
|
||||
paramForAudio.put("vhost","__defaultVhost__");
|
||||
paramForAudio.put("app",app);
|
||||
paramForAudio.put("stream",stream);
|
||||
paramForAudio.put("ssrc", ssrc);
|
||||
|
||||
paramForAudio.put("dst_url", dstIpForAudio);
|
||||
paramForAudio.put("dst_port", dstPortForAudio);
|
||||
String is_Udp = isUdp ? "1" : "0";
|
||||
paramForAudio.put("is_udp", is_Udp);
|
||||
paramForAudio.put("src_port", sendInfo.getSendLocalPortForAudio());
|
||||
paramForAudio.put("only_audio", "1");
|
||||
if (ptForAudio != null) {
|
||||
paramForAudio.put("pt", ptForAudio);
|
||||
}
|
||||
|
||||
sendRtpItemForAudio = SendRtpItem.getInstance(app, stream, ssrc, dstIpForAudio, dstPortForAudio, !isUdp, sendInfo.getSendLocalPortForAudio(), ptForAudio);
|
||||
} else {
|
||||
paramForAudio = null;
|
||||
sendRtpItemForAudio = null;
|
||||
}
|
||||
if (!ObjectUtils.isEmpty(dstIpForVideo) && dstPortForVideo > 0) {
|
||||
paramForVideo = new HashMap<>();
|
||||
paramForVideo.put("vhost","__defaultVhost__");
|
||||
paramForVideo.put("app",app);
|
||||
paramForVideo.put("stream",stream);
|
||||
paramForVideo.put("ssrc", ssrc);
|
||||
|
||||
paramForVideo.put("dst_url", dstIpForVideo);
|
||||
paramForVideo.put("dst_port", dstPortForVideo);
|
||||
String is_Udp = isUdp ? "1" : "0";
|
||||
paramForVideo.put("is_udp", is_Udp);
|
||||
paramForVideo.put("src_port", sendInfo.getSendLocalPortForVideo());
|
||||
paramForVideo.put("only_audio", "0");
|
||||
if (ptForVideo != null) {
|
||||
paramForVideo.put("pt", ptForVideo);
|
||||
}
|
||||
|
||||
sendRtpItemForVideo = SendRtpItem.getInstance(app, stream, ssrc, dstIpForAudio, dstPortForAudio, !isUdp, sendInfo.getSendLocalPortForVideo(), ptForVideo);
|
||||
} else {
|
||||
paramForVideo = null;
|
||||
sendRtpItemForVideo = null;
|
||||
}
|
||||
|
||||
Boolean streamReady = mediaServerService.isStreamReady(mediaServer, app, stream);
|
||||
if (streamReady) {
|
||||
if (paramForVideo != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForVideo);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, paramForVideo);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[视频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
if (sendRtpItemForVideo != null) {
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItemForVideo);
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, sendRtpItemForVideo);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}
|
||||
if(paramForAudio != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForAudio);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, paramForAudio);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[音频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
if(sendRtpItemForAudio != null) {
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItemForAudio);
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, sendRtpItemForAudio);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
}
|
||||
}else {
|
||||
logger.info("[第三方服务对接->发送流] 流不存在,等待流上线,callId->{}", callId);
|
||||
|
@ -310,8 +267,8 @@ public class RtpController {
|
|||
}, 10000);
|
||||
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
OtherRtpSendInfo finalSendInfo = sendInfo;
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
OtherRtpSendInfo finalSendInfo = sendInfo;
|
||||
hookSubscribe.addSubscribe(hook,
|
||||
(hookData)->{
|
||||
dynamicTask.stop(uuid);
|
||||
|
@ -321,27 +278,15 @@ public class RtpController {
|
|||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (paramForVideo != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForVideo);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, paramForVideo);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[视频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
if (sendRtpItemForVideo != null) {
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItemForVideo);
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, sendRtpItemForVideo);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
}
|
||||
if(paramForAudio != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForAudio);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, paramForAudio);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
}else {
|
||||
redisTemplate.delete(key);
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流失败,callId->{}, {}", callId, jsonObject.getString("msg"));
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[音频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
if(sendRtpItemForAudio != null) {
|
||||
mediaServerService.startSendRtp(mediaServer, null, sendRtpItemForAudio);
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, sendRtpItemForAudio);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
}
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
});
|
||||
|
@ -359,19 +304,9 @@ public class RtpController {
|
|||
if (sendInfo == null){
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "未开启发流");
|
||||
}
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost","__defaultVhost__");
|
||||
param.put("app",sendInfo.getPushApp());
|
||||
param.put("stream",sendInfo.getPushStream());
|
||||
param.put("ssrc",sendInfo.getPushSSRC());
|
||||
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
Boolean result = zlmServerFactory.stopSendRtpStream(mediaServerItem, param);
|
||||
if (!result) {
|
||||
logger.info("[第三方服务对接->关闭发送流] 失败 callId->{}", callId);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "停止发流失败");
|
||||
}else {
|
||||
logger.info("[第三方服务对接->关闭发送流] 成功 callId->{}", callId);
|
||||
}
|
||||
mediaServerService.stopSendRtp(mediaServerItem, sendInfo.getPushApp(), sendInfo.getPushStream(), sendInfo.getPushSSRC());
|
||||
logger.info("[第三方服务对接->关闭发送流] 成功 callId->{}", callId);
|
||||
redisTemplate.delete(key);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue