示例#1
0
        public int Get(ref JitterBuffer.JitterBufferPacket packet, int desired_span, out int start_offset)
        {
            if (desired_span <= 0)
            {
                throw new ArgumentOutOfRangeException("desired_span");
            }
            start_offset = 0;
            int i;

            if (this.reset_state)
            {
                bool flag = false;
                long num  = 0L;
                for (i = 0; i < 200; i++)
                {
                    if (this.packets[i].data != null && (!flag || this.packets[i].timestamp < num))
                    {
                        num  = this.packets[i].timestamp;
                        flag = true;
                    }
                }
                if (!flag)
                {
                    packet.timestamp = 0L;
                    packet.span      = (long)this.interp_requested;
                    return(1);
                }
                this.reset_state       = false;
                this.pointer_timestamp = num;
                this.next_stop         = num;
            }
            this.last_returned_timestamp = this.pointer_timestamp;
            if (this.interp_requested != 0)
            {
                packet.timestamp        = this.pointer_timestamp;
                packet.span             = (long)this.interp_requested;
                this.pointer_timestamp += (long)this.interp_requested;
                packet.len              = 0;
                this.interp_requested   = 0;
                this.buffered           = packet.span - (long)desired_span;
                return(2);
            }
            i = 0;
            while (i < 200 && (this.packets[i].data == null || this.packets[i].timestamp != this.pointer_timestamp || this.packets[i].timestamp + this.packets[i].span < this.pointer_timestamp + (long)desired_span))
            {
                i++;
            }
            if (i == 200)
            {
                i = 0;
                while (i < 200 && (this.packets[i].data == null || this.packets[i].timestamp > this.pointer_timestamp || this.packets[i].timestamp + this.packets[i].span < this.pointer_timestamp + (long)desired_span))
                {
                    i++;
                }
            }
            if (i == 200)
            {
                i = 0;
                while (i < 200 && (this.packets[i].data == null || this.packets[i].timestamp > this.pointer_timestamp || this.packets[i].timestamp + this.packets[i].span <= this.pointer_timestamp))
                {
                    i++;
                }
            }
            if (i == 200)
            {
                bool flag2 = false;
                long num2  = 0L;
                long num3  = 0L;
                int  num4  = 0;
                for (i = 0; i < 200; i++)
                {
                    if (this.packets[i].data != null && this.packets[i].timestamp < this.pointer_timestamp + (long)desired_span && this.packets[i].timestamp >= this.pointer_timestamp && (!flag2 || this.packets[i].timestamp < num2 || (this.packets[i].timestamp == num2 && this.packets[i].span > num3)))
                    {
                        num2  = this.packets[i].timestamp;
                        num3  = this.packets[i].span;
                        num4  = i;
                        flag2 = true;
                    }
                }
                if (flag2)
                {
                    i = num4;
                }
            }
            if (i != 200)
            {
                this.lost_count = 0;
                if (this.arrival[i] != 0L)
                {
                    this.UpdateTimings((int)this.packets[i].timestamp - (int)this.arrival[i] - this.buffer_margin);
                }
                if (this.DestroyBufferCallback != null)
                {
                    packet.data = this.packets[i].data;
                    packet.len  = this.packets[i].len;
                }
                else
                {
                    if (this.packets[i].len <= packet.len)
                    {
                        packet.len = this.packets[i].len;
                    }
                    for (long num5 = 0L; num5 < (long)packet.len; num5 += 1L)
                    {
                        checked
                        {
                            packet.data[(int)((IntPtr)num5)] = this.packets[i].data[(int)((IntPtr)num5)];
                        }
                    }
                    this.FreeBuffer(this.packets[i].data);
                }
                this.packets[i].data = null;
                int num6 = (int)this.packets[i].timestamp - (int)this.pointer_timestamp;
                if (start_offset != 0)
                {
                    start_offset = num6;
                }
                packet.timestamp             = this.packets[i].timestamp;
                this.last_returned_timestamp = packet.timestamp;
                packet.span            = this.packets[i].span;
                packet.sequence        = this.packets[i].sequence;
                packet.user_data       = this.packets[i].user_data;
                packet.len             = this.packets[i].len;
                this.pointer_timestamp = this.packets[i].timestamp + this.packets[i].span;
                this.buffered          = packet.span - (long)desired_span;
                if (start_offset != 0)
                {
                    this.buffered += (long)start_offset;
                }
                return(0);
            }
            this.lost_count++;
            short num7 = this.ComputeOptDelay();

            if (num7 < 0)
            {
                this.ShiftTimings((short)-num7);
                packet.timestamp = this.pointer_timestamp;
                packet.span      = (long)(-(long)num7);
                packet.len       = 0;
                this.buffered    = packet.span - (long)desired_span;
                return(2);
            }
            packet.timestamp        = this.pointer_timestamp;
            desired_span            = JitterBuffer.RoundDown(desired_span, this.concealment_size);
            packet.span             = (long)desired_span;
            this.pointer_timestamp += (long)desired_span;
            packet.len              = 0;
            this.buffered           = packet.span - (long)desired_span;
            return(1);
        }
示例#2
0
        public void Put(JitterBuffer.JitterBufferPacket packet)
        {
            if (!this.reset_state)
            {
                for (int i = 0; i < 200; i++)
                {
                    if (this.packets[i].data != null && this.packets[i].timestamp + this.packets[i].span <= this.pointer_timestamp)
                    {
                        if (this.DestroyBufferCallback != null)
                        {
                            this.DestroyBufferCallback(this.packets[i].data);
                        }
                        else
                        {
                            this.FreeBuffer(this.packets[i].data);
                        }
                        this.packets[i].data = null;
                    }
                }
            }
            bool flag;

            if (!this.reset_state && packet.timestamp < this.next_stop)
            {
                this.UpdateTimings((int)packet.timestamp - (int)this.next_stop - this.buffer_margin);
                flag = true;
            }
            else
            {
                flag = false;
            }
            if (this.lost_count > 20)
            {
                this.Reset();
            }
            if (this.reset_state || packet.timestamp + packet.span + (long)this.delay_step >= this.pointer_timestamp)
            {
                int i = 0;
                while (i < 200 && this.packets[i].data != null)
                {
                    i++;
                }
                if (i == 200)
                {
                    long timestamp = this.packets[0].timestamp;
                    i = 0;
                    for (int j = 1; j < 200; j++)
                    {
                        if (this.packets[i].data == null || this.packets[j].timestamp < timestamp)
                        {
                            timestamp = this.packets[j].timestamp;
                            i         = j;
                        }
                    }
                    if (this.DestroyBufferCallback != null)
                    {
                        this.DestroyBufferCallback(this.packets[i].data);
                    }
                    else
                    {
                        this.FreeBuffer(this.packets[i].data);
                    }
                    this.packets[i].data = null;
                }
                if (this.DestroyBufferCallback != null)
                {
                    this.packets[i].data = packet.data;
                }
                else
                {
                    this.packets[i].data = this.AllocBuffer((long)packet.len);
                    for (int j = 0; j < packet.len; j++)
                    {
                        this.packets[i].data[j] = packet.data[j];
                    }
                }
                this.packets[i].timestamp = packet.timestamp;
                this.packets[i].span      = packet.span;
                this.packets[i].len       = packet.len;
                this.packets[i].sequence  = packet.sequence;
                this.packets[i].user_data = packet.user_data;
                if (this.reset_state || flag)
                {
                    this.arrival[i] = 0L;
                    return;
                }
                this.arrival[i] = this.next_stop;
            }
        }