diff --git a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java index 1711938a..b7f57d75 100755 --- a/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java +++ b/src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommander.java @@ -15,12 +15,11 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.SIPRequestHeaderProvider; import com.genersoft.iot.vmp.gb28181.utils.NumericUtil; import com.genersoft.iot.vmp.gb28181.utils.SipUtils; import com.genersoft.iot.vmp.media.event.hook.Hook; +import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; import com.genersoft.iot.vmp.media.event.hook.HookType; import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; -import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; import com.genersoft.iot.vmp.media.zlm.dto.MediaServer; -import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam; import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.utils.DateUtil; import gov.nist.javax.sip.message.SIPRequest; @@ -279,6 +278,7 @@ public class SIPCommander implements ISIPCommander { logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort()); Hook rtpHook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServerItem.getId()); + System.out.println("rtpHook: " + rtpHook.toString()); subscribe.addSubscribe(rtpHook, (hookData) -> { if (event != null) { event.response(hookData); diff --git a/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java b/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java index e753fb6c..c33eeccc 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java +++ b/src/main/java/com/genersoft/iot/vmp/media/bean/MediaInfo.java @@ -128,7 +128,7 @@ public class MediaInfo { } public static MediaInfo getInstance(OnStreamChangedHookParam param, MediaServer mediaServer) { - List tracks = param.getTracks(); + MediaInfo mediaInfo = new MediaInfo(); mediaInfo.setApp(param.getApp()); mediaInfo.setStream(param.getStream()); @@ -139,6 +139,10 @@ public class MediaInfo { mediaInfo.setOriginType(param.getOriginType()); mediaInfo.setAliveSecond(param.getAliveSecond()); mediaInfo.setBytesSpeed(param.getBytesSpeed()); + List tracks = param.getTracks(); + if (tracks == null || tracks.isEmpty()) { + return mediaInfo; + } for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) { switch (mediaTrack.getCodec_id()) { case 0: diff --git a/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java b/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java index 64b8ffeb..598178fe 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java +++ b/src/main/java/com/genersoft/iot/vmp/media/event/hook/HookSubscribe.java @@ -4,14 +4,11 @@ import com.genersoft.iot.vmp.media.event.media.MediaArrivalEvent; import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent; import com.genersoft.iot.vmp.media.event.media.MediaEvent; import com.genersoft.iot.vmp.media.event.media.MediaPublishEvent; -import org.mybatis.logging.Logger; -import org.mybatis.logging.LoggerFactory; import org.springframework.context.event.EventListener; import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Scheduled; import org.springframework.stereotype.Component; -import java.time.Instant; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -40,6 +37,9 @@ public class HookSubscribe { public void onApplicationEvent(MediaArrivalEvent event) { if ("rtsp".equals(event.getSchema())) { System.out.println("流到来的处理: " + allSubscribes.size()); + for (String s : allSubscribes.keySet()) { + System.out.println("key: " + s); + } sendNotify(HookType.on_media_arrival, event); } @@ -70,6 +70,7 @@ public class HookSubscribe { private void sendNotify(HookType hookType, MediaEvent event) { Hook paramHook = Hook.getInstance(hookType, event.getApp(), event.getStream(), event.getMediaServer().getId()); + System.out.println("sendNotify: " + paramHook.toString()); Event hookSubscribeEvent = allSubscribes.get(paramHook.toString()); if (hookSubscribeEvent != null) { HookData data = HookData.getInstance(event); @@ -86,6 +87,7 @@ public class HookSubscribe { } public void removeSubscribe(Hook hook) { + System.out.println("removeSubscribe: " + hook.toString()); allSubscribes.remove(hook.toString()); allHook.remove(hook.toString()); } @@ -98,6 +100,7 @@ public class HookSubscribe { long expireTime = System.currentTimeMillis() - subscribeExpire; for (Hook hook : allHook.values()) { if (hook.getCreateTime() < expireTime) { + System.out.println("execute removeSubscribe: " + hook.toString()); allSubscribes.remove(hook.toString()); allHook.remove(hook.toString()); } diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java index 7873cf5b..e0793a5c 100755 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMHttpHookListener.java @@ -12,7 +12,6 @@ import com.genersoft.iot.vmp.gb28181.transmit.cmd.ISIPCommanderForPlatform; import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander; import com.genersoft.iot.vmp.media.bean.ResultForOnPublish; import com.genersoft.iot.vmp.media.event.hook.HookSubscribe; -import com.genersoft.iot.vmp.media.event.hook.HookType; import com.genersoft.iot.vmp.media.event.media.*; import com.genersoft.iot.vmp.media.event.mediaServer.MediaSendRtpStoppedEvent; import com.genersoft.iot.vmp.media.service.IMediaServerService; @@ -36,7 +35,6 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import java.util.HashMap; -import java.util.List; import java.util.Map; /** @@ -207,8 +205,8 @@ public class ZLMHttpHookListener { applicationEventPublisher.publishEvent(mediaArrivalEvent); } else { logger.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); - MediaDepartureEvent mediaArrivalEvent = MediaDepartureEvent.getInstance(this, param, mediaServer); - applicationEventPublisher.publishEvent(mediaArrivalEvent); + MediaDepartureEvent mediaDepartureEvent = MediaDepartureEvent.getInstance(this, param, mediaServer); + applicationEventPublisher.publishEvent(mediaDepartureEvent); } return HookResult.SUCCESS(); }