Skip to content

Commit

Permalink
reset the rtcp packet before put back to the pool
Browse files Browse the repository at this point in the history
  • Loading branch information
tyohan committed Sep 19, 2024
1 parent e5596f0 commit be62eca
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packet.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,17 @@ var (
// will be returned. Otherwise, the underlying type of the returned packet will be
// CompoundPacket.
func Unmarshal(rawData []byte) ([]Packet, error) {
// Preallocate a slice with a reasonable initial capacity
estimatedPackets := len(rawData) / 100 // Estimate based on average packet size
packets := make([]Packet, 0, estimatedPackets)

for len(rawData) != 0 {
p, processed, err := unmarshal(rawData)
if err != nil {
// Release already allocated packets in case of error
for _, packet := range packets {
packet.Release()
}
return nil, err
}

Expand Down Expand Up @@ -156,58 +162,72 @@ func unmarshal(rawData []byte) (packet Packet, bytesprocessed int, err error) {

// Implement the Release method for each concrete packet type

Check failure on line 163 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: comment on exported method SenderReport.Release should be of the form "Release ..." (revive)
func (p *SenderReport) Release() {
*p = SenderReport{} // Reset the packet
senderReportPool.Put(p)

Check warning on line 166 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L164-L166

Added lines #L164 - L166 were not covered by tests
}

func (p *ReceiverReport) Release() {

Check failure on line 169 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method ReceiverReport.Release should have comment or be unexported (revive)
*p = ReceiverReport{} // Reset the packet
receiverReportPool.Put(p)
}

func (p *SourceDescription) Release() {

Check failure on line 174 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method SourceDescription.Release should have comment or be unexported (revive)
*p = SourceDescription{} // Reset the packet
sourceDescriptionPool.Put(p)
}

func (p *Goodbye) Release() {

Check failure on line 179 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method Goodbye.Release should have comment or be unexported (revive)
*p = Goodbye{} // Reset the packet
goodbyePool.Put(p)
}

func (p *TransportLayerNack) Release() {

Check failure on line 184 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method TransportLayerNack.Release should have comment or be unexported (revive)
*p = TransportLayerNack{} // Reset the packet
transportLayerNackPool.Put(p)

Check warning on line 186 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L184-L186

Added lines #L184 - L186 were not covered by tests
}

func (p *RapidResynchronizationRequest) Release() {

Check failure on line 189 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method RapidResynchronizationRequest.Release should have comment or be unexported (revive)
*p = RapidResynchronizationRequest{} // Reset the packet
rapidResynchronizationRequestPool.Put(p)

Check warning on line 191 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L189-L191

Added lines #L189 - L191 were not covered by tests
}

func (p *TransportLayerCC) Release() {

Check failure on line 194 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method TransportLayerCC.Release should have comment or be unexported (revive)
*p = TransportLayerCC{} // Reset the packet
transportLayerCCPool.Put(p)

Check warning on line 196 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L194-L196

Added lines #L194 - L196 were not covered by tests
}

func (p *CCFeedbackReport) Release() {

Check failure on line 199 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method CCFeedbackReport.Release should have comment or be unexported (revive)
*p = CCFeedbackReport{} // Reset the packet
ccFeedbackReportPool.Put(p)

Check warning on line 201 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L199-L201

Added lines #L199 - L201 were not covered by tests
}

func (p *PictureLossIndication) Release() {

Check failure on line 204 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method PictureLossIndication.Release should have comment or be unexported (revive)
*p = PictureLossIndication{} // Reset the packet
pictureLossIndicationPool.Put(p)

Check warning on line 206 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L204-L206

Added lines #L204 - L206 were not covered by tests
}

func (p *SliceLossIndication) Release() {

Check failure on line 209 in packet.go

View workflow job for this annotation

GitHub Actions / lint / Go

exported: exported method SliceLossIndication.Release should have comment or be unexported (revive)
*p = SliceLossIndication{} // Reset the packet
sliceLossIndicationPool.Put(p)

Check warning on line 211 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L209-L211

Added lines #L209 - L211 were not covered by tests
}

func (p *ReceiverEstimatedMaximumBitrate) Release() {
*p = ReceiverEstimatedMaximumBitrate{} // Reset the packet
receiverEstimatedMaximumBitratePool.Put(p)

Check warning on line 216 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L214-L216

Added lines #L214 - L216 were not covered by tests
}

func (p *FullIntraRequest) Release() {
*p = FullIntraRequest{} // Reset the packet
fullIntraRequestPool.Put(p)

Check warning on line 221 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L219-L221

Added lines #L219 - L221 were not covered by tests
}

func (p *ExtendedReport) Release() {
*p = ExtendedReport{} // Reset the packet
extendedReportPool.Put(p)

Check warning on line 226 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L224-L226

Added lines #L224 - L226 were not covered by tests
}

func (p *ApplicationDefined) Release() {
*p = ApplicationDefined{} // Reset the packet
applicationDefinedPool.Put(p)

Check warning on line 231 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L229-L231

Added lines #L229 - L231 were not covered by tests
}

Expand All @@ -219,5 +239,6 @@ func (p *CompoundPacket) Release() {
}

func (p *RawPacket) Release() {
*p = RawPacket{} // Reset the packet
rawPacketPool.Put(p)

Check warning on line 243 in packet.go

View check run for this annotation

Codecov / codecov/patch

packet.go#L241-L243

Added lines #L241 - L243 were not covered by tests
}
7 changes: 6 additions & 1 deletion packet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,15 @@ func realPacket() []byte {
func BenchmarkUnmarshal(b *testing.B) {
packetData := realPacket()
for i := 0; i < b.N; i++ {
_, err := Unmarshal(packetData)
pkts, err := Unmarshal(packetData)
if err != nil {
b.Fatalf("Error unmarshalling packets: %s", err)
}

for _, pkt := range pkts {
pkt.Release()
}

}
}

Expand Down

0 comments on commit be62eca

Please sign in to comment.