Commit d202291aa80273cf30e63388606fa1e7f8098c4d
1 parent
973e75f8
优化单端口下的ssrc修复
Showing
1 changed file
with
27 additions
and
0 deletions
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -90,6 +90,9 @@ public class PlayServiceImpl implements IPlayService { |
| 90 | 90 | @Autowired |
| 91 | 91 | private DynamicTask dynamicTask; |
| 92 | 92 | |
| 93 | + @Autowired | |
| 94 | + private ZLMHttpHookSubscribe subscribe; | |
| 95 | + | |
| 93 | 96 | |
| 94 | 97 | |
| 95 | 98 | |
| ... | ... | @@ -259,6 +262,7 @@ public class PlayServiceImpl implements IPlayService { |
| 259 | 262 | } |
| 260 | 263 | }, userSetting.getPlayTimeout()*1000); |
| 261 | 264 | final String ssrc = ssrcInfo.getSsrc(); |
| 265 | + final String stream = ssrcInfo.getStream(); | |
| 262 | 266 | cmder.playStreamCmd(mediaServerItem, ssrcInfo, device, channelId, (MediaServerItem mediaServerItemInuse, JSONObject response) -> { |
| 263 | 267 | logger.info("收到订阅消息: " + response.toJSONString()); |
| 264 | 268 | dynamicTask.stop(timeOutTaskKey); |
| ... | ... | @@ -278,6 +282,7 @@ public class PlayServiceImpl implements IPlayService { |
| 278 | 282 | if (ssrc.equals(ssrcInResponse)) { |
| 279 | 283 | return; |
| 280 | 284 | } |
| 285 | + logger.info("[SIP 消息] 收到invite 200, 发现下级自定义了ssrc 开启修正"); | |
| 281 | 286 | if (!mediaServerItem.isRtpEnable() || device.isSsrcCheck()) { |
| 282 | 287 | if (!mediaServerItem.getSsrcConfig().checkSsrc(ssrcInResponse)) { |
| 283 | 288 | // ssrc 不可用 |
| ... | ... | @@ -289,10 +294,32 @@ public class PlayServiceImpl implements IPlayService { |
| 289 | 294 | errorEvent.response(event); |
| 290 | 295 | return; |
| 291 | 296 | } |
| 297 | + | |
| 298 | + // 单端口模式streamId也有变化,需要重新设置监听 | |
| 299 | + if (!mediaServerItem.isRtpEnable()) { | |
| 300 | + // 添加订阅 | |
| 301 | + JSONObject subscribeKey = new JSONObject(); | |
| 302 | + subscribeKey.put("app", "rtp"); | |
| 303 | + subscribeKey.put("stream", stream); | |
| 304 | + subscribeKey.put("regist", true); | |
| 305 | + subscribeKey.put("schema", "rtmp"); | |
| 306 | + subscribeKey.put("mediaServerId", mediaServerItem.getId()); | |
| 307 | + subscribe.removeSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed,subscribeKey); | |
| 308 | + subscribeKey.put("stream", String.format("%08x", Integer.parseInt(ssrcInResponse)).toUpperCase()); | |
| 309 | + subscribe.addSubscribe(ZLMHttpHookSubscribe.HookType.on_stream_changed, subscribeKey, | |
| 310 | + (MediaServerItem mediaServerItemInUse, JSONObject response)->{ | |
| 311 | + logger.info("[ZLM HOOK] ssrc修正后收到订阅消息: " + response.toJSONString()); | |
| 312 | + dynamicTask.stop(timeOutTaskKey); | |
| 313 | + // hook响应 | |
| 314 | + onPublishHandlerForPlay(mediaServerItemInUse, response, device.getDeviceId(), channelId, uuid); | |
| 315 | + hookEvent.response(mediaServerItemInUse, response); | |
| 316 | + }); | |
| 317 | + } | |
| 292 | 318 | // 关闭rtp server |
| 293 | 319 | mediaServerService.closeRTPServer(device.getDeviceId(), channelId, finalSsrcInfo.getStream()); |
| 294 | 320 | // 重新开启ssrc server |
| 295 | 321 | mediaServerService.openRTPServer(mediaServerItem, finalSsrcInfo.getStream(), ssrcInResponse, device.isSsrcCheck(), false); |
| 322 | + | |
| 296 | 323 | } |
| 297 | 324 | } |
| 298 | 325 | }, (event) -> { | ... | ... |