Validate RTP packets. (#2778)
* Validate RTP packets. Check version, payload type (if available) and SSRC (if available) and drop bad packets. And let repair mechanisms take effect for those packets. * address data race reported by test * fix an unlock and test packets
This commit is contained in:
@@ -15,9 +15,11 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/pion/interceptor"
|
||||
"github.com/pion/rtp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
)
|
||||
|
||||
@@ -51,3 +53,20 @@ func GetHeaderExtensionID(extensions []interceptor.RTPHeaderExtension, extension
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// ValidateRTPPacket checks for a valid RTP packet and returns an error if fields are incorrect
|
||||
func ValidateRTPPacket(pkt *rtp.Packet, expectedPayloadType uint8, expectedSSRC uint32) error {
|
||||
if pkt.Version != 2 {
|
||||
return errors.New("invalid RTP version")
|
||||
}
|
||||
|
||||
if expectedPayloadType != 0 && pkt.PayloadType != expectedPayloadType {
|
||||
return errors.New("invalid RTP payload type")
|
||||
}
|
||||
|
||||
if expectedSSRC != 0 && pkt.SSRC != expectedSSRC {
|
||||
return errors.New("invalid RTP SSRC")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user