mirror of
https://github.com/pion/webrtc.git
synced 2025-10-27 01:00:35 +08:00
Add extmap support
Extmaps are configured via the SettingEngine. This allows a user to set arbitrary values, and when answering ids and entries are properly excluded. Co-authored-by: Gabor Pongracz <gabor.pongracz@proemergotech.com>
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/pion/ice/v2"
|
||||
"github.com/pion/logging"
|
||||
"github.com/pion/sdp/v2"
|
||||
"github.com/pion/transport/vnet"
|
||||
)
|
||||
|
||||
@@ -49,6 +50,7 @@ type SettingEngine struct {
|
||||
SRTCP *uint
|
||||
}
|
||||
sdpMediaLevelFingerprints bool
|
||||
sdpExtensions map[SDPSectionType][]sdp.ExtMap
|
||||
answeringDTLSRole DTLSRole
|
||||
disableCertificateFingerprintVerification bool
|
||||
disableSRTPReplayProtection bool
|
||||
@@ -245,3 +247,65 @@ func (e *SettingEngine) DisableSRTCPReplayProtection(isDisabled bool) {
|
||||
func (e *SettingEngine) SetSDPMediaLevelFingerprints(sdpMediaLevelFingerprints bool) {
|
||||
e.sdpMediaLevelFingerprints = sdpMediaLevelFingerprints
|
||||
}
|
||||
|
||||
// AddSDPExtensions adds available and offered extensions for media type.
|
||||
//
|
||||
// Ext IDs are optional and generated if you do not provide them
|
||||
// SDP answers will only include extensions supported by both sides
|
||||
func (e *SettingEngine) AddSDPExtensions(mediaType SDPSectionType, exts []sdp.ExtMap) {
|
||||
if e.sdpExtensions == nil {
|
||||
e.sdpExtensions = make(map[SDPSectionType][]sdp.ExtMap)
|
||||
}
|
||||
if _, ok := e.sdpExtensions[mediaType]; !ok {
|
||||
e.sdpExtensions[mediaType] = []sdp.ExtMap{}
|
||||
}
|
||||
e.sdpExtensions[mediaType] = append(e.sdpExtensions[mediaType], exts...)
|
||||
}
|
||||
|
||||
func (e *SettingEngine) getSDPExtensions() map[SDPSectionType][]sdp.ExtMap {
|
||||
var lastID int
|
||||
idMap := map[string]int{}
|
||||
|
||||
// Build provided ext id map
|
||||
for _, extList := range e.sdpExtensions {
|
||||
for _, ext := range extList {
|
||||
if ext.Value != 0 {
|
||||
idMap[ext.URI.String()] = ext.Value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find next available ID
|
||||
nextID := func() {
|
||||
var done bool
|
||||
for !done {
|
||||
lastID++
|
||||
var found bool
|
||||
for _, v := range idMap {
|
||||
if lastID == v {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
done = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Assign missing IDs across all media types based on URI
|
||||
for mType, extList := range e.sdpExtensions {
|
||||
for i, ext := range extList {
|
||||
if ext.Value == 0 {
|
||||
if id, ok := idMap[ext.URI.String()]; ok {
|
||||
e.sdpExtensions[mType][i].Value = id
|
||||
} else {
|
||||
nextID()
|
||||
e.sdpExtensions[mType][i].Value = lastID
|
||||
idMap[ext.URI.String()] = lastID
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return e.sdpExtensions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user