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,6 +760,29 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | ||
| 760 | } | 760 | } |
| 761 | try{ | 761 | try{ |
| 762 | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); | 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 | SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); | 786 | SIPRequest messageRequest = (SIPRequest)dialog.createRequest(Request.MESSAGE); |
| 764 | String characterSet = platform.getCharacterSet(); | 787 | String characterSet = platform.getCharacterSet(); |
| 765 | StringBuffer mediaStatusXml = new StringBuffer(200); | 788 | StringBuffer mediaStatusXml = new StringBuffer(200); |
| @@ -775,20 +798,23 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | @@ -775,20 +798,23 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | ||
| 775 | SipURI sipURI = (SipURI) messageRequest.getRequestURI(); | 798 | SipURI sipURI = (SipURI) messageRequest.getRequestURI(); |
| 776 | sipURI.setHost(platform.getServerIP()); | 799 | sipURI.setHost(platform.getServerIP()); |
| 777 | sipURI.setPort(platform.getServerPort()); | 800 | sipURI.setPort(platform.getServerPort()); |
| 778 | - | ||
| 779 | - ClientTransaction transaction = null; | 801 | + ClientTransaction clientTransaction; |
| 780 | if ("TCP".equals(platform.getTransport())) { | 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 | } catch (SipException e) { | 808 | } catch (SipException e) { |
| 787 | e.printStackTrace(); | 809 | e.printStackTrace(); |
| 788 | return false; | 810 | return false; |
| 789 | } catch (ParseException e) { | 811 | } catch (ParseException e) { |
| 790 | e.printStackTrace(); | 812 | e.printStackTrace(); |
| 791 | return false; | 813 | return false; |
| 814 | + } catch (NoSuchFieldException e) { | ||
| 815 | + throw new RuntimeException(e); | ||
| 816 | + } catch (IllegalAccessException e) { | ||
| 817 | + throw new RuntimeException(e); | ||
| 792 | } | 818 | } |
| 793 | return true; | 819 | return true; |
| 794 | 820 | ||
| @@ -811,13 +837,22 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | @@ -811,13 +837,22 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | ||
| 811 | byte[] dialogByteArray = sendRtpItem.getDialog(); | 837 | byte[] dialogByteArray = sendRtpItem.getDialog(); |
| 812 | if (dialogByteArray != null) { | 838 | if (dialogByteArray != null) { |
| 813 | SIPDialog dialog = (SIPDialog) SerializeUtils.deSerialize(dialogByteArray); | 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 | SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); | 846 | SIPDialog sipDialog = ((SipStackImpl) sipStack).putDialog(dialog); |
| 816 | if (dialog != sipDialog) { | 847 | if (dialog != sipDialog) { |
| 817 | dialog = sipDialog; | 848 | dialog = sipDialog; |
| 818 | } | 849 | } |
| 819 | try { | 850 | try { |
| 820 | - dialog.setSipProvider(udpSipProvider); | 851 | + if ("TCP".equals(platform.getTransport())) { |
| 852 | + dialog.setSipProvider(tcpSipProvider); | ||
| 853 | + } else { | ||
| 854 | + dialog.setSipProvider(udpSipProvider); | ||
| 855 | + } | ||
| 821 | Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); | 856 | Field sipStackField = SIPDialog.class.getDeclaredField("sipStack"); |
| 822 | sipStackField.setAccessible(true); | 857 | sipStackField.setAccessible(true); |
| 823 | sipStackField.set(dialog, sipStack); | 858 | sipStackField.set(dialog, sipStack); |
| @@ -825,17 +860,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | @@ -825,17 +860,15 @@ public class SIPCommanderFroPlatform implements ISIPCommanderForPlatform { | ||
| 825 | eventListenersField.setAccessible(true); | 860 | eventListenersField.setAccessible(true); |
| 826 | eventListenersField.set(dialog, new HashSet<>()); | 861 | eventListenersField.set(dialog, new HashSet<>()); |
| 827 | 862 | ||
| 828 | - byte[] transactionByteArray = sendRtpItem.getTransaction(); | ||
| 829 | - ClientTransaction clientTransaction = (ClientTransaction) SerializeUtils.deSerialize(transactionByteArray); | ||
| 830 | Request byeRequest = dialog.createRequest(Request.BYE); | 863 | Request byeRequest = dialog.createRequest(Request.BYE); |
| 831 | 864 | ||
| 832 | SipURI byeURI = (SipURI) byeRequest.getRequestURI(); | 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 | if ("TCP".equals(platform.getTransport())) { | 869 | if ("TCP".equals(platform.getTransport())) { |
| 837 | clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); | 870 | clientTransaction = tcpSipProvider.getNewClientTransaction(byeRequest); |
| 838 | - } else if ("UDP".equals(platform.getTransport())) { | 871 | + } else { |
| 839 | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); | 872 | clientTransaction = udpSipProvider.getNewClientTransaction(byeRequest); |
| 840 | } | 873 | } |
| 841 | dialog.sendRequest(clientTransaction); | 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,6 +18,7 @@ import com.genersoft.iot.vmp.media.zlm.dto.MediaServerItem; | ||
| 18 | import com.genersoft.iot.vmp.service.IMediaServerService; | 18 | import com.genersoft.iot.vmp.service.IMediaServerService; |
| 19 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; | 19 | import com.genersoft.iot.vmp.storager.IRedisCatchStorage; |
| 20 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; | 20 | import com.genersoft.iot.vmp.storager.IVideoManagerStorage; |
| 21 | +import com.genersoft.iot.vmp.utils.SerializeUtils; | ||
| 21 | import org.ehcache.shadow.org.terracotta.offheapstore.storage.IntegerStorageEngine; | 22 | import org.ehcache.shadow.org.terracotta.offheapstore.storage.IntegerStorageEngine; |
| 22 | import org.slf4j.Logger; | 23 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; | 24 | import org.slf4j.LoggerFactory; |
| @@ -118,6 +119,11 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In | @@ -118,6 +119,11 @@ public class AckRequestProcessor extends SIPRequestProcessorParent implements In | ||
| 118 | logger.error("RTP推流失败: 请检查ZLM服务"); | 119 | logger.error("RTP推流失败: 请检查ZLM服务"); |
| 119 | } else if (jsonObject.getInteger("code") == 0) { | 120 | } else if (jsonObject.getInteger("code") == 0) { |
| 120 | logger.info("RTP推流成功[ {}/{} ],{}->{}:{}, " ,param.get("app"), param.get("stream"), jsonObject.getString("local_port"), param.get("dst_url"), param.get("dst_port")); | 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 | } else { | 127 | } else { |
| 122 | logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); | 128 | logger.error("RTP推流失败: {}, 参数:{}",jsonObject.getString("msg"),JSONObject.toJSON(param)); |
| 123 | if (sendRtpItem.isOnlyAudio()) { | 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,10 +264,7 @@ public class InviteRequestProcessor extends SIPRequestProcessorParent implements | ||
| 264 | } | 264 | } |
| 265 | sendRtpItem.setCallId(callIdHeader.getCallId()); | 265 | sendRtpItem.setCallId(callIdHeader.getCallId()); |
| 266 | sendRtpItem.setPlayType("Play".equals(sessionName)?InviteStreamType.PLAY:InviteStreamType.PLAYBACK); | 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 | Long finalStartTime = startTime; | 268 | Long finalStartTime = startTime; |
| 272 | Long finalStopTime = stopTime; | 269 | Long finalStopTime = stopTime; |
| 273 | ZLMHttpHookSubscribe.Event hookEvent = (mediaServerItemInUSe, responseJSON)->{ | 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,8 +87,9 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i | ||
| 87 | SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); | 87 | SsrcTransaction ssrcTransaction = sessionManager.getSsrcTransaction(null, null, callIdHeader.getCallId(), null); |
| 88 | if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 | 88 | if (ssrcTransaction != null) { // 兼容海康 媒体通知 消息from字段不是设备ID的问题 |
| 89 | cmder.streamByeCmd(device.getDeviceId(), ssrcTransaction.getChannelId(), null, callIdHeader.getCallId()); | 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 | if (sendRtpItem != null) { | 93 | if (sendRtpItem != null) { |
| 93 | ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(sendRtpItem.getPlatformId()); | 94 | ParentPlatform parentPlatform = storage.queryParentPlatByServerGBId(sendRtpItem.getPlatformId()); |
| 94 | if (parentPlatform == null) { | 95 | if (parentPlatform == null) { |
| @@ -98,7 +99,6 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i | @@ -98,7 +99,6 @@ public class MediaStatusNotifyMessageHandler extends SIPRequestProcessorParent i | ||
| 98 | sipCommanderFroPlatform.sendMediaStatusNotify(parentPlatform, sendRtpItem); | 99 | sipCommanderFroPlatform.sendMediaStatusNotify(parentPlatform, sendRtpItem); |
| 99 | } | 100 | } |
| 100 | } | 101 | } |
| 101 | - | ||
| 102 | } | 102 | } |
| 103 | } | 103 | } |
| 104 | 104 |