hook优化
This commit is contained in:
@@ -6,12 +6,11 @@ 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.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.event.hook.HookSubscribeFactory;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribeForRtpServerTimeout;
|
||||
import com.genersoft.iot.vmp.media.event.hook.HookSubscribeForStreamChange;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.hook.OnRtpServerTimeoutHookParam;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
@@ -109,12 +108,11 @@ public class RtpController {
|
||||
}
|
||||
// 注册回调如果rtp收流超时则通过回调发送通知
|
||||
if (callBack != null) {
|
||||
HookSubscribeForRtpServerTimeout hookSubscribeForRtpServerTimeout = HookSubscribeFactory.on_rtp_server_timeout(stream, String.valueOf(ssrcInt), mediaServerItem.getId());
|
||||
Hook hook = Hook.getInstance(HookType.on_rtp_server_timeout, "rtp", stream, mediaServerItem.getId());
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
hookSubscribe.addSubscribe(hookSubscribeForRtpServerTimeout,
|
||||
(mediaServerItemInUse, hookParam)->{
|
||||
OnRtpServerTimeoutHookParam serverTimeoutHookParam = (OnRtpServerTimeoutHookParam) hookParam;
|
||||
if (stream.equals(serverTimeoutHookParam.getStream_id())) {
|
||||
hookSubscribe.addSubscribe(hook,
|
||||
(hookData)->{
|
||||
if (stream.equals(hookData.getStream())) {
|
||||
logger.info("[开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调", callId);
|
||||
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
|
||||
OkHttpClient client = httpClientBuilder.build();
|
||||
@@ -125,7 +123,7 @@ public class RtpController {
|
||||
} catch (IOException e) {
|
||||
logger.error("[第三方服务对接->开启收流和获取发流信息] 等待收流超时 callId->{}, 发送回调失败", callId, e);
|
||||
}
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForRtpServerTimeout);
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -225,7 +223,7 @@ public class RtpController {
|
||||
if (!((dstPortForAudio > 0 && !ObjectUtils.isEmpty(dstPortForAudio) || (dstPortForVideo > 0 && !ObjectUtils.isEmpty(dstIpForVideo))))) {
|
||||
throw new ControllerException(ErrorCode.ERROR400.getCode(), "至少应该存在一组音频或视频发送参数");
|
||||
}
|
||||
MediaServer mediaServerItem = mediaServerService.getDefaultMediaServer();
|
||||
MediaServer mediaServer = mediaServerService.getDefaultMediaServer();
|
||||
String key = VideoManagerConstants.WVP_OTHER_SEND_RTP_INFO + userSetting.getServerId() + "_" + callId;
|
||||
OtherRtpSendInfo sendInfo = (OtherRtpSendInfo)redisTemplate.opsForValue().get(key);
|
||||
if (sendInfo == null) {
|
||||
@@ -278,10 +276,10 @@ public class RtpController {
|
||||
paramForVideo = null;
|
||||
}
|
||||
|
||||
Boolean streamReady = zlmServerFactory.isStreamReady(mediaServerItem, app, stream);
|
||||
Boolean streamReady = zlmServerFactory.isStreamReady(mediaServer, app, stream);
|
||||
if (streamReady) {
|
||||
if (paramForVideo != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, paramForVideo);
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForVideo);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, paramForVideo);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
@@ -292,7 +290,7 @@ public class RtpController {
|
||||
}
|
||||
}
|
||||
if(paramForAudio != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, paramForAudio);
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForAudio);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, paramForAudio);
|
||||
redisTemplate.opsForValue().set(key, sendInfo);
|
||||
@@ -305,18 +303,18 @@ public class RtpController {
|
||||
}else {
|
||||
logger.info("[第三方服务对接->发送流] 流不存在,等待流上线,callId->{}", callId);
|
||||
String uuid = UUID.randomUUID().toString();
|
||||
HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(app, stream, true, "rtsp", mediaServerItem.getId());
|
||||
Hook hook = Hook.getInstance(HookType.on_media_arrival, app, stream, mediaServer.getId());
|
||||
dynamicTask.startDelay(uuid, ()->{
|
||||
logger.info("[第三方服务对接->发送流] 等待流上线超时 callId->{}", callId);
|
||||
redisTemplate.delete(key);
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
}, 10000);
|
||||
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
OtherRtpSendInfo finalSendInfo = sendInfo;
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
||||
hookSubscribe.addSubscribe(hookSubscribeForStreamChange,
|
||||
(mediaServerItemInUse, response)->{
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
hookSubscribe.addSubscribe(hook,
|
||||
(hookData)->{
|
||||
dynamicTask.stop(uuid);
|
||||
logger.info("[第三方服务对接->发送流] 流上线,开始发流 callId->{}", callId);
|
||||
try {
|
||||
@@ -325,7 +323,7 @@ public class RtpController {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
if (paramForVideo != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, paramForVideo);
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForVideo);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 视频流发流成功,callId->{},param->{}", callId, paramForVideo);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
@@ -336,7 +334,7 @@ public class RtpController {
|
||||
}
|
||||
}
|
||||
if(paramForAudio != null) {
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServerItem, paramForAudio);
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpStream(mediaServer, paramForAudio);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
logger.info("[第三方服务对接->发送流] 音频流发流成功,callId->{},param->{}", callId, paramForAudio);
|
||||
redisTemplate.opsForValue().set(key, finalSendInfo);
|
||||
@@ -346,7 +344,7 @@ public class RtpController {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "[音频流发流失败] " + jsonObject.getString("msg"));
|
||||
}
|
||||
}
|
||||
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
||||
hookSubscribe.removeSubscribe(hook);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user