尝试使用 zlmStreamProxy

This commit is contained in:
shikong 2023-10-08 10:46:57 +08:00
parent e5620f237b
commit c930d2d79d
2 changed files with 36 additions and 12 deletions

View File

@ -13,4 +13,5 @@ public class ZlmHookConfig {
private String hook;
private Duration delay = Duration.ofMillis(100);
private Duration fixed = Duration.ofSeconds(30);
private Boolean proxy = true;
}

View File

@ -11,6 +11,7 @@ import cn.skcks.docking.gb28181.core.sip.gb28181.sdp.GB28181Description;
import cn.skcks.docking.gb28181.core.sip.message.subscribe.GenericSubscribe;
import cn.skcks.docking.gb28181.core.sip.utils.SipUtil;
import cn.skcks.docking.gb28181.media.config.ZlmMediaConfig;
import cn.skcks.docking.gb28181.media.dto.proxy.AddStreamProxy;
import cn.skcks.docking.gb28181.media.dto.rtp.StartSendRtp;
import cn.skcks.docking.gb28181.media.dto.rtp.StartSendRtpResp;
import cn.skcks.docking.gb28181.media.proxy.ZlmMediaService;
@ -107,12 +108,23 @@ public class DeviceProxyService {
zlmStreamChangeHookService.getUnregistHandler().put(callId,()->{
sendBye(request,device,key);
});
FfmpegExecuteResultHandler executeResultHandler = mediaStatus(request, device, key);
String zlmRtpUrl = "rtmp://" + zlmMediaConfig.getIp() + ":" + zlmRtmpConfig.getPort() + "/live/" + callId;
Executor executor = pushRtpTask(fromUrl, zlmRtpUrl, time + 60, executeResultHandler);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
callbackTask.put(device.getDeviceCode(), executor);
executeResultHandler.waitFor();
if(zlmHookConfig.getProxy()){
AddStreamProxy addStreamProxy = AddStreamProxy.builder()
.app("live")
.stream(callId)
.url(fromUrl)
.timeoutSec(30.0)
.build();
zlmMediaService.addStreamProxy(addStreamProxy);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
} else {
FfmpegExecuteResultHandler executeResultHandler = mediaStatus(request, device, key);
String zlmRtpUrl = "rtmp://" + zlmMediaConfig.getIp() + ":" + zlmRtmpConfig.getPort() + "/live/" + callId;
Executor executor = pushRtpTask(fromUrl, zlmRtpUrl, time + 60, executeResultHandler);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
callbackTask.put(device.getDeviceCode(), executor);
executeResultHandler.waitFor();
}
} catch (Exception e) {
throw new RuntimeException(e);
}
@ -147,12 +159,23 @@ public class DeviceProxyService {
zlmStreamChangeHookService.getUnregistHandler().put(callId,()->{
sendBye(request,device,key);
});
FfmpegExecuteResultHandler executeResultHandler = mediaStatus(request, device, key);
String zlmRtpUrl = "rtmp://" + zlmMediaConfig.getIp() + ":" + zlmRtmpConfig.getPort() + "/live/" + callId;
Executor executor = pushDownload2RtpTask(fromUrl, zlmRtpUrl, time + 60, executeResultHandler);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
downloadTask.put(device.getDeviceCode(), executor);
executeResultHandler.waitFor();
if(zlmHookConfig.getProxy()){
AddStreamProxy addStreamProxy = AddStreamProxy.builder()
.app("live")
.stream(callId)
.url(fromUrl)
.timeoutSec(30.0)
.build();
zlmMediaService.addStreamProxy(addStreamProxy);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
} else {
FfmpegExecuteResultHandler executeResultHandler = mediaStatus(request, device, key);
String zlmRtpUrl = "rtmp://" + zlmMediaConfig.getIp() + ":" + zlmRtmpConfig.getPort() + "/live/" + callId;
Executor executor = pushDownload2RtpTask(fromUrl, zlmRtpUrl, time + 60, executeResultHandler);
scheduledExecutorService.schedule(subscriber::onComplete, time + 60, TimeUnit.SECONDS);
downloadTask.put(device.getDeviceCode(), executor);
executeResultHandler.waitFor();
}
} catch (Exception e) {
throw new RuntimeException(e);
}