|
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,7 +132,15 @@ func (jb *JitterBuffer) PlayoutHead() uint16 { |
132 | 132 | return jb.playoutHead |
133 | 133 | } |
134 | 134 |
|
135 | | -// SetPlayoutHead allows you to manually specify the packet you wish to pop next |
| 135 | +// Length returns the current number of packets in the buffer. |
| 136 | +func (jb *JitterBuffer) Length() uint16 { |
| 137 | + jb.mutex.Lock() |
| 138 | + defer jb.mutex.Unlock() |
| 139 | + |
| 140 | + return jb.packets.Length() |
| 141 | +} |
| 142 | + |
| 143 | +// SetPlayoutHead allows you to manually specify the packet you wish to pop next. |
136 | 144 | // If you have encountered a packet that hasn't resolved you can skip it. |
137 | 145 | func (jb *JitterBuffer) SetPlayoutHead(playoutHead uint16) { |
138 | 146 | jb.mutex.Lock() |
@@ -171,7 +179,7 @@ func (jb *JitterBuffer) Push(packet *rtp.Packet) { |
171 | 179 | } |
172 | 180 |
|
173 | 181 | jb.updateStats(packet.SequenceNumber) |
174 | | - jb.packets.Push(packet, packet.SequenceNumber) |
| 182 | + jb.packets.Push(packet) |
175 | 183 | jb.updateState() |
176 | 184 | } |
177 | 185 |
|
@@ -253,8 +261,6 @@ func (jb *JitterBuffer) PopAtSequence(sq uint16) (*rtp.Packet, error) { |
253 | 261 | // PeekAtSequence will return an RTP packet from the jitter buffer at the specified Sequence |
254 | 262 | // without removing it from the buffer. |
255 | 263 | func (jb *JitterBuffer) PeekAtSequence(sq uint16) (*rtp.Packet, error) { |
256 | | - jb.mutex.Lock() |
257 | | - defer jb.mutex.Unlock() |
258 | 264 | packet, err := jb.packets.Find(sq) |
259 | 265 | if err != nil { |
260 | 266 | return nil, err |
|
0 commit comments