Commit 5df95ba8500540ef5a033512a685b69822e84585
1 parent
19a52a20
级联回放增加MediaStatus消息 #377
Showing
4 changed files
with
57 additions
and
21 deletions
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/cmd/impl/SIPCommanderFroPlatform.java
| ... | ... | @@ -760,6 +760,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 760 | 760 | } |
| 761 | 761 | try{ |
| 762 | 762 | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); |
| 763 | + SipStack sipStack; | |
| 764 | + if ("TCP".equals(platform.getTransport())) { | |
| 765 | + sipStack = tcpSipProvider.getSipStack(); | |
| 766 | + } else { | |
| 767 | + sipStack = udpSipProvider.getSipStack(); | |
| 768 | + } | |
| 769 | + SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); | |
| 770 | + if (dialog != sipDialog) { | |
| 771 | + dialog = sipDialog; | |
| 772 | + } | |
| 773 | + if ("TCP".equals(platform.getTransport())) { | |
| 774 | + dialog.setSipProvider(tcpSipProvider); | |
| 775 | + } else { | |
| 776 | + dialog.setSipProvider(udpSipProvider); | |
| 777 | + } | |
| 778 | + | |
| 779 | + Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); | |
| 780 | + sipStackField.setAccessible(true); | |
| 781 | + sipStackField.set(dialog, sipStack); | |
| 782 | + Field eventListenersField = SIPDialog.class.getDeclaredField("eventListeners"); | |
| 783 | + eventListenersField.setAccessible(true); | |
| 784 | + eventListenersField.set(dialog, new HashSet<>()); | |
| 785 | + | |
| 763 | 786 | SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); |
| 764 | 787 | String characterSet = platform.getCharacterSet(); |
| 765 | 788 | StringBuffer mediaStatusXml = new StringBuffer(200); |
| ... | ... | @@ -775,20 +798,23 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 775 | 798 | SipURI sipURI = (SipURI) messageRequest.getRequestURI(); |
| 776 | 799 | sipURI.setHost(platform.getServerIP()); |
| 777 | 800 | sipURI.setPort(platform.getServerPort()); |
| 778 | - | |
| 779 | - ClientTransaction transaction = null; | |
| 801 | + ClientTransaction clientTransaction; | |
| 780 | 802 | if ("TCP".equals(platform.getTransport())) { |
| 781 | - transaction = tcpSipProvider.getNewClientTransaction(messageRequest); | |
| 782 | - } else if ("UDP".equals(platform.getTransport())) { | |
| 783 | - transaction = udpSipProvider.getNewClientTransaction(messageRequest); | |
| 803 | + clientTransaction = tcpSipProvider.getNewClientTransaction(messageRequest); | |
| 804 | + }else { | |
| 805 | + clientTransaction = udpSipProvider.getNewClientTransaction(messageRequest); | |
| 784 | 806 | } |
| 785 | - transaction.sendRequest(); | |
| 807 | + dialog.sendRequest(clientTransaction); | |
| 786 | 808 | } catch (SipException e) { |
| 787 | 809 | e.printStackTrace(); |
| 788 | 810 | return false; |
| 789 | 811 | } catch (ParseException e) { |
| 790 | 812 | e.printStackTrace(); |
| 791 | 813 | return false; |
| 814 | + } catch (NoSuchFieldException e) { | |
| 815 | + throw new RuntimeException(e); | |
| 816 | + } catch (IllegalAccessException e) { | |
| 817 | + throw new RuntimeException(e); | |
| 792 | 818 | } |
| 793 | 819 | return true; |
| 794 | 820 | |
| ... | ... | @@ -811,13 +837,22 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 811 | 837 | byte[] dialogByteArray = sendRtpItem.getDialog(); |
| 812 | 838 | if (dialogByteArray != null) { |
| 813 | 839 | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); |
| 814 | - SipStack sipStack = udpSipProvider.getSipStack(); | |
| 840 | + SipStack sipStack; | |
| 841 | + if ("TCP".equals(platform.getTransport())) { | |
| 842 | + sipStack = tcpSipProvider.getSipStack(); | |
| 843 | + } else { | |
| 844 | + sipStack = udpSipProvider.getSipStack(); | |
| 845 | + } | |
| 815 | 846 | SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); |
| 816 | 847 | if (dialog != sipDialog) { |
| 817 | 848 | dialog = sipDialog; |
| 818 | 849 | } |
| 819 | 850 | try { |
| 820 | - dialog.setSipProvider(udpSipProvider); | |
| 851 | + if ("TCP".equals(platform.getTransport())) { | |
| 852 | + dialog.setSipProvider(tcpSipProvider); | |
| 853 | + } else { | |
| 854 | + dialog.setSipProvider(udpSipProvider); | |
| 855 | + } | |
| 821 | 856 | Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); |
| 822 | 857 | sipStackField.setAccessible(true); |
| 823 | 858 | sipStackField.set(dialog, sipStack); |
| ... | ... | @@ -825,17 +860,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { |
| 825 | 860 | eventListenersField.setAccessible(true); |
| 826 | 861 | eventListenersField.set(dialog, new HashSet<>()); |
| 827 | 862 | |
| 828 | - byte[] transactionByteArray = sendRtpItem.getTransaction(); | |
| 829 | - ClientTransaction clientTransaction = (ClientTransaction) SerializeUtils.deSerialize(transactionByteArray); | |
| 830 | 863 | Request byeRequest = dialog.createRequest(Request.BYE); |
| 831 | 864 | |
| 832 | 865 | SipURI byeURI = (SipURI) byeRequest.getRequestURI(); |
| 833 | - SIPRequest request = (SIPRequest) clientTransaction.getRequest(); | |
| 834 | - byeURI.setHost(request.getRemoteAddress().getHostAddress()); | |
| 835 | - byeURI.setPort(request.getRemotePort()); | |
| 866 | + byeURI.setHost(platform.getServerIP()); | |
| 867 | + byeURI.setPort(platform.getServerPort()); | |
| 868 | + ClientTransaction clientTransaction; | |
| 836 | 869 | if ("TCP".equals(platform.getTransport())) { |
| 837 | 870 | clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); |
| 838 | - } else if ("UDP".equals(platform.getTransport())) { | |
| 871 | + } else { | |
| 839 | 872 | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); |
| 840 | 873 | } |
| 841 | 874 | dialog.sendRequest(clientTransaction); | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/AckRequestProcessor.java
| ... | ... | @@ -18,6 +18,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; |
| 18 | 18 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | 19 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 20 | 20 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 21 | +import com.genersoft.iot.vmp.utils.SerializeUtils; | |
| 21 | 22 | import org.ehcache.shadow.org.terracotta.offheapstore.storage.IntegerStorageEngine; |
| 22 | 23 | import org.slf4j.Logger; |
| 23 | 24 | import org.slf4j.LoggerFactory; |
| ... | ... | @@ -118,6 +119,11 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In |
| 118 | 119 | logger.error("RTP推流失败: 请检查ZLM服务"); |
| 119 | 120 | } else if (jsonObject.getInteger("code") == 0) { |
| 120 | 121 | logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port")); |
| 122 | + byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); | |
| 123 | + sendRtpItem.setDialog(dialogByteArray); | |
| 124 | + byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); | |
| 125 | + sendRtpItem.setTransaction(transactionByteArray); | |
| 126 | + redisCatchStorage.updateSendRTPSever(sendRtpItem); | |
| 121 | 127 | } else { |
| 122 | 128 | logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); |
| 123 | 129 | if (sendRtpItem.isOnlyAudio()) { | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/InviteRequestProcessor.java
| ... | ... | @@ -264,10 +264,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements |
| 264 | 264 | } |
| 265 | 265 | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| 266 | 266 | sendRtpItem.setPlayType("Play".equals(sessionName)?InviteStreamType.PLAY:InviteStreamType.PLAYBACK); |
| 267 | - byte[] dialogByteArray = SerializeUtils.serialize(evt.getDialog()); | |
| 268 | - sendRtpItem.setDialog(dialogByteArray); | |
| 269 | - byte[] transactionByteArray = SerializeUtils.serialize(evt.getServerTransaction()); | |
| 270 | - sendRtpItem.setTransaction(transactionByteArray); | |
| 267 | + | |
| 271 | 268 | Long finalStartTime = startTime; |
| 272 | 269 | Long finalStopTime = stopTime; |
| 273 | 270 | ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON)->{ | ... | ... |
src/main/java/com/genersoft/iot/vmp/gb28181/transmit/event/request/impl/message/notify/cmd/MediaStatusNotifyMessageHandler.java
| ... | ... | @@ -87,8 +87,9 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i |
| 87 | 87 | SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); |
| 88 | 88 | if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 |
| 89 | 89 | cmder.streamByeCmd(device.getDeviceId(), ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); |
| 90 | - // 如果级联播放,需要给上级发送此通知 | |
| 91 | - SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); | |
| 90 | + | |
| 91 | + // 如果级联播放,需要给上级发送此通知 TODO 多个上级同时观看一个下级 可能存在停错的问题,需要将点播CallId进行上下级绑定 | |
| 92 | + SendRtpItem sendRtpItem = redisCatchStorage.querySendRTPServer(null, ssrcTransaction.getChannelId(), null, null); | |
| 92 | 93 | if (sendRtpItem != null) { |
| 93 | 94 | ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(sendRtpItem.getPlatformId()); |
| 94 | 95 | if (parentPlatform == null) { |
| ... | ... | @@ -98,7 +99,6 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i |
| 98 | 99 | sipCommanderFroPlatform.sendMediaStatusNotify(parentPlatform, sendRtpItem); |
| 99 | 100 | } |
| 100 | 101 | } |
| 101 | - | |
| 102 | 102 | } |
| 103 | 103 | } |
| 104 | 104 | ... | ... |