| | |
| | | import com.alibaba.fastjson2.JSON;
|
| | | import com.alibaba.fastjson2.JSONObject;
|
| | | import com.genersoft.iot.vmp.conf.UserSetting;
|
| | | 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.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.HookSubscribe;
|
| | | 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.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;
|
| | | 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.ZLMServerConfig;
|
| | | import com.genersoft.iot.vmp.media.zlm.dto.hook.*;
|
| | |
| | | import org.springframework.web.bind.annotation.*;
|
| | |
|
| | | 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;
|
| | |
| | | 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(() -> {
|
| | | HookSubscribe.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());
|
| | |
| | | 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<HookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_rtp_server_timeout);
|
| | | if (subscribes != null && !subscribes.isEmpty()) {
|
| | | for (HookSubscribe.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<HookSubscribe.Event> subscribes = this.subscribe.getSubscribes(HookType.on_record_mp4);
|
| | | if (subscribes != null && !subscribes.isEmpty()) {
|
| | | for (HookSubscribe.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();
|
| | | }
|