临时提交

pull/1411/head
648540858 2024-04-01 15:22:45 +08:00
parent 5973dcd975
commit ecd1d2a414
4 changed files with 15 additions and 10 deletions

View File

@ -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.NumericUtil;
import com.genersoft.iot.vmp.gb28181.utils.SipUtils; 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.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.event.hook.HookType;
import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.service.IMediaServerService;
import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; 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.MediaServer;
import com.genersoft.iot.vmp.media.zlm.dto.hook.HookParam;
import com.genersoft.iot.vmp.service.bean.SSRCInfo; import com.genersoft.iot.vmp.service.bean.SSRCInfo;
import com.genersoft.iot.vmp.utils.DateUtil; import com.genersoft.iot.vmp.utils.DateUtil;
import gov.nist.javax.sip.message.SIPRequest; 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()); logger.info("{} 分配的ZLM为: {} [{}:{}]", stream, mediaServerItem.getId(), mediaServerItem.getSdpIp(), ssrcInfo.getPort());
Hook rtpHook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServerItem.getId()); Hook rtpHook = Hook.getInstance(HookType.on_media_arrival, "rtp", stream, mediaServerItem.getId());
System.out.println("rtpHook: " + rtpHook.toString());
subscribe.addSubscribe(rtpHook, (hookData) -> { subscribe.addSubscribe(rtpHook, (hookData) -> {
if (event != null) { if (event != null) {
event.response(hookData); event.response(hookData);

View File

@ -128,7 +128,7 @@ public class MediaInfo {
} }
public static MediaInfo getInstance(OnStreamChangedHookParam param, MediaServer mediaServer) { public static MediaInfo getInstance(OnStreamChangedHookParam param, MediaServer mediaServer) {
List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
MediaInfo mediaInfo = new MediaInfo(); MediaInfo mediaInfo = new MediaInfo();
mediaInfo.setApp(param.getApp()); mediaInfo.setApp(param.getApp());
mediaInfo.setStream(param.getStream()); mediaInfo.setStream(param.getStream());
@ -139,6 +139,10 @@ public class MediaInfo {
mediaInfo.setOriginType(param.getOriginType()); mediaInfo.setOriginType(param.getOriginType());
mediaInfo.setAliveSecond(param.getAliveSecond()); mediaInfo.setAliveSecond(param.getAliveSecond());
mediaInfo.setBytesSpeed(param.getBytesSpeed()); mediaInfo.setBytesSpeed(param.getBytesSpeed());
List<OnStreamChangedHookParam.MediaTrack> tracks = param.getTracks();
if (tracks == null || tracks.isEmpty()) {
return mediaInfo;
}
for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) { for (OnStreamChangedHookParam.MediaTrack mediaTrack : tracks) {
switch (mediaTrack.getCodec_id()) { switch (mediaTrack.getCodec_id()) {
case 0: case 0:

View File

@ -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.MediaDepartureEvent;
import com.genersoft.iot.vmp.media.event.media.MediaEvent; import com.genersoft.iot.vmp.media.event.media.MediaEvent;
import com.genersoft.iot.vmp.media.event.media.MediaPublishEvent; 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.context.event.EventListener;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled; import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.time.Instant;
import java.util.Map; import java.util.Map;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -40,6 +37,9 @@ public class HookSubscribe {
public void onApplicationEvent(MediaArrivalEvent event) { public void onApplicationEvent(MediaArrivalEvent event) {
if ("rtsp".equals(event.getSchema())) { if ("rtsp".equals(event.getSchema())) {
System.out.println("流到来的处理: " + allSubscribes.size()); System.out.println("流到来的处理: " + allSubscribes.size());
for (String s : allSubscribes.keySet()) {
System.out.println("key: " + s);
}
sendNotify(HookType.on_media_arrival, event); sendNotify(HookType.on_media_arrival, event);
} }
@ -70,6 +70,7 @@ public class HookSubscribe {
private void sendNotify(HookType hookType, MediaEvent event) { private void sendNotify(HookType hookType, MediaEvent event) {
Hook paramHook = Hook.getInstance(hookType, event.getApp(), event.getStream(), event.getMediaServer().getId()); Hook paramHook = Hook.getInstance(hookType, event.getApp(), event.getStream(), event.getMediaServer().getId());
System.out.println("sendNotify: " + paramHook.toString());
Event hookSubscribeEvent = allSubscribes.get(paramHook.toString()); Event hookSubscribeEvent = allSubscribes.get(paramHook.toString());
if (hookSubscribeEvent != null) { if (hookSubscribeEvent != null) {
HookData data = HookData.getInstance(event); HookData data = HookData.getInstance(event);
@ -86,6 +87,7 @@ public class HookSubscribe {
} }
public void removeSubscribe(Hook hook) { public void removeSubscribe(Hook hook) {
System.out.println("removeSubscribe: " + hook.toString());
allSubscribes.remove(hook.toString()); allSubscribes.remove(hook.toString());
allHook.remove(hook.toString()); allHook.remove(hook.toString());
} }
@ -98,6 +100,7 @@ public class HookSubscribe {
long expireTime = System.currentTimeMillis() - subscribeExpire; long expireTime = System.currentTimeMillis() - subscribeExpire;
for (Hook hook : allHook.values()) { for (Hook hook : allHook.values()) {
if (hook.getCreateTime() < expireTime) { if (hook.getCreateTime() < expireTime) {
System.out.println("execute removeSubscribe: " + hook.toString());
allSubscribes.remove(hook.toString()); allSubscribes.remove(hook.toString());
allHook.remove(hook.toString()); allHook.remove(hook.toString());
} }

View File

@ -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.gb28181.transmit.cmd.impl.SIPCommander;
import com.genersoft.iot.vmp.media.bean.ResultForOnPublish; 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.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.media.*;
import com.genersoft.iot.vmp.media.event.mediaServer.MediaSendRtpStoppedEvent; import com.genersoft.iot.vmp.media.event.mediaServer.MediaSendRtpStoppedEvent;
import com.genersoft.iot.vmp.media.service.IMediaServerService; import com.genersoft.iot.vmp.media.service.IMediaServerService;
@ -36,7 +35,6 @@ import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map; import java.util.Map;
/** /**
@ -207,8 +205,8 @@ public class ZLMHttpHookListener {
applicationEventPublisher.publishEvent(mediaArrivalEvent); applicationEventPublisher.publishEvent(mediaArrivalEvent);
} else { } else {
logger.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream()); logger.info("[ZLM HOOK] 流注销, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
MediaDepartureEvent mediaArrivalEvent = MediaDepartureEvent.getInstance(this, param, mediaServer); MediaDepartureEvent mediaDepartureEvent = MediaDepartureEvent.getInstance(this, param, mediaServer);
applicationEventPublisher.publishEvent(mediaArrivalEvent); applicationEventPublisher.publishEvent(mediaDepartureEvent);
} }
return HookResult.SUCCESS(); return HookResult.SUCCESS();
} }