diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/ZlmHookConfig.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/ZlmHookConfig.java index 18f30f8..b1e0635 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/ZlmHookConfig.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/config/sip/ZlmHookConfig.java @@ -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); } diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java index bc07847..7cc7b19 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/device/DeviceProxyService.java @@ -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); diff --git a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/zlm/hook/ZlmStreamChangeHookService.java b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/zlm/hook/ZlmStreamChangeHookService.java index 62c9f00..8f0dfbb 100644 --- a/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/zlm/hook/ZlmStreamChangeHookService.java +++ b/gb28181-mocking-service/src/main/java/cn/skcks/docking/gb28181/mocking/service/zlm/hook/ZlmStreamChangeHookService.java @@ -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(); + }); } } diff --git a/gb28181-mocking-starter/src/main/resources/application-local.yml b/gb28181-mocking-starter/src/main/resources/application-local.yml index 2bedfed..4141c58 100644 --- a/gb28181-mocking-starter/src/main/resources/application-local.yml +++ b/gb28181-mocking-starter/src/main/resources/application-local.yml @@ -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/'