Commit 6a2ff9951584cb014a8e07703678e0f4d748746d
1 parent
6bfd4877
合并主线
Showing
2 changed files
with
47 additions
and
28 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -159,12 +159,33 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 159 | 159 | String requesterId = SipUtils.getUserIdFromFromHeader(request); |
| 160 | 160 | CallIdHeader callIdHeader = (CallIdHeader) request.getHeader(CallIdHeader.NAME); |
| 161 | 161 | ServerTransaction serverTransaction = getServerTransaction(evt); |
| 162 | - if (requesterId == null || channelId == null) { | |
| 163 | - logger.info("无法从FromHeader的Address中获取到平台id,返回400"); | |
| 162 | + if (requesterId == null) { | |
| 163 | + logger.info("无法从FromHeader的Address中获取到平台/设备id,返回400"); | |
| 164 | 164 | // 参数不全, 发400,请求错误 |
| 165 | 165 | responseAck(serverTransaction, Response.BAD_REQUEST); |
| 166 | 166 | return; |
| 167 | 167 | } |
| 168 | + String ssrc = null; | |
| 169 | + SessionDescription sdp = null; | |
| 170 | + String ssrcDefault = "0000000000"; | |
| 171 | + if (channelId == null) { | |
| 172 | + // 解析sdp消息, 使用jainsip 自带的sdp解析方式 | |
| 173 | + String contentString = new String(request.getRawContent()); | |
| 174 | + | |
| 175 | + // jainSip不支持y=字段, 移除以解析。 | |
| 176 | + int ssrcIndex = contentString.indexOf("y="); | |
| 177 | + | |
| 178 | + if (ssrcIndex >= 0) { | |
| 179 | + //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段 | |
| 180 | + ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); | |
| 181 | + String substring = contentString.substring(0, contentString.indexOf("y=")); | |
| 182 | + sdp = SdpFactory.getInstance().createSessionDescription(substring); | |
| 183 | + } else { | |
| 184 | + ssrc = ssrcDefault; | |
| 185 | + sdp = SdpFactory.getInstance().createSessionDescription(contentString); | |
| 186 | + } | |
| 187 | + channelId = sdp.getOrigin().getUsername(); | |
| 188 | + } | |
| 168 | 189 | |
| 169 | 190 | |
| 170 | 191 | // 查询请求是否来自上级平台\设备 |
| ... | ... | @@ -232,24 +253,23 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 232 | 253 | responseAck(serverTransaction, Response.NOT_FOUND); // 通道不存在,发404,资源不存在 |
| 233 | 254 | return; |
| 234 | 255 | } |
| 235 | - // 解析sdp消息, 使用jainsip 自带的sdp解析方式 | |
| 236 | - String contentString = new String(request.getRawContent()); | |
| 237 | - | |
| 238 | - // jainSip不支持y=字段, 移除以解析。 | |
| 239 | - int ssrcIndex = contentString.indexOf("y="); | |
| 240 | - // 检查是否有y字段 | |
| 241 | - String ssrcDefault = "0000000000"; | |
| 242 | - String ssrc; | |
| 243 | - SessionDescription sdp; | |
| 244 | - if (ssrcIndex >= 0) { | |
| 245 | - //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段 | |
| 246 | - ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); | |
| 247 | - String substring = contentString.substring(0, contentString.indexOf("y=")); | |
| 248 | - sdp = SdpFactory.getInstance().createSessionDescription(substring); | |
| 249 | - } else { | |
| 250 | - ssrc = ssrcDefault; | |
| 251 | - sdp = SdpFactory.getInstance().createSessionDescription(contentString); | |
| 256 | + if (sdp == null || ssrc == null) { | |
| 257 | + // 解析sdp消息, 使用jainsip 自带的sdp解析方式 | |
| 258 | + String contentString = new String(request.getRawContent()); | |
| 259 | + | |
| 260 | + // jainSip不支持y=字段, 移除以解析。 | |
| 261 | + int ssrcIndex = contentString.indexOf("y="); | |
| 262 | + if (ssrcIndex >= 0) { | |
| 263 | + //ssrc规定长度为10个字节,不取余下长度以避免后续还有“f=”字段 | |
| 264 | + ssrc = contentString.substring(ssrcIndex + 2, ssrcIndex + 12); | |
| 265 | + String substring = contentString.substring(0, contentString.indexOf("y=")); | |
| 266 | + sdp = SdpFactory.getInstance().createSessionDescription(substring); | |
| 267 | + } else { | |
| 268 | + ssrc = ssrcDefault; | |
| 269 | + sdp = SdpFactory.getInstance().createSessionDescription(contentString); | |
| 270 | + } | |
| 252 | 271 | } |
| 272 | + | |
| 253 | 273 | String sessionName = sdp.getSessionName().getValue(); |
| 254 | 274 | |
| 255 | 275 | Long startTime = null; |
| ... | ... | @@ -339,6 +359,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 339 | 359 | |
| 340 | 360 | Long finalStartTime = startTime; |
| 341 | 361 | Long finalStopTime = stopTime; |
| 362 | + String finalChannelId = channelId; | |
| 342 | 363 | ZlmHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON) -> { |
| 343 | 364 | String app = responseJSON.getString("app"); |
| 344 | 365 | String stream = responseJSON.getString("stream"); |
| ... | ... | @@ -351,7 +372,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 351 | 372 | |
| 352 | 373 | StringBuffer content = new StringBuffer(200); |
| 353 | 374 | content.append("v=0\r\n"); |
| 354 | - content.append("o=" + channelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); | |
| 375 | + content.append("o=" + finalChannelId + " 0 0 IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); | |
| 355 | 376 | content.append("s=" + sessionName + "\r\n"); |
| 356 | 377 | content.append("c=IN IP4 " + mediaServerItemInUSe.getSdpIp() + "\r\n"); |
| 357 | 378 | if ("Playback".equalsIgnoreCase(sessionName)) { |
| ... | ... | @@ -416,7 +437,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 416 | 437 | if (result.getEvent() != null) { |
| 417 | 438 | errorEvent.response(result.getEvent()); |
| 418 | 439 | } |
| 419 | - redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); | |
| 440 | + redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null); | |
| 420 | 441 | try { |
| 421 | 442 | responseAck(serverTransaction, Response.REQUEST_TIMEOUT); |
| 422 | 443 | } catch (SipException e) { |
| ... | ... | @@ -461,8 +482,8 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 461 | 482 | // 写入redis, 超时时回复 |
| 462 | 483 | redisCatchStorage.updateSendRTPSever(sendRtpItem); |
| 463 | 484 | playService.play(mediaServerItem, ssrcInfo, device, channelId, hookEvent, errorEvent, (code, msg) -> { |
| 464 | - logger.info("[上级点播]超时, 用户:{}, 通道:{}", username, channelId); | |
| 465 | - redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), channelId, callIdHeader.getCallId(), null); | |
| 485 | + logger.info("[上级点播]超时, 用户:{}, 通道:{}", username, finalChannelId); | |
| 486 | + redisCatchStorage.deleteSendRTPServer(platform.getServerGBId(), finalChannelId, callIdHeader.getCallId(), null); | |
| 466 | 487 | }, null); |
| 467 | 488 | } else { |
| 468 | 489 | sendRtpItem.setStreamId(playTransaction.getStream()); |
| ... | ... | @@ -916,7 +937,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 916 | 937 | |
| 917 | 938 | Boolean streamReady = zlmrtpServerFactory.isStreamReady(mediaServerItem, app, stream); |
| 918 | 939 | if (streamReady) { |
| 919 | - sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc); | |
| 940 | + sendOk(device, sendRtpItem, sdp, serverTransaction, mediaServerItem, mediaTransmissionTCP, ssrc); | |
| 920 | 941 | }else { |
| 921 | 942 | logger.warn("[语音通话], 未发现待推送的流,app={},stream={}", app, stream); |
| 922 | 943 | playService.stopAudioBroadcast(device.getDeviceId(), audioBroadcastCatch.getChannelId()); | ... | ... |
src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
| ... | ... | @@ -610,8 +610,6 @@ public class PlayServiceImpl implements IPlayService { |
| 610 | 610 | if (ObjectUtils.isEmpty(device.getMediaServerId()) || "auto".equals(device.getMediaServerId())) { |
| 611 | 611 | mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); |
| 612 | 612 | } else { |
| 613 | - mediaServerItem = mediaServerService.getOne(mediaServerId); | |
| 614 | - } else { | |
| 615 | 613 | mediaServerItem = mediaServerService.getOne(device.getMediaServerId()); |
| 616 | 614 | } |
| 617 | 615 | if (mediaServerItem == null) { |
| ... | ... | @@ -987,9 +985,9 @@ public class PlayServiceImpl implements IPlayService { |
| 987 | 985 | return null; |
| 988 | 986 | } |
| 989 | 987 | MediaServerItem mediaServerItem = mediaServerService.getMediaServerForMinimumLoad(); |
| 990 | -// String app = "broadcast"; | |
| 988 | + String app = "broadcast"; | |
| 991 | 989 | // TODO 从sip user agent中判断是什么品牌设备,大华默认使用talk模式,其他使用broadcast模式 |
| 992 | - String app = "talk"; | |
| 990 | +// String app = "talk"; | |
| 993 | 991 | String stream = device.getDeviceId() + "_" + channelId; |
| 994 | 992 | StreamInfo broadcast = mediaService.getStreamInfoByAppAndStream(mediaServerItem, "broadcast", stream, null, null, null, false); |
| 995 | 993 | AudioBroadcastResult audioBroadcastResult = new AudioBroadcastResult(); | ... | ... |