新增对录像辅助服务的ip配置支持

修正sql更新脚本中错误的语句
pull/1097/head
Samler 2023-10-04 03:15:43 +08:00
parent 94a0de0d27
commit 215031e263
12 changed files with 88 additions and 27 deletions

View File

@ -1,8 +1,11 @@
alter table wvp_device_channel alter table wvp_device_channel
change stream_id stream_id varying(255) change stream_id stream_id character varying(255)
alter table wvp_platform alter table wvp_platform
add auto_push_channel bool default false add auto_push_channel bool default false
alter table wvp_stream_proxy alter table wvp_stream_proxy
add stream_key varying(255) add stream_key character varying(255)
alter table wvp_media_server
add record_assist_ip character varying(50)

View File

@ -160,6 +160,7 @@ create table wvp_media_server (
rtp_port_range character varying(50), rtp_port_range character varying(50),
send_rtp_port_range character varying(50), send_rtp_port_range character varying(50),
record_assist_port integer, record_assist_port integer,
record_assist_ip character varying(50),
default_server bool default false, default_server bool default false,
create_time character varying(50), create_time character varying(50),
update_time character varying(50), update_time character varying(50),

View File

@ -81,6 +81,9 @@ public class MediaConfig{
@Value("${media.record-assist-port:0}") @Value("${media.record-assist-port:0}")
private Integer recordAssistPort = 0; private Integer recordAssistPort = 0;
@Value("${media.record-assist-ip:${media.ip}}")
private String recordAssistIp;
public String getId() { public String getId() {
return id; return id;
} }
@ -159,6 +162,10 @@ public class MediaConfig{
return recordAssistPort; return recordAssistPort;
} }
public String getRecordAssistIp() {
return recordAssistIp;
}
public String getSdpIp() { public String getSdpIp() {
if (ObjectUtils.isEmpty(sdpIp)){ if (ObjectUtils.isEmpty(sdpIp)){
return ip; return ip;
@ -211,6 +218,7 @@ public class MediaConfig{
mediaServerItem.setRtpPortRange(rtpPortRange); mediaServerItem.setRtpPortRange(rtpPortRange);
mediaServerItem.setSendRtpPortRange(rtpSendPortRange); mediaServerItem.setSendRtpPortRange(rtpSendPortRange);
mediaServerItem.setRecordAssistPort(recordAssistPort); mediaServerItem.setRecordAssistPort(recordAssistPort);
mediaServerItem.setRecordAssistIp(recordAssistIp);
mediaServerItem.setHookAliveInterval(30.00f); mediaServerItem.setHookAliveInterval(30.00f);
mediaServerItem.setCreateTime(DateUtil.getNow()); mediaServerItem.setCreateTime(DateUtil.getNow());

View File

@ -242,8 +242,12 @@ public class ProxyServletConfig {
String uri = null; String uri = null;
if (mediaInfo != null) { if (mediaInfo != null) {
String ip = mediaInfo.getRecordAssistIp();
if (ip == null) {
ip = mediaInfo.getIp();
}
// String realRequestURI = requestURI.substring(requestURI.indexOf(mediaInfo.getId())+ mediaInfo.getId().length()); // String realRequestURI = requestURI.substring(requestURI.indexOf(mediaInfo.getId())+ mediaInfo.getId().length());
uri = String.format("http://%s:%s", mediaInfo.getIp(), mediaInfo.getRecordAssistPort()); uri = String.format("http://%s:%s", ip, mediaInfo.getRecordAssistPort());
}else { }else {
uri = "http://127.0.0.1:" + serverPort +"/index/hook/null"; // 只是一个能返回404的请求而已 其他的也可以 uri = "http://127.0.0.1:" + serverPort +"/index/hook/null"; // 只是一个能返回404的请求而已 其他的也可以
} }
@ -259,7 +263,12 @@ public class ProxyServletConfig {
MediaServerItem mediaInfo = getMediaInfoByUri(requestURI); MediaServerItem mediaInfo = getMediaInfoByUri(requestURI);
HttpHost host; HttpHost host;
if (mediaInfo != null) { if (mediaInfo != null) {
host = new HttpHost(mediaInfo.getIp(), mediaInfo.getRecordAssistPort()); String ip = mediaInfo.getRecordAssistIp();
if (ip == null) {
ip = mediaInfo.getIp();
}
host = new HttpHost(ip, mediaInfo.getRecordAssistPort());
}else { }else {
host = new HttpHost("127.0.0.1", serverPort); host = new HttpHost("127.0.0.1", serverPort);
} }

View File

@ -51,7 +51,7 @@ public class AssistRESTfulUtils {
return null; return null;
} }
StringBuffer stringBuffer = new StringBuffer(); StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(String.format("http://%s:%s/%s", mediaServerItem.getIp(), mediaServerItem.getRecordAssistPort(), api)); stringBuffer.append(String.format("http://%s:%s/%s", mediaServerItem.getRecordAssistIp(), mediaServerItem.getRecordAssistPort(), api));
JSONObject responseJSON = null; JSONObject responseJSON = null;
if (param != null && param.keySet().size() > 0) { if (param != null && param.keySet().size() > 0) {

View File

@ -285,20 +285,26 @@ public class ZLMHttpHookListener {
result.setEnable_mp4(true); result.setEnable_mp4(true);
} }
} }
if (mediaInfo.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) { if (mediaInfo.getRecordAssistPort() > 0) {
logger.info("推流时发现尚未设置录像路径从assist服务中读取"); if (mediaInfo.getRecordAssistIp() == null) {
JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null); mediaInfo.setRecordAssistIp(mediaInfo.getIp());
if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) { }
JSONObject dataJson = info.getJSONObject("data");
if (dataJson != null) { if (userSetting.getRecordPath() == null) {
String recordPath = dataJson.getString("record"); logger.info("推流时发现尚未设置录像路径从assist服务中读取");
userSetting.setRecordPath(recordPath); JSONObject info = assistRESTfulUtils.getInfo(mediaInfo, null);
result.setMp4_save_path(recordPath); if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
// 修改zlm中的录像路径 JSONObject dataJson = info.getJSONObject("data");
if (mediaInfo.isAutoConfig()) { if (dataJson != null) {
taskExecutor.execute(() -> { String recordPath = dataJson.getString("record");
mediaServerService.setZLMConfig(mediaInfo, false); userSetting.setRecordPath(recordPath);
}); result.setMp4_save_path(recordPath);
// 修改zlm中的录像路径
if (mediaInfo.isAutoConfig()) {
taskExecutor.execute(() -> {
mediaServerService.setZLMConfig(mediaInfo, false);
});
}
} }
} }
} }

View File

@ -68,6 +68,9 @@ public class MediaServerItem{
@Schema(description = "assist服务端口") @Schema(description = "assist服务端口")
private int recordAssistPort; private int recordAssistPort;
@Schema(description = "assist服务IP")
private String recordAssistIp;
@Schema(description = "创建时间") @Schema(description = "创建时间")
private String createTime; private String createTime;
@ -106,6 +109,7 @@ public class MediaServerItem{
rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口 rtpEnable = false; // 默认使用单端口;直到用户自己设置开启多端口
rtpPortRange = zlmServerConfig.getPortRange().replace("_",","); // 默认使用30000,30500作为级联时发送流的端口号 rtpPortRange = zlmServerConfig.getPortRange().replace("_",","); // 默认使用30000,30500作为级联时发送流的端口号
recordAssistPort = 0; // 默认关闭 recordAssistPort = 0; // 默认关闭
recordAssistIp = ip; // 默认使用media.ip
} }
@ -245,6 +249,14 @@ public class MediaServerItem{
this.recordAssistPort = recordAssistPort; this.recordAssistPort = recordAssistPort;
} }
public String getRecordAssistIp() {
return recordAssistIp;
}
public void setRecordAssistIp(String recordAssistIp) {
this.recordAssistIp = recordAssistIp;
}
public boolean isDefaultServer() { public boolean isDefaultServer() {
return defaultServer; return defaultServer;
} }

View File

@ -420,13 +420,19 @@ public class MediaServerServiceImpl implements IMediaServerService {
if (serverItem.isAutoConfig()) { if (serverItem.isAutoConfig()) {
// 查看assist服务的录像路径配置 // 查看assist服务的录像路径配置
if (serverItem.getRecordAssistPort() > 0 && userSetting.getRecordPath() == null) { if (serverItem.getRecordAssistPort() > 0) {
JSONObject info = assistRESTfulUtils.getInfo(serverItem, null); if (serverItem.getRecordAssistIp() == null) {
if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) { serverItem.setRecordAssistIp(serverItem.getIp());
JSONObject dataJson = info.getJSONObject("data"); }
if (dataJson != null) {
String recordPath = dataJson.getString("record"); if (userSetting.getRecordPath() == null) {
userSetting.setRecordPath(recordPath); JSONObject info = assistRESTfulUtils.getInfo(serverItem, null);
if (info != null && info.getInteger("code") != null && info.getInteger("code") == 0 ) {
JSONObject dataJson = info.getJSONObject("data");
if (dataJson != null) {
String recordPath = dataJson.getString("record");
userSetting.setRecordPath(recordPath);
}
} }
} }
} }
@ -588,7 +594,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrex)); param.put("hook.on_send_rtp_stopped",String.format("%s/on_send_rtp_stopped", hookPrex));
param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrex)); param.put("hook.on_rtp_server_timeout",String.format("%s/on_rtp_server_timeout", hookPrex));
if (mediaServerItem.getRecordAssistPort() > 0) { if (mediaServerItem.getRecordAssistPort() > 0) {
param.put("hook.on_record_mp4",String.format("http://127.0.0.1:%s/api/record/on_record_mp4", mediaServerItem.getRecordAssistPort())); param.put("hook.on_record_mp4",String.format("http://%s:%s/api/record/on_record_mp4", mediaServerItem.getRecordAssistIp(), mediaServerItem.getRecordAssistPort()));
}else { }else {
param.put("hook.on_record_mp4",""); param.put("hook.on_record_mp4","");
} }
@ -664,6 +670,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
mediaServerItem.setStreamIp(ip); mediaServerItem.setStreamIp(ip);
mediaServerItem.setHookIp(sipConfig.getIp().split(",")[0]); mediaServerItem.setHookIp(sipConfig.getIp().split(",")[0]);
mediaServerItem.setSdpIp(ip); mediaServerItem.setSdpIp(ip);
mediaServerItem.setRecordAssistIp(ip);
return mediaServerItem; return mediaServerItem;
} }

View File

@ -750,6 +750,10 @@ public class PlayServiceImpl implements IPlayService {
return null; return null;
} }
if (mediaServerItem.getRecordAssistPort() > 0) { if (mediaServerItem.getRecordAssistPort() > 0) {
if (mediaServerItem.getRecordAssistIp() == null) {
mediaServerItem.setRecordAssistIp(mediaServerItem.getIp());
}
JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream(), null); JSONObject jsonObject = assistRESTfulUtils.fileDuration(mediaServerItem, inviteInfo.getStreamInfo().getApp(), inviteInfo.getStreamInfo().getStream(), null);
if (jsonObject == null) { if (jsonObject == null) {
throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接Assist服务失败"); throw new ControllerException(ErrorCode.ERROR100.getCode(), "连接Assist服务失败");

View File

@ -31,6 +31,7 @@ public interface MediaServerMapper {
"rtp_port_range,"+ "rtp_port_range,"+
"send_rtp_port_range,"+ "send_rtp_port_range,"+
"record_assist_port,"+ "record_assist_port,"+
"record_assist_ip,"+
"default_server,"+ "default_server,"+
"create_time,"+ "create_time,"+
"update_time,"+ "update_time,"+
@ -55,6 +56,7 @@ public interface MediaServerMapper {
"#{rtpPortRange}, " + "#{rtpPortRange}, " +
"#{sendRtpPortRange}, " + "#{sendRtpPortRange}, " +
"#{recordAssistPort}, " + "#{recordAssistPort}, " +
"#{recordAssistIp}, " +
"#{defaultServer}, " + "#{defaultServer}, " +
"#{createTime}, " + "#{createTime}, " +
"#{updateTime}, " + "#{updateTime}, " +
@ -81,6 +83,7 @@ public interface MediaServerMapper {
"<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" + "<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" + "<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" + "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
"<if test=\"recordAssistIp != null\">, record_assist_ip=#{recordAssistIp}</if>" +
"<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" + "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
"WHERE id=#{id}"+ "WHERE id=#{id}"+
" </script>"}) " </script>"})
@ -105,6 +108,7 @@ public interface MediaServerMapper {
"<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" + "<if test=\"sendRtpPortRange != null\">, send_rtp_port_range=#{sendRtpPortRange}</if>" +
"<if test=\"secret != null\">, secret=#{secret}</if>" + "<if test=\"secret != null\">, secret=#{secret}</if>" +
"<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" + "<if test=\"recordAssistPort != null\">, record_assist_port=#{recordAssistPort}</if>" +
"<if test=\"recordAssistIp != null\">, record_assist_ip=#{recordAssistIp}</if>" +
"<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" + "<if test=\"hookAliveInterval != null\">, hook_alive_interval=#{hookAliveInterval}</if>" +
"WHERE ip=#{ip} and http_port=#{httpPort}"+ "WHERE ip=#{ip} and http_port=#{httpPort}"+
" </script>"}) " </script>"})

View File

@ -149,6 +149,8 @@ media:
send-port-range: 50502,50506 # 端口范围 send-port-range: 50502,50506 # 端口范围
# 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载 0 表示不使用 # 录像辅助服务, 部署此服务可以实现zlm录像的管理与下载 0 表示不使用
record-assist-port: 0 record-assist-port: 0
# 录像辅助服务ip置空使用media.ip
record-assist-ip:
# [可选] 日志配置, 一般不需要改 # [可选] 日志配置, 一般不需要改
logging: logging:

View File

@ -95,6 +95,9 @@
- -
<el-input v-model="sendRtpPortRange2" placeholder="终止" @change="portRangeChange" clearable style="width: 100px" prop="rtpPortRange2" :disabled="mediaServerForm.defaultServer"></el-input> <el-input v-model="sendRtpPortRange2" placeholder="终止" @change="portRangeChange" clearable style="width: 100px" prop="rtpPortRange2" :disabled="mediaServerForm.defaultServer"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="录像管理服务IP" prop="ip">
<el-input v-model="mediaServerForm.recordAssistIp" placeholder="录像管理服务IP" clearable :disabled="mediaServerForm.defaultServer"></el-input>
</el-form-item>
<el-form-item label="录像管理服务端口" prop="recordAssistPort"> <el-form-item label="录像管理服务端口" prop="recordAssistPort">
<el-input v-model.number="mediaServerForm.recordAssistPort" :disabled="mediaServerForm.defaultServer"> <el-input v-model.number="mediaServerForm.recordAssistPort" :disabled="mediaServerForm.defaultServer">
<!-- <el-button v-if="mediaServerForm.recordAssistPort > 0" slot="append" type="primary" @click="checkRecordServer"></el-button>--> <!-- <el-button v-if="mediaServerForm.recordAssistPort > 0" slot="append" type="primary" @click="checkRecordServer"></el-button>-->
@ -174,6 +177,7 @@ export default {
httpPort: "", httpPort: "",
httpSSlPort: "", httpSSlPort: "",
recordAssistPort: "", recordAssistPort: "",
recordAssistIp: "",
rtmpPort: "", rtmpPort: "",
rtmpSSlPort: "", rtmpSSlPort: "",
rtpEnable: false, rtpEnable: false,
@ -334,6 +338,7 @@ export default {
httpPort: "", httpPort: "",
httpSSlPort: "", httpSSlPort: "",
recordAssistPort: "", recordAssistPort: "",
recordAssistIp: "",
rtmpPort: "", rtmpPort: "",
rtmpSSlPort: "", rtmpSSlPort: "",
rtpEnable: false, rtpEnable: false,