RtpMapAttributeParser implements SdpParser<RtpMapAttribute> { @Override public RtpMapAttribute parse(String sdp) throws SdpException { try { int index = 0; String[] values = sdp.trim().substring(9).split("\\s|/"); int payloadType = Integer.parseInt(values[index++]); String codec = values[index++]; int clockRate = Integer.parseInt(values[index++]); int codecParams = 1; if(index == values.length - 1) { codecParams = Integer.parseInt(values[index]); } return new RtpMapAttribute(payloadType, codec, clockRate, codecParams); } catch (Exception e) { throw new SdpException(PARSE_ERROR + sdp, e); } }  @Override boolean canParse(String sdp); @Override RtpMapAttribute parse(String sdp); @Override void parse(RtpMapAttribute field, String sdp);  }
@Test public void testSimpleParse() throws SdpException { String line = "a=rtpmap:97 L16/8000\n\r"; RtpMapAttribute attr = parser.parse(line); Assert.assertEquals(97, attr.getPayloadType()); Assert.assertEquals("L16", attr.getCodec()); Assert.assertEquals(8000, attr.getClockRate()); Assert.assertEquals(1, attr.getCodecParams()); }
@Test public void testComplexParse() throws SdpException { String line = "a=rtpmap:98 L16/11025/2\n\r"; RtpMapAttribute attr = parser.parse(line); Assert.assertEquals(98, attr.getPayloadType()); Assert.assertEquals("L16", attr.getCodec()); Assert.assertEquals(11025, attr.getClockRate()); Assert.assertEquals(2, attr.getCodecParams()); }
@Test public void testSimpleToComplexParseOverwrite() throws SdpException { String line1 = "a=rtpmap:97 L16/8000\n\r"; String line2 = "a=rtpmap:98 L16/11025/2\n\r"; RtpMapAttribute attr = parser.parse(line1); parser.parse(attr, line2); Assert.assertEquals(98, attr.getPayloadType()); Assert.assertEquals("L16", attr.getCodec()); Assert.assertEquals(11025, attr.getClockRate()); Assert.assertEquals(2, attr.getCodecParams()); }
@Test public void testComplexToSimpleParseOverwrite() throws SdpException { String line1 = "a=rtpmap:98 L16/11025/2\n\r"; String line2 = "a=rtpmap:97 L16/8000\n\r"; RtpMapAttribute attr = parser.parse(line1); parser.parse(attr, line2); Assert.assertEquals(97, attr.getPayloadType()); Assert.assertEquals("L16", attr.getCodec()); Assert.assertEquals(8000, attr.getClockRate()); Assert.assertEquals(1, attr.getCodecParams()); }