优化拉流代理启停
parent
1d28869fd3
commit
8805966f89
|
@ -759,7 +759,7 @@ public class MediaServerServiceImpl implements IMediaServerService {
|
||||||
streamMediaInfo.setBytesSpeed(mediaInfoJson.getInteger("bytesSpeed"));
|
streamMediaInfo.setBytesSpeed(mediaInfoJson.getInteger("bytesSpeed"));
|
||||||
|
|
||||||
JSONArray tracks = mediaInfoJson.getJSONArray("tracks");
|
JSONArray tracks = mediaInfoJson.getJSONArray("tracks");
|
||||||
if (!tracks.isEmpty()) {
|
if (tracks != null && !tracks.isEmpty()) {
|
||||||
for (int i = 0; i < tracks.size(); i++) {
|
for (int i = 0; i < tracks.size(); i++) {
|
||||||
JSONObject tracksJson = tracks.getJSONObject(i);
|
JSONObject tracksJson = tracks.getJSONObject(i);
|
||||||
StreamMediaTrack streamMediaTrack = new StreamMediaTrack();
|
StreamMediaTrack streamMediaTrack = new StreamMediaTrack();
|
||||||
|
|
|
@ -113,7 +113,7 @@ public class MediaServiceImpl implements IMediaService {
|
||||||
@Override
|
@Override
|
||||||
public boolean isReady(MediaServerItem mediaInfo, String app, String stream) {
|
public boolean isReady(MediaServerItem mediaInfo, String app, String stream) {
|
||||||
JSONObject jsonObject = zlmresTfulUtils.getMediaInfo(mediaInfo, app, "rtsp", stream);
|
JSONObject jsonObject = zlmresTfulUtils.getMediaInfo(mediaInfo, app, "rtsp", stream);
|
||||||
return jsonObject != null && jsonObject.getInteger("code") == 0 && jsonObject.getBoolean("online");
|
return jsonObject != null && jsonObject.getInteger("code") == 0 && jsonObject.getInteger("aliveSecond") > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -260,6 +260,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
boolean stopOldProxy = !streamProxyInDb.getType().equals(param.getType())
|
boolean stopOldProxy = !streamProxyInDb.getType().equals(param.getType())
|
||||||
|| !streamProxyInDb.getUrl().equals(param.getUrl())
|
|| !streamProxyInDb.getUrl().equals(param.getUrl())
|
||||||
|| !streamProxyInDb.getMediaServerId().equals(param.getMediaServerId())
|
|| !streamProxyInDb.getMediaServerId().equals(param.getMediaServerId())
|
||||||
|
|| (streamProxyInDb.isEnable() && !param.isEnable())
|
||||||
|| (streamProxyInDb.getType().equals("ffmpeg") && (
|
|| (streamProxyInDb.getType().equals("ffmpeg") && (
|
||||||
streamProxyInDb.getDstUrl().equals(param.getDstUrl())
|
streamProxyInDb.getDstUrl().equals(param.getDstUrl())
|
||||||
|| streamProxyInDb.getFfmpegCmdKey().equals(param.getFfmpegCmdKey())
|
|| streamProxyInDb.getFfmpegCmdKey().equals(param.getFfmpegCmdKey())
|
||||||
|
@ -281,15 +282,11 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
};
|
};
|
||||||
if(stopOldProxy) {
|
if(stopOldProxy) {
|
||||||
stopProxy(param, mediaInfo, (code, msg, data) -> {
|
stopProxy(param, mediaInfo, (code, msg, data) -> {
|
||||||
if (code == ErrorCode.SUCCESS.getCode()) {
|
|
||||||
if (param.isEnable()) {
|
if (param.isEnable()) {
|
||||||
startProxy(param, mediaInfo, startProxyCallback);
|
startProxy(param, mediaInfo, startProxyCallback);
|
||||||
}else {
|
}else {
|
||||||
callback.run(code, msg, null);
|
callback.run(code, msg, null);
|
||||||
}
|
}
|
||||||
}else {
|
|
||||||
callback.run(code, "停止旧的代理失败: " + msg, null);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}else {
|
}else {
|
||||||
if (param.isEnable()) {
|
if (param.isEnable()) {
|
||||||
|
@ -303,6 +300,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startProxy(StreamProxy streamProxy, MediaServerItem mediaInfo, GeneralCallback<StreamInfo> callback) {
|
public void startProxy(StreamProxy streamProxy, MediaServerItem mediaInfo, GeneralCallback<StreamInfo> callback) {
|
||||||
|
logger.info("[开始拉流代理] {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
||||||
// 检测是否在线
|
// 检测是否在线
|
||||||
boolean ready = mediaService.isReady(mediaInfo, streamProxy.getApp(), streamProxy.getStream());
|
boolean ready = mediaService.isReady(mediaInfo, streamProxy.getApp(), streamProxy.getStream());
|
||||||
if (ready) {
|
if (ready) {
|
||||||
|
@ -317,26 +315,26 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
}else {
|
}else {
|
||||||
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
|
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
|
||||||
mediaInfo, streamProxy.getApp(), streamProxy.getStream(), null, null);
|
mediaInfo, streamProxy.getApp(), streamProxy.getStream(), null, null);
|
||||||
|
logger.info("[开始拉流代理] 已拉起,直接返回 {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
||||||
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
|
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
String talkKey = UUID.randomUUID().toString();
|
|
||||||
String delayTalkKey = UUID.randomUUID().toString();
|
String delayTalkKey = UUID.randomUUID().toString();
|
||||||
|
|
||||||
HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(streamProxy.getApp(), streamProxy.getStream(), true, "rtsp", mediaInfo.getId());
|
HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(streamProxy.getApp(), streamProxy.getStream(), true, "rtsp", mediaInfo.getId());
|
||||||
hookSubscribe.addSubscribe(hookSubscribeForStreamChange, (mediaServerItem, response) -> {
|
hookSubscribe.addSubscribe(hookSubscribeForStreamChange, (mediaServerItem, response) -> {
|
||||||
dynamicTask.stop(talkKey);
|
dynamicTask.stop(delayTalkKey);
|
||||||
streamProxy.setStatus(true);
|
streamProxy.setStatus(true);
|
||||||
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
|
StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream(
|
||||||
mediaInfo, streamProxy.getApp(), streamProxy.getStream(), null, null);
|
mediaInfo, streamProxy.getApp(), streamProxy.getStream(), null, null);
|
||||||
logger.info("[拉流代理] 启用成功: {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
logger.info("[开始拉流代理] 成功: {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
||||||
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
|
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo);
|
||||||
});
|
});
|
||||||
|
|
||||||
dynamicTask.startDelay(delayTalkKey, ()->{
|
dynamicTask.startDelay(delayTalkKey, ()->{
|
||||||
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
||||||
dynamicTask.stop(talkKey);
|
dynamicTask.stop(delayTalkKey);
|
||||||
callback.run(ErrorCode.ERROR100.getCode(), "启用超时,请检查源地址是否可用", null);
|
callback.run(ErrorCode.ERROR100.getCode(), "启用超时,请检查源地址是否可用", null);
|
||||||
streamProxy.setProxyError("启用超时");
|
streamProxy.setProxyError("启用超时");
|
||||||
}, 10000);
|
}, 10000);
|
||||||
|
@ -355,7 +353,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
}
|
}
|
||||||
if (result.getInteger("code") != 0) {
|
if (result.getInteger("code") != 0) {
|
||||||
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
hookSubscribe.removeSubscribe(hookSubscribeForStreamChange);
|
||||||
dynamicTask.stop(talkKey);
|
dynamicTask.stop(delayTalkKey);
|
||||||
callback.run(result.getInteger("code"), result.getString("msg"), null);
|
callback.run(result.getInteger("code"), result.getString("msg"), null);
|
||||||
}else {
|
}else {
|
||||||
JSONObject data = result.getJSONObject("data");
|
JSONObject data = result.getJSONObject("data");
|
||||||
|
@ -375,6 +373,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopProxy(StreamProxy streamProxy, MediaServerItem mediaInfo, GeneralCallback<StreamInfo> callback) {
|
public void stopProxy(StreamProxy streamProxy, MediaServerItem mediaInfo, GeneralCallback<StreamInfo> callback) {
|
||||||
|
logger.info("[停止拉流代理] {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
||||||
boolean ready = mediaService.isReady(mediaInfo, streamProxy.getApp(), streamProxy.getStream());
|
boolean ready = mediaService.isReady(mediaInfo, streamProxy.getApp(), streamProxy.getStream());
|
||||||
if (ready) {
|
if (ready) {
|
||||||
if ("ffmpeg".equalsIgnoreCase(streamProxy.getType())){
|
if ("ffmpeg".equalsIgnoreCase(streamProxy.getType())){
|
||||||
|
@ -392,6 +391,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
if (redisTemplate.opsForValue().get(key) == null) {
|
if (redisTemplate.opsForValue().get(key) == null) {
|
||||||
redisTemplate.delete(key);
|
redisTemplate.delete(key);
|
||||||
}
|
}
|
||||||
|
logger.info("[停止拉流代理] 成功 {}/{}", streamProxy.getApp(), streamProxy.getStream());
|
||||||
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), null);
|
callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,7 +418,7 @@ public class StreamProxyServiceImpl implements IStreamProxyService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else {
|
}else {
|
||||||
logger.info("[拉流代理参数处理] 直接拉流,源地址: {}, app: {}, stream: {}", param.getUrl(), param.getApp(), param.getStream());
|
logger.info("[拉流代理参数处理] 方式:直接拉流,源地址: {}, app: {}, stream: {}", param.getUrl(), param.getApp(), param.getStream());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -296,14 +296,14 @@ public interface CommonChannelMapper {
|
||||||
int deleteByDeviceIDs(List<String> clearChannels);
|
int deleteByDeviceIDs(List<String> clearChannels);
|
||||||
|
|
||||||
@Update("<script> "+
|
@Update("<script> "+
|
||||||
"UPDATE wvp_common_channel SET commonGbStatus = true WHERE common_gb_id in" +
|
"UPDATE wvp_common_channel SET common_gb_status = true WHERE common_gb_id in" +
|
||||||
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
|
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
|
||||||
"</script>")
|
"</script>")
|
||||||
void channelsOnlineFromList(List<CommonGbChannel> channelList);
|
void channelsOnlineFromList(List<CommonGbChannel> channelList);
|
||||||
|
|
||||||
|
|
||||||
@Update("<script> "+
|
@Update("<script> "+
|
||||||
"UPDATE wvp_common_channel SET commonGbStatus = false WHERE common_gb_id in" +
|
"UPDATE wvp_common_channel SET common_gb_status = false WHERE common_gb_id in" +
|
||||||
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
|
"<foreach collection='channelList' item='item' open='(' separator=',' close=')' > #{item.commonGbId}</foreach>" +
|
||||||
"</script>")
|
"</script>")
|
||||||
void channelsOfflineFromList(List<CommonGbChannel> channelList);
|
void channelsOfflineFromList(List<CommonGbChannel> channelList);
|
||||||
|
|
|
@ -12,11 +12,11 @@ import java.util.List;
|
||||||
@Repository
|
@Repository
|
||||||
public interface StreamProxyMapper {
|
public interface StreamProxyMapper {
|
||||||
|
|
||||||
@Insert("INSERT INTO wvp_stream_proxy (type, name, app, stream,media_server_id, url, src_url, dst_url, " +
|
@Insert("INSERT INTO wvp_stream_proxy (type, name, app, stream,media_server_id, url, dst_url, " +
|
||||||
"timeout_ms, ffmpeg_cmd_key, rtp_type, enable_audio, enable_mp4, enable, status, stream_key, " +
|
"timeout_ms, ffmpeg_cmd_key, rtp_type, enable_audio, enable_mp4, enable, status, stream_key, " +
|
||||||
"enable_remove_none_reader, enable_disable_none_reader, create_time, longitude, latitude, " +
|
"enable_remove_none_reader, enable_disable_none_reader, create_time, longitude, latitude, " +
|
||||||
"common_gb_channel_id, gb_id) VALUES " +
|
"common_gb_channel_id, gb_id) VALUES " +
|
||||||
"(#{type}, #{name}, #{app}, #{stream}, #{mediaServerId}, #{url}, #{srcUrl}, #{dstUrl}, " +
|
"(#{type}, #{name}, #{app}, #{stream}, #{mediaServerId}, #{url}, #{dstUrl}, " +
|
||||||
"#{timeoutMs}, #{ffmpegCmdKey}, #{rtpType}, #{enableAudio}, #{enableMp4}, #{enable}, #{status}, #{streamKey}, " +
|
"#{timeoutMs}, #{ffmpegCmdKey}, #{rtpType}, #{enableAudio}, #{enableMp4}, #{enable}, #{status}, #{streamKey}, " +
|
||||||
"#{enableRemoveNoneReader}, #{enableDisableNoneReader}, #{createTime} , #{longitude} , #{latitude}, " +
|
"#{enableRemoveNoneReader}, #{enableDisableNoneReader}, #{createTime} , #{longitude} , #{latitude}, " +
|
||||||
"#{commonGbChannelId}, #{gbId})")
|
"#{commonGbChannelId}, #{gbId})")
|
||||||
|
@ -30,7 +30,6 @@ public interface StreamProxyMapper {
|
||||||
"stream=#{stream}," +
|
"stream=#{stream}," +
|
||||||
"url=#{url}, " +
|
"url=#{url}, " +
|
||||||
"media_server_id=#{mediaServerId}, " +
|
"media_server_id=#{mediaServerId}, " +
|
||||||
"src_url=#{srcUrl}," +
|
|
||||||
"dst_url=#{dstUrl}, " +
|
"dst_url=#{dstUrl}, " +
|
||||||
"timeout_ms=#{timeoutMs}, " +
|
"timeout_ms=#{timeoutMs}, " +
|
||||||
"ffmpeg_cmd_key=#{ffmpegCmdKey}, " +
|
"ffmpeg_cmd_key=#{ffmpegCmdKey}, " +
|
||||||
|
|
|
@ -192,7 +192,7 @@ public class StreamProxyController {
|
||||||
});
|
});
|
||||||
|
|
||||||
streamProxyService.edit(param, (code, msg, streamInfo) -> {
|
streamProxyService.edit(param, (code, msg, streamInfo) -> {
|
||||||
logger.info("[添加拉流代理] {}", code == ErrorCode.SUCCESS.getCode()? "成功":"失败: " + msg);
|
logger.info("[编辑拉流代理] {}", code == ErrorCode.SUCCESS.getCode()? "成功":"失败: " + msg);
|
||||||
if (code == ErrorCode.SUCCESS.getCode()) {
|
if (code == ErrorCode.SUCCESS.getCode()) {
|
||||||
result.setResult(new StreamContent(streamInfo));
|
result.setResult(new StreamContent(streamInfo));
|
||||||
}else {
|
}else {
|
||||||
|
|
|
@ -152,6 +152,9 @@ alter table wvp_stream_push
|
||||||
alter table wvp_stream_push
|
alter table wvp_stream_push
|
||||||
drop column alive_second;
|
drop column alive_second;
|
||||||
|
|
||||||
|
alter table wvp_stream_proxy
|
||||||
|
drop column src_url;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue