StartSendRtp 延迟可配置

This commit is contained in:
shikong 2023-10-07 11:34:44 +08:00
parent a69fa97ba6
commit e4be1e1373
4 changed files with 16 additions and 11 deletions

View File

@ -4,9 +4,12 @@ import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import java.time.Duration;
@Data
@Configuration
@ConfigurationProperties(prefix = "media.local")
public class ZlmHookConfig {
private String hook;
private Duration delay = Duration.ofMillis(100);
}

View File

@ -90,11 +90,6 @@ public class DeviceProxyService {
MediaDescription mediaDescription = (MediaDescription)gb28181Description.getMediaDescriptions(true).get(0);
boolean tcp = StringUtils.containsIgnoreCase(mediaDescription.getMedia().getProtocol(), "TCP");
zlmStreamChangeHookService.handlerMap.put(callId,()->{
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
StartSendRtp startSendRtp = new StartSendRtp();
startSendRtp.setApp("live");
startSendRtp.setStream(callId);
@ -132,11 +127,6 @@ public class DeviceProxyService {
MediaDescription mediaDescription = (MediaDescription)gb28181Description.getMediaDescriptions(true).get(0);
boolean tcp = StringUtils.containsIgnoreCase(mediaDescription.getMedia().getProtocol(), "TCP");
zlmStreamChangeHookService.handlerMap.put(callId,()->{
try {
Thread.sleep(500);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
StartSendRtp startSendRtp = new StartSendRtp();
startSendRtp.setApp("live");
startSendRtp.setStream(callId);

View File

@ -1,6 +1,8 @@
package cn.skcks.docking.gb28181.mocking.service.zlm.hook;
import cn.skcks.docking.gb28181.mocking.config.sip.ZlmHookConfig;
import lombok.Data;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@ -11,7 +13,9 @@ import java.util.concurrent.ConcurrentMap;
@Slf4j
@Data
@Service
@RequiredArgsConstructor
public class ZlmStreamChangeHookService {
private ZlmHookConfig zlmHookConfig;
public interface ZlmStreamChangeHookHandler{
void handler();
}
@ -24,6 +28,13 @@ public class ZlmStreamChangeHookService {
return;
}
Optional.ofNullable(handlerMap.remove(streamId)).ifPresent(ZlmStreamChangeHookHandler::handler);
Optional.ofNullable(handlerMap.remove(streamId)).ifPresent((handler)->{
try {
Thread.sleep(zlmHookConfig.getDelay().toMillis());
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
handler.handler();
});
}
}

View File

@ -68,6 +68,7 @@ gb28181:
media:
local:
hook: http://10.10.10.20:18182/zlm/hook
delay: 100ms
ip: 10.10.10.200
url: 'http://10.10.10.200:5081'
# url: 'http://10.10.10.200:12580/anything/'