Do not bind buffer if codec is invalid. (#4028)

Seeing cases of codec with zero clock rate. Do not bind to those.
This commit is contained in:
Raja Subramanian
2025-10-25 14:30:30 +05:30
committed by GitHub
parent cef6fdb7b6
commit a2ce73e0d0
2 changed files with 29 additions and 4 deletions
+18 -2
View File
@@ -53,6 +53,10 @@ const (
InitPacketBufferSizeAudio = 70
)
var (
errInvalidCodec = errors.New("invalid codec")
)
type pendingPacket struct {
arrivalTime int64
packet []byte
@@ -214,11 +218,16 @@ func (b *Buffer) SetAudioLossProxying(enable bool) {
b.enableAudioLossProxying = enable
}
func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapability, bitrates int) {
func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapability, bitrates int) error {
b.Lock()
defer b.Unlock()
if b.bound {
return
return nil
}
if codec.ClockRate == 0 {
b.logger.Warnw("invalid codec", nil, "params", params, "codec", codec, "bitrates", bitrates)
return errInvalidCodec
}
b.rtpStats = rtpstats.NewRTPStatsReceiver(rtpstats.RTPStatsParams{
@@ -322,6 +331,8 @@ func (b *Buffer) Bind(params webrtc.RTPParameters, codec webrtc.RTPCodecCapabili
if mime.IsMimeTypeVideo(b.mime) {
go b.seedKeyFrame(b.keyFrameSeederGeneration.Inc())
}
return nil
}
func (b *Buffer) OnCodecChange(fn func(webrtc.RTPCodecParameters)) {
@@ -460,6 +471,11 @@ func (b *Buffer) writeRTX(rtxPkt *rtp.Packet, arrivalTime int64) (n int, err err
b.rtxPktBuf = make([]byte, bucket.MaxPktSize)
}
if len(rtxPkt.Payload) < 2 {
b.logger.Warnw("rtx payload too short", nil, "size", len(rtxPkt.Payload))
return
}
repairedPkt := *rtxPkt
repairedPkt.PayloadType = b.payloadType
repairedPkt.SequenceNumber = binary.BigEndian.Uint16(rtxPkt.Payload[:2])