Files
livekit/pkg/sfu/flexfec/decoder_benchmark_test.go
6342d8fd1b Enable upstream FlexFEC03 (#4845)
* Add upstream FlexFEC recovery support

* Guard short TWCC extensions in FEC packets

* Release completed FlexFEC states

* Validate FlexFEC payload type range

* Invoke FEC callbacks after unlocking

* Reduce FlexFEC protection state allocations

* Avoid allocations for complete FlexFEC packets

* Optimize ordered FlexFEC packet insertion

* Reuse RTP packet storage for FlexFEC recovery

* Limit pending FlexFEC repair packets

* Lower FlexFEC repair window to two seconds

* Harden upstream FlexFEC handling

* Test FlexFEC with E2EE media

* Fix FlexFEC negotiation with libwebrtc publishers

* Enhance payload length validation in decoder

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* remove the ability to configure payload type for FlexFEC

* moved some helpers into protocol

* Handle big gaps in media sequence numbers

Reset buffers when a big gap in media sequence numbers is detected.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* bump protocol & psrpc deps

* Handle FEC packet recovery failure

Increment FEC packets discarded counter and remove packet.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* do not NACK on fec recovered packet (#4896)

* do not NACK on fec recovered packet

* fix test race in CI

* Fix FEC write return after merging RTX feedback changes

* PR fixes for FlexFEC implementation (#4898)

* do not NACK on fec recovered packet

* refactor common code into unlockAndInvokeFECRecovery

* add FEC stats to RTPStats

* add log for when fecdecoder unavailable after creation

* rename markAsFECRepair to setFECRepairBufferLimit for clarity

* refactor packet generation for tests into util

* fix test race in CI

* move the unlocks back inline for readability

* update RTPstats

* Fix FEC write return after merging RTX feedback changes

* Use shared RTP packet helper in merged FEC NACK test

* Remove redundant return from FEC write handler

* packet post process (#5020)

* packet post process

* remove redundant writeRTX

* send out RTCP (NACK and RR) from packetPostProcess only

* handle FEC decoder on receiver restart (#5032)

* handle FEC decoder on receiver restart

* move onStreamRestartLocked into BufferBaseParams

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Raja Subramanian <raja.gobi@tutanota.com>
2026-10-22 13:58:04 -07:00

115 lines
3.1 KiB
Go

// Copyright 2026 LiveKit, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package flexfec
import (
"testing"
pionflexfec "github.com/pion/interceptor/pkg/flexfec"
"github.com/pion/rtp"
"github.com/livekit/protocol/logger"
)
func benchmarkMediaPackets(count, payloadSize int) []rtp.Packet {
packets := make([]rtp.Packet, count)
for i := range packets {
packets[i] = rtp.Packet{
Header: rtp.Header{
Version: 2,
PayloadType: testMediaPT,
SequenceNumber: 100 + uint16(i),
Timestamp: 3000 * uint32(i),
SSRC: testMediaSSRC,
},
Payload: make([]byte, payloadSize),
}
}
return packets
}
func benchmarkMediaLookup(media []rtp.Packet, missingIndex int) MediaPacketLookup {
packets := make(map[uint16][]byte, len(media))
for i := range media {
if i == missingIndex {
continue
}
raw, err := media[i].Marshal()
if err != nil {
panic(err)
}
packets[media[i].SequenceNumber] = raw
}
return func(sequenceNumber uint16, dst []byte) (int, error) {
packet, ok := packets[sequenceNumber]
if !ok {
return 0, errTestMediaPacketNotFound
}
return copy(dst, packet), nil
}
}
func BenchmarkDecoderMediaSteadyState1200(b *testing.B) {
decoder := NewDecoder(testFECSSRC, testMediaSSRC, nil, logger.GetLogger())
packet := benchmarkMediaPackets(1, 1200)[0]
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
packet.SequenceNumber = uint16(i)
packet.Timestamp = uint32(i) * 3000
decoder.DecodeFEC(&packet)
}
}
func BenchmarkDecoderCompleteWindow10x1200(b *testing.B) {
media := benchmarkMediaPackets(10, 1200)
fecPackets := pionflexfec.NewFlexEncoder03(testFECPT, testFECSSRC).EncodeFec(media, 1)
lookup := benchmarkMediaLookup(media, -1)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
decoder := NewDecoder(testFECSSRC, testMediaSSRC, lookup, logger.GetLogger())
for j := range media {
decoder.DecodeFEC(&media[j])
}
if recovered := decoder.DecodeFEC(&fecPackets[0]); len(recovered) != 0 {
b.Fatalf("expected no recovered packets, got %d", len(recovered))
}
}
}
func BenchmarkDecoderRecoveryWindow10x1200(b *testing.B) {
media := benchmarkMediaPackets(10, 1200)
fecPackets := pionflexfec.NewFlexEncoder03(testFECPT, testFECSSRC).EncodeFec(media, 1)
lookup := benchmarkMediaLookup(media, 4)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
decoder := NewDecoder(testFECSSRC, testMediaSSRC, lookup, logger.GetLogger())
for j := range media {
if j != 4 {
decoder.DecodeFEC(&media[j])
}
}
if recovered := decoder.DecodeFEC(&fecPackets[0]); len(recovered) != 1 {
b.Fatalf("expected one recovered packet, got %d", len(recovered))
}
}
}