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:
co-authored by
Claude Fable 5.1
parent
08c5433449
commit
0392ca90b4
@@ -1044,10 +1044,11 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
codecBytes := tp.codecHeader()
|
||||
poolEntity := PacketFactory.Get().(*[]byte)
|
||||
payload := *poolEntity
|
||||
copy(payload, tp.codecBytes)
|
||||
n := copy(payload[len(tp.codecBytes):], extPkt.Packet.Payload[tp.incomingHeaderSize:])
|
||||
copy(payload, codecBytes)
|
||||
n := copy(payload[len(codecBytes):], extPkt.Packet.Payload[tp.incomingHeaderSize:])
|
||||
if n != len(extPkt.Packet.Payload[tp.incomingHeaderSize:]) {
|
||||
d.params.Logger.Errorw(
|
||||
"payload overflow", errPayloadOverflow,
|
||||
@@ -1057,7 +1058,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) int32 {
|
||||
PacketFactory.Put(poolEntity)
|
||||
return 0
|
||||
}
|
||||
payload = payload[:len(tp.codecBytes)+n]
|
||||
payload = payload[:len(codecBytes)+n]
|
||||
|
||||
trailerStripped := 0
|
||||
if d.params.StripPacketTrailer {
|
||||
@@ -1129,7 +1130,7 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) int32 {
|
||||
tp.rtp.extTimestamp,
|
||||
hdr.Marker,
|
||||
int8(layer),
|
||||
payload[:len(tp.codecBytes)],
|
||||
payload[:len(codecBytes)],
|
||||
tp.incomingHeaderSize,
|
||||
tp.ddBytes,
|
||||
actBytes,
|
||||
|
||||
Reference in New Issue
Block a user