示例#1
0
        public byte[] ReverseTransform(byte[] pkt, int offset, int length)
        {
            // wrap 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 = reverseEngine.GetDefaultContextControl().DeriveContext(ssrc);
                context.DeriveSrtcpKeys();
                contexts[ssrc] = context;
            }

            // Decode packet to RTCP format
            bool reversed = context.ReverseTransformPacket(packet);

            if (reversed)
            {
                return(packet.GetData());
            }

            return(null);
        }
        public byte[] ReverseTransform(byte[] pkt, int offset, int length)
        {
            var isLocked = Interlocked.CompareExchange(ref _isLocked, 1, 0) != 0;

            try
            {
                // wrap 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 = reverseEngine.GetDefaultContextControl().DeriveContext(ssrc);
                    context.DeriveSrtcpKeys();
                    contexts.AddOrUpdate(ssrc, context, (a, b) => context);
                }

                // Decode packet to RTCP format
                byte[] result   = null;
                bool   reversed = context.ReverseTransformPacket(packet);
                if (reversed)
                {
                    result = packet.GetData();
                }
                return(result);
            }
            finally
            {
                //Unlock
                if (!isLocked)
                {
                    Interlocked.CompareExchange(ref _isLocked, 0, 1);
                }
            }
        }
示例#3
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());
        }