适配zlm的hook保活

This commit is contained in:
648540858
2021-12-07 21:13:55 +08:00
parent a2f0854138
commit 9b1af8ef13
27 changed files with 223 additions and 87 deletions

View File

@@ -359,8 +359,8 @@ public class ZLMHttpHookListener {
type = "PULL";
}
}
zlmMediaListManager.removeMedia( app, streamId);
redisCatchStorage.removeStream(mediaServerItem, OriginType.values()[item.getOriginType()].getType(), app, streamId);
zlmMediaListManager.removeMedia(app, streamId);
redisCatchStorage.removeStream(mediaServerItem, type, app, streamId);
}
// 发送流变化redis消息

View File

@@ -7,6 +7,7 @@ import com.genersoft.iot.vmp.conf.MediaConfig;
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
import com.genersoft.iot.vmp.service.IMediaServerService;
import com.genersoft.iot.vmp.service.IStreamProxyService;
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
@@ -39,6 +40,9 @@ public class ZLMRunner implements CommandLineRunner {
@Autowired
private IMediaServerService mediaServerService;
@Autowired
private IRedisCatchStorage redisCatchStorage;
@Autowired
private MediaConfig mediaConfig;
@@ -70,8 +74,14 @@ public class ZLMRunner implements CommandLineRunner {
}
});
// TODO 订阅 zlm保活事件, 当zlm离线时做业务的处理
// 订阅 zlm保活事件, 当zlm离线时做业务的处理
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_keepalive,null,
(MediaServerItem mediaServerItem, JSONObject response)->{
String mediaServerId = response.getString("mediaServerId");
if (mediaServerId !=null ) {
mediaServerService.updateMediaServerKeepalive(mediaServerId, response.getJSONObject("data"));
}
});
// 获取zlm信息
logger.info("等待默认zlm接入...");

View File

@@ -65,6 +65,9 @@ public class ZLMServerConfig {
@JSONField(name = "hook.admin_params")
private String hookAdminParams;
@JSONField(name = "hook.alive_interval")
private int hookAliveInterval;
@JSONField(name = "hook.enable")
private String hookEnable;
@@ -791,4 +794,12 @@ public class ZLMServerConfig {
public void setShellPhell(String shellPhell) {
this.shellPhell = shellPhell;
}
public int getHookAliveInterval() {
return hookAliveInterval;
}
public void setHookAliveInterval(int hookAliveInterval) {
this.hookAliveInterval = hookAliveInterval;
}
}

View File

@@ -39,6 +39,8 @@ public class MediaServerItem{
private int streamNoneReaderDelayMS;
private int hookAliveInterval;
private boolean rtpEnable;
private boolean status;
@@ -87,6 +89,7 @@ public class MediaServerItem{
autoConfig = true; // 默认值true;
secret = zlmServerConfig.getApiSecret();
streamNoneReaderDelayMS = zlmServerConfig.getGeneralStreamNoneReaderDelayMS();
hookAliveInterval = zlmServerConfig.getHookAliveInterval();
rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口
rtpPortRange = "30000,30500"; // 默认使用30000,30500作为级联时发送流的端口号
sendRtpPortRange = "30000,30500"; // 默认使用30000,30500作为级联时发送流的端口号
@@ -309,4 +312,12 @@ public class MediaServerItem{
public void setSendRtpPortRange(String sendRtpPortRange) {
this.sendRtpPortRange = sendRtpPortRange;
}
public int getHookAliveInterval() {
return hookAliveInterval;
}
public void setHookAliveInterval(int hookAliveInterval) {
this.hookAliveInterval = hookAliveInterval;
}
}

View File

@@ -0,0 +1,25 @@
package com.genersoft.iot.vmp.media.zlm.event;
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
import org.springframework.context.ApplicationEvent;
public abstract class ZLMEventAbstract extends ApplicationEvent {
private static final long serialVersionUID = 1L;
private String mediaServerId;
public ZLMEventAbstract(Object source) {
super(source);
}
public String getMediaServerId() {
return mediaServerId;
}
public void setMediaServerId(String mediaServerId) {
this.mediaServerId = mediaServerId;
}
}