From 446f729e559730b813291f072a6e33a012923018 Mon Sep 17 00:00:00 2001
From: 648540858 <648540858@qq.com>
Date: 星期六, 10 六月 2023 00:32:42 +0800
Subject: [PATCH] 优化sdp解析,兼容带有f=的设备

---
 src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java |   33 +++++++++++++++------------------
 1 files changed, 15 insertions(+), 18 deletions(-)

diff --git a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
index efba170..3907895 100644
--- a/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
+++ b/src/main/java/com/genersoft/iot/vmp/service/impl/PlayServiceImpl.java
@@ -18,6 +18,7 @@
 import com.genersoft.iot.vmp.gb28181.transmit.callback.DeferredResultHolder;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommander;
 import com.genersoft.iot.vmp.gb28181.transmit.cmd.impl.SIPCommanderFroPlatform;
+import com.genersoft.iot.vmp.gb28181.utils.SipUtils;
 import com.genersoft.iot.vmp.media.zlm.AssistRESTfulUtils;
 import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
 import com.genersoft.iot.vmp.media.zlm.ZLMRTPServerFactory;
@@ -297,17 +298,16 @@
                 ResponseEvent responseEvent = (ResponseEvent) event.event;
                 String contentString = new String(responseEvent.getResponse().getRawContent());
                 // 鑾峰彇ssrc
-                int ssrcIndex = contentString.indexOf("y=");
+                String ssrcInResponse = SipUtils.getSsrcFromSdp(contentString);
+
                 // 妫�鏌ユ槸鍚︽湁y瀛楁
-                if (ssrcIndex >= 0) {
-                    //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
-                    String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12).trim();
+                if (ssrcInResponse != null) {
                     // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
                     if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
                         if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
-                            String substring = contentString.substring(0, contentString.indexOf("y="));
                             try {
-                                SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
+                                Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString);
+                                SessionDescription sdp = gb28181Sdp.getBaseSdb();
                                 int port = -1;
                                 Vector mediaDescriptions = sdp.getMediaDescriptions(true);
                                 for (Object description : mediaDescriptions) {
@@ -607,17 +607,16 @@
                         ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
                         String contentString = new String(responseEvent.getResponse().getRawContent());
                         // 鑾峰彇ssrc
-                        int ssrcIndex = contentString.indexOf("y=");
+                        String ssrcInResponse = SipUtils.getSsrcFromSdp(contentString);
+
                         // 妫�鏌ユ槸鍚︽湁y瀛楁
-                        if (ssrcIndex >= 0) {
-                            //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
-                            String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+                        if (ssrcInResponse != null) {
                             // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
                             if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
                                 if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
-                                    String substring = contentString.substring(0, contentString.indexOf("y="));
                                     try {
-                                        SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
+                                        Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString);
+                                        SessionDescription sdp = gb28181Sdp.getBaseSdb();
                                         int port = -1;
                                         Vector mediaDescriptions = sdp.getMediaDescriptions(true);
                                         for (Object description : mediaDescriptions) {
@@ -800,17 +799,15 @@
                         ResponseEvent responseEvent = (ResponseEvent) eventResult.event;
                         String contentString = new String(responseEvent.getResponse().getRawContent());
                         // 鑾峰彇ssrc
-                        int ssrcIndex = contentString.indexOf("y=");
+                        String ssrcInResponse = SipUtils.getSsrcFromSdp(contentString);
                         // 妫�鏌ユ槸鍚︽湁y瀛楁
-                        if (ssrcIndex >= 0) {
-                            //ssrc瑙勫畾闀垮害涓�10瀛楄妭锛屼笉鍙栦綑涓嬮暱搴︿互閬垮厤鍚庣画杩樻湁鈥渇=鈥濆瓧娈� TODO 鍚庣画瀵逛笉瑙勮寖鐨勯潪10浣峴src鍏煎
-                            String ssrcInResponse = contentString.substring(ssrcIndex + 2, ssrcIndex + 12);
+                        if (ssrcInResponse != null) {
                             // 鏌ヨ鍒皊src涓嶄竴鑷翠笖寮�鍚簡ssrc鏍¢獙鍒欓渶瑕侀拡瀵瑰鐞�
                             if (ssrcInfo.getSsrc().equals(ssrcInResponse)) {
                                 if (device.getStreamMode().equalsIgnoreCase("TCP-ACTIVE")) {
-                                    String substring = contentString.substring(0, contentString.indexOf("y="));
                                     try {
-                                        SessionDescription sdp = SdpFactory.getInstance().createSessionDescription(substring);
+                                        Gb28181Sdp gb28181Sdp = SipUtils.parseSDP(contentString);
+                                        SessionDescription sdp = gb28181Sdp.getBaseSdb();
                                         int port = -1;
                                         Vector mediaDescriptions = sdp.getMediaDescriptions(true);
                                         for (Object description : mediaDescriptions) {

--
Gitblit v1.8.0