From 937e59143004b11a808eb93eb894ffe53871a19a Mon Sep 17 00:00:00 2001 From: panlinlin <648540858@qq.com> Date: 星期四, 15 四月 2021 17:48:52 +0800 Subject: [PATCH] 解决串流,解决编辑上级平台却新建了的问题 --- src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java | 28 ++++++++++++++++++++++++++-- 1 files changed, 26 insertions(+), 2 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..e76a2d8 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: // 绔彛鍗犵敤 -- Gitblit v1.8.0