Add padding when creating extension header and remove extensions after process the sound levels coming from the focus.

cusax-fix
Damian Minkov 16 years ago
parent b29c174c95
commit f6113a5000

@ -10,7 +10,6 @@
import java.net.*;
import javax.media.protocol.*;
import javax.media.rtp.*;
/**
* @author Bing SU (nova.su@gmail.com)

@ -587,6 +587,26 @@ public void addExtension(byte[] extBuff, int newExtensionLen)
this.length = newBuffLen - offset;
}
/**
* Removes the extension from the packet and its header.
*/
public void removeExtension()
{
if(!getExtensionBit())
return;
int payloadOffset = offset + getHeaderLength();
int extHeaderLen = getExtensionLength() + EXT_HEADER_SIZE;
System.arraycopy(buffer, payloadOffset,
buffer, payloadOffset - extHeaderLen, getPayloadLength());
this.length -= extHeaderLen;
setExtensionBit(false);
}
/**
* Returns a bi-dimensional byte array containing a map binding CSRC IDs to
* audio levels as reported by the remote party that sent this packet.

@ -120,6 +120,8 @@ public RawPacket reverseTransform(RawPacket pkt)
csrcLevelDispatcher.addLevels(levels);
}
pkt.removeExtension();
}
return pkt;
}
@ -161,7 +163,6 @@ public synchronized RawPacket transform(RawPacket pkt)
byte[] levelsExt = createLevelExtensionBuffer(csrcList);
pkt.addExtension(levelsExt, extensionBuffLen);
}
return pkt;
@ -208,6 +209,15 @@ private byte[] createLevelExtensionBuffer(long[] csrcList)
{
int buffLen = 1 + //CSRC one byte extension hdr
csrcList.length;
// calculate extension padding
int padLen = 4 - buffLen%4;
if(padLen == 4)
padLen = 0;
buffLen += padLen;
byte[] extensionBuff = getExtensionBuff(buffLen);
extensionBuff[0] =

@ -347,26 +347,30 @@ public void setROC(int rocIn) {
*
* @param pkt the RTP packet that is going to be sent out
*/
public void transformPacket(RawPacket pkt) {
public void transformPacket(RawPacket pkt)
{
/* Encrypt the packet using Counter Mode encryption */
if (policy.getEncType() == SRTPPolicy.AESCM_ENCRYPTION) {
if (policy.getEncType() == SRTPPolicy.AESCM_ENCRYPTION)
{
processPacketAESCM(pkt);
}
/* Encrypt the packet using F8 Mode encryption */
else if (policy.getEncType() == SRTPPolicy.AESF8_ENCRYPTION) {
else if (policy.getEncType() == SRTPPolicy.AESF8_ENCRYPTION)
{
/* Encrypt the packet using F8 Mode encryption */
processPacketAESF8(pkt);
}
/* Authenticate the packet */
if (policy.getAuthType() == SRTPPolicy.HMACSHA1_AUTHENTICATION) {
if (policy.getAuthType() == SRTPPolicy.HMACSHA1_AUTHENTICATION)
{
authenticatePacketHMCSHA1(pkt, roc);
pkt.append(tagStore, policy.getAuthTagLength());
}
/* Update the ROC if necessary */
int seqNo = pkt.getSequenceNumber();
if (seqNo == 0xFFFF) {
if (seqNo == 0xFFFF)
{
roc++;
}
}
@ -509,7 +513,7 @@ public void processPacketAESF8(RawPacket pkt) {
*/
private void authenticatePacketHMCSHA1(RawPacket pkt, int rocIn)
{
hmacSha1.update(pkt.getBuffer(), 0, pkt.getLength());
hmacSha1.update(pkt.getBuffer(), pkt.getOffset(), pkt.getLength());
// byte[] rb = new byte[4];
rbStore[0] = (byte) (rocIn >> 24);
rbStore[1] = (byte) (rocIn >> 16);

Loading…
Cancel
Save