|
66 | 66 | // order, and allows removing in either sequence number order or via a |
67 | 67 | // provided timestamp. |
68 | 68 | type JitterBuffer struct { |
69 | | - packets *PriorityQueue |
| 69 | + packets *RBTree |
70 | 70 | minStartCount uint16 |
71 | 71 | overflowLen uint16 |
72 | 72 | lastSequence uint16 |
@@ -132,13 +132,14 @@ func (jb *JitterBuffer) PlayoutHead() uint16 { |
132 | 132 | return jb.playoutHead |
133 | 133 | } |
134 | 134 |
|
| 135 | +// Length returns the current number of packets in the buffer. |
135 | 136 | func (jb *JitterBuffer) Length() uint16 { |
136 | 137 | jb.mutex.Lock() |
137 | 138 | defer jb.mutex.Unlock() |
138 | 139 | return jb.packets.Length() |
139 | 140 | } |
140 | 141 |
|
141 | | -// SetPlayoutHead allows you to manually specify the packet you wish to pop next |
| 142 | +// SetPlayoutHead allows you to manually specify the packet you wish to pop next. |
142 | 143 | // If you have encountered a packet that hasn't resolved you can skip it. |
143 | 144 | func (jb *JitterBuffer) SetPlayoutHead(playoutHead uint16) { |
144 | 145 | jb.mutex.Lock() |
@@ -177,7 +178,7 @@ func (jb *JitterBuffer) Push(packet *rtp.Packet) { |
177 | 178 | } |
178 | 179 |
|
179 | 180 | jb.updateStats(packet.SequenceNumber) |
180 | | - jb.packets.Push(packet, packet.SequenceNumber) |
| 181 | + jb.packets.Push(packet) |
181 | 182 | jb.updateState() |
182 | 183 | } |
183 | 184 |
|
@@ -259,8 +260,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) { |
259 | 260 | // PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence |
260 | 261 | // without removing it from the buffer. |
261 | 262 | func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) { |
262 | | - jb.mutex.Lock() |
263 | | - defer jb.mutex.Unlock() |
264 | 263 | packet, err := jb.packets.Find(sq) |
265 | 264 | if err != nil { |
266 | 265 | return nil, err |
|
0 commit comments