RtcpPacket implements Serializable { public int decode(byte[] rawData, int offSet) { this.size = 0; while (offSet < rawData.length) { int type = rawData[offSet + 1] & 0x000000FF; switch (type) { case RtcpHeader.RTCP_SR: packetCount++; this.senderReport = new RtcpSenderReport(); offSet = this.senderReport.decode(rawData, offSet); this.size += this.senderReport.length; break; case RtcpHeader.RTCP_RR: packetCount++; this.receiverReport = new RtcpReceiverReport(); offSet = this.receiverReport.decode(rawData, offSet); this.size += this.receiverReport.length; break; case RtcpHeader.RTCP_SDES: packetCount++; this.sdes = new RtcpSdes(); offSet = this.sdes.decode(rawData, offSet); this.size += this.sdes.length; break; case RtcpHeader.RTCP_APP: packetCount++; this.appDefined = new RtcpAppDefined(); offSet = this.appDefined.decode(rawData, offSet); this.size += this.appDefined.length; break; case RtcpHeader.RTCP_BYE: packetCount++; this.bye = new RtcpBye(); offSet = this.bye.decode(rawData, offSet); this.size += this.bye.length; break; default: logger.error("Received type = "+type+" RTCP Packet decoding falsed. offSet = "+offSet +". Packet count = "+ packetCount); offSet = rawData.length; break; } } return offSet; } RtcpPacket();  RtcpPacket(RtcpSenderReport senderReport, RtcpReceiverReport receiverReport, RtcpSdes sdes, RtcpBye bye, RtcpAppDefined appDefined);  RtcpPacket(RtcpReport report, RtcpSdes sdes, RtcpBye bye);  RtcpPacket(RtcpReport report, RtcpSdes sdes); int decode(byte[] rawData, int offSet); int encode(byte[] rawData, int offSet); boolean isSender(); RtcpPacketType getPacketType(); RtcpReport getReport(); RtcpSenderReport getSenderReport(); RtcpReceiverReport getReceiverReport(); RtcpSdes getSdes(); RtcpBye getBye(); boolean hasBye(); RtcpAppDefined getAppDefined(); int getPacketCount(); int getSize(); @Override String toString(); static final int MAX_SOURCES; }
@Test public void testDecode() { RtcpPacket rtcpPacket = new RtcpPacket(); int length = rtcpPacket.decode(p, 0); assertEquals(p.length, length); RtcpSenderReport rtcpSenderReport = rtcpPacket.getSenderReport(); assertEquals(2, rtcpSenderReport.getVersion()); assertFalse(rtcpSenderReport.isPadding()); assertEquals(0, rtcpSenderReport.getCount()); assertEquals(RtcpHeader.RTCP_SR, rtcpSenderReport.getPacketType()); assertEquals(28, rtcpSenderReport.getLength()); assertEquals(266283887, rtcpSenderReport.getSsrc()); assertEquals(3471178652l, rtcpSenderReport.getNtpSec()); assertEquals(133143986, rtcpSenderReport.getNtpFrac()); assertEquals(1586529211, rtcpSenderReport.getRtpTs()); assertEquals(1, rtcpSenderReport.getPsent()); assertEquals(11, rtcpSenderReport.getOsent()); RtcpSdes rtcpSdes = rtcpPacket.getSdes(); assertEquals(2, rtcpSdes.getVersion()); assertFalse(rtcpSdes.isPadding()); assertEquals(1, rtcpSdes.getCount()); assertEquals(RtcpHeader.RTCP_SDES, rtcpSdes.getPacketType()); assertEquals(28, rtcpSdes.getLength()); RtcpSdesChunk rtcpSdesChunk = rtcpSdes.getSdesChunks()[0]; assertNotNull(rtcpSdesChunk); assertEquals(266283887, rtcpSdesChunk.getSsrc()); assertEquals(2, rtcpSdesChunk.getItemCount()); RtcpSdesItem rtcpSdesItem = rtcpSdesChunk.getRtcpSdesItems()[0]; assertNotNull(rtcpSdesItem); assertEquals(RtcpSdesItem.RTCP_SDES_CNAME, rtcpSdesItem.getType()); assertEquals(14, rtcpSdesItem.getLength()); assertEquals("QTSS1262189851", rtcpSdesItem.getText()); rtcpSdesItem = rtcpSdesChunk.getRtcpSdesItems()[1]; assertNotNull(rtcpSdesItem); assertEquals(RtcpSdesItem.RTCP_SDES_END, rtcpSdesItem.getType()); RtcpAppDefined rtcpAppDefined = rtcpPacket.getAppDefined(); assertEquals(2, rtcpAppDefined.getVersion()); assertFalse(rtcpAppDefined.isPadding()); assertEquals(1, rtcpAppDefined.getCount()); assertEquals(RtcpHeader.RTCP_APP, rtcpAppDefined.getPacketType()); assertEquals(266283887, rtcpAppDefined.getSsrc()); assertEquals("qtsi", rtcpAppDefined.getName()); byte[] expected = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61, 0x74, 0x00, 0x04, 0x00, 0x00, 0x00, 0x14 }; java.util.Arrays.equals(expected, rtcpAppDefined.getData()); }