RtcpPacket implements Serializable { public int encode(byte[] rawData, int offSet) { int initalOffSet = offSet; if (this.senderReport != null) { packetCount++; offSet = this.senderReport.encode(rawData, offSet); } if (this.receiverReport != null) { packetCount++; offSet = this.receiverReport.encode(rawData, offSet); } if (this.sdes != null) { packetCount++; offSet = this.sdes.encode(rawData, offSet); } if (this.appDefined != null) { packetCount++; offSet = this.appDefined.encode(rawData, offSet); } if (this.bye != null) { packetCount++; offSet = this.bye.encode(rawData, offSet); } this.size = offSet - initalOffSet; 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 testEncode() { RtcpSenderReport rtcpSenderReport = new RtcpSenderReport(false, 266283887, 3471178652l, 133143986, 1586529211, 1, 11); RtcpSdes rtcpSdes = new RtcpSdes(false); RtcpSdesItem rtcpSdesItem = new RtcpSdesItem(RtcpSdesItem.RTCP_SDES_CNAME, "QTSS1262189851"); RtcpSdesChunk rtcpSdesChunk = new RtcpSdesChunk(266283887); rtcpSdesChunk.addRtcpSdesItem(rtcpSdesItem); rtcpSdes.addRtcpSdesChunk(rtcpSdesChunk); byte[] appData = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x61, 0x74, 0x00, 0x04, 0x00, 0x00, 0x00, 0x14 }; RtcpAppDefined rtcpAppDefined = new RtcpAppDefined(false, 1, 266283887, "qtsi", appData); RtcpPacket rtcpPacket = new RtcpPacket(rtcpSenderReport, null, rtcpSdes, null, rtcpAppDefined); byte[] rawData = new byte[256]; int length = rtcpPacket.encode(rawData, 0); assertEquals(p.length, length); for (int i = 0; i < p.length; i++) { assertEquals(p[i], rawData[i]); } }