优化zlm结果封装完成
This commit is contained in:
@@ -398,6 +398,8 @@ public class PlatformServiceImpl implements IPlatformService, CommandLineRunner
|
||||
SipTransactionInfo transactionInfo = statusTaskRunner.getRegisterTransactionInfo(platformInDb.getServerGBId());
|
||||
// 注销后出发平台离线, 如果是启用的平台,那么下次丢失检测会检测到并重新注册上线
|
||||
sendUnRegister(platformInDb, transactionInfo);
|
||||
}else if (platform.isEnable()) {
|
||||
sendRegister(platform, null);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -209,7 +209,7 @@ public class AssistRESTfulUtils {
|
||||
if (response.isSuccessful()) {
|
||||
try {
|
||||
String responseStr = Objects.requireNonNull(response.body()).string();
|
||||
callback.run(JSON.parseObject(responseStr));
|
||||
callback.run(responseStr);
|
||||
} catch (IOException e) {
|
||||
log.error(String.format("[ %s ]请求失败: %s", url, e.getMessage()));
|
||||
}
|
||||
|
||||
@@ -11,8 +11,7 @@ import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaNodeServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMResult;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.*;
|
||||
import com.genersoft.iot.vmp.streamProxy.bean.StreamProxy;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
||||
import com.genersoft.iot.vmp.vmanager.bean.WVPResult;
|
||||
@@ -72,10 +71,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
if (mediaServer == null) {
|
||||
return false;
|
||||
}
|
||||
ZLMResult zlmResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (zlmResult != null) {
|
||||
zlmResult.getData()
|
||||
JSONArray data = zlmResult.getJSONArray("data");
|
||||
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (mediaServerConfig != null) {
|
||||
List<JSONObject> data = mediaServerConfig.getData();
|
||||
if (data != null && !data.isEmpty()) {
|
||||
ZLMServerConfig zlmServerConfig= JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
return zlmServerConfig.getGeneralMediaServerId().equals(mediaServer.getId());
|
||||
@@ -102,15 +100,15 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
mediaServer.setFlvPort(port);
|
||||
mediaServer.setWsFlvPort(port);
|
||||
mediaServer.setSecret(secret);
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (responseJSON == null) {
|
||||
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (mediaServerConfigResult == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接失败");
|
||||
}
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
if (data == null) {
|
||||
List<JSONObject> configList = mediaServerConfigResult.getData();
|
||||
if (configList == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
|
||||
}
|
||||
ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
ZLMServerConfig zlmServerConfig = JSON.parseObject(JSON.toJSONString(configList.get(0)), ZLMServerConfig.class);
|
||||
if (zlmServerConfig == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "读取配置失败");
|
||||
}
|
||||
@@ -140,12 +138,12 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
if (!ObjectUtils.isEmpty(ssrc)) {
|
||||
param.put("ssrc", ssrc);
|
||||
}
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
|
||||
if (jsonObject.getInteger("code") != null && jsonObject.getInteger("code") == 0) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
|
||||
if (zlmResult.getCode() == 0) {
|
||||
log.info("[停止发流] 成功: 参数:{}", JSON.toJSONString(param));
|
||||
return true;
|
||||
}else {
|
||||
log.info("停止发流结果: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
|
||||
log.info("停止发流结果: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -159,9 +157,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
if (!ObjectUtils.isEmpty(ssrc)) {
|
||||
param.put("ssrc", ssrc);
|
||||
}
|
||||
JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
|
||||
log.error("停止发流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.stopSendRtp(mediaInfo, param);
|
||||
if (zlmResult.getCode() != 0 ) {
|
||||
log.error("停止发流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -170,12 +168,12 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
@Override
|
||||
public boolean deleteRecordDirectory(MediaServer mediaServer, String app, String stream, String date, String fileName) {
|
||||
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件, server: {} {}:{}->{}/{}", mediaServer.getId(), app, stream, date, fileName);
|
||||
JSONObject jsonObject = zlmresTfulUtils.deleteRecordDirectory(mediaServer, app,
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.deleteRecordDirectory(mediaServer, app,
|
||||
stream, date, fileName);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
if (zlmResult.getCode() == 0) {
|
||||
return true;
|
||||
}else {
|
||||
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件错误, server: {} {}:{}->{}/{}, 结果: {}", mediaServer.getId(), app, stream, date, fileName, jsonObject);
|
||||
log.info("[zlm-deleteRecordDirectory] 删除磁盘文件错误, server: {} {}:{}->{}/{}, 结果: {}", mediaServer.getId(), app, stream, date, fileName, zlmResult);
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "删除磁盘文件失败");
|
||||
}
|
||||
}
|
||||
@@ -183,15 +181,14 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
@Override
|
||||
public List<StreamInfo> getMediaList(MediaServer mediaServer, String app, String stream, String callId) {
|
||||
List<StreamInfo> streamInfoList = new ArrayList<>();
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.getMediaList(mediaServer, app, stream);
|
||||
ZLMResult<JSONArray> zlmResult = zlmresTfulUtils.getMediaList(mediaServer, app, stream);
|
||||
if (zlmResult != null) {
|
||||
if (zlmResult.getCode() == 0) {
|
||||
ZLMResult<JSONArray> result = (ZLMResult<JSONArray>)zlmResult;
|
||||
if (result.getData() == null) {
|
||||
if (zlmResult.getData() == null) {
|
||||
return streamInfoList;
|
||||
}
|
||||
for (int i = 0; i < result.getData().size(); i++) {
|
||||
JSONObject mediaJSON = result.getData().getJSONObject(0);
|
||||
for (int i = 0; i < zlmResult.getData().size(); i++) {
|
||||
JSONObject mediaJSON = zlmResult.getData().getJSONObject(0);
|
||||
MediaInfo mediaInfo = MediaInfo.getInstance(mediaJSON, mediaServer, userSetting.getServerId());
|
||||
StreamInfo streamInfo = getStreamInfoByAppAndStream(mediaServer, mediaInfo.getApp(), mediaInfo.getStream(), mediaInfo, callId, true);
|
||||
if (streamInfo != null) {
|
||||
@@ -251,9 +248,9 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
|
||||
@Override
|
||||
public Boolean connectRtpServer(MediaServer mediaServer, String address, int port, String stream) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.connectRtpServer(mediaServer, address, port, stream);
|
||||
log.info("[TCP主动连接对方] 结果: {}", jsonObject);
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.connectRtpServer(mediaServer, address, port, stream);
|
||||
log.info("[TCP主动连接对方] 结果: {}", zlmResult);
|
||||
return zlmResult.getCode() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -269,34 +266,34 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
|
||||
@Override
|
||||
public MediaInfo getMediaInfo(MediaServer mediaServer, String app, String stream) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.getMediaInfo(mediaServer, app, "rtsp", stream);
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
ZLMResult<JSONObject> zlmResult = zlmresTfulUtils.getMediaInfo(mediaServer, app, "rtsp", stream);
|
||||
if (zlmResult.getCode() != 0) {
|
||||
return null;
|
||||
}
|
||||
return MediaInfo.getInstance(jsonObject, mediaServer, userSetting.getServerId());
|
||||
return MediaInfo.getInstance(zlmResult.getData(), mediaServer, userSetting.getServerId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean pauseRtpCheck(MediaServer mediaServer, String streamKey) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.pauseRtpCheck(mediaServer, streamKey);
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.pauseRtpCheck(mediaServer, streamKey);
|
||||
return zlmResult.getCode() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean resumeRtpCheck(MediaServer mediaServer, String streamKey) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.resumeRtpCheck(mediaServer, streamKey);
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.resumeRtpCheck(mediaServer, streamKey);
|
||||
return zlmResult.getCode() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFfmpegCmd(MediaServer mediaServer, String cmdKey) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (mediaServerConfigResult == null || mediaServerConfigResult.getCode() != 0) {
|
||||
log.warn("[getFfmpegCmd] 获取流媒体配置失败");
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "获取流媒体配置失败");
|
||||
}
|
||||
JSONArray dataArray = jsonObject.getJSONArray("data");
|
||||
JSONObject mediaServerConfig = dataArray.getJSONObject(0);
|
||||
List<JSONObject> data = mediaServerConfigResult.getData();
|
||||
JSONObject mediaServerConfig = data.get(0);
|
||||
if (ObjectUtils.isEmpty(cmdKey)) {
|
||||
cmdKey = "ffmpeg.cmd";
|
||||
}
|
||||
@@ -306,42 +303,42 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
@Override
|
||||
public WVPResult<String> addStreamProxy(MediaServer mediaServer, String app, String stream, String url,
|
||||
boolean enableAudio, boolean enableMp4, String rtpType, Integer timeout) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.addStreamProxy(mediaServer, app, stream, url, enableAudio, enableMp4, rtpType, timeout);
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
ZLMResult<StreamProxyResult> zlmResult = zlmresTfulUtils.addStreamProxy(mediaServer, app, stream, url, enableAudio, enableMp4, rtpType, timeout);
|
||||
if (zlmResult.getCode() != 0) {
|
||||
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "添加代理失败");
|
||||
}else {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
StreamProxyResult data = zlmResult.getData();
|
||||
if (data == null) {
|
||||
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "代理结果异常: " + jsonObject);
|
||||
return WVPResult.fail(ErrorCode.ERROR100.getCode(), "代理结果异常");
|
||||
}else {
|
||||
return WVPResult.success(data.getString("key"));
|
||||
return WVPResult.success(data.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delFFmpegSource(MediaServer mediaServer, String streamKey) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(mediaServer, streamKey);
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
ZLMResult<FlagData> flagDataZLMResult = zlmresTfulUtils.delFFmpegSource(mediaServer, streamKey);
|
||||
return flagDataZLMResult != null && flagDataZLMResult.getCode() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean delStreamProxy(MediaServer mediaServer, String streamKey) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
ZLMResult<FlagData> flagDataZLMResult = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
|
||||
return flagDataZLMResult != null && flagDataZLMResult.getCode() == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getFFmpegCMDs(MediaServer mediaServer) {
|
||||
Map<String, String> result = new HashMap<>();
|
||||
JSONObject mediaServerConfigResuly = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (mediaServerConfigResuly != null && mediaServerConfigResuly.getInteger("code") == 0
|
||||
&& mediaServerConfigResuly.getJSONArray("data").size() > 0){
|
||||
JSONObject mediaServerConfig = mediaServerConfigResuly.getJSONArray("data").getJSONObject(0);
|
||||
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServer);
|
||||
if (mediaServerConfigResult != null && mediaServerConfigResult.getCode() == 0
|
||||
&& !mediaServerConfigResult.getData().isEmpty()){
|
||||
JSONObject jsonObject = mediaServerConfigResult.getData().get(0);
|
||||
|
||||
for (String key : mediaServerConfig.keySet()) {
|
||||
for (String key : jsonObject.keySet()) {
|
||||
if (key.startsWith("ffmpeg.cmd")){
|
||||
result.put(key, mediaServerConfig.getString(key));
|
||||
result.put(key, jsonObject.getString(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -374,15 +371,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
}
|
||||
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpPassive(mediaServer, param, null);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
|
||||
log.error("启动监听TCP被动推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
ZLMResult<?> zlmResult = zlmServerFactory.startSendRtpPassive(mediaServer, param, null);
|
||||
if (zlmResult.getCode() != 0 ) {
|
||||
log.error("启动监听TCP被动推流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
log.info("调用ZLM-TCP被动推流接口, 结果: {}", jsonObject);
|
||||
log.info("启动监听TCP被动推流成功[ {}/{} ],{}->{}:{}, " , sendRtpItem.getApp(), sendRtpItem.getStream(),
|
||||
jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
|
||||
return jsonObject.getInteger("local_port");
|
||||
log.info("调用ZLM-TCP被动推流接口成功: 本地端口: {}", zlmResult.getLocal_port());
|
||||
return zlmResult.getLocal_port();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -404,13 +399,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
}
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
JSONObject jsonObject = zlmresTfulUtils.startSendRtp(mediaServer, param);
|
||||
if (jsonObject == null ) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.startSendRtp(mediaServer, param);
|
||||
if (zlmResult == null ) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接zlm失败");
|
||||
}else if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
}else if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
log.info("[推流结果]:{} ,参数: {}",jsonObject, JSONObject.toJSONString(param));
|
||||
log.info("[推流结果]:{} ,参数: {}", zlmResult, JSONObject.toJSONString(param));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -425,15 +420,13 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
param.put("only_audio", sendRtpItem.isOnlyAudio() ? "1" : "0");
|
||||
param.put("recv_stream_id", sendRtpItem.getReceiveStream());
|
||||
param.put("enable_origin_recv_limit", "1");
|
||||
JSONObject jsonObject = zlmServerFactory.startSendRtpTalk(mediaServer, param, null);
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0 ) {
|
||||
log.error("启动监听TCP被动推流失败: {}, 参数:{}", jsonObject.getString("msg"), JSON.toJSONString(param));
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
ZLMResult<?> zlmResult = zlmServerFactory.startSendRtpTalk(mediaServer, param, null);
|
||||
if (zlmResult.getCode() != 0 ) {
|
||||
log.error("启动监听TCP被动推流失败: {}, 参数:{}", zlmResult.getMsg(), JSON.toJSONString(param));
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
log.info("调用ZLM-TCP被动推流接口, 结果: {}", jsonObject);
|
||||
log.info("启动监听TCP被动推流成功[ {}/{} ],{}->{}:{}, " , sendRtpItem.getApp(), sendRtpItem.getStream(),
|
||||
jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port"));
|
||||
return jsonObject.getInteger("local_port");
|
||||
log.info("调用ZLM-TCP被动推流接口, 成功 本地端口: {}", zlmResult.getLocal_port());
|
||||
return zlmResult.getLocal_port();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -488,28 +481,26 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
closeStreams(mediaServer, streamProxy.getApp(), streamProxy.getStream());
|
||||
}
|
||||
|
||||
JSONObject jsonObject = null;
|
||||
ZLMResult<StreamProxyResult> zlmResult = null;
|
||||
if ("ffmpeg".equalsIgnoreCase(streamProxy.getType())){
|
||||
if (streamProxy.getTimeout() == 0) {
|
||||
streamProxy.setTimeout(15);
|
||||
}
|
||||
jsonObject = zlmresTfulUtils.addFFmpegSource(mediaServer, streamProxy.getSrcUrl().trim(), dstUrl,
|
||||
zlmResult = zlmresTfulUtils.addFFmpegSource(mediaServer, streamProxy.getSrcUrl().trim(), dstUrl,
|
||||
streamProxy.getTimeout(), streamProxy.isEnableAudio(), streamProxy.isEnableMp4(),
|
||||
streamProxy.getFfmpegCmdKey());
|
||||
}else {
|
||||
jsonObject = zlmresTfulUtils.addStreamProxy(mediaServer, streamProxy.getApp(), streamProxy.getStream(), streamProxy.getSrcUrl().trim(),
|
||||
zlmResult = zlmresTfulUtils.addStreamProxy(mediaServer, streamProxy.getApp(), streamProxy.getStream(), streamProxy.getSrcUrl().trim(),
|
||||
streamProxy.isEnableAudio(), streamProxy.isEnableMp4(), streamProxy.getRtspType(), streamProxy.getTimeout());
|
||||
}
|
||||
if (jsonObject == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
|
||||
}else if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}else {
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
StreamProxyResult data = zlmResult.getData();
|
||||
if (data == null) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), "代理结果异常: " + jsonObject);
|
||||
throw new ControllerException(zlmResult.getCode(), "代理结果异常: " + zlmResult);
|
||||
}else {
|
||||
return data.getString("key");
|
||||
return data.getKey();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -535,62 +526,61 @@ public class ZLMMediaNodeServerService implements IMediaNodeServerService {
|
||||
|
||||
@Override
|
||||
public void stopProxy(MediaServer mediaServer, String streamKey, String type) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
|
||||
if (jsonObject == null) {
|
||||
ZLMResult<FlagData> zlmResult = zlmresTfulUtils.delStreamProxy(mediaServer, streamKey);
|
||||
if (zlmResult == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
|
||||
}else if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
}else if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> listRtpServer(MediaServer mediaServer) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.listRtpServer(mediaServer);
|
||||
ZLMResult<List<RtpServerResult>> zlmResult = zlmresTfulUtils.listRtpServer(mediaServer);
|
||||
List<String> result = new ArrayList<>();
|
||||
if (jsonObject == null || jsonObject.getInteger("code") != 0) {
|
||||
if (zlmResult.getCode() != 0) {
|
||||
return result;
|
||||
}
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
List<RtpServerResult> data = zlmResult.getData();
|
||||
if (data == null || data.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
for (int i = 0; i < data.size(); i++) {
|
||||
JSONObject dataJSONObject = data.getJSONObject(i);
|
||||
result.add(dataJSONObject.getString("stream_id"));
|
||||
for (RtpServerResult datum : data) {
|
||||
result.add(datum.getStream_id());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void loadMP4File(MediaServer mediaServer, String app, String stream, String datePath) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.loadMP4File(mediaServer, app, stream, datePath);
|
||||
if (jsonObject == null) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.loadMP4File(mediaServer, app, stream, datePath);
|
||||
if (zlmResult == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
|
||||
}
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void seekRecordStamp(MediaServer mediaServer, String app, String stream, Double stamp, String schema) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.seekRecordStamp(mediaServer, app, stream, stamp, schema);
|
||||
if (jsonObject == null) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.seekRecordStamp(mediaServer, app, stream, stamp, schema);
|
||||
if (zlmResult == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
|
||||
}
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRecordSpeed(MediaServer mediaServer, String app, String stream, Integer speed, String schema) {
|
||||
JSONObject jsonObject = zlmresTfulUtils.setRecordSpeed(mediaServer, app, stream, speed, schema);
|
||||
if (jsonObject == null) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.setRecordSpeed(mediaServer, app, stream, speed, schema);
|
||||
if (zlmResult == null) {
|
||||
throw new ControllerException(ErrorCode.ERROR100.getCode(), "请求失败");
|
||||
}
|
||||
if (jsonObject.getInteger("code") != 0) {
|
||||
throw new ControllerException(jsonObject.getInteger("code"), jsonObject.getString("msg"));
|
||||
if (zlmResult.getCode() != 0) {
|
||||
throw new ControllerException(zlmResult.getCode(), zlmResult.getMsg());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.conf.DynamicTask;
|
||||
import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
||||
@@ -9,6 +8,7 @@ import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerChangeEvent;
|
||||
import com.genersoft.iot.vmp.media.event.mediaServer.MediaServerDeleteEvent;
|
||||
import com.genersoft.iot.vmp.media.service.IMediaServerService;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMResult;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent;
|
||||
import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent;
|
||||
@@ -23,6 +23,7 @@ import org.springframework.util.ObjectUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
@@ -136,13 +137,13 @@ public class ZLMMediaServerStatusManager {
|
||||
continue;
|
||||
}
|
||||
log.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMResult<List<JSONObject>> mediaServerConfigResult = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig zlmServerConfig = null;
|
||||
if (responseJson == null) {
|
||||
if (mediaServerConfigResult == null) {
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
continue;
|
||||
}
|
||||
JSONArray data = responseJson.getJSONArray("data");
|
||||
List<JSONObject> data = mediaServerConfigResult.getData();
|
||||
if (data == null || data.isEmpty()) {
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
}else {
|
||||
@@ -158,14 +159,14 @@ public class ZLMMediaServerStatusManager {
|
||||
continue;
|
||||
}
|
||||
log.info("[ZLM-尝试连接] ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
JSONObject responseJson = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
ZLMServerConfig zlmServerConfig = null;
|
||||
if (responseJson == null) {
|
||||
if (mediaServerConfig == null) {
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
continue;
|
||||
}
|
||||
JSONArray data = responseJson.getJSONArray("data");
|
||||
List<JSONObject> data = mediaServerConfig.getData();
|
||||
if (data == null || data.isEmpty()) {
|
||||
log.info("[ZLM-尝试连接]失败, ID:{}, 地址: {}:{}", mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
offlineZlmTimeMap.put(mediaServerItem.getId(), System.currentTimeMillis());
|
||||
@@ -190,8 +191,8 @@ public class ZLMMediaServerStatusManager {
|
||||
eventPublisher.mediaServerOnlineEventPublish(mediaServerItem);
|
||||
if(mediaServerItem.isAutoConfig()) {
|
||||
if (config == null) {
|
||||
JSONObject responseJSON = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
JSONArray data = responseJSON.getJSONArray("data");
|
||||
ZLMResult<List<JSONObject>> mediaServerConfig = zlmresTfulUtils.getMediaServerConfig(mediaServerItem);
|
||||
List<JSONObject> data = mediaServerConfig.getData();
|
||||
if (data != null && !data.isEmpty()) {
|
||||
config = JSON.parseObject(JSON.toJSONString(data.get(0)), ZLMServerConfig.class);
|
||||
}
|
||||
@@ -298,9 +299,9 @@ public class ZLMMediaServerStatusManager {
|
||||
param.put("record.appName", recordPathFile.getName());
|
||||
}
|
||||
|
||||
JSONObject responseJSON = zlmresTfulUtils.setServerConfig(mediaServerItem, param);
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.setServerConfig(mediaServerItem, param);
|
||||
|
||||
if (responseJSON != null && responseJSON.getInteger("code") == 0) {
|
||||
if (zlmResult != null && zlmResult.getCode() == 0) {
|
||||
if (restart) {
|
||||
log.info("[媒体服务节点] 设置成功,开始重启以保证配置生效 {} -> {}:{}",
|
||||
mediaServerItem.getId(), mediaServerItem.getIp(), mediaServerItem.getHttpPort());
|
||||
|
||||
@@ -2,8 +2,8 @@ package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaInfo;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
import com.genersoft.iot.vmp.media.zlm.dto.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -233,11 +233,16 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> getMediaList(MediaServer mediaServer, String app, String stream, String schema, RequestCallback callback){
|
||||
public ZLMResult<JSONArray> getMediaList(MediaServer mediaServer, String app, String stream, String schema, ResultCallback callback){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
if (app != null) {
|
||||
param.put("app",app);
|
||||
@@ -249,19 +254,39 @@ public class ZLMRESTfulUtils {
|
||||
param.put("schema",schema);
|
||||
}
|
||||
param.put("vhost","__defaultVhost__");
|
||||
String response = sendPost(mediaServer, "getMediaList",param, callback);
|
||||
String response = sendPost(mediaServer, "getMediaList",param, (responseStr -> {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (responseStr == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
ZLMResult<JSONArray> zlmResult = JSON.parseObject(responseStr, new TypeReference<ZLMResult<JSONArray>>() {});
|
||||
if (zlmResult == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
callback.run(zlmResult);
|
||||
}
|
||||
|
||||
}
|
||||
}));
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<JSONArray>>() {});
|
||||
ZLMResult<JSONArray> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<JSONArray>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> getMediaList(MediaServer mediaServer, String app, String stream){
|
||||
public ZLMResult<JSONArray> getMediaList(MediaServer mediaServer, String app, String stream){
|
||||
return getMediaList(mediaServer, app, stream,null, null);
|
||||
}
|
||||
|
||||
public ZLMResult<?> getMediaInfo(MediaServer mediaServer, String app, String schema, String stream){
|
||||
public ZLMResult<JSONObject> getMediaInfo(MediaServer mediaServer, String app, String schema, String stream){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("app",app);
|
||||
param.put("schema",schema);
|
||||
@@ -272,7 +297,15 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<MediaInfo>>() {});
|
||||
JSONObject jsonObject = JSON.parseObject(response);
|
||||
if (jsonObject == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
ZLMResult<JSONObject> zlmResult = new ZLMResult<>();
|
||||
zlmResult.setCode(0);
|
||||
zlmResult.setData(jsonObject);
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,11 +316,16 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> addFFmpegSource(MediaServer mediaServer, String src_url, String dst_url, Integer timeout_sec,
|
||||
public ZLMResult<StreamProxyResult> addFFmpegSource(MediaServer mediaServer, String src_url, String dst_url, Integer timeout_sec,
|
||||
boolean enable_audio, boolean enable_mp4, String ffmpeg_cmd_key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("src_url", src_url);
|
||||
@@ -300,11 +338,16 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
|
||||
ZLMResult<StreamProxyResult> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> delFFmpegSource(MediaServer mediaServer, String key){
|
||||
public ZLMResult<FlagData> delFFmpegSource(MediaServer mediaServer, String key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("key", key);
|
||||
|
||||
@@ -312,28 +355,43 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> delStreamProxy(MediaServer mediaServer, String key){
|
||||
public ZLMResult<FlagData> delStreamProxy(MediaServer mediaServer, String key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("key", key);
|
||||
String response = sendPost(mediaServer, "delStreamProxy",param, null);
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> getMediaServerConfig(MediaServer mediaServer ){
|
||||
public ZLMResult<List<JSONObject>> getMediaServerConfig(MediaServer mediaServer ){
|
||||
|
||||
String response = sendPost(mediaServer, "getServerConfig",null, null);
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<List<ZLMServerConfig>>>() {});
|
||||
ZLMResult<List<JSONObject>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<JSONObject>>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -342,7 +400,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +414,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,12 +428,20 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void closeRtpServer(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
|
||||
sendPost(mediaServer, "closeRtpServer",param, (response -> {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (response == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
@@ -375,12 +451,17 @@ public class ZLMRESTfulUtils {
|
||||
|
||||
}
|
||||
|
||||
public ZLMResult<?> listRtpServer(MediaServer mediaServer) {
|
||||
public ZLMResult<List<RtpServerResult>> listRtpServer(MediaServer mediaServer) {
|
||||
String response = sendPost(mediaServer, "listRtpServer",null, null);
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<List<RtpServerResult>>>() {});
|
||||
ZLMResult<List<RtpServerResult>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<RtpServerResult>>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -389,7 +470,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -398,12 +484,48 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
|
||||
String response = sendPost(mediaServer, "startSendRtpPassive",param, (responseStr -> {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (responseStr == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(responseStr, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
callback.run(zlmResult);
|
||||
}
|
||||
}
|
||||
}));
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ResultCallback callback) {
|
||||
String response = sendPost(mediaServer, "startSendRtpTalk",param, (responseStr -> {
|
||||
if (callback == null) {
|
||||
return;
|
||||
}
|
||||
if (responseStr == null) {
|
||||
callback.run(ZLMResult.getFailForMediaServer());
|
||||
}else {
|
||||
@@ -413,16 +535,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, RequestCallback callback) {
|
||||
String response = sendPost(mediaServer, "startSendRtpTalk",param, null);
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -431,7 +549,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,11 +563,16 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> addStreamProxy(MediaServer mediaServer, String app, String stream, String url, boolean enable_audio, boolean enable_mp4, String rtp_type, Integer timeOut) {
|
||||
public ZLMResult<StreamProxyResult> addStreamProxy(MediaServer mediaServer, String app, String stream, String url, boolean enable_audio, boolean enable_mp4, String rtp_type, Integer timeOut) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", app);
|
||||
@@ -461,11 +589,16 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
|
||||
ZLMResult<StreamProxyResult> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<StreamProxyResult>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> closeStreams(MediaServer mediaServer, String app, String stream) {
|
||||
public ZLMResult<FlagData> closeStreams(MediaServer mediaServer, String app, String stream) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", app);
|
||||
@@ -476,16 +609,26 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
ZLMResult<FlagData> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<FlagData>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ZLMResult<?> getAllSession(MediaServer mediaServer) {
|
||||
public ZLMResult<List<SessionData>> getAllSession(MediaServer mediaServer) {
|
||||
String response = sendPost(mediaServer, "getAllSession",null, null);
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, new TypeReference<ZLMResult<SessionData>>() {});
|
||||
ZLMResult<List<SessionData>> zlmResult = JSON.parseObject(response, new TypeReference<ZLMResult<List<SessionData>>>() {});
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,7 +654,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -522,7 +670,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -535,7 +688,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -548,7 +706,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -563,7 +726,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -578,7 +746,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -593,7 +766,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -610,7 +788,12 @@ public class ZLMRESTfulUtils {
|
||||
if (response == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return JSON.parseObject(response, ZLMResult.class);
|
||||
ZLMResult<?> zlmResult = JSON.parseObject(response, ZLMResult.class);
|
||||
if (zlmResult == null) {
|
||||
return ZLMResult.getFailForMediaServer();
|
||||
}else {
|
||||
return zlmResult;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package com.genersoft.iot.vmp.media.zlm;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.genersoft.iot.vmp.common.CommonCallback;
|
||||
import com.genersoft.iot.vmp.gb28181.bean.SendRtpInfo;
|
||||
import com.genersoft.iot.vmp.media.bean.MediaServer;
|
||||
@@ -128,19 +127,14 @@ public class ZLMServerFactory {
|
||||
}
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("stream_id", streamId);
|
||||
zlmresTfulUtils.closeRtpServer(serverItem, param, jsonObject -> {
|
||||
if (jsonObject != null ) {
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
if (callback != null) {
|
||||
callback.run(jsonObject.getInteger("hit") == 1);
|
||||
}
|
||||
return;
|
||||
}else {
|
||||
log.error("关闭RTP Server 失败: " + jsonObject.getString("msg"));
|
||||
zlmresTfulUtils.closeRtpServer(serverItem, param, zlmResult -> {
|
||||
if (zlmResult.getCode() == 0) {
|
||||
if (callback != null) {
|
||||
callback.run(zlmResult.getHit() >= 1);
|
||||
}
|
||||
return;
|
||||
}else {
|
||||
// 检查ZLM状态
|
||||
log.error("关闭RTP Server 失败: 请检查ZLM服务");
|
||||
log.error("关闭RTP Server 失败: " + zlmResult.getMsg());
|
||||
}
|
||||
if (callback != null) {
|
||||
callback.run(false);
|
||||
@@ -152,22 +146,22 @@ public class ZLMServerFactory {
|
||||
/**
|
||||
* 调用zlm RESTFUL API —— startSendRtp
|
||||
*/
|
||||
public JSONObject startSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) {
|
||||
public ZLMResult<?> startSendRtpStream(MediaServer mediaServerItem, Map<String, Object>param) {
|
||||
return zlmresTfulUtils.startSendRtp(mediaServerItem, param);
|
||||
}
|
||||
|
||||
/**
|
||||
* 调用zlm RESTFUL API —— startSendRtpPassive
|
||||
*/
|
||||
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param) {
|
||||
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object>param) {
|
||||
return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param);
|
||||
}
|
||||
|
||||
public JSONObject startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param, ZLMRESTfulUtils.RequestCallback callback) {
|
||||
public ZLMResult<?> startSendRtpPassive(MediaServer mediaServerItem, Map<String, Object> param, ZLMRESTfulUtils.ResultCallback callback) {
|
||||
return zlmresTfulUtils.startSendRtpPassive(mediaServerItem, param, callback);
|
||||
}
|
||||
|
||||
public JSONObject startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ZLMRESTfulUtils.RequestCallback callback) {
|
||||
public ZLMResult<?> startSendRtpTalk(MediaServer mediaServer, Map<String, Object> param, ZLMRESTfulUtils.ResultCallback callback) {
|
||||
return zlmresTfulUtils.startSendRtpTalk(mediaServer, param, callback);
|
||||
}
|
||||
|
||||
@@ -185,29 +179,7 @@ public class ZLMServerFactory {
|
||||
&& !result.getData().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询转推的流是否有其它观看者
|
||||
* @param streamId
|
||||
* @return
|
||||
*/
|
||||
public int totalReaderCount(MediaServer mediaServerItem, String app, String streamId) {
|
||||
JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo(mediaServerItem, app, "rtsp", streamId);
|
||||
if (mediaInfo == null) {
|
||||
return 0;
|
||||
}
|
||||
Integer code = mediaInfo.getInteger("code");
|
||||
if (code < 0) {
|
||||
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
return -1;
|
||||
}
|
||||
if ( code == 0 && mediaInfo.getBoolean("online") != null && ! mediaInfo.getBoolean("online")) {
|
||||
log.warn("查询流({}/{})是否有其它观看者时得到: {}", app, streamId, mediaInfo.getString("msg"));
|
||||
return -1;
|
||||
}
|
||||
return mediaInfo.getInteger("totalReaderCount");
|
||||
}
|
||||
|
||||
public JSONObject startSendRtp(MediaServer mediaInfo, SendRtpInfo sendRtpItem) {
|
||||
public ZLMResult<?> startSendRtp(MediaServer mediaInfo, SendRtpInfo sendRtpItem) {
|
||||
String is_Udp = sendRtpItem.isTcp() ? "0" : "1";
|
||||
log.info("rtp/{}开始推流, 目标={}:{},SSRC={}", sendRtpItem.getStream(), sendRtpItem.getIp(), sendRtpItem.getPort(), sendRtpItem.getSsrc());
|
||||
Map<String, Object> param = new HashMap<>(12);
|
||||
@@ -228,45 +200,43 @@ public class ZLMServerFactory {
|
||||
return null;
|
||||
}
|
||||
// 如果是非严格模式,需要关闭端口占用
|
||||
JSONObject startSendRtpStreamResult = null;
|
||||
ZLMResult<?> zlmResult = null;
|
||||
if (sendRtpItem.getLocalPort() != 0) {
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
|
||||
zlmResult = startSendRtpPassive(mediaInfo, param);
|
||||
}else {
|
||||
param.put("is_udp", is_Udp);
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
|
||||
zlmResult = startSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
}else {
|
||||
if (sendRtpItem.isTcpActive()) {
|
||||
startSendRtpStreamResult = startSendRtpPassive(mediaInfo, param);
|
||||
zlmResult = startSendRtpPassive(mediaInfo, param);
|
||||
}else {
|
||||
param.put("is_udp", is_Udp);
|
||||
param.put("dst_url", sendRtpItem.getIp());
|
||||
param.put("dst_port", sendRtpItem.getPort());
|
||||
startSendRtpStreamResult = startSendRtpStream(mediaInfo, param);
|
||||
zlmResult = startSendRtpStream(mediaInfo, param);
|
||||
}
|
||||
}
|
||||
return startSendRtpStreamResult;
|
||||
return zlmResult;
|
||||
}
|
||||
|
||||
public Boolean updateRtpServerSSRC(MediaServer mediaServerItem, String streamId, String ssrc) {
|
||||
boolean result = false;
|
||||
JSONObject jsonObject = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
|
||||
if (jsonObject == null) {
|
||||
log.error("[更新RTPServer] 失败: 请检查ZLM服务");
|
||||
} else if (jsonObject.getInteger("code") == 0) {
|
||||
ZLMResult<?> zlmResult = zlmresTfulUtils.updateRtpServerSSRC(mediaServerItem, streamId, ssrc);
|
||||
if (zlmResult.getCode() == 0) {
|
||||
result= true;
|
||||
log.info("[更新RTPServer] 成功");
|
||||
} else {
|
||||
log.error("[更新RTPServer] 失败: {}, streamId:{},ssrc:{}->\r\n{}",jsonObject.getString("msg"),
|
||||
streamId, ssrc, jsonObject);
|
||||
log.error("[更新RTPServer] 失败: {}, streamId:{},ssrc:{}", zlmResult.getMsg(),
|
||||
streamId, ssrc);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public JSONObject stopSendRtpStream(MediaServer mediaServerItem, SendRtpInfo sendRtpItem) {
|
||||
public ZLMResult<?> stopSendRtpStream(MediaServer mediaServerItem, SendRtpInfo sendRtpItem) {
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("vhost", "__defaultVhost__");
|
||||
param.put("app", sendRtpItem.getApp());
|
||||
|
||||
@@ -19,24 +19,40 @@ public class ZLMResult<T> {
|
||||
private Integer port;
|
||||
private Integer hit;
|
||||
|
||||
public static ZLMResult<?> getFailForMediaServer() {
|
||||
ZLMResult<?> zlmResult = new ZLMResult<>();
|
||||
public static <T> ZLMResult<T> getFailForMediaServer() {
|
||||
ZLMResult<T> zlmResult = new ZLMResult<>();
|
||||
zlmResult.setCode(-2);
|
||||
zlmResult.setMsg("流媒体调用失败");
|
||||
return zlmResult;
|
||||
}
|
||||
|
||||
public static ZLMResult<?> getMediaServer(int code, String msg) {
|
||||
public static <T> ZLMResult<T> getMediaServer(int code, String msg) {
|
||||
return getMediaServer(code, msg, null);
|
||||
}
|
||||
|
||||
public static ZLMResult<?> getMediaServer(int code, String msg, Object data) {
|
||||
ZLMResult<Object> zlmResult = new ZLMResult<>();
|
||||
public static <T> ZLMResult<T> getMediaServer(int code, String msg, T data) {
|
||||
ZLMResult<T> zlmResult = new ZLMResult<>();
|
||||
zlmResult.setCode(code);
|
||||
zlmResult.setMsg(msg);
|
||||
zlmResult.setData(data);
|
||||
return zlmResult;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ZLMResult{" +
|
||||
"code=" + code +
|
||||
", msg='" + msg + '\'' +
|
||||
", data=" + data +
|
||||
(online != null ? (", online=" + online) : "") +
|
||||
(exist != null ? (", exist=" + exist) : "") +
|
||||
(peer_ip != null ? (", peer_ip=" + peer_ip) : "") +
|
||||
(peer_port != null ? (", peer_port=" + peer_port) : "") +
|
||||
(local_ip != null ? (", local_ip=" + local_ip) : "") +
|
||||
(local_port != null ? (", local_port=" + local_port) : "") +
|
||||
(changed != null ? (", changed=" + changed) : "") +
|
||||
(port != null ? (", port=" + port) : "") +
|
||||
(hit != null ? (", hit=" + hit) : "") +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user