From bc2b288547d91569a6178e000694793ba6a4eb91 Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期一, 26 四月 2021 13:11:09 +0800 Subject: [PATCH] 打包加入依赖的onvif包 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 36 ++++++++++++++++++++++++++++++------ 1 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java index 02fb742..ffe91d2 100644 --- a/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java +++ b/src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java @@ -1,5 +1,6 @@ package com.genersoft.iot.vmp.media.zlm; +import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.genersoft.iot.vmp.gb28181.bean.SendRtpItem; import com.genersoft.iot.vmp.gb28181.session.SsrcUtil; @@ -27,7 +28,28 @@ private int currentPort = 0; + private Map<String, Integer> currentStreams = null; + public int createRTPServer(String streamId) { + if (currentStreams == null) { + currentStreams = new HashMap<>(); + JSONObject jsonObject = zlmresTfulUtils.listRtpServer(); + JSONArray data = jsonObject.getJSONArray("data"); + if (data != null) { + for (int i = 0; i < data.size(); i++) { + JSONObject dataItem = data.getJSONObject(i); + currentStreams.put(dataItem.getString("stream_id"), dataItem.getInteger("port")); + } + } + } + // 宸茬粡鍦ㄦ帹娴� + if (currentStreams.get(streamId) != null) { + Map<String, Object> closeRtpServerParam = new HashMap<>(); + closeRtpServerParam.put("stream_id", streamId); + zlmresTfulUtils.closeRtpServer(closeRtpServerParam); + currentStreams.remove(streamId); + } + Map<String, Object> param = new HashMap<>(); int result = -1; int newPort = getPortFromUdpPortRange(); @@ -35,14 +57,16 @@ param.put("enable_tcp", 1); param.put("stream_id", streamId); JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param); - System.out.println(jsonObject); if (jsonObject != null) { switch (jsonObject.getInteger("code")){ case 0: result= newPort; break; - case -300: // id宸茬粡瀛樺湪 + case -300: // id宸茬粡瀛樺湪, 鍙兘宸茬粡鍦ㄥ叾浠栫鍙f帹娴� + Map<String, Object> closeRtpServerParam = new HashMap<>(); + closeRtpServerParam.put("stream_id", streamId); + zlmresTfulUtils.closeRtpServer(closeRtpServerParam); result = newPort; break; case -400: // 绔彛鍗犵敤 @@ -165,12 +189,12 @@ public Boolean startSendRtpStream(Map<String, Object>param) { Boolean result = false; JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param); - System.out.println(jsonObject); + logger.info(jsonObject.toJSONString()); if (jsonObject == null) { logger.error("RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟"); } else if (jsonObject.getInteger("code") == 0) { result= true; - logger.error("RTP鎺ㄦ祦璇锋眰鎴愬姛锛屾湰鍦版帹娴佺鍙o細" + jsonObject.getString("local_port")); + logger.info("RTP鎺ㄦ祦璇锋眰鎴愬姛锛屾湰鍦版帹娴佺鍙o細" + jsonObject.getString("local_port")); } else { logger.error("RTP鎺ㄦ祦澶辫触: " + jsonObject.getString("msg")); } @@ -209,12 +233,12 @@ public Boolean stopSendRtpStream(Map<String, Object>param) { Boolean result = false; JSONObject jsonObject = zlmresTfulUtils.stopSendRtp(param); - System.out.println(jsonObject); + logger.info(jsonObject.toJSONString()); if (jsonObject == null) { logger.error("鍋滄RTP鎺ㄦ祦澶辫触: 璇锋鏌LM鏈嶅姟"); } else if (jsonObject.getInteger("code") == 0) { result= true; - logger.error("鍋滄RTP鎺ㄦ祦鎴愬姛"); + logger.info("鍋滄RTP鎺ㄦ祦鎴愬姛"); } else { logger.error("鍋滄RTP鎺ㄦ祦澶辫触: " + jsonObject.getString("msg")); } -- Gitblit v1.8.0