mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Propagate duplicated keys error in SDP better.
The current code does not catch the IAE thrown when building a MediaDescription or SessionDescription. This CL catches the IAE and propagates it as a ParserException. Issue: #9014. #minor-release PiperOrigin-RevId: 377544439
This commit is contained in:
parent
4e85184955
commit
efdd55fad5
@ -189,7 +189,7 @@ import java.util.regex.Pattern;
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return sessionDescriptionBuilder.build();
|
return sessionDescriptionBuilder.build();
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||||
throw ParserException.createForMalformedManifest(/* message= */ null, e);
|
throw ParserException.createForMalformedManifest(/* message= */ null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -200,7 +200,7 @@ import java.util.regex.Pattern;
|
|||||||
throws ParserException {
|
throws ParserException {
|
||||||
try {
|
try {
|
||||||
sessionDescriptionBuilder.addMediaDescription(mediaDescriptionBuilder.build());
|
sessionDescriptionBuilder.addMediaDescription(mediaDescriptionBuilder.build());
|
||||||
} catch (IllegalStateException e) {
|
} catch (IllegalArgumentException | IllegalStateException e) {
|
||||||
throw ParserException.createForMalformedManifest(/* message= */ null, e);
|
throw ParserException.createForMalformedManifest(/* message= */ null, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import static org.junit.Assert.assertThrows;
|
|||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
import com.google.android.exoplayer2.ParserException;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.robolectric.annotation.internal.DoNotInstrument;
|
import org.robolectric.annotation.internal.DoNotInstrument;
|
||||||
@ -151,6 +152,35 @@ public class SessionDescriptionTest {
|
|||||||
assertThat(sessionDescription).isEqualTo(expectedSession);
|
assertThat(sessionDescription).isEqualTo(expectedSession);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parse_sdpStringWithDuplicatedMediaAttribute_throwsParserException() {
|
||||||
|
String testMediaSdpInfo =
|
||||||
|
"v=0\r\n"
|
||||||
|
+ "o=MNobody 2890844526 2890842807 IN IP4 192.0.2.46\r\n"
|
||||||
|
+ "s=SDP Seminar\r\n"
|
||||||
|
+ "i=A Seminar on the session description protocol\r\n"
|
||||||
|
+ "m=audio 3456 RTP/AVP 0\r\n"
|
||||||
|
+ "a=control:audio\r\n"
|
||||||
|
+ "a=control:audio\r\n";
|
||||||
|
|
||||||
|
assertThrows(ParserException.class, () -> SessionDescriptionParser.parse(testMediaSdpInfo));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parse_sdpStringWithDuplicatedSessionAttribute_throwsParserException() {
|
||||||
|
String testMediaSdpInfo =
|
||||||
|
"v=0\r\n"
|
||||||
|
+ "o=MNobody 2890844526 2890842807 IN IP4 192.0.2.46\r\n"
|
||||||
|
+ "s=SDP Seminar\r\n"
|
||||||
|
+ "a=control:*\r\n"
|
||||||
|
+ "a=control:*\r\n"
|
||||||
|
+ "i=A Seminar on the session description protocol\r\n"
|
||||||
|
+ "m=audio 3456 RTP/AVP 0\r\n"
|
||||||
|
+ "a=control:audio\r\n";
|
||||||
|
|
||||||
|
assertThrows(ParserException.class, () -> SessionDescriptionParser.parse(testMediaSdpInfo));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void buildMediaDescription_withInvalidRtpmapAttribute_throwsIllegalStateException() {
|
public void buildMediaDescription_withInvalidRtpmapAttribute_throwsIllegalStateException() {
|
||||||
assertThrows(
|
assertThrows(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user