| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.genersoft.iot.vmp.conf.UserSetting; |
| | | import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaItem; |
| | | import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | result = rtpInfo.getInteger("local_port"); |
| | | if (result == 0) { |
| | | // 此时说明rtpServer已经创建但是流还没有推上来 |
| | | |
| | | // 此时重新打开rtpServer |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("stream_id", streamId); |
| | | JSONObject jsonObject = zlmresTfulUtils.closeRtpServer(mediaServerItem, param); |
| | | if (jsonObject != null ) { |
| | | if (jsonObject.getInteger("code") == 0) { |
| | | return createRTPServer(mediaServerItem, streamId, ssrc, port); |
| | | }else { |
| | | logger.warn("[开启rtpServer], 重启RtpServer错误"); |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | // private int getPortFromportRange(MediaServerItem mediaServerItem) { |
| | | // int currentPort = mediaServerItem.getCurrentPort(); |
| | | // if (currentPort == 0) { |
| | | // String[] portRangeStrArray = mediaServerItem.getSendRtpPortRange().split(","); |
| | | // if (portRangeStrArray.length != 2) { |
| | | // portRangeArray[0] = 30000; |
| | | // portRangeArray[1] = 30500; |
| | | // }else { |
| | | // portRangeArray[0] = Integer.parseInt(portRangeStrArray[0]); |
| | | // portRangeArray[1] = Integer.parseInt(portRangeStrArray[1]); |
| | | // } |
| | | // } |
| | | // |
| | | // if (currentPort == 0 || currentPort++ > portRangeArray[1]) { |
| | | // currentPort = portRangeArray[0]; |
| | | // mediaServerItem.setCurrentPort(currentPort); |
| | | // return portRangeArray[0]; |
| | | // } else { |
| | | // if (currentPort % 2 == 1) { |
| | | // currentPort++; |
| | | // } |
| | | // currentPort++; |
| | | // mediaServerItem.setCurrentPort(currentPort); |
| | | // return currentPort; |
| | | // } |
| | | // } |
| | | |
| | | /** |
| | | * 创建一个国标推流 |
| | |
| | | Boolean result = false; |
| | | JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(mediaServerItem, param); |
| | | if (jsonObject == null) { |
| | | logger.error("停止RTP推流失败: 请检查ZLM服务"); |
| | | logger.error("[停止RTP推流] 失败: 请检查ZLM服务"); |
| | | } else if (jsonObject.getInteger("code") == 0) { |
| | | result= true; |
| | | logger.info("停止RTP推流成功"); |
| | | logger.info("[停止RTP推流] 成功"); |
| | | } else { |
| | | logger.error("停止RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); |
| | | logger.error("[停止RTP推流] 失败: {}, 参数:{}->\r\n{}",jsonObject.getString("msg"),JSONObject.toJSON(param), jsonObject); |
| | | } |
| | | return result; |
| | | } |
| | |
| | | public void closeAllSendRtpStream() { |
| | | |
| | | } |
| | | |
| | | public MediaItem getMediaInfo(MediaServerItem mediaServerItem, String app, String stream) { |
| | | JSONObject json = zlmresTfulUtils.getMediaList(mediaServerItem, app, stream); |
| | | MediaItem mediaItem = null; |
| | | if (json == null || json.getInteger("code") != 0) { |
| | | return null; |
| | | } else { |
| | | JSONArray data = json.getJSONArray("data"); |
| | | if (data == null || data.size() == 0) { |
| | | return null; |
| | | }else { |
| | | mediaItem = JSONObject.toJavaObject(data.getJSONObject(0), MediaItem.class); |
| | | } |
| | | } |
| | | return mediaItem; |
| | | } |
| | | } |