Ejemplo n.º 1
0
        public byte[] Transform(byte[] pkt, int offset, int length)
        {
            // Wrap the data into raw packet for readable format
            this.packet.Wrap(pkt, offset, length);

            // Associate the packet with its encryption context
            long ssrc = this.packet.GetRTCPSSRC();
            SrtcpCryptoContext context = null;

            contexts.TryGetValue(ssrc, out context);

            if (context == null)
            {
                context = forwardEngine.GetDefaultContextControl().DeriveContext(ssrc);
                context.DeriveSrtcpKeys();
                contexts.AddOrUpdate(ssrc, context, (a, b) => context);
            }

            // Secure packet into SRTCP format
            context.TransformPacket(packet);
            return(packet.GetData());
        }
Ejemplo n.º 2
0
        public byte[] Transform(byte[] pkt, int offset, int length)
        {
            var isLocked = Interlocked.CompareExchange(ref _isLocked, 1, 0) != 0;

            try
            {
                // Wrap the data into raw packet for readable format
                var packet = !isLocked ? this.packet : new RawPacket();
                packet.Wrap(pkt, offset, length);

                // Associate the packet with its encryption context
                long ssrc = packet.GetRTCPSSRC();
                SrtcpCryptoContext context = null;
                contexts.TryGetValue(ssrc, out context);

                if (context == null)
                {
                    context = forwardEngine.GetDefaultContextControl().DeriveContext(ssrc);
                    context.DeriveSrtcpKeys();
                    contexts.AddOrUpdate(ssrc, context, (a, b) => context);
                }

                // Secure packet into SRTCP format
                context.TransformPacket(packet);
                byte[] result = packet.GetData();

                return(result);
            }
            finally
            {
                //Unlock
                if (!isLocked)
                {
                    Interlocked.CompareExchange(ref _isLocked, 0, 1);
                }
            }
        }