Skip to content

Commit

Permalink
jitter buffer backports
Browse files Browse the repository at this point in the history
commit f718b7f
Author: David Colburn <[email protected]>
Date:   Thu Mar 28 13:52:50 2024 -0400

    fix jitter buffer panic (livekit#432)

commit 7ca41b6
Author: David Colburn <[email protected]>
Date:   Thu Jan 18 14:01:04 2024 -0800

    fix panic (livekit#383)

commit 167f58a
Author: David Colburn <[email protected]>
Date:   Mon Jan 15 21:34:41 2024 -0800

    remove packet loss logging (livekit#377)

    * remove packet loss logging

    * unused function
  • Loading branch information
aet committed May 26, 2024
1 parent 4d884cf commit 1840aa9
Showing 1 changed file with 1 addition and 40 deletions.
41 changes: 1 addition & 40 deletions pkg/jitter/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package jitter

import (
"fmt"
"sync"
"time"

Expand Down Expand Up @@ -111,12 +110,6 @@ func (b *Buffer) Push(pkt *rtp.Packet) {
// drop if packet comes before previously pushed packet
if !p.padding {
b.packetsDropped++
b.logger.Debugw("packet dropped",
"sequence number", pkt.SequenceNumber,
"timestamp", pkt.Timestamp,
"reason", "too late",
"minimum sequence number", b.prevSN+1,
)
if b.onPacketDropped != nil {
b.onPacketDropped()
}
Expand Down Expand Up @@ -404,30 +397,14 @@ func (b *Buffer) drop() {
// on sequence number reset, skip callback because we don't know whether we lost any
if !b.head.reset {
b.packetsDropped++
b.logger.Debugw("packet dropped",
"sequence number", formatSN(b.prevSN+1, b.head.packet.SequenceNumber-1),
"reason", "lost",
)
dropped = true
}

count := 0
from := b.head.packet.SequenceNumber
ts := b.head.packet.Timestamp
for b.head != nil && !b.head.start && before32(b.head.packet.Timestamp-b.maxSampleSize, b.minTS) {
dropped = true
count++
b.packetsDropped++
b.dropHead()
}
if count > 0 {
b.logger.Debugw("packet dropped",
"sequence number", formatSN(from, b.head.packet.SequenceNumber-1),
"timestamp", ts,
"reason", "incomplete sample",
"minimum timestamp", b.minTS,
)
}

b.prevSN = b.head.packet.SequenceNumber - 1
}
Expand All @@ -441,7 +418,6 @@ func (b *Buffer) drop() {
// drop all packets within this sample
dropped = true
count := 0
from := c.packet.SequenceNumber
ts := c.packet.Timestamp
for {
b.packetsDropped++
Expand All @@ -450,17 +426,10 @@ func (b *Buffer) drop() {
c = b.head

// break if head is part of a new sample
if b.head.packet.Timestamp != ts {
if b.head == nil || b.head.packet.Timestamp != ts {
break
}
}

b.logger.Debugw("packet dropped",
"sequence number", formatSN(from, b.head.packet.SequenceNumber-1),
"timestamp", ts,
"reason", "incomplete sample",
"minimum timestamp", b.minTS,
)
}

if dropped && b.onPacketDropped != nil {
Expand Down Expand Up @@ -525,11 +494,3 @@ func before32(a, b uint32) bool {
func outsideRange(a, b uint16) bool {
return a-b > 3000 && b-a > 3000
}

func formatSN(from, to uint16) string {
if from == to {
return fmt.Sprint(from)
} else {
return fmt.Sprintf("%d-%d", from, to)
}
}

0 comments on commit 1840aa9

Please sign in to comment.