package webrtc
import (
"fmt"
"strings"
"github.com/pion/webrtc/v4/internal/fmtp"
)
type RTPCodecType int
const (
RTPCodecTypeUnknown RTPCodecType = iota
RTPCodecTypeAudio
RTPCodecTypeVideo
)
func (t RTPCodecType ) String () string {
switch t {
case RTPCodecTypeAudio :
return "audio"
case RTPCodecTypeVideo :
return "video"
default :
return ErrUnknownType .Error()
}
}
func NewRTPCodecType (r string ) RTPCodecType {
switch {
case strings .EqualFold (r , RTPCodecTypeAudio .String ()):
return RTPCodecTypeAudio
case strings .EqualFold (r , RTPCodecTypeVideo .String ()):
return RTPCodecTypeVideo
default :
return RTPCodecType (0 )
}
}
type RTPCodecCapability struct {
MimeType string
ClockRate uint32
Channels uint16
SDPFmtpLine string
RTCPFeedback []RTCPFeedback
}
type RTPHeaderExtensionCapability struct {
URI string
}
type RTPHeaderExtensionParameter struct {
URI string
ID int
}
type RTPCodecParameters struct {
RTPCodecCapability
PayloadType PayloadType
statsID string
}
type RTPParameters struct {
HeaderExtensions []RTPHeaderExtensionParameter
Codecs []RTPCodecParameters
}
type codecMatchType int
const (
codecMatchNone codecMatchType = 0
codecMatchPartial codecMatchType = 1
codecMatchExact codecMatchType = 2
)
func codecParametersFuzzySearch(
needle RTPCodecParameters ,
haystack []RTPCodecParameters ,
) (RTPCodecParameters , codecMatchType ) {
needleFmtp := fmtp .Parse (
needle .RTPCodecCapability .MimeType ,
needle .RTPCodecCapability .ClockRate ,
needle .RTPCodecCapability .Channels ,
needle .RTPCodecCapability .SDPFmtpLine )
for _ , c := range haystack {
cfmtp := fmtp .Parse (
c .RTPCodecCapability .MimeType ,
c .RTPCodecCapability .ClockRate ,
c .RTPCodecCapability .Channels ,
c .RTPCodecCapability .SDPFmtpLine )
if needleFmtp .Match (cfmtp ) {
return c , codecMatchExact
}
}
for _ , c := range haystack {
if strings .EqualFold (c .RTPCodecCapability .MimeType , needle .RTPCodecCapability .MimeType ) &&
fmtp .ClockRateEqual (c .RTPCodecCapability .MimeType ,
c .RTPCodecCapability .ClockRate ,
needle .RTPCodecCapability .ClockRate ) &&
fmtp .ChannelsEqual (c .RTPCodecCapability .MimeType ,
c .RTPCodecCapability .Channels ,
needle .RTPCodecCapability .Channels ) {
return c , codecMatchPartial
}
}
return RTPCodecParameters {}, codecMatchNone
}
func findRTXPayloadType(needle PayloadType , haystack []RTPCodecParameters ) PayloadType {
aptStr := fmt .Sprintf ("apt=%d" , needle )
for _ , c := range haystack {
if aptStr == c .SDPFmtpLine {
return c .PayloadType
}
}
return PayloadType (0 )
}
func findFECPayloadType(haystack []RTPCodecParameters ) PayloadType {
for _ , c := range haystack {
if strings .Contains (c .RTPCodecCapability .MimeType , MimeTypeFlexFEC ) {
return c .PayloadType
}
}
return PayloadType (0 )
}
func rtcpFeedbackIntersection(a , b []RTCPFeedback ) (out []RTCPFeedback ) {
for _ , aFeedback := range a {
for _ , bFeeback := range b {
if aFeedback .Type == bFeeback .Type && aFeedback .Parameter == bFeeback .Parameter {
out = append (out , aFeedback )
break
}
}
}
return
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .