|  |  |  | 
|---|
|  |  |  | package com.genersoft.iot.vmp.service.impl; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | import com.alibaba.fastjson.JSONObject; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.common.StreamInfo; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.gb28181.bean.GbStream; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.media.zlm.dto.StreamProxyItem; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IGbStreamService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IMediaServerService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IMediaService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.IVideoManagerStorager; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.GbStreamMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.PlatformGbStreamMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.storager.dao.StreamProxyMapper; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.service.IStreamProxyService; | 
|---|
|  |  |  | import com.genersoft.iot.vmp.vmanager.bean.WVPResult; | 
|---|
|  |  |  | import com.github.pagehelper.PageInfo; | 
|---|
|  |  |  | import org.slf4j.Logger; | 
|---|
|  |  |  | import org.slf4j.LoggerFactory; | 
|---|
|  |  |  | 
|---|
|  |  |  | private IVideoManagerStorager videoManagerStorager; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private IRedisCatchStorage redisCatchStorage; | 
|---|
|  |  |  | private IMediaService mediaService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Autowired | 
|---|
|  |  |  | private ZLMRESTfulUtils zlmresTfulUtils;; | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public String save(StreamProxyItem param) { | 
|---|
|  |  |  | public WVPResult<StreamInfo> save(StreamProxyItem param) { | 
|---|
|  |  |  | MediaServerItem mediaInfo; | 
|---|
|  |  |  | WVPResult<StreamInfo> wvpResult = new WVPResult<>(); | 
|---|
|  |  |  | wvpResult.setCode(0); | 
|---|
|  |  |  | if ("auto".equals(param.getMediaServerId())){ | 
|---|
|  |  |  | mediaInfo = mediaServerService.getMediaServerForMinimumLoad(); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | 
|---|
|  |  |  | } | 
|---|
|  |  |  | if (mediaInfo == null) { | 
|---|
|  |  |  | logger.warn("保存代理未找到在线的ZLM..."); | 
|---|
|  |  |  | return "保存失败"; | 
|---|
|  |  |  | wvpResult.setMsg("保存失败"); | 
|---|
|  |  |  | return wvpResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | String dstUrl = String.format("rtmp://%s:%s/%s/%s", "127.0.0.1", mediaInfo.getRtmpPort(), param.getApp(), | 
|---|
|  |  |  | param.getStream() ); | 
|---|
|  |  |  | 
|---|
|  |  |  | result.append(", 但是启用失败,请检查流地址是否可用"); | 
|---|
|  |  |  | param.setEnable(false); | 
|---|
|  |  |  | videoManagerStorager.updateStreamProxy(param); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( | 
|---|
|  |  |  | mediaInfo, param.getApp(), param.getStream(), null); | 
|---|
|  |  |  | wvpResult.setData(streamInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | 
|---|
|  |  |  | result.append(", 但是启用失败,请检查流地址是否可用"); | 
|---|
|  |  |  | param.setEnable(false); | 
|---|
|  |  |  | videoManagerStorager.updateStreamProxy(param); | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | StreamInfo streamInfo = mediaService.getStreamInfoByAppAndStream( | 
|---|
|  |  |  | mediaInfo, param.getApp(), param.getStream(), null); | 
|---|
|  |  |  | wvpResult.setData(streamInfo); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | }else { | 
|---|
|  |  |  | 
|---|
|  |  |  | result.append(",  关联国标平台[ " + param.getPlatformGbId() + " ]失败"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return result.toString(); | 
|---|
|  |  |  | wvpResult.setMsg(result.toString()); | 
|---|
|  |  |  | return wvpResult; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  |  | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public StreamProxyItem getStreamProxyByAppAndStream(String app, String streamId) { | 
|---|
|  |  |  | return videoManagerStorager.getStreamProxyByAppAndStream(app, streamId); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|