Implement ICE restarts for WHIP.
This commit is contained in:
@@ -226,3 +226,50 @@ func PatchSDP(s sdp.SessionDescription, f SDPFrag) (sdp.SessionDescription, bool
|
||||
}
|
||||
return s, override
|
||||
}
|
||||
|
||||
func getCandidates(as []sdp.Attribute, mid *string, index *uint16, ufrag string) []webrtc.ICECandidateInit {
|
||||
var cs []webrtc.ICECandidateInit
|
||||
for _, a := range as {
|
||||
if a.Key != "candidate" {
|
||||
continue
|
||||
}
|
||||
c := webrtc.ICECandidateInit{
|
||||
Candidate: a.Value,
|
||||
SDPMid: mid,
|
||||
SDPMLineIndex: index,
|
||||
}
|
||||
if ufrag != "" {
|
||||
c.UsernameFragment = &ufrag
|
||||
}
|
||||
cs = append(cs, c)
|
||||
}
|
||||
return cs
|
||||
|
||||
}
|
||||
|
||||
// FromSDP extracts the ICE information from an [sdp.SessionDescription]
|
||||
func FromSDP(s sdp.SessionDescription) SDPFrag {
|
||||
var f SDPFrag
|
||||
ufrag, _ := s.Attribute("ice-ufrag")
|
||||
f.UsernameFragment = ufrag
|
||||
pwd, _ := s.Attribute("ice-pwd")
|
||||
f.Password = pwd
|
||||
f.Candidates = getCandidates(s.Attributes, nil, nil, ufrag)
|
||||
|
||||
for index, m := range s.MediaDescriptions {
|
||||
var mm MediaDescription
|
||||
mm.MLine = m.MediaName.String()
|
||||
mid, _ := m.Attribute("mid")
|
||||
mm.Mid = mid
|
||||
ufrag, _ := m.Attribute("ice-ufrag")
|
||||
mm.UsernameFragment = ufrag
|
||||
pwd, _ := m.Attribute("ice-pwd")
|
||||
mm.Password = pwd
|
||||
i := uint16(index)
|
||||
mm.Candidates = getCandidates(
|
||||
m.Attributes, &mid, &i, ufrag,
|
||||
)
|
||||
f.MediaDescriptions = append(f.MediaDescriptions, mm)
|
||||
}
|
||||
return f
|
||||
}
|
||||
|
||||
@@ -300,3 +300,29 @@ func TestPatchSDP(t *testing.T) {
|
||||
testPatchSDP(t, sdpOffer, sdpfragRestart, "HWmk", 0)
|
||||
})
|
||||
}
|
||||
|
||||
func TestFromSDP(t *testing.T) {
|
||||
frag := `m=audio 9 UDP/TLS/RTP/SAVPF 111 63 9 0 8 13 110 126
|
||||
a=ice-ufrag:qiKa
|
||||
a=ice-pwd:bcfs93hb/+ZLuUE2K50HVbkr
|
||||
a=mid:0
|
||||
m=video 9 UDP/TLS/RTP/SAVPF 96 97 103 104 107 108 109 114 115 116 117 118 39 40 45 46 98 99 100 101 119 120 121
|
||||
a=ice-ufrag:qiKa
|
||||
a=ice-pwd:bcfs93hb/+ZLuUE2K50HVbkr
|
||||
a=mid:1
|
||||
`
|
||||
var f SDPFrag
|
||||
err := f.Unmarshal([]byte(frag))
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
var s sdp.SessionDescription
|
||||
err = s.Unmarshal([]byte(sdpOffer))
|
||||
if err != nil {
|
||||
t.Fatalf("Unmarshal: %v", err)
|
||||
}
|
||||
ff := FromSDP(s)
|
||||
if !reflect.DeepEqual(ff, f) {
|
||||
t.Errorf("Not equal: %v %v", ff, f)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user