修复sdp解析错误

pull/893/head
648540858 2023-06-12 22:54:40 +08:00
parent 52f9c295f9
commit fa80ba6f2b
1 changed files with 4 additions and 8 deletions

View File

@ -207,22 +207,18 @@ public class SipUtils {
if (mediaDescriptionIndex == 0 && ssrcIndex == 0) { if (mediaDescriptionIndex == 0 && ssrcIndex == 0) {
sdp = SdpFactory.getInstance().createSessionDescription(sdpStr); sdp = SdpFactory.getInstance().createSessionDescription(sdpStr);
}else { }else {
int baseSdpIndex = Math.min(mediaDescriptionIndex, ssrcIndex);
//ssrc规定长度为10字节不取余下长度以避免后续还有“f=”字段
String substring = sdpStr.substring(0, baseSdpIndex);
sdp = SdpFactory.getInstance().createSessionDescription(substring);
String lines[] = sdpStr.split("\\r?\\n"); String lines[] = sdpStr.split("\\r?\\n");
StringBuilder sdpBuffer = new StringBuilder();
for (String line : lines) { for (String line : lines) {
if (line.trim().startsWith("y=")) { if (line.trim().startsWith("y=")) {
ssrc = line.substring(2); ssrc = line.substring(2);
}else if (line.trim().startsWith("f=")) { }else if (line.trim().startsWith("f=")) {
mediaDescription = line.substring(2); mediaDescription = line.substring(2);
} }else {
if (ssrc != null && mediaDescription != null) { sdpBuffer.append(line.trim()).append("\r\n");
break;
} }
} }
sdp = SdpFactory.getInstance().createSessionDescription(sdpBuffer.toString());
} }
return Gb28181Sdp.getInstance(sdp, ssrc, mediaDescription); return Gb28181Sdp.getInstance(sdp, ssrc, mediaDescription);
} }