添加zlm集群支持
This commit is contained in:
@@ -1,54 +0,0 @@
|
||||
//package com.genersoft.iot.vmp.media.zlm;
|
||||
//
|
||||
//import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
//import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.beans.factory.annotation.Value;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//import org.springframework.web.client.HttpClientErrorException;
|
||||
//import org.springframework.web.client.RestTemplate;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//
|
||||
//@RestController
|
||||
//@RequestMapping("/zlm")
|
||||
//public class ZLMHTTPProxyController {
|
||||
//
|
||||
//
|
||||
// // private final static Logger logger = LoggerFactory.getLogger(ZLMHTTPProxyController.class);
|
||||
//
|
||||
// @Autowired
|
||||
// private IRedisCatchStorage redisCatchStorage;
|
||||
//
|
||||
// @Autowired
|
||||
// private MediaConfig mediaConfig;
|
||||
//
|
||||
// @ResponseBody
|
||||
// @RequestMapping(value = "/**/**/**", produces = "application/json;charset=UTF-8")
|
||||
// public Object proxy(HttpServletRequest request, HttpServletResponse response){
|
||||
//
|
||||
// if (redisCatchStorage.getMediaInfo() == null) {
|
||||
// return "未接入流媒体";
|
||||
// }
|
||||
// ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
// String requestURI = String.format("http://%s:%s%s?%s&%s",
|
||||
// mediaInfo.getLocalIP(),
|
||||
// mediaConfig.getHttpPort(),
|
||||
// request.getRequestURI().replace("/zlm",""),
|
||||
// mediaInfo.getHookAdminParams(),
|
||||
// request.getQueryString()
|
||||
// );
|
||||
// // 发送请求
|
||||
// RestTemplate restTemplate = new RestTemplate();
|
||||
// //将指定的url返回的参数自动封装到自定义好的对应类对象中
|
||||
// Object result = null;
|
||||
// try {
|
||||
// result = restTemplate.getForObject(requestURI,Object.class);
|
||||
//
|
||||
// }catch (HttpClientErrorException httpClientErrorException) {
|
||||
// response.setStatus(httpClientErrorException.getStatusCode().value());
|
||||
// }
|
||||
// return result;
|
||||
// }
|
||||
//}
|
||||
@@ -9,6 +9,9 @@ import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.conf.UserSetup;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.Device;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.service.IPlayService;
|
||||
@@ -53,10 +56,10 @@ public class ZLMHttpHookListener {
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private ZLMServerManger zlmServerManger;
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@Autowired
|
||||
private ZLMMediaListManager zlmMediaListManager;
|
||||
@@ -81,6 +84,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_flow_report API调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
@@ -98,6 +102,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_http_access API 调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("err", "");
|
||||
@@ -117,9 +122,14 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_play API调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_play, json);
|
||||
if (subscribe != null ) {
|
||||
subscribe.response(json);
|
||||
IMediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo != null) {
|
||||
subscribe.response(mediaInfo, json);
|
||||
}
|
||||
|
||||
}
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
@@ -133,20 +143,25 @@ public class ZLMHttpHookListener {
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_publish", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onPublish(@RequestBody JSONObject json){
|
||||
public ResponseEntity<String> onPublish(@RequestBody JSONObject json) {
|
||||
|
||||
logger.debug("ZLM HOOK on_publish API调用,参数:" + json.toString());
|
||||
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_publish, json);
|
||||
if (subscribe != null) subscribe.response(json);
|
||||
|
||||
if (subscribe != null) {
|
||||
IMediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo != null) {
|
||||
subscribe.response(mediaInfo, json);
|
||||
}
|
||||
}
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
ret.put("enableHls", true);
|
||||
ret.put("enableMP4", userSetup.isRecordPushLive());
|
||||
ret.put("enableRtxp", true);
|
||||
return new ResponseEntity<String>(ret.toString(),HttpStatus.OK);
|
||||
return new ResponseEntity<String>(ret.toString(), HttpStatus.OK);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,6 +175,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_record_mp4 API调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
@@ -177,6 +193,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_rtsp_realm API调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("realm", "");
|
||||
@@ -195,6 +212,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_rtsp_auth API调用,参数:" + json.toString());
|
||||
}
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("encrypted", false);
|
||||
@@ -216,9 +234,15 @@ public class ZLMHttpHookListener {
|
||||
// TODO 如果是带有rtpstream则开启按需拉流
|
||||
// String app = json.getString("app");
|
||||
// String stream = json.getString("stream");
|
||||
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_shell_login, json);
|
||||
if (subscribe != null) subscribe.response(json);
|
||||
if (subscribe != null ) {
|
||||
IMediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo != null) {
|
||||
subscribe.response(mediaInfo, json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
@@ -237,9 +261,15 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_stream_changed API调用,参数:" + json.toString());
|
||||
}
|
||||
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
ZLMHttpHookSubscribe.Event subscribe = this.subscribe.getSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, json);
|
||||
if (subscribe != null) subscribe.response(json);
|
||||
if (subscribe != null ) {
|
||||
IMediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (mediaInfo != null) {
|
||||
subscribe.response(mediaInfo, json);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 流消失移除redis play
|
||||
String app = json.getString("app");
|
||||
@@ -251,6 +281,11 @@ public class ZLMHttpHookListener {
|
||||
logger.info("[stream: " + streamId + "] on_stream_changed->>" + schema);
|
||||
}
|
||||
if ("rtmp".equals(schema)){
|
||||
if (regist) {
|
||||
mediaServerService.addCount(mediaServerId);
|
||||
}else {
|
||||
mediaServerService.removeCount(mediaServerId);
|
||||
}
|
||||
if ("rtp".equals(app) && !regist ) {
|
||||
StreamInfo streamInfo = redisCatchStorage.queryPlayByStreamId(streamId);
|
||||
if (streamInfo!=null){
|
||||
@@ -262,10 +297,11 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
}else {
|
||||
if (!"rtp".equals(app) ){
|
||||
IMediaServerItem mediaServerItem = mediaServerService.getOne(mediaServerId);
|
||||
if (regist) {
|
||||
zlmMediaListManager.addMedia(app, streamId);
|
||||
zlmMediaListManager.addMedia(mediaServerItem, app, streamId);
|
||||
}else {
|
||||
zlmMediaListManager.removeMedia(app, streamId);
|
||||
zlmMediaListManager.removeMedia( app, streamId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -288,7 +324,7 @@ public class ZLMHttpHookListener {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_stream_none_reader API调用,参数:" + json.toString());
|
||||
}
|
||||
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
String streamId = json.getString("stream");
|
||||
String app = json.getString("app");
|
||||
|
||||
@@ -329,11 +365,12 @@ public class ZLMHttpHookListener {
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_stream_not_found", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onStreamNotFound(@RequestBody JSONObject json){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_stream_not_found API调用,参数:" + json.toString());
|
||||
}
|
||||
if (userSetup.isAutoApplyPlay()) {
|
||||
String mediaServerId = json.getString("mediaServerId");
|
||||
IMediaServerItem mediaInfo = mediaServerService.getOne(mediaServerId);
|
||||
if (userSetup.isAutoApplyPlay() && mediaInfo != null) {
|
||||
String app = json.getString("app");
|
||||
String streamId = json.getString("stream");
|
||||
if ("rtp".equals(app) && streamId.contains("gb_play") ) {
|
||||
@@ -344,9 +381,9 @@ public class ZLMHttpHookListener {
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
if (device != null) {
|
||||
UUID uuid = UUID.randomUUID();
|
||||
cmder.playStreamCmd(device, channelId, (JSONObject response) -> {
|
||||
cmder.playStreamCmd(mediaInfo, device, channelId, (IMediaServerItem mediaServerItemInuse, JSONObject response) -> {
|
||||
logger.info("收到订阅消息: " + response.toJSONString());
|
||||
playService.onPublishHandlerForPlay(response, deviceId, channelId, uuid.toString());
|
||||
playService.onPublishHandlerForPlay(mediaServerItemInuse, response, deviceId, channelId, uuid.toString());
|
||||
}, null);
|
||||
}
|
||||
|
||||
@@ -367,26 +404,19 @@ public class ZLMHttpHookListener {
|
||||
*/
|
||||
@ResponseBody
|
||||
@PostMapping(value = "/on_server_started", produces = "application/json;charset=UTF-8")
|
||||
public ResponseEntity<String> onServerStarted(HttpServletRequest request, @RequestBody JSONObject json){
|
||||
public ResponseEntity<String> onServerStarted(HttpServletRequest request, @RequestBody JSONObject jsonObject){
|
||||
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("ZLM HOOK on_server_started API调用,参数:" + json.toString());
|
||||
logger.debug("ZLM HOOK on_server_started API调用,参数:" + jsonObject.toString());
|
||||
}
|
||||
|
||||
// String data = json.getString("data");
|
||||
// List<MediaServerConfig> mediaServerConfigs = JSON.parseArray(JSON.toJSONString(json), MediaServerConfig.class);
|
||||
// MediaServerConfig mediaServerConfig = mediaServerConfigs.get(0);
|
||||
|
||||
String remoteAddr = request.getRemoteAddr();
|
||||
jsonObject.put("ip", remoteAddr);
|
||||
List<ZLMHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(ZLMHttpHookSubscribe.HookType.on_server_started);
|
||||
if (subscribes != null && subscribes.size() > 0) {
|
||||
if (subscribes != null && subscribes.size() > 0) {
|
||||
for (ZLMHttpHookSubscribe.Event subscribe : subscribes) {
|
||||
subscribe.response(json);
|
||||
subscribe.response(null, jsonObject);
|
||||
}
|
||||
}
|
||||
ZLMServerConfig ZLMServerConfig = JSON.toJavaObject(json, ZLMServerConfig.class);
|
||||
zlmServerManger.updateServerCatch(ZLMServerConfig);
|
||||
// 重新发起代理
|
||||
|
||||
JSONObject ret = new JSONObject();
|
||||
ret.put("code", 0);
|
||||
ret.put("msg", "success");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.*;
|
||||
@@ -30,7 +32,7 @@ public class ZLMHttpHookSubscribe {
|
||||
}
|
||||
|
||||
public interface Event{
|
||||
void response(JSONObject response);
|
||||
void response(IMediaServerItem mediaServerItem, JSONObject response);
|
||||
}
|
||||
|
||||
private Map<HookType, Map<JSONObject, ZLMHttpHookSubscribe.Event>> allSubscribes = new ConcurrentHashMap<>();
|
||||
|
||||
@@ -2,6 +2,8 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamPushItem;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.GbStream;
|
||||
@@ -45,11 +47,11 @@ public class ZLMMediaListManager {
|
||||
private ZLMHttpHookSubscribe subscribe;
|
||||
|
||||
|
||||
public void updateMediaList() {
|
||||
public void updateMediaList(MediaServerItem mediaServerItem) {
|
||||
storager.clearMediaList();
|
||||
|
||||
// 使用异步的当时更新媒体流列表
|
||||
zlmresTfulUtils.getMediaList((mediaList ->{
|
||||
zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{
|
||||
if (mediaList == null) return;
|
||||
String dataStr = mediaList.getString("data");
|
||||
|
||||
@@ -57,10 +59,10 @@ public class ZLMMediaListManager {
|
||||
Map<String, StreamPushItem> result = new HashMap<>();
|
||||
List<StreamPushItem> streamPushItems = null;
|
||||
// 获取所有的国标关联
|
||||
List<GbStream> gbStreams = gbStreamMapper.selectAll();
|
||||
// List<GbStream> gbStreams = gbStreamMapper.selectAllByMediaServerId(mediaServerItem.getId());
|
||||
if (code == 0 ) {
|
||||
if (dataStr != null) {
|
||||
streamPushItems = streamPushService.handleJSON(dataStr);
|
||||
streamPushItems = streamPushService.handleJSON(dataStr, mediaServerItem);
|
||||
}
|
||||
}else {
|
||||
logger.warn("更新视频流失败,错误code: " + code);
|
||||
@@ -72,24 +74,27 @@ public class ZLMMediaListManager {
|
||||
JSONObject jsonObject = new JSONObject();
|
||||
jsonObject.put("app", streamPushItem.getApp());
|
||||
jsonObject.put("stream", streamPushItem.getStream());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_play,jsonObject,(response)->{
|
||||
updateMedia(response.getString("app"), response.getString("stream"));
|
||||
});
|
||||
jsonObject.put("mediaServerId", mediaServerItem.getId());
|
||||
subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_play,jsonObject,
|
||||
(IMediaServerItem mediaServerItemInuse, JSONObject response)->{
|
||||
updateMedia(mediaServerItem, response.getString("app"), response.getString("stream"));
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
public void addMedia(String app, String streamId) {
|
||||
public void addMedia(IMediaServerItem mediaServerItem, String app, String streamId) {
|
||||
//使用异步更新推流
|
||||
updateMedia(app, streamId);
|
||||
updateMedia(mediaServerItem, app, streamId);
|
||||
}
|
||||
|
||||
|
||||
public void updateMedia(String app, String streamId) {
|
||||
public void updateMedia(IMediaServerItem mediaServerItem, String app, String streamId) {
|
||||
//使用异步更新推流
|
||||
zlmresTfulUtils.getMediaList(app, streamId, "rtmp", json->{
|
||||
zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId, "rtmp", json->{
|
||||
|
||||
if (json == null) return;
|
||||
String dataStr = json.getString("data");
|
||||
@@ -99,7 +104,7 @@ public class ZLMMediaListManager {
|
||||
List<StreamPushItem> streamPushItems = null;
|
||||
if (code == 0 ) {
|
||||
if (dataStr != null) {
|
||||
streamPushItems = streamPushService.handleJSON(dataStr);
|
||||
streamPushItems = streamPushService.handleJSON(dataStr, mediaServerItem);
|
||||
}
|
||||
}else {
|
||||
logger.warn("更新视频流失败,错误code: " + code);
|
||||
@@ -122,32 +127,32 @@ public class ZLMMediaListManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void clearAllSessions() {
|
||||
logger.info("清空所有国标相关的session");
|
||||
JSONObject allSessionJSON = zlmresTfulUtils.getAllSession();
|
||||
ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
HashSet<String> allLocalPorts = new HashSet();
|
||||
if (allSessionJSON.getInteger("code") == 0) {
|
||||
JSONArray data = allSessionJSON.getJSONArray("data");
|
||||
if (data.size() > 0) {
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject sessionJOSN = data.getJSONObject(i);
|
||||
Integer local_port = sessionJOSN.getInteger("local_port");
|
||||
if (!local_port.equals(Integer.valueOf(mediaInfo.getHttpPort())) &&
|
||||
!local_port.equals(Integer.valueOf(mediaInfo.getHttpSSLport())) &&
|
||||
!local_port.equals(Integer.valueOf(mediaInfo.getRtmpPort())) &&
|
||||
!local_port.equals(Integer.valueOf(mediaInfo.getRtspPort())) &&
|
||||
!local_port.equals(Integer.valueOf(mediaInfo.getRtspSSlport())) &&
|
||||
!local_port.equals(Integer.valueOf(mediaInfo.getHookOnFlowReport()))){
|
||||
allLocalPorts.add(sessionJOSN.getInteger("local_port") + "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (allLocalPorts.size() > 0) {
|
||||
List<String> result = new ArrayList<>(allLocalPorts);
|
||||
String localPortSStr = String.join(",", result);
|
||||
zlmresTfulUtils.kickSessions(localPortSStr);
|
||||
}
|
||||
}
|
||||
// public void clearAllSessions() {
|
||||
// logger.info("清空所有国标相关的session");
|
||||
// JSONObject allSessionJSON = zlmresTfulUtils.getAllSession();
|
||||
// ZLMServerConfig mediaInfo = redisCatchStorage.getMediaInfo();
|
||||
// HashSet<String> allLocalPorts = new HashSet();
|
||||
// if (allSessionJSON.getInteger("code") == 0) {
|
||||
// JSONArray data = allSessionJSON.getJSONArray("data");
|
||||
// if (data.size() > 0) {
|
||||
// for (int i = 0; i < data.size(); i++) {
|
||||
// JSONObject sessionJOSN = data.getJSONObject(i);
|
||||
// Integer local_port = sessionJOSN.getInteger("local_port");
|
||||
// if (!local_port.equals(Integer.valueOf(mediaInfo.getHttpPort())) &&
|
||||
// !local_port.equals(Integer.valueOf(mediaInfo.getHttpSSLport())) &&
|
||||
// !local_port.equals(Integer.valueOf(mediaInfo.getRtmpPort())) &&
|
||||
// !local_port.equals(Integer.valueOf(mediaInfo.getRtspPort())) &&
|
||||
// !local_port.equals(Integer.valueOf(mediaInfo.getRtspSSlport())) &&
|
||||
// !local_port.equals(Integer.valueOf(mediaInfo.getHookOnFlowReport()))){
|
||||
// allLocalPorts.add(sessionJOSN.getInteger("local_port") + "");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (allLocalPorts.size() > 0) {
|
||||
// List<String> result = new ArrayList<>(allLocalPorts);
|
||||
// String localPortSStr = String.join(",", result);
|
||||
// zlmresTfulUtils.kickSessions(localPortSStr);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import okhttp3.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
@@ -21,23 +23,18 @@ public class ZLMRESTfulUtils {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMRESTfulUtils.class);
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
|
||||
|
||||
public interface RequestCallback{
|
||||
void run(JSONObject response);
|
||||
}
|
||||
|
||||
public JSONObject sendPost(String api, Map<String, Object> param, RequestCallback callback) {
|
||||
public JSONObject sendPost(IMediaServerItem mediaServerItem, String api, Map<String, Object> param, RequestCallback callback) {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
String url = String.format("http://%s:%s/index/api/%s", mediaConfig.getIp(), mediaConfig.getHttpPort(), api);
|
||||
String url = String.format("http://%s:%s/index/api/%s", mediaServerItem.getIp(), mediaServerItem.getHttpPort(), api);
|
||||
JSONObject responseJSON = null;
|
||||
logger.debug(url);
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
builder.add("secret",mediaConfig.getSecret());
|
||||
builder.add("secret",mediaServerItem.getSecret());
|
||||
if (param != null && param.keySet().size() > 0) {
|
||||
for (String key : param.keySet()){
|
||||
if (param.get(key) != null) {
|
||||
@@ -96,14 +93,14 @@ public class ZLMRESTfulUtils {
|
||||
}
|
||||
|
||||
|
||||
public void sendPostForImg(String api, Map<String, Object> param, String targetPath, String fileName) {
|
||||
public void sendPostForImg(IMediaServerItem mediaServerItem, String api, Map<String, Object> param, String targetPath, String fileName) {
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
String url = String.format("http://%s:%s/index/api/%s", mediaConfig.getIp(), mediaConfig.getHttpPort(), api);
|
||||
String url = String.format("http://%s:%s/index/api/%s", mediaServerItem.getIp(), mediaServerItem.getHttpPort(), api);
|
||||
JSONObject responseJSON = null;
|
||||
logger.debug(url);
|
||||
|
||||
FormBody.Builder builder = new FormBody.Builder();
|
||||
builder.add("secret",mediaConfig.getSecret());
|
||||
builder.add("secret",mediaServerItem.getSecret());
|
||||
if (param != null && param.keySet().size() > 0) {
|
||||
for (String key : param.keySet()){
|
||||
if (param.get(key) != null) {
|
||||
@@ -142,39 +139,39 @@ public class ZLMRESTfulUtils {
|
||||
}
|
||||
|
||||
|
||||
public JSONObject getMediaList(String app, String stream, String schema, RequestCallback callback){
|
||||
public JSONObject getMediaList(IMediaServerItem mediaServerItem,String app, String stream, String schema, RequestCallback callback){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
if (app != null) param.put("app",app);
|
||||
if (stream != null) param.put("stream",stream);
|
||||
if (schema != null) param.put("schema",schema);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
return sendPost("getMediaList",param, callback);
|
||||
return sendPost(mediaServerItem, "getMediaList",param, callback);
|
||||
}
|
||||
|
||||
public JSONObject getMediaList(String app, String stream){
|
||||
return getMediaList(app, stream,null, null);
|
||||
public JSONObject getMediaList(IMediaServerItem mediaServerItem,String app, String stream){
|
||||
return getMediaList(mediaServerItem, app, stream,null, null);
|
||||
}
|
||||
|
||||
public JSONObject getMediaList(RequestCallback callback){
|
||||
return sendPost("getMediaList",null, callback);
|
||||
public JSONObject getMediaList(IMediaServerItem mediaServerItem,RequestCallback callback){
|
||||
return sendPost(mediaServerItem, "getMediaList",null, callback);
|
||||
}
|
||||
|
||||
public JSONObject getMediaInfo(String app, String schema, String stream){
|
||||
public JSONObject getMediaInfo(IMediaServerItem mediaServerItem,String app, String schema, String stream){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("app",app);
|
||||
param.put("schema",schema);
|
||||
param.put("stream",stream);
|
||||
param.put("vhost","__defaultVhost__");
|
||||
return sendPost("getMediaInfo",param, null);
|
||||
return sendPost(mediaServerItem, "getMediaInfo",param, null);
|
||||
}
|
||||
|
||||
public JSONObject getRtpInfo(String stream_id){
|
||||
public JSONObject getRtpInfo(IMediaServerItem mediaServerItem,String stream_id){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id",stream_id);
|
||||
return sendPost("getRtpInfo",param, null);
|
||||
return sendPost(mediaServerItem, "getRtpInfo",param, null);
|
||||
}
|
||||
|
||||
public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms,
|
||||
public JSONObject addFFmpegSource(IMediaServerItem mediaServerItem,String src_url, String dst_url, String timeout_ms,
|
||||
boolean enable_hls, boolean enable_mp4, String ffmpeg_cmd_key){
|
||||
logger.info(src_url);
|
||||
logger.info(dst_url);
|
||||
@@ -185,44 +182,44 @@ public class ZLMRESTfulUtils {
|
||||
param.put("enable_hls", enable_hls);
|
||||
param.put("enable_mp4", enable_mp4);
|
||||
param.put("ffmpeg_cmd_key", ffmpeg_cmd_key);
|
||||
return sendPost("addFFmpegSource",param, null);
|
||||
return sendPost(mediaServerItem, "addFFmpegSource",param, null);
|
||||
}
|
||||
|
||||
public JSONObject delFFmpegSource(String key){
|
||||
public JSONObject delFFmpegSource(IMediaServerItem mediaServerItem,String key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("key", key);
|
||||
return sendPost("delFFmpegSource",param, null);
|
||||
return sendPost(mediaServerItem, "delFFmpegSource",param, null);
|
||||
}
|
||||
|
||||
public JSONObject getMediaServerConfig(){
|
||||
return sendPost("getServerConfig",null, null);
|
||||
public JSONObject getMediaServerConfig(IMediaServerItem mediaServerItem){
|
||||
return sendPost(mediaServerItem, "getServerConfig",null, null);
|
||||
}
|
||||
|
||||
public JSONObject setServerConfig(Map<String, Object> param){
|
||||
return sendPost("setServerConfig",param, null);
|
||||
public JSONObject setServerConfig(IMediaServerItem mediaServerItem, Map<String, Object> param){
|
||||
return sendPost(mediaServerItem,"setServerConfig",param, null);
|
||||
}
|
||||
|
||||
public JSONObject openRtpServer(Map<String, Object> param){
|
||||
return sendPost("openRtpServer",param, null);
|
||||
public JSONObject openRtpServer(IMediaServerItem mediaServerItem,Map<String, Object> param){
|
||||
return sendPost(mediaServerItem, "openRtpServer",param, null);
|
||||
}
|
||||
|
||||
public JSONObject closeRtpServer(Map<String, Object> param) {
|
||||
return sendPost("closeRtpServer",param, null);
|
||||
public JSONObject closeRtpServer(IMediaServerItem mediaServerItem,Map<String, Object> param) {
|
||||
return sendPost(mediaServerItem, "closeRtpServer",param, null);
|
||||
}
|
||||
|
||||
public JSONObject listRtpServer() {
|
||||
return sendPost("listRtpServer",null, null);
|
||||
public JSONObject listRtpServer(IMediaServerItem mediaServerItem) {
|
||||
return sendPost(mediaServerItem, "listRtpServer",null, null);
|
||||
}
|
||||
|
||||
public JSONObject startSendRtp(Map<String, Object> param) {
|
||||
return sendPost("startSendRtp",param, null);
|
||||
public JSONObject startSendRtp(IMediaServerItem mediaServerItem,Map<String, Object> param) {
|
||||
return sendPost(mediaServerItem, "startSendRtp",param, null);
|
||||
}
|
||||
|
||||
public JSONObject stopSendRtp(Map<String, Object> param) {
|
||||
return sendPost("stopSendRtp",param, null);
|
||||
public JSONObject stopSendRtp(IMediaServerItem mediaServerItem,Map<String, Object> param) {
|
||||
return sendPost(mediaServerItem, "stopSendRtp",param, null);
|
||||
}
|
||||
|
||||
public JSONObject addStreamProxy(String app, String stream, String url, boolean enable_hls, boolean enable_mp4, String rtp_type) {
|
||||
public JSONObject addStreamProxy(IMediaServerItem mediaServerItem,String app, String stream, String url, boolean enable_hls, boolean enable_mp4, String rtp_type) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", app);
|
||||
@@ -231,33 +228,33 @@ public class ZLMRESTfulUtils {
|
||||
param.put("enable_hls", enable_hls?1:0);
|
||||
param.put("enable_mp4", enable_mp4?1:0);
|
||||
param.put("rtp_type", rtp_type);
|
||||
return sendPost("addStreamProxy",param, null);
|
||||
return sendPost(mediaServerItem, "addStreamProxy",param, null);
|
||||
}
|
||||
|
||||
public JSONObject closeStreams(String app, String stream) {
|
||||
public JSONObject closeStreams(IMediaServerItem mediaServerItem,String app, String stream) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", app);
|
||||
param.put("stream", stream);
|
||||
param.put("force", 1);
|
||||
return sendPost("close_streams",param, null);
|
||||
return sendPost(mediaServerItem, "close_streams",param, null);
|
||||
}
|
||||
|
||||
public JSONObject getAllSession() {
|
||||
return sendPost("getAllSession",null, null);
|
||||
public JSONObject getAllSession(IMediaServerItem mediaServerItem) {
|
||||
return sendPost(mediaServerItem, "getAllSession",null, null);
|
||||
}
|
||||
|
||||
public void kickSessions(String localPortSStr) {
|
||||
public void kickSessions(IMediaServerItem mediaServerItem, String localPortSStr) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("local_port", localPortSStr);
|
||||
sendPost("kick_sessions",param, null);
|
||||
sendPost(mediaServerItem, "kick_sessions",param, null);
|
||||
}
|
||||
|
||||
public void getSnap(String flvUrl, int timeout_sec, int expire_sec, String targetPath, String fileName) {
|
||||
public void getSnap(IMediaServerItem mediaServerItem, String flvUrl, int timeout_sec, int expire_sec, String targetPath, String fileName) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("url", flvUrl);
|
||||
param.put("timeout_sec", timeout_sec);
|
||||
param.put("expire_sec", expire_sec);
|
||||
sendPostForImg("getSnap",param, targetPath, fileName);
|
||||
sendPostForImg(mediaServerItem, "getSnap",param, targetPath, fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem;
|
||||
import com.genersoft.iot.vmp.gb28181.session.SsrcUtil;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -30,10 +32,10 @@ public class ZLMRTPServerFactory {
|
||||
|
||||
private Map<String, Integer> currentStreams = null;
|
||||
|
||||
public int createRTPServer(String streamId) {
|
||||
public int createRTPServer(IMediaServerItem mediaServerItem, String streamId) {
|
||||
if (currentStreams == null) {
|
||||
currentStreams = new HashMap<>();
|
||||
JSONObject jsonObject = zlmresTfulUtils.listRtpServer();
|
||||
JSONObject jsonObject = zlmresTfulUtils.listRtpServer(mediaServerItem);
|
||||
if (jsonObject != null) {
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
if (data != null) {
|
||||
@@ -48,7 +50,7 @@ public class ZLMRTPServerFactory {
|
||||
if (currentStreams.get(streamId) != null) {
|
||||
Map<String, Object> closeRtpServerParam = new HashMap<>();
|
||||
closeRtpServerParam.put("stream_id", streamId);
|
||||
zlmresTfulUtils.closeRtpServer(closeRtpServerParam);
|
||||
zlmresTfulUtils.closeRtpServer(mediaServerItem, closeRtpServerParam);
|
||||
currentStreams.remove(streamId);
|
||||
}
|
||||
|
||||
@@ -58,7 +60,7 @@ public class ZLMRTPServerFactory {
|
||||
param.put("port", newPort);
|
||||
param.put("enable_tcp", 1);
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param);
|
||||
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(mediaServerItem, param);
|
||||
|
||||
if (jsonObject != null) {
|
||||
switch (jsonObject.getInteger("code")){
|
||||
@@ -68,11 +70,11 @@ public class ZLMRTPServerFactory {
|
||||
case -300: // id已经存在, 可能已经在其他端口推流
|
||||
Map<String, Object> closeRtpServerParam = new HashMap<>();
|
||||
closeRtpServerParam.put("stream_id", streamId);
|
||||
zlmresTfulUtils.closeRtpServer(closeRtpServerParam);
|
||||
zlmresTfulUtils.closeRtpServer(mediaServerItem, closeRtpServerParam);
|
||||
result = newPort;
|
||||
break;
|
||||
case -400: // 端口占用
|
||||
result= createRTPServer(streamId);
|
||||
result= createRTPServer(mediaServerItem, streamId);
|
||||
break;
|
||||
default:
|
||||
logger.error("创建RTP Server 失败 {}: " + jsonObject.getString("msg"), newPort);
|
||||
@@ -85,20 +87,22 @@ public class ZLMRTPServerFactory {
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean closeRTPServer(String streamId) {
|
||||
public boolean closeRTPServer(IMediaServerItem serverItem, String streamId) {
|
||||
boolean result = false;
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(param);
|
||||
if (jsonObject != null ) {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
result = jsonObject.getInteger("hit") == 1;
|
||||
if (serverItem !=null){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(serverItem, param);
|
||||
if (jsonObject != null ) {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
result = jsonObject.getInteger("hit") == 1;
|
||||
}else {
|
||||
logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
}
|
||||
}else {
|
||||
logger.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
// 检查ZLM状态
|
||||
logger.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
}
|
||||
}else {
|
||||
// 检查ZLM状态
|
||||
logger.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -131,11 +135,11 @@ public class ZLMRTPServerFactory {
|
||||
* @param tcp 是否为tcp
|
||||
* @return SendRtpItem
|
||||
*/
|
||||
public SendRtpItem createSendRtpItem(String ip, int port, String ssrc, String platformId, String deviceId, String channelId, boolean tcp){
|
||||
public SendRtpItem createSendRtpItem(IMediaServerItem serverItem, String ip, int port, String ssrc, String platformId, String deviceId, String channelId, boolean tcp){
|
||||
String playSsrc = SsrcUtil.getPlaySsrc();
|
||||
int localPort = createRTPServer(SsrcUtil.getPlaySsrc());
|
||||
int localPort = createRTPServer(serverItem, SsrcUtil.getPlaySsrc());
|
||||
if (localPort != -1) {
|
||||
closeRTPServer(playSsrc);
|
||||
closeRTPServer(serverItem, playSsrc);
|
||||
}else {
|
||||
logger.error("没有可用的端口");
|
||||
return null;
|
||||
@@ -150,6 +154,7 @@ public class ZLMRTPServerFactory {
|
||||
sendRtpItem.setTcp(tcp);
|
||||
sendRtpItem.setApp("rtp");
|
||||
sendRtpItem.setLocalPort(localPort);
|
||||
sendRtpItem.setMediaServerId(serverItem.getId());
|
||||
return sendRtpItem;
|
||||
}
|
||||
|
||||
@@ -163,11 +168,11 @@ public class ZLMRTPServerFactory {
|
||||
* @param tcp 是否为tcp
|
||||
* @return SendRtpItem
|
||||
*/
|
||||
public SendRtpItem createSendRtpItem(String ip, int port, String ssrc, String platformId, String app, String stream, String channelId, boolean tcp){
|
||||
public SendRtpItem createSendRtpItem(IMediaServerItem serverItem, String ip, int port, String ssrc, String platformId, String app, String stream, String channelId, boolean tcp){
|
||||
String playSsrc = SsrcUtil.getPlaySsrc();
|
||||
int localPort = createRTPServer(SsrcUtil.getPlaySsrc());
|
||||
int localPort = createRTPServer(serverItem, SsrcUtil.getPlaySsrc());
|
||||
if (localPort != -1) {
|
||||
closeRTPServer(playSsrc);
|
||||
closeRTPServer(serverItem, playSsrc);
|
||||
}else {
|
||||
logger.error("没有可用的端口");
|
||||
return null;
|
||||
@@ -182,21 +187,21 @@ public class ZLMRTPServerFactory {
|
||||
sendRtpItem.setChannelId(channelId);
|
||||
sendRtpItem.setTcp(tcp);
|
||||
sendRtpItem.setLocalPort(localPort);
|
||||
sendRtpItem.setMediaServerId(serverItem.getId());
|
||||
return sendRtpItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用zlm RESTful API —— startSendRtp
|
||||
*/
|
||||
public Boolean startSendRtpStream(Map<String, Object>param) {
|
||||
public Boolean startSendRtpStream(IMediaServerItem mediaServerItem, Map<String, Object>param) {
|
||||
Boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param);
|
||||
logger.info(jsonObject.toJSONString());
|
||||
JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServerItem, param);
|
||||
if (jsonObject == null) {
|
||||
logger.error("RTP推流失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
result= true;
|
||||
logger.info("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port"));
|
||||
logger.info("RTP推流[ {}/{} ]请求成功,本地推流端口:{}" ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"));
|
||||
} else {
|
||||
logger.error("RTP推流失败: " + jsonObject.getString("msg"));
|
||||
}
|
||||
@@ -206,16 +211,16 @@ public class ZLMRTPServerFactory {
|
||||
/**
|
||||
* 查询待转推的流是否就绪
|
||||
*/
|
||||
public Boolean isRtpReady(String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
|
||||
public Boolean isRtpReady(MediaServerItem mediaServerItem, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem,"rtp", "rtmp", streamId);
|
||||
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询待转推的流是否就绪
|
||||
*/
|
||||
public Boolean isStreamReady(String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(app, "rtmp", streamId);
|
||||
public Boolean isStreamReady(IMediaServerItem mediaServerItem, String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId);
|
||||
return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
|
||||
}
|
||||
|
||||
@@ -224,18 +229,17 @@ public class ZLMRTPServerFactory {
|
||||
* @param streamId
|
||||
* @return
|
||||
*/
|
||||
public int totalReaderCount(String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(app, "rtmp", streamId);
|
||||
public int totalReaderCount(IMediaServerItem mediaServerItem, String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtmp", streamId);
|
||||
return mediaInfo.getInteger("totalReaderCount");
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用zlm RESTful API —— stopSendRtp
|
||||
*/
|
||||
public Boolean stopSendRtpStream(Map<String, Object>param) {
|
||||
public Boolean stopSendRtpStream(IMediaServerItem mediaServerItem,Map<String, Object>param) {
|
||||
Boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(param);
|
||||
logger.info(jsonObject.toJSONString());
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param);
|
||||
if (jsonObject == null) {
|
||||
logger.error("停止RTP推流失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
|
||||
@@ -4,7 +4,10 @@ import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.IMediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
||||
import com.genersoft.iot.vmp.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.storager.IVideoManagerStorager;
|
||||
import com.genersoft.iot.vmp.service.IStreamProxyService;
|
||||
import org.slf4j.Logger;
|
||||
@@ -14,10 +17,10 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import javax.print.attribute.standard.Media;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
@Order(value=1)
|
||||
@@ -25,140 +28,131 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
|
||||
private final static Logger logger = LoggerFactory.getLogger(ZLMRunner.class);
|
||||
|
||||
@Autowired
|
||||
private IVideoManagerStorager storager;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
@Value("${server.port}")
|
||||
private String serverPort;
|
||||
|
||||
@Value("${server.ssl.enabled:false}")
|
||||
private boolean sslEnabled;
|
||||
|
||||
private boolean startGetMedia = false;
|
||||
private Map<String, Boolean> startGetMedia;
|
||||
|
||||
@Autowired
|
||||
private ZLMRESTfulUtils zlmresTfulUtils;
|
||||
|
||||
@Autowired
|
||||
private ZLMMediaListManager zlmMediaListManager;
|
||||
|
||||
@Autowired
|
||||
private ZLMHttpHookSubscribe hookSubscribe;
|
||||
|
||||
@Autowired
|
||||
private ZLMServerManger zlmServerManger;
|
||||
|
||||
@Autowired
|
||||
private IStreamProxyService streamProxyService;
|
||||
|
||||
@Autowired
|
||||
private IMediaServerService mediaServerService;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
@Override
|
||||
public void run(String... strings) throws Exception {
|
||||
// 订阅 zlm启动事件
|
||||
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null,(response)->{
|
||||
ZLMServerConfig ZLMServerConfig = JSONObject.toJavaObject(response, ZLMServerConfig.class);
|
||||
zLmRunning(ZLMServerConfig);
|
||||
IMediaServerItem presetMediaServer = mediaServerService.getOneByHostAndPort(
|
||||
mediaConfig.getIp(), mediaConfig.getHttpPort());
|
||||
if (presetMediaServer != null) {
|
||||
mediaConfig.setId(presetMediaServer.getId());
|
||||
mediaServerService.update(mediaConfig);
|
||||
}
|
||||
|
||||
// 订阅 zlm启动事件, 新的zlm也会从这里进入系统
|
||||
hookSubscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_server_started,null,
|
||||
(IMediaServerItem mediaServerItem, JSONObject response)->{
|
||||
ZLMServerConfig zlmServerConfig = JSONObject.toJavaObject(response, ZLMServerConfig.class);
|
||||
if (zlmServerConfig !=null ) {
|
||||
startGetMedia.remove(zlmServerConfig.getGeneralMediaServerId());
|
||||
mediaServerService.handLeZLMServerConfig(zlmServerConfig);
|
||||
// zLmRunning(zlmServerConfig);
|
||||
}
|
||||
});
|
||||
|
||||
// 获取zlm信息
|
||||
logger.info("等待zlm接入...");
|
||||
startGetMedia = true;
|
||||
ZLMServerConfig ZLMServerConfig = getMediaServerConfig();
|
||||
logger.info("等待默认zlm接入...");
|
||||
|
||||
if (ZLMServerConfig != null) {
|
||||
zLmRunning(ZLMServerConfig);
|
||||
// 获取所有的zlm, 并开启主动连接
|
||||
List<IMediaServerItem> all = mediaServerService.getAll();
|
||||
if (presetMediaServer == null) {
|
||||
all.add(mediaConfig.getMediaSerItem());
|
||||
}
|
||||
for (IMediaServerItem mediaServerItem : all) {
|
||||
if (startGetMedia == null) startGetMedia = new HashMap<>();
|
||||
startGetMedia.put(mediaServerItem.getId(), true);
|
||||
new Thread(() -> {
|
||||
ZLMServerConfig zlmServerConfig = getMediaServerConfig(mediaServerItem);
|
||||
if (zlmServerConfig != null) {
|
||||
startGetMedia.remove(mediaServerItem.getId());
|
||||
mediaServerService.handLeZLMServerConfig(zlmServerConfig);
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
Timer timer = new Timer();
|
||||
// 1分钟后未连接到则不再去主动连接
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (startGetMedia != null) {
|
||||
Set<String> allZlmId = startGetMedia.keySet();
|
||||
for (String id : allZlmId) {
|
||||
logger.error("[ {} ]]主动连接失败,不再主动连接", id);
|
||||
startGetMedia.put(id, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, 60 * 1000 * 2);
|
||||
}
|
||||
|
||||
public ZLMServerConfig getMediaServerConfig() {
|
||||
if (!startGetMedia) return null;
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig();
|
||||
public ZLMServerConfig getMediaServerConfig(IMediaServerItem mediaServerItem) {
|
||||
if ( startGetMedia.get(mediaServerItem.getId()) == null || !startGetMedia.get(mediaServerItem.getId())) return null;
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig ZLMServerConfig = null;
|
||||
if (responseJSON != null) {
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
if (data != null && data.size() > 0) {
|
||||
ZLMServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
|
||||
ZLMServerConfig.setIp(mediaServerItem.getIp());
|
||||
}
|
||||
} else {
|
||||
logger.error("getMediaServerConfig失败, 1s后重试");
|
||||
logger.error("[ {} ]-[ {}:{} ]主动连接失败失败, 2s后重试",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
Thread.sleep(2000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ZLMServerConfig = getMediaServerConfig();
|
||||
ZLMServerConfig = getMediaServerConfig(mediaServerItem);
|
||||
}
|
||||
return ZLMServerConfig;
|
||||
}
|
||||
|
||||
private void saveZLMConfig() {
|
||||
logger.info("设置zlm...");
|
||||
String protocol = sslEnabled ? "https" : "http";
|
||||
String hookPrex = String.format("%s://%s:%s/index/hook", protocol, mediaConfig.getHookIp(), serverPort);
|
||||
String recordHookPrex = null;
|
||||
if (mediaConfig.getRecordAssistPort() != 0) {
|
||||
recordHookPrex = String.format("http://127.0.0.1:%s/api/record", mediaConfig.getRecordAssistPort());
|
||||
}
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("api.secret",mediaConfig.getSecret()); // -profile:v Baseline
|
||||
param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s");
|
||||
param.put("hook.enable","1");
|
||||
param.put("hook.on_flow_report","");
|
||||
param.put("hook.on_play",String.format("%s/on_play", hookPrex));
|
||||
param.put("hook.on_http_access","");
|
||||
param.put("hook.on_publish", String.format("%s/on_publish", hookPrex));
|
||||
param.put("hook.on_record_mp4",recordHookPrex != null? String.format("%s/on_record_mp4", recordHookPrex): "");
|
||||
param.put("hook.on_record_ts","");
|
||||
param.put("hook.on_rtsp_auth","");
|
||||
param.put("hook.on_rtsp_realm","");
|
||||
param.put("hook.on_server_started",String.format("%s/on_server_started", hookPrex));
|
||||
param.put("hook.on_shell_login",String.format("%s/on_shell_login", hookPrex));
|
||||
param.put("hook.on_stream_changed",String.format("%s/on_stream_changed", hookPrex));
|
||||
param.put("hook.on_stream_none_reader",String.format("%s/on_stream_none_reader", hookPrex));
|
||||
param.put("hook.on_stream_not_found",String.format("%s/on_stream_not_found", hookPrex));
|
||||
param.put("hook.timeoutSec","20");
|
||||
param.put("general.streamNoneReaderDelayMS",mediaConfig.getStreamNoneReaderDelayMS());
|
||||
|
||||
JSONObject responseJSON = zlmresTfulUtils.setServerConfig(param);
|
||||
|
||||
if (responseJSON != null && responseJSON.getInteger("code") == 0) {
|
||||
logger.info("设置zlm成功");
|
||||
}else {
|
||||
logger.info("设置zlm失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* zlm 连接成功或者zlm重启后
|
||||
*/
|
||||
private void zLmRunning(ZLMServerConfig zlmServerConfig){
|
||||
logger.info( "[ id: " + zlmServerConfig.getGeneralMediaServerId() + "] zlm接入成功...");
|
||||
// 关闭循环获取zlm配置
|
||||
startGetMedia = false;
|
||||
if (mediaConfig.isAutoConfig()) saveZLMConfig();
|
||||
zlmServerManger.updateServerCatch(zlmServerConfig);
|
||||
|
||||
// 清空所有session
|
||||
// zlmMediaListManager.clearAllSessions();
|
||||
|
||||
// 更新流列表
|
||||
zlmMediaListManager.updateMediaList();
|
||||
// 恢复流代理
|
||||
List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnable(true);
|
||||
for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
|
||||
logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
|
||||
JSONObject jsonObject = streamProxyService.addStreamProxyToZlm(streamProxyDto);
|
||||
if (jsonObject == null) {
|
||||
// 设置为未启用
|
||||
logger.info("恢复流代理失败,请检查流地址后重新启用" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
|
||||
streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream());
|
||||
}else if (jsonObject.getInteger("code") != 0){ // TODO 将错误信息存入数据库, 前端展示
|
||||
logger.info("恢复流代理失败:" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream() + "[ " + JSONObject.toJSONString(jsonObject) + " ]");
|
||||
streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream());
|
||||
}
|
||||
}
|
||||
}
|
||||
// private void zLmRunning(ZLMServerConfig zlmServerConfig){
|
||||
// logger.info( "[ id: " + zlmServerConfig.getGeneralMediaServerId() + "] zlm接入成功...");
|
||||
// // 关闭循环获取zlm配置
|
||||
// startGetMedia = false;
|
||||
// MediaServerItem mediaServerItem = new MediaServerItem(zlmServerConfig, sipIp);
|
||||
// storager.updateMediaServer(mediaServerItem);
|
||||
//
|
||||
// if (mediaServerItem.isAutoConfig()) setZLMConfig(mediaServerItem);
|
||||
// zlmServerManger.updateServerCatchFromHook(zlmServerConfig);
|
||||
//
|
||||
// // 清空所有session
|
||||
//// zlmMediaListManager.clearAllSessions();
|
||||
//
|
||||
// // 更新流列表
|
||||
// zlmMediaListManager.updateMediaList(mediaServerItem);
|
||||
// // 恢复流代理, 只查找这个这个流媒体
|
||||
// List<StreamProxyItem> streamProxyListForEnable = storager.getStreamProxyListForEnableInMediaServer(
|
||||
// mediaServerItem.getId(), true);
|
||||
// for (StreamProxyItem streamProxyDto : streamProxyListForEnable) {
|
||||
// logger.info("恢复流代理," + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
|
||||
// JSONObject jsonObject = streamProxyService.addStreamProxyToZlm(streamProxyDto);
|
||||
// if (jsonObject == null) {
|
||||
// // 设置为未启用
|
||||
// logger.info("恢复流代理失败,请检查流地址后重新启用" + streamProxyDto.getApp() + "/" + streamProxyDto.getStream());
|
||||
// streamProxyService.stop(streamProxyDto.getApp(), streamProxyDto.getStream());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -34,12 +34,15 @@ public class ZLMServerConfig {
|
||||
@JSONField(name = "general.streamNoneReaderDelayMS")
|
||||
private String generalStreamNoneReaderDelayMS;
|
||||
|
||||
@JSONField(name = "ip")
|
||||
private String ip;
|
||||
|
||||
private String sdpIp;
|
||||
|
||||
private String streamIp;
|
||||
|
||||
private String hookIp;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
private String createTime;
|
||||
@@ -66,7 +69,7 @@ public class ZLMServerConfig {
|
||||
private String hookEnable;
|
||||
|
||||
@JSONField(name = "hook.on_flow_report")
|
||||
private Integer hookOnFlowReport;
|
||||
private String hookOnFlowReport;
|
||||
|
||||
@JSONField(name = "hook.on_http_access")
|
||||
private String hookOnHttpAccess;
|
||||
@@ -117,7 +120,7 @@ public class ZLMServerConfig {
|
||||
private String httpNotFound;
|
||||
|
||||
@JSONField(name = "http.port")
|
||||
private Integer httpPort;
|
||||
private int httpPort;
|
||||
|
||||
@JSONField(name = "http.rootPath")
|
||||
private String httpRootPath;
|
||||
@@ -126,7 +129,7 @@ public class ZLMServerConfig {
|
||||
private String httpSendBufSize;
|
||||
|
||||
@JSONField(name = "http.sslport")
|
||||
private Integer httpSSLport;
|
||||
private int httpSSLport;
|
||||
|
||||
@JSONField(name = "multicast.addrMax")
|
||||
private String multicastAddrMax;
|
||||
@@ -159,10 +162,10 @@ public class ZLMServerConfig {
|
||||
private String rtmpModifyStamp;
|
||||
|
||||
@JSONField(name = "rtmp.port")
|
||||
private Integer rtmpPort;
|
||||
private int rtmpPort;
|
||||
|
||||
@JSONField(name = "rtmp.sslport")
|
||||
private Integer rtmpSslPort;
|
||||
private int rtmpSslPort;
|
||||
|
||||
@JSONField(name = "rtp.audioMtuSize")
|
||||
private String rtpAudioMtuSize;
|
||||
@@ -186,7 +189,7 @@ public class ZLMServerConfig {
|
||||
private String rtpProxyDumpDir;
|
||||
|
||||
@JSONField(name = "rtp_proxy.port")
|
||||
private Integer rtpProxyPort;
|
||||
private int rtpProxyPort;
|
||||
|
||||
@JSONField(name = "rtp_proxy.timeoutSec")
|
||||
private String rtpProxyTimeoutSec;
|
||||
@@ -201,10 +204,10 @@ public class ZLMServerConfig {
|
||||
private String rtspKeepAliveSecond;
|
||||
|
||||
@JSONField(name = "rtsp.port")
|
||||
private Integer rtspPort;
|
||||
private int rtspPort;
|
||||
|
||||
@JSONField(name = "rtsp.sslport")
|
||||
private Integer rtspSSlport;
|
||||
private int rtspSSlport;
|
||||
|
||||
@JSONField(name = "shell.maxReqSize")
|
||||
private String shellMaxReqSize;
|
||||
@@ -212,6 +215,15 @@ public class ZLMServerConfig {
|
||||
@JSONField(name = "shell.shell")
|
||||
private String shellPhell;
|
||||
|
||||
|
||||
public String getHookIp() {
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
public void setHookIp(String hookIp) {
|
||||
this.hookIp = hookIp;
|
||||
}
|
||||
|
||||
public String getApiDebug() {
|
||||
return apiDebug;
|
||||
}
|
||||
@@ -388,11 +400,11 @@ public class ZLMServerConfig {
|
||||
this.hookEnable = hookEnable;
|
||||
}
|
||||
|
||||
public Integer getHookOnFlowReport() {
|
||||
public String getHookOnFlowReport() {
|
||||
return hookOnFlowReport;
|
||||
}
|
||||
|
||||
public void setHookOnFlowReport(Integer hookOnFlowReport) {
|
||||
public void setHookOnFlowReport(String hookOnFlowReport) {
|
||||
this.hookOnFlowReport = hookOnFlowReport;
|
||||
}
|
||||
|
||||
@@ -524,11 +536,11 @@ public class ZLMServerConfig {
|
||||
this.httpNotFound = httpNotFound;
|
||||
}
|
||||
|
||||
public Integer getHttpPort() {
|
||||
public int getHttpPort() {
|
||||
return httpPort;
|
||||
}
|
||||
|
||||
public void setHttpPort(Integer httpPort) {
|
||||
public void setHttpPort(int httpPort) {
|
||||
this.httpPort = httpPort;
|
||||
}
|
||||
|
||||
@@ -548,11 +560,11 @@ public class ZLMServerConfig {
|
||||
this.httpSendBufSize = httpSendBufSize;
|
||||
}
|
||||
|
||||
public Integer getHttpSSLport() {
|
||||
public int getHttpSSLport() {
|
||||
return httpSSLport;
|
||||
}
|
||||
|
||||
public void setHttpSSLport(Integer httpSSLport) {
|
||||
public void setHttpSSLport(int httpSSLport) {
|
||||
this.httpSSLport = httpSSLport;
|
||||
}
|
||||
|
||||
@@ -636,19 +648,19 @@ public class ZLMServerConfig {
|
||||
this.rtmpModifyStamp = rtmpModifyStamp;
|
||||
}
|
||||
|
||||
public Integer getRtmpPort() {
|
||||
public int getRtmpPort() {
|
||||
return rtmpPort;
|
||||
}
|
||||
|
||||
public void setRtmpPort(Integer rtmpPort) {
|
||||
public void setRtmpPort(int rtmpPort) {
|
||||
this.rtmpPort = rtmpPort;
|
||||
}
|
||||
|
||||
public Integer getRtmpSslPort() {
|
||||
public int getRtmpSslPort() {
|
||||
return rtmpSslPort;
|
||||
}
|
||||
|
||||
public void setRtmpSslPort(Integer rtmpSslPort) {
|
||||
public void setRtmpSslPort(int rtmpSslPort) {
|
||||
this.rtmpSslPort = rtmpSslPort;
|
||||
}
|
||||
|
||||
@@ -708,11 +720,11 @@ public class ZLMServerConfig {
|
||||
this.rtpProxyDumpDir = rtpProxyDumpDir;
|
||||
}
|
||||
|
||||
public Integer getRtpProxyPort() {
|
||||
public int getRtpProxyPort() {
|
||||
return rtpProxyPort;
|
||||
}
|
||||
|
||||
public void setRtpProxyPort(Integer rtpProxyPort) {
|
||||
public void setRtpProxyPort(int rtpProxyPort) {
|
||||
this.rtpProxyPort = rtpProxyPort;
|
||||
}
|
||||
|
||||
@@ -748,19 +760,19 @@ public class ZLMServerConfig {
|
||||
this.rtspKeepAliveSecond = rtspKeepAliveSecond;
|
||||
}
|
||||
|
||||
public Integer getRtspPort() {
|
||||
public int getRtspPort() {
|
||||
return rtspPort;
|
||||
}
|
||||
|
||||
public void setRtspPort(Integer rtspPort) {
|
||||
public void setRtspPort(int rtspPort) {
|
||||
this.rtspPort = rtspPort;
|
||||
}
|
||||
|
||||
public Integer getRtspSSlport() {
|
||||
public int getRtspSSlport() {
|
||||
return rtspSSlport;
|
||||
}
|
||||
|
||||
public void setRtspSSlport(Integer rtspSSlport) {
|
||||
public void setRtspSSlport(int rtspSSlport) {
|
||||
this.rtspSSlport = rtspSSlport;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.genersoft.iot.vmp.conf.MediaConfig;
|
||||
import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@Component
|
||||
public class ZLMServerManger {
|
||||
|
||||
@Autowired
|
||||
private IRedisCatchStorage redisCatchStorage;
|
||||
|
||||
@Autowired
|
||||
private MediaConfig mediaConfig;
|
||||
|
||||
public void updateServerCatch(ZLMServerConfig zlmServerConfig) {
|
||||
|
||||
zlmServerConfig.setIp(mediaConfig.getIp());
|
||||
zlmServerConfig.setStreamIp(mediaConfig.getStreamIp());
|
||||
zlmServerConfig.setSdpIp(mediaConfig.getSdpIp());
|
||||
zlmServerConfig.setHttpPort(mediaConfig.getHttpPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getHttpSSlPort()))
|
||||
zlmServerConfig.setHttpSSLport(mediaConfig.getHttpSSlPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getRtspPort()))
|
||||
zlmServerConfig.setRtspPort(mediaConfig.getRtspPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getRtspSSLPort()))
|
||||
zlmServerConfig.setRtspSSlport(mediaConfig.getRtspSSLPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getRtmpPort()))
|
||||
zlmServerConfig.setRtmpPort(mediaConfig.getRtmpPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getRtmpSSlPort()))
|
||||
zlmServerConfig.setRtmpSslPort(mediaConfig.getRtmpSSlPort());
|
||||
|
||||
if(!StringUtils.isEmpty(mediaConfig.getRtpProxyPort()))
|
||||
zlmServerConfig.setRtpProxyPort(mediaConfig.getRtpProxyPort());
|
||||
|
||||
redisCatchStorage.updateMediaInfo(zlmServerConfig);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.genersoft.iot.vmp.media.zlm.dto;
|
||||
|
||||
public interface IMediaServerItem {
|
||||
|
||||
String getId();
|
||||
|
||||
void setId(String id);
|
||||
|
||||
String getIp();
|
||||
|
||||
void setIp(String ip);
|
||||
|
||||
String getHookIp();
|
||||
|
||||
void setHookIp(String hookIp);
|
||||
|
||||
String getSdpIp();
|
||||
|
||||
void setSdpIp(String sdpIp);
|
||||
|
||||
String getStreamIp();
|
||||
|
||||
void setStreamIp(String streamIp);
|
||||
|
||||
int getHttpPort();
|
||||
|
||||
void setHttpPort(int httpPort);
|
||||
|
||||
int getHttpSSlPort();
|
||||
|
||||
void setHttpSSlPort(int httpSSlPort);
|
||||
|
||||
int getRtmpPort();
|
||||
|
||||
void setRtmpPort(int rtmpPort);
|
||||
|
||||
int getRtmpSSlPort();
|
||||
|
||||
void setRtmpSSlPort(int rtmpSSlPort);
|
||||
|
||||
int getRtpProxyPort();
|
||||
|
||||
void setRtpProxyPort(int rtpProxyPort);
|
||||
|
||||
int getRtspPort();
|
||||
|
||||
void setRtspPort(int rtspPort);
|
||||
|
||||
int getRtspSSLPort();
|
||||
|
||||
void setRtspSSLPort(int rtspSSLPort);
|
||||
|
||||
boolean isAutoConfig();
|
||||
|
||||
void setAutoConfig(boolean autoConfig);
|
||||
|
||||
String getSecret();
|
||||
|
||||
void setSecret(String secret);
|
||||
|
||||
String getStreamNoneReaderDelayMS();
|
||||
|
||||
void setStreamNoneReaderDelayMS(String streamNoneReaderDelayMS);
|
||||
|
||||
boolean isRtpEnable();
|
||||
|
||||
void setRtpEnable(boolean rtpEnable);
|
||||
|
||||
String getRtpPortRange();
|
||||
|
||||
void setRtpPortRange(String rtpPortRange);
|
||||
|
||||
int getRecordAssistPort();
|
||||
|
||||
void setRecordAssistPort(int recordAssistPort);
|
||||
|
||||
boolean isDocker();
|
||||
|
||||
void setDocker(boolean docker);
|
||||
|
||||
String getUpdateTime();
|
||||
|
||||
void setUpdateTime(String updateTime);
|
||||
|
||||
String getCreateTime();
|
||||
|
||||
void setCreateTime(String createTime);
|
||||
|
||||
int getCount();
|
||||
|
||||
void setCount(int count);
|
||||
}
|
||||
@@ -78,6 +78,10 @@ public class MediaItem {
|
||||
*/
|
||||
private String vhost;
|
||||
|
||||
/**
|
||||
* 是否是docker部署, docker部署不会自动更新zlm使用的端口,需要自己手动修改
|
||||
*/
|
||||
private boolean docker;
|
||||
|
||||
public static class MediaTrack {
|
||||
/**
|
||||
@@ -364,4 +368,12 @@ public class MediaItem {
|
||||
public OriginSock getOriginSock() {
|
||||
return originSock;
|
||||
}
|
||||
|
||||
public boolean isDocker() {
|
||||
return docker;
|
||||
}
|
||||
|
||||
public void setDocker(boolean docker) {
|
||||
this.docker = docker;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,254 @@
|
||||
package com.genersoft.iot.vmp.media.zlm.dto;
|
||||
|
||||
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMServerConfig;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
public class MediaServerItem implements IMediaServerItem{
|
||||
|
||||
private String id;
|
||||
|
||||
private String ip;
|
||||
|
||||
private String hookIp;
|
||||
|
||||
private String sdpIp;
|
||||
|
||||
private String streamIp;
|
||||
|
||||
private int httpPort;
|
||||
|
||||
private int httpSSlPort;
|
||||
|
||||
private int rtmpPort;
|
||||
|
||||
private int rtmpSSlPort;
|
||||
|
||||
private int rtpProxyPort;
|
||||
|
||||
private int rtspPort;
|
||||
|
||||
private int rtspSSLPort;
|
||||
|
||||
private boolean autoConfig;
|
||||
|
||||
private String secret;
|
||||
|
||||
private String streamNoneReaderDelayMS;
|
||||
|
||||
private boolean rtpEnable;
|
||||
|
||||
private String rtpPortRange;
|
||||
|
||||
private int recordAssistPort;
|
||||
|
||||
private String createTime;
|
||||
|
||||
private String updateTime;
|
||||
|
||||
private boolean docker;
|
||||
|
||||
private int count;
|
||||
|
||||
public MediaServerItem() {
|
||||
}
|
||||
|
||||
public MediaServerItem(ZLMServerConfig zlmServerConfig, String sipIp) {
|
||||
id = zlmServerConfig.getGeneralMediaServerId();
|
||||
ip = zlmServerConfig.getIp();
|
||||
hookIp = StringUtils.isEmpty(zlmServerConfig.getHookIp())? sipIp: zlmServerConfig.getHookIp();
|
||||
sdpIp = StringUtils.isEmpty(zlmServerConfig.getSdpIp())? zlmServerConfig.getIp(): zlmServerConfig.getSdpIp();
|
||||
streamIp = StringUtils.isEmpty(zlmServerConfig.getStreamIp())? zlmServerConfig.getIp(): zlmServerConfig.getStreamIp();
|
||||
httpPort = zlmServerConfig.getHttpPort();
|
||||
httpSSlPort = zlmServerConfig.getHttpSSLport();
|
||||
rtmpPort = zlmServerConfig.getRtmpPort();
|
||||
rtmpSSlPort = zlmServerConfig.getRtmpSslPort();
|
||||
rtpProxyPort = zlmServerConfig.getRtpProxyPort();
|
||||
rtspPort = zlmServerConfig.getRtspPort();
|
||||
rtspSSLPort = zlmServerConfig.getRtspSSlport();
|
||||
autoConfig = true; // 默认值true;
|
||||
secret = zlmServerConfig.getApiSecret();
|
||||
streamNoneReaderDelayMS = zlmServerConfig.getGeneralStreamNoneReaderDelayMS();
|
||||
rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口
|
||||
recordAssistPort = 0; // 默认关闭
|
||||
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getIp() {
|
||||
return ip;
|
||||
}
|
||||
|
||||
public void setIp(String ip) {
|
||||
this.ip = ip;
|
||||
}
|
||||
|
||||
public String getHookIp() {
|
||||
return hookIp;
|
||||
}
|
||||
|
||||
public void setHookIp(String hookIp) {
|
||||
this.hookIp = hookIp;
|
||||
}
|
||||
|
||||
public String getSdpIp() {
|
||||
return sdpIp;
|
||||
}
|
||||
|
||||
public void setSdpIp(String sdpIp) {
|
||||
this.sdpIp = sdpIp;
|
||||
}
|
||||
|
||||
public String getStreamIp() {
|
||||
return streamIp;
|
||||
}
|
||||
|
||||
public void setStreamIp(String streamIp) {
|
||||
this.streamIp = streamIp;
|
||||
}
|
||||
|
||||
public int getHttpPort() {
|
||||
return httpPort;
|
||||
}
|
||||
|
||||
public void setHttpPort(int httpPort) {
|
||||
this.httpPort = httpPort;
|
||||
}
|
||||
|
||||
public int getHttpSSlPort() {
|
||||
return httpSSlPort;
|
||||
}
|
||||
|
||||
public void setHttpSSlPort(int httpSSlPort) {
|
||||
this.httpSSlPort = httpSSlPort;
|
||||
}
|
||||
|
||||
public int getRtmpPort() {
|
||||
return rtmpPort;
|
||||
}
|
||||
|
||||
public void setRtmpPort(int rtmpPort) {
|
||||
this.rtmpPort = rtmpPort;
|
||||
}
|
||||
|
||||
public int getRtmpSSlPort() {
|
||||
return rtmpSSlPort;
|
||||
}
|
||||
|
||||
public void setRtmpSSlPort(int rtmpSSlPort) {
|
||||
this.rtmpSSlPort = rtmpSSlPort;
|
||||
}
|
||||
|
||||
public int getRtpProxyPort() {
|
||||
return rtpProxyPort;
|
||||
}
|
||||
|
||||
public void setRtpProxyPort(int rtpProxyPort) {
|
||||
this.rtpProxyPort = rtpProxyPort;
|
||||
}
|
||||
|
||||
public int getRtspPort() {
|
||||
return rtspPort;
|
||||
}
|
||||
|
||||
public void setRtspPort(int rtspPort) {
|
||||
this.rtspPort = rtspPort;
|
||||
}
|
||||
|
||||
public int getRtspSSLPort() {
|
||||
return rtspSSLPort;
|
||||
}
|
||||
|
||||
public void setRtspSSLPort(int rtspSSLPort) {
|
||||
this.rtspSSLPort = rtspSSLPort;
|
||||
}
|
||||
|
||||
public boolean isAutoConfig() {
|
||||
return autoConfig;
|
||||
}
|
||||
|
||||
public void setAutoConfig(boolean autoConfig) {
|
||||
this.autoConfig = autoConfig;
|
||||
}
|
||||
|
||||
public String getSecret() {
|
||||
return secret;
|
||||
}
|
||||
|
||||
public void setSecret(String secret) {
|
||||
this.secret = secret;
|
||||
}
|
||||
|
||||
public String getStreamNoneReaderDelayMS() {
|
||||
return streamNoneReaderDelayMS;
|
||||
}
|
||||
|
||||
public void setStreamNoneReaderDelayMS(String streamNoneReaderDelayMS) {
|
||||
this.streamNoneReaderDelayMS = streamNoneReaderDelayMS;
|
||||
}
|
||||
|
||||
public boolean isRtpEnable() {
|
||||
return rtpEnable;
|
||||
}
|
||||
|
||||
public void setRtpEnable(boolean rtpEnable) {
|
||||
this.rtpEnable = rtpEnable;
|
||||
}
|
||||
|
||||
public String getRtpPortRange() {
|
||||
return rtpPortRange;
|
||||
}
|
||||
|
||||
public void setRtpPortRange(String rtpPortRange) {
|
||||
this.rtpPortRange = rtpPortRange;
|
||||
}
|
||||
|
||||
public int getRecordAssistPort() {
|
||||
return recordAssistPort;
|
||||
}
|
||||
|
||||
public void setRecordAssistPort(int recordAssistPort) {
|
||||
this.recordAssistPort = recordAssistPort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDocker() {
|
||||
return docker;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setDocker(boolean docker) {
|
||||
this.docker = docker;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
|
||||
public String getUpdateTime() {
|
||||
return updateTime;
|
||||
}
|
||||
|
||||
public void setUpdateTime(String updateTime) {
|
||||
this.updateTime = updateTime;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setCount(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ public class StreamProxyItem extends GbStream {
|
||||
private String type;
|
||||
private String app;
|
||||
private String stream;
|
||||
private String mediaServerId;
|
||||
private String url;
|
||||
private String src_url;
|
||||
private String dst_url;
|
||||
@@ -17,6 +18,7 @@ public class StreamProxyItem extends GbStream {
|
||||
private boolean enable_hls;
|
||||
private boolean enable_mp4;
|
||||
private String platformGbId;
|
||||
private String createTime;
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
@@ -42,6 +44,16 @@ public class StreamProxyItem extends GbStream {
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMediaServerId() {
|
||||
return mediaServerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaServerId(String mediaServerId) {
|
||||
this.mediaServerId = mediaServerId;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
@@ -122,4 +134,12 @@ public class StreamProxyItem extends GbStream {
|
||||
public void setPlatformGbId(String platformGbId) {
|
||||
this.platformGbId = platformGbId;
|
||||
}
|
||||
|
||||
public String getCreateTime() {
|
||||
return createTime;
|
||||
}
|
||||
|
||||
public void setCreateTime(String createTime) {
|
||||
this.createTime = createTime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,11 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
|
||||
*/
|
||||
private String vhost;
|
||||
|
||||
/**
|
||||
* 使用的流媒体ID
|
||||
*/
|
||||
private String mediaServerId;
|
||||
|
||||
public String getVhost() {
|
||||
return vhost;
|
||||
}
|
||||
@@ -202,5 +207,14 @@ public class StreamPushItem extends GbStream implements Comparable<StreamPushIte
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getMediaServerId() {
|
||||
return mediaServerId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMediaServerId(String mediaServerId) {
|
||||
this.mediaServerId = mediaServerId;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.genersoft.iot.vmp.media.zlm.dto;
|
||||
|
||||
/**
|
||||
* 记录zlm运行中一些参数
|
||||
*/
|
||||
public class ZLMRunInfo {
|
||||
|
||||
/**
|
||||
* zlm当前流数量
|
||||
*/
|
||||
private int mediaCount;
|
||||
|
||||
/**
|
||||
* 在线状态
|
||||
*/
|
||||
private boolean online;
|
||||
|
||||
public int getMediaCount() {
|
||||
return mediaCount;
|
||||
}
|
||||
|
||||
public void setMediaCount(int mediaCount) {
|
||||
this.mediaCount = mediaCount;
|
||||
}
|
||||
|
||||
public boolean isOnline() {
|
||||
return online;
|
||||
}
|
||||
|
||||
public void setOnline(boolean online) {
|
||||
this.online = online;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user