添加 proxy-media-url
支持替换 返回的 url
This commit is contained in:
parent
d7837a1975
commit
e55bd2aea5
@ -37,6 +37,12 @@ public class ProxySipConfig {
|
|||||||
*/
|
*/
|
||||||
private boolean usePlaybackToDownload = false;
|
private boolean usePlaybackToDownload = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 代理 zlm 地址, 用于 /video/device/video.mp4 替换返回值地址
|
||||||
|
* <p>例: http://127.0.0.1:5080</p>
|
||||||
|
*/
|
||||||
|
private String proxyMediaUrl = "";
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public SipConfig sipConfig(){
|
public SipConfig sipConfig(){
|
||||||
SipConfig sipConfig = new SipConfig();
|
SipConfig sipConfig = new SipConfig();
|
||||||
|
@ -80,6 +80,7 @@ public class Gb28181DownloadService {
|
|||||||
private final VideoService videoService;
|
private final VideoService videoService;
|
||||||
private final WvpProxyConfig wvpProxyConfig;
|
private final WvpProxyConfig wvpProxyConfig;
|
||||||
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
private final ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
private final ConcurrentMap<String, DeferredResult<JsonResponse<String>>> requestMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@ -185,22 +186,50 @@ public class Gb28181DownloadService {
|
|||||||
result.setResult(JsonResponse.error("设备(通道)不存在"));
|
result.setResult(JsonResponse.error("设备(通道)不存在"));
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
download(deviceCode, startTime, endTime).whenComplete((videoInfo, e)->{
|
requestMap.computeIfPresent(deviceCode,(key,requestResult)->{
|
||||||
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
|
if(!requestResult.hasResult()){
|
||||||
String existCallId = RedisUtil.StringOps.get(cacheKey);
|
requestResult.setResult(JsonResponse.error("同一设备重复请求, 本次请求结束"));
|
||||||
scheduledExecutorService.schedule(()->{
|
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
|
||||||
log.info("到达结束时间 发送 bye 关闭 {} {}", videoInfo.getDevice(), videoInfo.getCallId());
|
String existCallId = RedisUtil.StringOps.get(cacheKey);
|
||||||
String deviceIp = docking.getIp();
|
if(StringUtils.isNotBlank(existCallId)){
|
||||||
int devicePort = Integer.parseInt(docking.getPort());
|
String deviceIp = docking.getIp();
|
||||||
sender.sendRequest((provider,localIp,localPort)->
|
int devicePort = Integer.parseInt(docking.getPort());
|
||||||
SipRequestBuilder.createByeRequest(deviceIp, devicePort, device.getGbDeviceChannelId(), SipUtil.generateFromTag(), null, existCallId));
|
sender.sendRequest((provider,localIp,localPort)->
|
||||||
RedisUtil.KeyOps.delete(cacheKey);
|
SipRequestBuilder.createByeRequest(deviceIp, devicePort, device.getGbDeviceChannelId(), SipUtil.generateFromTag(), null, existCallId));
|
||||||
zlmMediaService.closeRtpServer(CloseRtpServer.builder()
|
RedisUtil.KeyOps.delete(cacheKey);
|
||||||
.streamId(videoInfo.streamId)
|
}
|
||||||
.build());
|
}
|
||||||
}, time, TimeUnit.MILLISECONDS);
|
return null;
|
||||||
result.setResult(JsonResponse.success(videoInfo.getUrl()));
|
|
||||||
});
|
});
|
||||||
|
requestMap.put(deviceCode, result);
|
||||||
|
|
||||||
|
// 间隔一定时间(200ms) 给设备足够的时间结束前次请求
|
||||||
|
scheduledExecutorService.schedule(()->{
|
||||||
|
download(deviceCode, startTime, endTime).whenComplete((videoInfo, e)->{
|
||||||
|
log.info("获取媒体信息 {}", videoInfo);
|
||||||
|
String cacheKey = CacheUtil.getKey(docking.getGbDeviceId(), device.getGbDeviceChannelId());
|
||||||
|
String existCallId = RedisUtil.StringOps.get(cacheKey);
|
||||||
|
// 到达时间后主动结束, 防止某些设备不会主动结束
|
||||||
|
scheduledExecutorService.schedule(()->{
|
||||||
|
log.info("到达结束时间 发送 bye 关闭 {} {}", videoInfo.getDevice(), videoInfo.getCallId());
|
||||||
|
String deviceIp = docking.getIp();
|
||||||
|
int devicePort = Integer.parseInt(docking.getPort());
|
||||||
|
if(StringUtils.isNotBlank(existCallId)) {
|
||||||
|
sender.sendRequest((provider, localIp, localPort) ->
|
||||||
|
SipRequestBuilder.createByeRequest(deviceIp, devicePort, device.getGbDeviceChannelId(), SipUtil.generateFromTag(), null, existCallId));
|
||||||
|
}
|
||||||
|
RedisUtil.KeyOps.delete(cacheKey);
|
||||||
|
zlmMediaService.closeRtpServer(CloseRtpServer.builder()
|
||||||
|
.streamId(videoInfo.streamId)
|
||||||
|
.build());
|
||||||
|
}, time, TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
|
String url = StringUtils.isNotBlank(proxySipConfig.getProxyMediaUrl()) ?
|
||||||
|
StringUtils.replace(videoInfo.getUrl(), zlmMediaConfig.getUrl(), proxySipConfig.getProxyMediaUrl()):
|
||||||
|
videoInfo.getUrl();
|
||||||
|
result.setResult(JsonResponse.success(url));
|
||||||
|
});
|
||||||
|
}, 200, TimeUnit.MILLISECONDS);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ spring:
|
|||||||
|
|
||||||
media:
|
media:
|
||||||
ip: 10.10.10.200
|
ip: 10.10.10.200
|
||||||
url: 'http://10.10.10.200:5081'
|
url: 'https://10.10.10.200:5444'
|
||||||
# url: 'http://10.10.10.200:12580/anything/'
|
# url: 'http://10.10.10.200:12580/anything/'
|
||||||
id: amrWMKmbKqoBjRQ9
|
id: amrWMKmbKqoBjRQ9
|
||||||
# secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
# secret: 035c73f7-bb6b-4889-a715-d9eb2d1925cc
|
||||||
@ -58,6 +58,7 @@ proxy:
|
|||||||
- 10.10.10.20
|
- 10.10.10.20
|
||||||
stream-mode: udp
|
stream-mode: udp
|
||||||
use-playback-to-download: true
|
use-playback-to-download: true
|
||||||
|
proxy-media-url: 'http://10.10.10.200/media'
|
||||||
# - 192.168.1.241
|
# - 192.168.1.241
|
||||||
ffmpeg-support:
|
ffmpeg-support:
|
||||||
ffmpeg: D:\Soft\Captura\ffmpeg\ffmpeg.exe
|
ffmpeg: D:\Soft\Captura\ffmpeg\ffmpeg.exe
|
||||||
|
@ -65,7 +65,9 @@ proxy:
|
|||||||
# - 192.168.3.10
|
# - 192.168.3.10
|
||||||
# - 192.168.1.241
|
# - 192.168.1.241
|
||||||
stream-mode: tcp_passive
|
stream-mode: tcp_passive
|
||||||
use-playback-to-download: true
|
use-playback-to-download: false
|
||||||
|
# 用于替换 返回的 url 值, 可用 nginx 或 caddy 代理 zlm
|
||||||
|
# proxy-media-url: 'http://10.10.10.200/media'
|
||||||
device-api:
|
device-api:
|
||||||
offset:
|
offset:
|
||||||
forward: 30s
|
forward: 30s
|
||||||
|
Loading…
Reference in New Issue
Block a user