Skip to content

Commit c44c340

Browse files
authored
packetPool: flush old packets whenever new payload starts (#21)
1 parent 077af8e commit c44c340

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

packet_pool.go

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ func (b *packetPool) add(p *Packet) (ps []*Packet) {
5353
return
5454
}
5555

56-
// Add packet
57-
if len(mps) > 0 || (len(mps) == 0 && p.Header.PayloadUnitStartIndicator) {
58-
mps = append(mps, p)
59-
}
60-
61-
// Check payload unit start indicator
62-
if p.Header.PayloadUnitStartIndicator && len(mps) > 1 {
63-
ps = mps[:len(mps)-1]
56+
// Flush buffer if new payload starts here
57+
if p.Header.PayloadUnitStartIndicator {
58+
ps = mps
6459
mps = []*Packet{p}
60+
} else {
61+
mps = append(mps, p)
6562
}
6663

6764
// Assign

packet_pool_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func TestPacketPool(t *testing.T) {
2525
ps := b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 0, HasPayload: true, PID: 1}})
2626
assert.Len(t, ps, 0)
2727
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 1, HasPayload: true, PayloadUnitStartIndicator: true, PID: 1}})
28-
assert.Len(t, ps, 0)
28+
assert.Len(t, ps, 1)
2929
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 1, HasPayload: true, PayloadUnitStartIndicator: true, PID: 2}})
3030
assert.Len(t, ps, 0)
3131
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 2, HasPayload: true, PID: 1}})
@@ -35,7 +35,7 @@ func TestPacketPool(t *testing.T) {
3535
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 5, HasPayload: true, PID: 1}})
3636
assert.Len(t, ps, 0)
3737
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 6, HasPayload: true, PayloadUnitStartIndicator: true, PID: 1}})
38-
assert.Len(t, ps, 0)
38+
assert.Len(t, ps, 1)
3939
ps = b.add(&Packet{Header: &PacketHeader{ContinuityCounter: 7, HasPayload: true, PID: 1}})
4040
assert.Len(t, ps, 0)
4141
ps = b.dump()

0 commit comments

Comments
 (0)