コード例 #1
0
ファイル: SrtcpTransformer.cs プロジェクト: xyanlong/AKStream
        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);
        }
コード例 #2
0
        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);
                }
            }
        }