From 624d212df27739f3f09f5420a2c562f3fd8cb505 Mon Sep 17 00:00:00 2001 From: claincly Date: Tue, 7 Sep 2021 13:30:31 +0100 Subject: [PATCH] Handle when additional spaces are in SDP's RTPMAP atrribute Issue: #9379 PiperOrigin-RevId: 395226701 --- RELEASENOTES.md | 3 +++ .../source/rtsp/MediaDescription.java | 4 ++-- .../source/rtsp/RtspMediaTrack.java | 8 -------- .../source/rtsp/SessionDescriptionTest.java | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 558df202ff..b9d070c2ce 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -18,6 +18,9 @@ thrown from `Requirements.isInternetConnectivityValidated` on devices running Android 11 ([#9002](https://github.com/google/ExoPlayer/issues/9002)). +* RTSP: + * Handle when additional spaces are in SDP's RTPMAP atrribute + ([#9379](https://github.com/google/ExoPlayer/issues/9379)). * UI: * Use `defStyleAttr` when obtaining styled attributes in `StyledPlayerView`, `PlayerView` and `PlayerControlView` diff --git a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java index 0a7d87436c..755a32f8a6 100644 --- a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java +++ b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/MediaDescription.java @@ -43,11 +43,11 @@ import java.util.HashMap; /** Parses the RTPMAP attribute value (with the part "a=rtpmap:" removed). */ public static RtpMapAttribute parse(String rtpmapString) throws ParserException { - String[] rtpmapInfo = Util.split(rtpmapString, " "); + String[] rtpmapInfo = Util.splitAtFirst(rtpmapString, " "); checkArgument(rtpmapInfo.length == 2); int payloadType = parseInt(rtpmapInfo[0]); - String[] mediaInfo = Util.split(rtpmapInfo[1], "/"); + String[] mediaInfo = Util.split(rtpmapInfo[1].trim(), "/"); checkArgument(mediaInfo.length >= 2); int clockRate = parseInt(mediaInfo[1]); int encodingParameters = C.INDEX_UNSET; diff --git a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspMediaTrack.java b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspMediaTrack.java index 2f6a3c3c01..cdd8e0b820 100644 --- a/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspMediaTrack.java +++ b/library/rtsp/src/main/java/com/google/android/exoplayer2/source/rtsp/RtspMediaTrack.java @@ -18,7 +18,6 @@ package com.google.android.exoplayer2.source.rtsp; import static com.google.android.exoplayer2.source.rtsp.MediaDescription.MEDIA_TYPE_AUDIO; import static com.google.android.exoplayer2.source.rtsp.RtpPayloadFormat.getMimeTypeFromRtpMediaType; import static com.google.android.exoplayer2.source.rtsp.SessionDescription.ATTR_CONTROL; -import static com.google.android.exoplayer2.source.rtsp.SessionDescription.ATTR_RTPMAP; import static com.google.android.exoplayer2.util.Assertions.checkArgument; import static com.google.android.exoplayer2.util.Assertions.checkNotNull; import static com.google.android.exoplayer2.util.NalUnitUtil.NAL_START_CODE; @@ -95,13 +94,6 @@ import com.google.common.collect.ImmutableMap; formatBuilder.setAverageBitrate(mediaDescription.bitrate); } - // rtpmap is mandatory in an RTSP session with dynamic payload types (RFC2326 Section C.1.3). - checkArgument(mediaDescription.attributes.containsKey(ATTR_RTPMAP)); - String rtpmapAttribute = castNonNull(mediaDescription.attributes.get(ATTR_RTPMAP)); - - // rtpmap string format: RFC2327 Page 22. - String[] rtpmap = Util.split(rtpmapAttribute, " "); - checkArgument(rtpmap.length == 2); int rtpPayloadType = mediaDescription.rtpMapAttribute.payloadType; String mimeType = getMimeTypeFromRtpMediaType(mediaDescription.rtpMapAttribute.mediaEncoding); diff --git a/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java b/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java index d71976148d..cd2f6c3266 100644 --- a/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java +++ b/library/rtsp/src/test/java/com/google/android/exoplayer2/source/rtsp/SessionDescriptionTest.java @@ -191,6 +191,25 @@ public class SessionDescriptionTest { assertThat(sessionDescription.attributes).containsEntry(ATTR_CONTROL, "session1"); } + @Test + public void parse_sdpStringWithExtraSpaceInRtpMapAttribute_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" + + "t=0 0\r\n" + + "a=control:*\r\n" + + "m=audio 3456 RTP/AVP 0\r\n" + + "a=rtpmap:97 AC3/44100 \r\n"; + + SessionDescription sessionDescription = SessionDescriptionParser.parse(testMediaSdpInfo); + MediaDescription.RtpMapAttribute rtpMapAttribute = + sessionDescription.mediaDescriptionList.get(0).rtpMapAttribute; + assertThat(rtpMapAttribute.payloadType).isEqualTo(97); + assertThat(rtpMapAttribute.mediaEncoding).isEqualTo("AC3"); + assertThat(rtpMapAttribute.clockRate).isEqualTo(44100); + } + @Test public void buildMediaDescription_withInvalidRtpmapAttribute_throwsIllegalStateException() { assertThrows(