Commit f840c85666369d407ff08ceb6ba30b17aa9d0d4e

Authored by lawrencehj
1 parent cbd2bc8e

修正一处可能导致死循环的代码

src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
... ... @@ -68,11 +68,16 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor {
68 68 if (System.currentTimeMillis() - startTime < 30 * 1000) {
69 69 if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) {
70 70 rtpPushed = true;
  71 + System.out.println("已获取设备推流,开始向上级推流");
71 72 zlmrtpServerFactory.startSendRtpStream(param);
72 73 } else {
  74 + System.out.println("等待设备推流.......");
73 75 Thread.sleep(2000);
74 76 continue;
75 77 }
  78 + } else {
  79 + rtpPushed = true;
  80 + System.out.println("设备推流超时,终止向上级推流");
76 81 }
77 82 } catch (InterruptedException e) {
78 83 e.printStackTrace();
... ...
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
... ... @@ -127,46 +127,28 @@ public class ZLMRTPServerFactory {
127 127 }
128 128  
129 129 /**
130   - *
  130 + * 调用zlm RESTful API —— startSendRtp
131 131 */
132 132 public Boolean startSendRtpStream(Map<String, Object>param) {
133 133 Boolean result = false;
134 134 JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param);
135 135 System.out.println(jsonObject);
136   - if (jsonObject != null) {
137   - switch (jsonObject.getInteger("code")){
138   - case 0:
139   - result= true;
140   - logger.error("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port"));
141   - break;
142   - // case -300: // id已经存在
143   - // result = false;
144   - // break;
145   - // case -400: // 端口占用
146   - // result= false;
147   - // break;
148   - default:
149   - logger.error("RTP推流失败: " + jsonObject.getString("msg"));
150   - break;
151   - }
152   - }else {
153   - // 检查ZLM状态
  136 + if (jsonObject == null) {
154 137 logger.error("RTP推流失败: 请检查ZLM服务");
  138 + } else if (jsonObject.getInteger("code") == 0) {
  139 + result= true;
  140 + logger.error("RTP推流请求成功,本地推流端口:" + jsonObject.getString("local_port"));
  141 + } else {
  142 + logger.error("RTP推流失败: " + jsonObject.getString("msg"));
155 143 }
156 144 return result;
157 145 }
158 146  
159 147 /**
160   - *
  148 + * 查询待转推的流是否就绪
161 149 */
162 150 public Boolean isRtpReady(String streamId) {
163 151 JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId);
164   - if (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online")) {
165   - logger.info("设备RTP推流成功");
166   - return true;
167   - } else {
168   - logger.info("设备RTP推流未完成");
169   - return false;
170   - }
  152 + return (mediaInfo.getInteger("code") == 0 && mediaInfo.getBoolean("online"));
171 153 }
172 154 }
... ...