优化国标点播下级平台,ssrc更新的时因为旧的端口释放慢导致点播失败的问题,使用新的接口直接更新ssrc

This commit is contained in:
648540858 2023-05-04 15:36:04 +08:00
parent c9757ca645
commit 37a455017d
5 changed files with 76 additions and 26 deletions

View File

@ -25,6 +25,8 @@ public class ZLMRESTfulUtils {
private OkHttpClient client;
public interface RequestCallback{
void run(JSONObject response);
}
@ -354,4 +356,11 @@ public class ZLMRESTfulUtils {
param.put("stream_id", stream_id);
return sendPost(mediaServerItem, "connectRtpServer",param, null);
}
public JSONObject updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) {
Map<String, Object> param = new HashMap<>(1);
param.put("ssrc", ssrc);
param.put("stream_id", streamId);
return sendPost(mediaServerItem, "updateRtpServerSSRC",param, null);
}
}

View File

@ -386,4 +386,19 @@ public class ZLMRTPServerFactory {
public void closeAllSendRtpStream() {
}
public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) {
boolean result = false;
JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
if (jsonObject == null) {
logger.error("[更新RTPServer] 失败: 请检查ZLM服务");
} else if (jsonObject.getInteger("code") == 0) {
result= true;
logger.info("[更新RTPServer] 成功");
} else {
logger.error("[更新RTPServer] 失败: {}, streamId{}ssrc{}->\r\n{}",jsonObject.getString("msg"),
streamId, ssrc, jsonObject);
}
return result;
}
}

View File

@ -50,6 +50,7 @@ public interface IMediaServerService {
void closeRTPServer(MediaServerItem mediaServerItem, String streamId);
void closeRTPServer(MediaServerItem mediaServerItem, String streamId, CommonCallback<Boolean> callback);
Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc);
void closeRTPServer(String mediaServerId, String streamId);

View File

@ -180,6 +180,11 @@ public class MediaServerServiceImpl implements IMediaServerService {
closeRTPServer(mediaServerItem, streamId);
}
@Override
public Boolean updateRtpServerSSRC(MediaServerItem mediaServerItem, String streamId, String ssrc) {
return zlmrtpServerFactory.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
}
@Override
public void releaseSsrc(String mediaServerItemId, String ssrc) {
MediaServerItem mediaServerItem = getOne(mediaServerItemId);

View File

@ -143,7 +143,7 @@ public class PlayServiceImpl implements IPlayService {
if (rtpInfo.getBoolean("exist")) {
int localPort = rtpInfo.getInteger("local_port");
if (localPort == 0) {
logger.warn("[点播]点播时发现rtpServerC存在,但是尚未开始推流");
logger.warn("[点播]点播时发现rtpServer存在,但是尚未开始推流");
// 此时说明rtpServer已经创建但是流还没有推上来
WVPResult wvpResult = new WVPResult();
wvpResult.setCode(ErrorCode.ERROR100.getCode());
@ -352,12 +352,9 @@ public class PlayServiceImpl implements IPlayService {
hookEvent.response(mediaServerItemInUse, response);
});
}
// 关闭rtp server
mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{
if (result) {
// 重新开启ssrc server
mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), false, ssrcInfo.getPort(), true, device.getStreamModeForParam());
}else {
Boolean result = mediaServerService.updateRtpServerSSRC(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse);
if (!result) {
try {
logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId);
cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
@ -375,7 +372,30 @@ public class PlayServiceImpl implements IPlayService {
event.statusCode = 500;
errorEvent.response(event);
}
});
// // 关闭rtp server
// mediaServerService.closeRTPServer(mediaServerItem, ssrcInfo.getStream(), result->{
// if (result) {
// // 重新开启ssrc server
// mediaServerService.openRTPServer(mediaServerItem, ssrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), false, ssrcInfo.getPort(), true, device.getStreamModeForParam());
// }else {
// try {
// logger.warn("[停止点播] {}/{}", device.getDeviceId(), channelId);
// cmder.streamByeCmd(device, channelId, ssrcInfo.getStream(), null, null);
// } catch (InvalidArgumentException | SipException | ParseException | SsrcTransactionNotFoundException e) {
// logger.error("[命令发送失败] 停止点播, 发送BYE: {}", e.getMessage());
// throw new ControllerException(ErrorCode.ERROR100.getCode(), "命令发送失败: " + e.getMessage());
// }
//
// dynamicTask.stop(timeOutTaskKey);
// // 释放ssrc
// mediaServerService.releaseSsrc(mediaServerItem.getId(), ssrcInfo.getSsrc());
//
// streamSession.remove(device.getDeviceId(), channelId, ssrcInfo.getStream());
// event.msg = "下级自定义了ssrc,重新设置收流信息失败";
// event.statusCode = 500;
// errorEvent.response(event);
// }
// });
}