| | |
| | | |
| | | private Map<String, ChannelOnlineEvent> channelOnlineEvents = new ConcurrentHashMap<>(); |
| | | |
| | | |
| | | public void updateMediaList(MediaServerItem mediaServerItem) { |
| | | storager.clearMediaList(); |
| | | |
| | | // 使用异步的当时更新媒体流列表 |
| | | zlmresTfulUtils.getMediaList(mediaServerItem, (mediaList ->{ |
| | | if (mediaList == null) { |
| | | return; |
| | | } |
| | | String dataStr = mediaList.getString("data"); |
| | | |
| | | Integer code = mediaList.getInteger("code"); |
| | | Map<String, StreamPushItem> result = new HashMap<>(); |
| | | List<StreamPushItem> streamPushItems = null; |
| | | // 获取所有的国标关联 |
| | | // List<GbStream> gbStreams = gbStreamMapper.selectAllByMediaServerId(mediaServerItem.getId()); |
| | | if (code == 0 ) { |
| | | if (dataStr != null) { |
| | | streamPushItems = streamPushService.handleJSON(dataStr, mediaServerItem); |
| | | } |
| | | }else { |
| | | logger.warn("更新视频流失败,错误code: " + code); |
| | | } |
| | | |
| | | if (streamPushItems != null) { |
| | | storager.updateMediaList(streamPushItems); |
| | | for (StreamPushItem streamPushItem : streamPushItems) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("app", streamPushItem.getApp()); |
| | | jsonObject.put("stream", streamPushItem.getStream()); |
| | | jsonObject.put("mediaServerId", mediaServerItem.getId()); |
| | | subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_play,jsonObject, |
| | | (MediaServerItem mediaServerItemInuse, JSONObject response)->{ |
| | | updateMedia(mediaServerItem, response.getString("app"), response.getString("stream")); |
| | | } |
| | | ); |
| | | } |
| | | } |
| | | })); |
| | | |
| | | } |
| | | |
| | | public void addMedia(MediaServerItem mediaServerItem, String app, String streamId) { |
| | | //使用异步更新推流 |
| | | updateMedia(mediaServerItem, app, streamId); |
| | | } |
| | | |
| | | public StreamPushItem addPush(MediaItem mediaItem) { |
| | | // 查找此直播流是否存在redis预设gbId |
| | | StreamPushItem transform = streamPushService.transform(mediaItem); |
| | | StreamPushItem pushInDb = streamPushService.getPush(mediaItem.getApp(), mediaItem.getStream()); |
| | | transform.setPushIng(mediaItem.isRegist()); |
| | | transform.setUpdateTime(DateUtil.getNow()); |
| | | transform.setPushTime(DateUtil.getNow()); |
| | | transform.setSelf(userSetting.getServerId().equals(mediaItem.getSeverId())); |
| | | if (pushInDb == null) { |
| | | transform.setCreateTime(DateUtil.getNow()); |
| | | streamPushMapper.add(transform); |
| | | }else { |
| | | streamPushMapper.update(transform); |
| | | |
| | | |
| | | // if (!StringUtils.isEmpty(pushInDb.getGbId())) { |
| | | // List<GbStream> gbStreamList = gbStreamMapper.selectByGBId(transform.getGbId()); |
| | | // if (gbStreamList != null && gbStreamList.size() == 1) { |
| | | // transform.setGbStreamId(gbStreamList.get(0).getGbStreamId()); |
| | | // transform.setPlatformId(gbStreamList.get(0).getPlatformId()); |
| | | // transform.setCatalogId(gbStreamList.get(0).getCatalogId()); |
| | | // transform.setGbId(gbStreamList.get(0).getGbId()); |
| | | // gbStreamMapper.update(transform); |
| | | // streamPushMapper.del(gbStreamList.get(0).getApp(), gbStreamList.get(0).getStream()); |
| | | // }else { |
| | | // transform.setCreateTime(DateUtil.getNow()); |
| | | // transform.setUpdateTime(DateUtil.getNow()); |
| | | // gbStreamMapper.add(transform); |
| | | // } |
| | | // 通知通道上线 |
| | | // if (transform != null) { |
| | | // if (channelOnlineEvents.get(transform.getGbId()) != null) { |
| | | // channelOnlineEvents.get(transform.getGbId()).run(transform.getApp(), transform.getStream(), transform.getServerId()); |
| | | // channelOnlineEvents.remove(transform.getGbId()); |
| | | // } |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | |
| | | |
| | | return transform; |
| | | } |
| | | |
| | | |
| | | public void updateMedia(MediaServerItem mediaServerItem, String app, String streamId) { |
| | | //使用异步更新推流 |
| | | zlmresTfulUtils.getMediaList(mediaServerItem, app, streamId, "rtmp", json->{ |
| | | |
| | | if (json == null) { |
| | | return; |
| | | } |
| | | String dataStr = json.getString("data"); |
| | | |
| | | Integer code = json.getInteger("code"); |
| | | Map<String, StreamPushItem> result = new HashMap<>(); |
| | | List<StreamPushItem> streamPushItems = null; |
| | | if (code == 0 ) { |
| | | if (dataStr != null) { |
| | | streamPushItems = streamPushService.handleJSON(dataStr, mediaServerItem); |
| | | } |
| | | }else { |
| | | logger.warn("更新视频流失败,错误code: " + code); |
| | | } |
| | | |
| | | if (streamPushItems != null && streamPushItems.size() == 1) { |
| | | storager.updateMedia(streamPushItems.get(0)); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | public int removeMedia(String app, String streamId) { |
| | | // 查找是否关联了国标, 关联了不删除, 置为离线 |