| | |
| | |
|
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.alibaba.fastjson2.JSONObject;
|
| | | import com.genersoft.iot.vmp.common.InviteInfo;
|
| | | import com.genersoft.iot.vmp.common.InviteSessionType;
|
| | | import com.genersoft.iot.vmp.conf.UserSetting;
|
| | | import com.genersoft.iot.vmp.conf.exception.SsrcTransactionNotFoundException;
|
| | | import com.genersoft.iot.vmp.gb28181.bean.*;
|
| | | import com.genersoft.iot.vmp.gb28181.event.EventPublisher;
|
| | | import com.genersoft.iot.vmp.gb28181.session.AudioBroadcastManager;
|
| | | import com.genersoft.iot.vmp.gb28181.session.SSRCFactory;
|
| | | import com.genersoft.iot.vmp.gb28181.session.VideoStreamSessionManager;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
|
| | | import com.genersoft.iot.vmp.gb28181.transmit.callback.RequestMessage;
|
| | | 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.MediaArrivalEvent;
|
| | | import com.genersoft.iot.vmp.media.event.MediaDepartureEvent;
|
| | | import com.genersoft.iot.vmp.media.event.MediaNotFoundEvent;
|
| | | import com.genersoft.iot.vmp.media.event.hook.HookSubscribe;
|
| | | 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;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookType;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServer;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.ZLMServerConfig;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.hook.*;
|
| | | import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerKeepaliveEvent;
|
| | | import com.genersoft.iot.vmp.media.zlm.event.HookZlmServerStartEvent;
|
| | | import com.genersoft.iot.vmp.service.*;
|
| | | import com.genersoft.iot.vmp.service.bean.MessageForPushChannel;
|
| | | import com.genersoft.iot.vmp.service.bean.SSRCInfo;
|
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage;
|
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage;
|
| | | import com.genersoft.iot.vmp.utils.DateUtil;
|
| | | import com.genersoft.iot.vmp.vmanager.bean.ErrorCode;
|
| | | import org.slf4j.Logger;
|
| | | import org.slf4j.LoggerFactory;
|
| | | import org.springframework.beans.factory.annotation.Autowired;
|
| | |
| | | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
| | | import org.springframework.util.ObjectUtils;
|
| | | import org.springframework.web.bind.annotation.*;
|
| | | import org.springframework.web.context.request.async.DeferredResult;
|
| | |
|
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.sip.InvalidArgumentException;
|
| | | import javax.sip.SipException;
|
| | | import java.text.ParseException;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.UUID;
|
| | |
|
| | | /**
|
| | | * @description:针对 ZLMediaServer的hook事件监听
|
| | |
| | | private ZLMMediaListManager zlmMediaListManager;
|
| | |
|
| | | @Autowired
|
| | | private ZlmHttpHookSubscribe subscribe;
|
| | | private HookSubscribe subscribe;
|
| | |
|
| | | @Autowired
|
| | | private UserSetting userSetting;
|
| | |
| | | @ResponseBody
|
| | | @PostMapping(value = "/on_play", produces = "application/json;charset=UTF-8")
|
| | | public HookResult onPlay(@RequestBody OnPlayHookParam param) {
|
| | | if (logger.isDebugEnabled()) {
|
| | | logger.debug("[ZLM HOOK] 播放鉴权:{}->{}", param.getMediaServerId(), param);
|
| | | }
|
| | |
|
| | | Map<String, String> paramMap = urlParamToMap(param.getParams());
|
| | | // 对于播放流进行鉴权
|
| | | boolean authenticateResult = mediaService.authenticatePlay(param.getApp(), param.getStream(), paramMap.get("callId"));
|
| | | if (!authenticateResult) {
|
| | | logger.info("[ZLM HOOK] 播放鉴权 失败:{}->{}", param.getMediaServerId(), param);
|
| | | return new HookResult(401, "Unauthorized");
|
| | | }
|
| | |
|
| | | logger.info("[ZLM HOOK] 播放鉴权 失败:{}->{}", param.getMediaServerId(), param);
|
| | | return HookResult.SUCCESS();
|
| | | }
|
| | |
|
| | |
| | | String mediaServerId = json.getString("mediaServerId");
|
| | | MediaServer mediaServer = mediaServerService.getOne(mediaServerId);
|
| | | if (mediaServer == null) {
|
| | | return new HookResultForOnPublish(200, "success");
|
| | | return new HookResultForOnPublish(0, "success");
|
| | | }
|
| | |
|
| | | taskExecutor.execute(() -> {
|
| | | ZlmHttpHookSubscribe.Event subscribe = this.subscribe.sendNotify(HookType.on_publish, json);
|
| | | if (subscribe != null) {
|
| | | subscribe.response(mediaServer, param);
|
| | | }
|
| | | });
|
| | |
|
| | | ResultForOnPublish resultForOnPublish = mediaService.authenticatePublish(mediaServer, param.getApp(), param.getStream(), param.getParams());
|
| | | if (resultForOnPublish != null) {
|
| | |
| | | public HookResult onStreamChanged(@RequestBody OnStreamChangedHookParam param) {
|
| | |
|
| | | MediaServer mediaServer = mediaServerService.getOne(param.getMediaServerId());
|
| | | if (mediaServer == null) {
|
| | | return HookResult.SUCCESS();
|
| | | }
|
| | |
|
| | | if (param.isRegist()) {
|
| | | logger.info("[ZLM HOOK] 流注册, {}->{}->{}/{}", param.getMediaServerId(), param.getSchema(), param.getApp(), param.getStream());
|
| | |
| | | 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();
|
| | | }
|
| | |
| | | if (!"rtp".equals(param.getApp())) {
|
| | | return HookResult.SUCCESS();
|
| | | }
|
| | | taskExecutor.execute(() -> {
|
| | | List<SendRtpItem> sendRtpItems = redisCatchStorage.querySendRTPServerByStream(param.getStream());
|
| | | if (sendRtpItems.size() > 0) {
|
| | | for (SendRtpItem sendRtpItem : sendRtpItems) {
|
| | | ParentPlatform parentPlatform = storager.queryParentPlatByServerGBId(sendRtpItem.getPlatformId());
|
| | | ssrcFactory.releaseSsrc(sendRtpItem.getMediaServerId(), sendRtpItem.getSsrc());
|
| | | try {
|
| | | commanderFroPlatform.streamByeCmd(parentPlatform, sendRtpItem.getCallId());
|
| | | } catch (SipException | InvalidArgumentException | ParseException e) {
|
| | | logger.error("[命令发送失败] 国标级联 发送BYE: {}", e.getMessage());
|
| | | }
|
| | | redisCatchStorage.deleteSendRTPServer(parentPlatform.getServerGBId(), sendRtpItem.getChannelId(),
|
| | | sendRtpItem.getCallId(), sendRtpItem.getStream());
|
| | | }
|
| | | try {
|
| | | MediaSendRtpStoppedEvent event = new MediaSendRtpStoppedEvent(this);
|
| | | MediaServer mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
| | | if (mediaServerItem != null) {
|
| | | event.setMediaServer(mediaServerItem);
|
| | | applicationEventPublisher.publishEvent(event);
|
| | | }
|
| | | });
|
| | | }catch (Exception e) {
|
| | | logger.info("[ZLM-HOOK-rtp发送关闭] 发送通知失败 ", e);
|
| | | }
|
| | |
|
| | | return HookResult.SUCCESS();
|
| | | }
|
| | |
| | | param) {
|
| | | logger.info("[ZLM HOOK] rtpServer收流超时:{}->{}({})", param.getMediaServerId(), param.getStream_id(), param.getSsrc());
|
| | |
|
| | | taskExecutor.execute(() -> {
|
| | | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout);
|
| | | if (subscribes != null && !subscribes.isEmpty()) {
|
| | | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) {
|
| | | subscribe.response(null, param);
|
| | | }
|
| | | try {
|
| | | MediaRtpServerTimeoutEvent event = new MediaRtpServerTimeoutEvent(this);
|
| | | MediaServer mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
| | | if (mediaServerItem != null) {
|
| | | event.setMediaServer(mediaServerItem);
|
| | | event.setApp("rtp");
|
| | | applicationEventPublisher.publishEvent(event);
|
| | | }
|
| | | });
|
| | | }catch (Exception e) {
|
| | | logger.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
| | | }
|
| | |
|
| | | return HookResult.SUCCESS();
|
| | | }
|
| | |
| | | public HookResult onRecordMp4(HttpServletRequest request, @RequestBody OnRecordMp4HookParam param) {
|
| | | logger.info("[ZLM HOOK] 录像完成事件:{}->{}", param.getMediaServerId(), param.getFile_path());
|
| | |
|
| | | taskExecutor.execute(() -> {
|
| | | List<ZlmHttpHookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_record_mp4);
|
| | | if (subscribes != null && !subscribes.isEmpty()) {
|
| | | for (ZlmHttpHookSubscribe.Event subscribe : subscribes) {
|
| | | subscribe.response(null, param);
|
| | | }
|
| | | try {
|
| | | MediaServer mediaServerItem = mediaServerService.getOne(param.getMediaServerId());
|
| | | if (mediaServerItem != null) {
|
| | | MediaRecordMp4Event event = MediaRecordMp4Event.getInstance(this, param, mediaServerItem);
|
| | | event.setMediaServer(mediaServerItem);
|
| | | applicationEventPublisher.publishEvent(event);
|
| | | }
|
| | | cloudRecordService.addRecord(param);
|
| | |
|
| | | });
|
| | | }catch (Exception e) {
|
| | | logger.info("[ZLM-HOOK-rtpServer收流超时] 发送通知失败 ", e);
|
| | | }
|
| | |
|
| | | return HookResult.SUCCESS();
|
| | | }
|