流媒体服务接口逻辑更改
This commit is contained in:
parent
1c64023502
commit
67bf690c8a
@ -64,6 +64,31 @@ public class ZKLmediaController {
|
||||
return R.fail();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建拉流任务,返回null代表创建拉流任务失败
|
||||
*
|
||||
* @param data 创建拉流设备信息(如果外网不建议使用这种方式)
|
||||
* @return 返回拉流任务信息
|
||||
*/
|
||||
@PostMapping("/realtime/addFfmpeg")
|
||||
public R<AddStreamProxyResp> addFfmpegTask(@RequestBody @Validated AddStreamProxy data) {
|
||||
String sourceUrl = "";
|
||||
if (FactoryNoEnum.HIK.getCode().equals(data.getFactoryNo())) {
|
||||
sourceUrl = String.format(HIK_REALTIME_RTSP_TEMPLATE, data.getAccount(), data.getPwd(), data.getVideoIp(), data.getVideoPort(), data.getChannelId());
|
||||
} else if (FactoryNoEnum.DAHUA.getCode().equals(data.getFactoryNo())) {
|
||||
sourceUrl = String.format(DAHUA_REALTIME_RTSP_TEMPLATE, data.getAccount(), data.getPwd(), data.getVideoIp(), data.getVideoPort(), data.getChannelId());
|
||||
} else {
|
||||
throw new RuntimeException("未知的设备类型!");
|
||||
}
|
||||
|
||||
AddStreamProxyResp addStreamProxyResp = zlMediaKitService.addFFmpegSource(sourceUrl);
|
||||
if (addStreamProxyResp != null) {
|
||||
return R.ok(addStreamProxyResp);
|
||||
}
|
||||
return R.fail();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建历史回放拉流任务,返回null代表创建拉流任务失败
|
||||
*
|
||||
|
@ -69,12 +69,12 @@ public interface ZLMediaKitService {
|
||||
/**
|
||||
* 通过 fork FFmpeg 进程的方式拉流代理,支持任意协议
|
||||
*/
|
||||
Object addFFmpegSource();
|
||||
AddStreamProxyResp addFFmpegSource(String src_url);
|
||||
|
||||
/**
|
||||
* 流注册成功后,也可以使用close_streams接口替代
|
||||
*/
|
||||
Object delFFmpegSource();
|
||||
Boolean delFFmpegSource(String key);
|
||||
|
||||
/**
|
||||
* 获取 rtp 代理时的某路 ssrc rtp 信息
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.dromara.sis.sdk.zkmedia;
|
||||
|
||||
import cn.hutool.core.util.IdUtil;
|
||||
import com.alibaba.fastjson2.TypeReference;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sis.config.ZLMediaKitConfig;
|
||||
@ -161,13 +162,52 @@ public class ZLMediaKitServiceImpl implements ZLMediaKitService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object addFFmpegSource() {
|
||||
public AddStreamProxyResp addFFmpegSource(String src_url) {
|
||||
|
||||
// 生成拉流任务key
|
||||
String taskKey = IdUtil.fastSimpleUUID();
|
||||
String targetUrl = "rtmp://127.0.0.1/live/" + taskKey;
|
||||
Map<String, Object> commonParams = getCommonParams();
|
||||
commonParams.put("src_url", src_url);
|
||||
commonParams.put("dst_url", targetUrl);
|
||||
commonParams.put("timeout_ms", 10000);
|
||||
commonParams.put("enable_hls", false);
|
||||
commonParams.put("enable_mp4", false);
|
||||
R<AddStreamProxyResp> result = HttpClientUtil.get(getRequestUrl("addFFmpegSource"), commonParams, AddStreamProxyResp.class);
|
||||
if (result != null) {
|
||||
if (result.getCode() == 0) {
|
||||
log.info("创建FFMPEG拉流任务成功.");
|
||||
}
|
||||
// 此处代表拉流任务已存在
|
||||
if (result.getCode() == -1) {
|
||||
log.info("FFMPEG拉流任务已存在,返回播放地址。");
|
||||
}
|
||||
|
||||
// RTMP 播放地址
|
||||
result.getData().setRtmp(String.format("rtmp://%s:%d/live/%s", zlmConfig.getIp(), zlmConfig.getRtmpPort(), taskKey));
|
||||
// RTSP 播放地址
|
||||
result.getData().setRtsp(String.format("rtsp://%s:%d/live/%s", zlmConfig.getIp(), zlmConfig.getRtspPort(), taskKey));
|
||||
// HTTP-FLV 播放地址
|
||||
result.getData().setFlv(String.format("http://%s:%d/live/%s.live.flv", zlmConfig.getIp(), zlmConfig.getHttpPort(), taskKey));
|
||||
result.getData().setWsFlv(String.format("ws://%s:%d/live/%s.live.flv", zlmConfig.getIp(), zlmConfig.getHttpPort(), taskKey));
|
||||
// HLS 播放地址
|
||||
result.getData().setHls(String.format("http://%s:%d/live/%s/hls.m3u8", zlmConfig.getIp(), zlmConfig.getHttpPort(), taskKey));
|
||||
// MP4 播放地址
|
||||
result.getData().setMp4(String.format("http://%s:%d/live/%s.live.mp4", zlmConfig.getIp(), zlmConfig.getHttpPort(), taskKey));
|
||||
return result.getData();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object delFFmpegSource() {
|
||||
return null;
|
||||
public Boolean delFFmpegSource(String key) {
|
||||
Map<String, Object> commonParams = getCommonParams();
|
||||
R<String> result = HttpClientUtil.get(getRequestUrl("addFFmpegSource?key=" + key), commonParams, String.class);
|
||||
if (result != null && result.getCode() == 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Loading…
Reference in New Issue
Block a user