// initial length (SSRC and the terminating SDES item, a zero octet)
int sdesLength = 5;
for (int i=0; i<sdesItems.size(); i++)
{
SourceDescription sdesItem = (SourceDescription)sdesItems.elementAt(i);
if ( !onlyCNAME || (sdesItem.getType() == SourceDescription.SOURCE_DESC_CNAME) )
{
sdesLength += sdesItem.getDescription().getBytes("UTF-8").length + 2;
}
}
// do we need padding to next 32-bit boundary
int padding = 0;
if ( (sdesLength % 4) != 0 )
{
padding = 4 - (sdesLength % 4);
sdesLength += padding;
}
// write the rtcp sdes packet
output.writeByte(0x81);
output.writeByte(RTCPPacket.PT_SDES & 0xFF);
output.writeShort(sdesLength / 4);
// only one chunk
output.writeInt((int)(ssrc & 0xFFFFFFFF));
// write sdes item(s) for ssrc
for (int i=0; i<sdesItems.size(); i++)
{
SourceDescription sdesItem = (SourceDescription)sdesItems.elementAt(i);
if ( !onlyCNAME || (sdesItem.getType() == SourceDescription.SOURCE_DESC_CNAME) )
{
output.writeByte(sdesItem.getType() & 0xFF);
byte[] desc = sdesItem.getDescription().getBytes("UTF-8");
output.writeByte(desc.length & 0xFF);
output.write(desc);
}
}