sfu: return VP8 munged header by value to avoid per-packet allocation (#4871)

CodecMunger.UpdateAndGet returned a freshly allocated slice for every
forwarded packet on every down track. Return the header in a fixed array
with a length instead and marshal into it with MarshalTo. TranslationParams
carries the array; WriteRTP slices it locally.

UpdateAndGet now allocates zero times per call (was one). Escape analysis
confirms TranslationParams stays on the stack.

Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Raja Subramanian
2026-09-15 21:34:10 +05:30
committed by GitHub
co-authored by Claude Fable 5.1
parent 08c5433449
commit 0392ca90b4
7 changed files with 66 additions and 40 deletions
+6 -1
View File
@@ -26,6 +26,9 @@ var (
ErrFilteredVP8TemporalLayer = errors.New("filtered VP8 temporal layer")
)
// MaxHeaderSize is the largest codec header the mungers produce (VP8: 6 bytes).
const MaxHeaderSize = 8
type CodecMunger interface {
GetState() any
SeedState(state any)
@@ -33,7 +36,9 @@ type CodecMunger interface {
SetLast(extPkt *buffer.ExtPacket)
UpdateOffsets(extPkt *buffer.ExtPacket)
UpdateAndGet(extPkt *buffer.ExtPacket, snOutOfOrder bool, snHasGap bool, maxTemporal int32) (int, []byte, error)
// UpdateAndGet returns the incoming codec header size and the munged
// header by value, so the per-packet path does not allocate.
UpdateAndGet(extPkt *buffer.ExtPacket, snOutOfOrder bool, snHasGap bool, maxTemporal int32) (int, [MaxHeaderSize]byte, int, error)
UpdateAndGetPadding(newPicture bool) ([]byte, error)
}