| | |
| | | import com.genersoft.iot.vmp.conf.exception.ControllerException; |
| | | import com.genersoft.iot.vmp.gb28181.event.subscribe.catalog.CatalogEvent; |
| | | import com.genersoft.iot.vmp.media.bean.MediaInfo; |
| | | import com.genersoft.iot.vmp.media.event.MediaArrivalEvent; |
| | | import com.genersoft.iot.vmp.media.event.MediaDepartureEvent; |
| | | import com.genersoft.iot.vmp.media.bean.MediaServer; |
| | | 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.media.MediaArrivalEvent; |
| | | import com.genersoft.iot.vmp.media.event.media.MediaDepartureEvent; |
| | | import com.genersoft.iot.vmp.media.event.media.MediaNotFoundEvent; |
| | | import com.genersoft.iot.vmp.media.service.IMediaServerService; |
| | | import com.genersoft.iot.vmp.media.zlm.ZLMServerFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.ZlmHttpHookSubscribe; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeFactory; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.HookSubscribeForStreamChange; |
| | | 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.hook.OnStreamChangedHookParam; |
| | | import com.genersoft.iot.vmp.service.IGbStreamService; |
| | | import com.genersoft.iot.vmp.service.IMediaService; |
| | | import com.genersoft.iot.vmp.service.IStreamProxyService; |
| | | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| | | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| | |
| | | private IVideoManagerStorage videoManagerStorager; |
| | | |
| | | @Autowired |
| | | private IMediaService mediaService; |
| | | |
| | | @Autowired |
| | | private ZLMServerFactory zlmServerFactory; |
| | | |
| | | @Autowired |
| | | private StreamProxyMapper streamProxyMapper; |
| | | |
| | | @Autowired |
| | |
| | | private IMediaServerService mediaServerService; |
| | | |
| | | @Autowired |
| | | private ZlmHttpHookSubscribe hookSubscribe; |
| | | private HookSubscribe hookSubscribe; |
| | | |
| | | @Autowired |
| | | private DynamicTask dynamicTask; |
| | |
| | | public void onApplicationEvent(MediaDepartureEvent event) { |
| | | if ("rtsp".equals(event.getSchema())) { |
| | | updateStatus(false, event.getApp(), event.getStream()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 流离开的处理 |
| | | */ |
| | | @Async("taskExecutor") |
| | | @EventListener |
| | | public void onApplicationEvent(MediaNotFoundEvent event) { |
| | | if ("rtp".equals(event.getApp())) { |
| | | return; |
| | | } |
| | | // 拉流代理 |
| | | StreamProxyItem streamProxyByAppAndStream = getStreamProxyByAppAndStream(event.getApp(), event.getStream()); |
| | | if (streamProxyByAppAndStream != null && streamProxyByAppAndStream.isEnableDisableNoneReader()) { |
| | | start(event.getApp(), event.getStream()); |
| | | } |
| | | } |
| | | |
| | |
| | | callback.run(ErrorCode.ERROR100.getCode(), "保存失败", null); |
| | | return; |
| | | } |
| | | HookSubscribeForStreamChange hookSubscribeForStreamChange = HookSubscribeFactory.on_stream_changed(param.getApp(), param.getStream(), true, "rtsp", mediaServer.getId()); |
| | | hookSubscribe.addSubscribe(hookSubscribeForStreamChange, (mediaServerItem, response) -> { |
| | | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( |
| | | Hook hook = Hook.getInstance(HookType.on_media_arrival, param.getApp(), param.getStream(), mediaServer.getId()); |
| | | hookSubscribe.addSubscribe(hook, (hookData) -> { |
| | | StreamInfo streamInfo = mediaServerService.getStreamInfoByAppAndStream( |
| | | mediaServer, param.getApp(), param.getStream(), null, null); |
| | | callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | }); |
| | |
| | | String talkKey = UUID.randomUUID().toString(); |
| | | String delayTalkKey = UUID.randomUUID().toString(); |
| | | dynamicTask.startDelay(delayTalkKey, ()->{ |
| | | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaServer.getId(), false); |
| | | StreamInfo streamInfo = mediaServerService.getStreamInfoByAppAndStreamWithCheck(param.getApp(), param.getStream(), mediaServer.getId(), false); |
| | | if (streamInfo != null) { |
| | | callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | }else { |
| | |
| | | }, 7000); |
| | | WVPResult<String> result = addStreamProxyToZlm(param); |
| | | if (result != null && result.getCode() == 0) { |
| | | hookSubscribe.removeSubscribe(hookSubscribeForStreamChange); |
| | | hookSubscribe.removeSubscribe(hook); |
| | | dynamicTask.stop(talkKey); |
| | | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( |
| | | StreamInfo streamInfo = mediaServerService.getStreamInfoByAppAndStream( |
| | | mediaServer, param.getApp(), param.getStream(), null, null); |
| | | callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | }else { |
| | |
| | | } |
| | | } |
| | | else{ |
| | | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( |
| | | StreamInfo streamInfo = mediaServerService.getStreamInfoByAppAndStream( |
| | | mediaServer, param.getApp(), param.getStream(), null, null); |
| | | callback.run(ErrorCode.SUCCESS.getCode(), ErrorCode.SUCCESS.getMsg(), streamInfo); |
| | | } |
| | |
| | | if (mediaServer == null) { |
| | | return null; |
| | | } |
| | | if (zlmServerFactory.isStreamReady(mediaServer, param.getApp(), param.getStream())) { |
| | | if (mediaServerService.isStreamReady(mediaServer, param.getApp(), param.getStream())) { |
| | | mediaServerService.closeStreams(mediaServer, param.getApp(), param.getStream()); |
| | | } |
| | | String msgResult; |
| | | if ("ffmpeg".equalsIgnoreCase(param.getType())){ |
| | | if (param.getTimeoutMs() == 0) { |
| | | param.setTimeoutMs(15); |
| | | } |
| | | result = mediaServerService.addFFmpegSource(mediaServer, param.getSrcUrl().trim(), param.getDstUrl(), |
| | | param.getTimeoutMs(), param.isEnableAudio(), param.isEnableMp4(), |
| | | param.getFfmpegCmdKey()); |
| | |
| | | result = mediaServerService.addStreamProxy(mediaServer, param.getApp(), param.getStream(), param.getUrl().trim(), |
| | | param.isEnableAudio(), param.isEnableMp4(), param.getRtpType()); |
| | | } |
| | | System.out.println("addStreamProxyToZlm===="); |
| | | System.out.println(result); |
| | | if (result != null && result.getCode() == 0) { |
| | | String key = result.getData(); |
| | | if (key == null) { |
| | |
| | | return null; |
| | | } |
| | | MediaServer mediaServer = mediaServerService.getOne(param.getMediaServerId()); |
| | | if (mediaServer == null) { |
| | | return null; |
| | | } |
| | | List<StreamInfo> mediaList = mediaServerService.getMediaList(mediaServer, param.getApp(), param.getStream(), null); |
| | | if (mediaList == null || mediaList.isEmpty()) { |
| | | return true; |
| | | } |
| | | Boolean result = false; |
| | | if ("ffmpeg".equalsIgnoreCase(param.getType())){ |
| | | result = mediaServerService.delFFmpegSource(mediaServer, param.getStreamKey()); |
| | |
| | | gbStreamMapper.del(app, stream); |
| | | videoManagerStorager.deleteStreamProxy(app, stream); |
| | | redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PULL", app, stream); |
| | | redisCatchStorage.removeStream(streamProxyItem.getMediaServerId(), "PUSH", app, stream); |
| | | Boolean result = removeStreamProxyFromZlm(streamProxyItem); |
| | | if (result != null && result) { |
| | | logger.info("[移除代理]: 代理: {}/{}, 从zlm移除成功", app, stream); |
| | |
| | | String type = "PULL"; |
| | | |
| | | // 发送redis消息 |
| | | List<OnStreamChangedHookParam> onStreamChangedHookParams = redisCatchStorage.getStreams(mediaServerId, type); |
| | | if (onStreamChangedHookParams.size() > 0) { |
| | | for (OnStreamChangedHookParam onStreamChangedHookParam : onStreamChangedHookParams) { |
| | | List<MediaInfo> mediaInfoList = redisCatchStorage.getStreams(mediaServerId, type); |
| | | if (mediaInfoList.size() > 0) { |
| | | for (MediaInfo mediaInfo : mediaInfoList) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("serverId", userSetting.getServerId()); |
| | | jsonObject.put("app", onStreamChangedHookParam.getApp()); |
| | | jsonObject.put("stream", onStreamChangedHookParam.getStream()); |
| | | jsonObject.put("app", mediaInfo.getApp()); |
| | | jsonObject.put("stream", mediaInfo.getStream()); |
| | | jsonObject.put("register", false); |
| | | jsonObject.put("mediaServerId", mediaServerId); |
| | | redisCatchStorage.sendStreamChangeMsg(type, jsonObject); |
| | | // 移除redis内流的信息 |
| | | redisCatchStorage.removeStream(mediaServerId, type, onStreamChangedHookParam.getApp(), onStreamChangedHookParam.getStream()); |
| | | redisCatchStorage.removeStream(mediaServerId, type, mediaInfo.getApp(), mediaInfo.getStream()); |
| | | } |
| | | } |
| | | } |
| | |
| | | private void syncPullStream(String mediaServerId){ |
| | | MediaServer mediaServer = mediaServerService.getOne(mediaServerId); |
| | | if (mediaServer != null) { |
| | | List<OnStreamChangedHookParam> allPullStream = redisCatchStorage.getStreams(mediaServerId, "PULL"); |
| | | if (!allPullStream.isEmpty()) { |
| | | List<MediaInfo> mediaInfoList = redisCatchStorage.getStreams(mediaServerId, "PULL"); |
| | | if (!mediaInfoList.isEmpty()) { |
| | | List<StreamInfo> mediaList = mediaServerService.getMediaList(mediaServer, null, null, null); |
| | | Map<String, StreamInfo> stringStreamInfoMap = new HashMap<>(); |
| | | if (mediaList != null && !mediaList.isEmpty()) { |