Commit f840c85666369d407ff08ceb6ba30b17aa9d0d4e
1 parent
cbd2bc8e
修正一处可能导致死循环的代码
Showing
2 changed files
with
14 additions
and
27 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/request/impl/AckRequestProcessor.java
| @@ -68,11 +68,16 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { | @@ -68,11 +68,16 @@ public class AckRequestProcessor extends SIPRequestAbstractProcessor { | ||
| 68 | if (System.currentTimeMillis() - startTime < 30 * 1000) { | 68 | if (System.currentTimeMillis() - startTime < 30 * 1000) { |
| 69 | if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) { | 69 | if (zlmrtpServerFactory.isRtpReady(streamInfo.getStreamId())) { |
| 70 | rtpPushed = true; | 70 | rtpPushed = true; |
| 71 | + System.out.println("已获取设备推流,开始向上级推流"); | ||
| 71 | zlmrtpServerFactory.startSendRtpStream(param); | 72 | zlmrtpServerFactory.startSendRtpStream(param); |
| 72 | } else { | 73 | } else { |
| 74 | + System.out.println("等待设备推流......."); | ||
| 73 | Thread.sleep(2000); | 75 | Thread.sleep(2000); |
| 74 | continue; | 76 | continue; |
| 75 | } | 77 | } |
| 78 | + } else { | ||
| 79 | + rtpPushed = true; | ||
| 80 | + System.out.println("设备推流超时,终止向上级推流"); | ||
| 76 | } | 81 | } |
| 77 | } catch (InterruptedException e) { | 82 | } catch (InterruptedException e) { |
| 78 | e.printStackTrace(); | 83 | e.printStackTrace(); |
src/main/java/com/genersoft/iot/vmp/media/zlm/ZLMRTPServerFactory.java
| @@ -127,46 +127,28 @@ public class ZLMRTPServerFactory { | @@ -127,46 +127,28 @@ public class ZLMRTPServerFactory { | ||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | /** | 129 | /** |
| 130 | - * | 130 | + * 调用zlm RESTful API —— startSendRtp |
| 131 | */ | 131 | */ |
| 132 | public Boolean startSendRtpStream(Map<String, Object>param) { | 132 | public Boolean startSendRtpStream(Map<String, Object>param) { |
| 133 | Boolean result = false; | 133 | Boolean result = false; |
| 134 | JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param); | 134 | JSONObject jsonObject = zlmresTfulUtils.startSendRtp(param); |
| 135 | System.out.println(jsonObject); | 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 | logger.error("RTP推流失败: 请检查ZLM服务"); | 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 | return result; | 144 | return result; |
| 157 | } | 145 | } |
| 158 | 146 | ||
| 159 | /** | 147 | /** |
| 160 | - * | 148 | + * 查询待转推的流是否就绪 |
| 161 | */ | 149 | */ |
| 162 | public Boolean isRtpReady(String streamId) { | 150 | public Boolean isRtpReady(String streamId) { |
| 163 | JSONObject mediaInfo = zlmresTfulUtils.getMediaInfo("rtp", "rtmp", streamId); | 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 | } |