public byte[] Transform(byte[] pkt, int offset, int length) { // Updates the contents of raw packet with new incoming packet this.rawPacket.Wrap(pkt, offset, length); // Associate packet to a crypto context long ssrc = rawPacket.GetSSRC(); SrtpCryptoContext context = null; contexts.TryGetValue(ssrc, out context); if (context == null) { context = forwardEngine.GetDefaultContext().deriveContext(ssrc, 0, 0); context.DeriveSrtpKeys(0); contexts[ssrc] = context; } // Transform RTP packet into SRTP context.TransformPacket(this.rawPacket); return(this.rawPacket.GetData()); }
public byte[] Transform(byte[] pkt, int offset, int length) { var isLocked = Interlocked.CompareExchange(ref _isLocked, 1, 0) != 0; try { // Updates the contents of raw packet with new incoming packet var rawPacket = !isLocked ? this.rawPacket : new RawPacket(); rawPacket.Wrap(pkt, offset, length); // Associate packet to a crypto context long ssrc = rawPacket.GetSSRC(); SrtpCryptoContext context = null; contexts.TryGetValue(ssrc, out context); if (context == null) { context = forwardEngine.GetDefaultContext().deriveContext(ssrc, 0, 0); context.DeriveSrtpKeys(0); contexts.AddOrUpdate(ssrc, context, (a, b) => context); } // Transform RTP packet into SRTP context.TransformPacket(rawPacket); byte[] result = rawPacket.GetData(); return(result); } finally { //Unlock if (!isLocked) { Interlocked.CompareExchange(ref _isLocked, 0, 1); } } }