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); }
private short ComputeOptDelay() { short num = 0; int num2 = 2147483647; int num3 = 0; int[] array = new int[3]; bool flag = false; int num4 = 0; int num5 = 0; JitterBuffer.TimingBuffer[] tb = this._tb; int num6 = 0; for (int i = 0; i < 3; i++) { num6 += tb[i].curr_count; } if (num6 == 0) { return(0); } float num7; if (this.latency_tradeoff != 0) { num7 = (float)this.latency_tradeoff * 100f / (float)num6; } else { num7 = (float)(this.auto_tradeoff * this.window_size / num6); } for (int i = 0; i < 3; i++) { array[i] = 0; } for (int i = 0; i < 40; i++) { int num8 = -1; int num9 = 32767; for (int j = 0; j < 3; j++) { if (array[j] < tb[j].filled && tb[j].timing[array[j]] < num9) { num8 = j; num9 = tb[j].timing[array[j]]; } } if (num8 == -1) { break; } if (i == 0) { num5 = num9; } num4 = num9; num9 = JitterBuffer.RoundDown(num9, this.delay_step); array[num8]++; int num10 = (int)((float)(-(float)num9) + num7 * (float)num3); if (num10 < num2) { num2 = num10; num = (short)num9; } num3++; if (num9 >= 0 && !flag) { flag = true; num3 += 4; } } int num11 = num4 - num5; this.auto_tradeoff = 1 + num11 / 40; if (num6 < 40 && num > 0) { return(0); } return(num); }