Allow trailing whitespace in RTSP SessionDescription lines

This CL fixes the parser for the RTSP SessionDescription such that it will not choke if there is trailing whitespace in the lines.

PiperOrigin-RevId: 750158624
This commit is contained in:
michaelkatz 2025-04-22 05:52:37 -07:00 committed by Copybara-Service
parent ba97999657
commit d3328456a7
3 changed files with 24 additions and 0 deletions

View File

@ -73,6 +73,9 @@
* DASH extension:
* Smooth Streaming extension:
* RTSP extension:
* Add parsing support for SessionDescriptions containing lines with
trailing whitespace characters
([#2357](https://github.com/androidx/media/issues/2357)).
* Decoder extensions (FFmpeg, VP9, AV1, etc.):
* MIDI extension:
* Leanback extension:

View File

@ -83,6 +83,8 @@ import java.util.regex.Pattern;
// Lines are separated by an CRLF.
for (String line : RtspMessageUtil.splitRtspMessageBody(sdpString)) {
line = line.trim();
if ("".equals(line)) {
continue;
}

View File

@ -342,6 +342,25 @@ public class SessionDescriptionTest {
assertThat(sessionDescription.mediaDescriptionList.get(0).mediaTitle).isNull();
}
@Test
public void parse_sdpStringWithTrailingWhitespace_succeeds() throws Exception {
String testMediaSdpInfo =
"v=0\r\n"
+ "o=MNobody 2890844526 2890842807 IN IP4 192.0.2.46\r\n"
+ "s=SDP Seminar\r\n"
+ "i=Sun Apr 20 12:59:09 2025\n\r\n"
+ "t=0 0\r\n"
+ "a=control:*\r\n"
+ "m=audio 3456 RTP/AVP 0\r\n"
+ "i=\r\n"
+ "a=rtpmap:97 AC3/44100 \r\n";
SessionDescription sessionDescription = SessionDescriptionParser.parse(testMediaSdpInfo);
assertThat(sessionDescription.sessionInfo).isEqualTo("Sun Apr 20 12:59:09 2025");
assertThat(sessionDescription.mediaDescriptionList.get(0).mediaTitle).isNull();
}
@Test
public void parse_sdpStringWithEmptySessionAttribute_throwsParserException() {
String testMediaSdpInfo =