Skip to content

Commit a8d8d8b

Browse files
authored
Better SDP errors and logs. (#512)
1 parent b22ab7c commit a8d8d8b

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

pkg/sip/errors.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sip
2+
3+
type SDPError struct {
4+
Err error
5+
}
6+
7+
func (e SDPError) Error() string {
8+
return e.Err.Error()
9+
}
10+
11+
func (e SDPError) Unwrap() error {
12+
return e.Err
13+
}

pkg/sip/inbound.go

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,24 @@ func (c *inboundCall) handleInvite(ctx context.Context, tid traceid.ID, req *sip
720720
}
721721

722722
runMedia := func(enc livekit.SIPMediaEncryption) ([]byte, error) {
723-
answerData, err := c.runMediaConn(tid, req.Body(), enc, conf, disp.EnabledFeatures)
723+
log := c.log()
724+
if h := req.ContentLength(); h != nil {
725+
log = log.WithValues("contentLength", int(*h))
726+
}
727+
if h := req.ContentType(); h != nil {
728+
log = log.WithValues("contentType", h.Value())
729+
switch h.Value() {
730+
default:
731+
log.Infow("unsupported offer type")
732+
case "application/sdp":
733+
}
734+
} else {
735+
log.Infow("no offer type specified")
736+
}
737+
rawSDP := req.Body()
738+
answerData, err := c.runMediaConn(tid, rawSDP, enc, conf, disp.EnabledFeatures)
724739
if err != nil {
740+
log = log.WithValues("sdp", string(rawSDP))
725741
isError := true
726742
status, reason := callDropped, "media-failed"
727743
if errors.Is(err, sdp.ErrNoCommonMedia) {
@@ -730,11 +746,14 @@ func (c *inboundCall) handleInvite(ctx context.Context, tid traceid.ID, req *sip
730746
} else if errors.Is(err, sdp.ErrNoCommonCrypto) {
731747
status, reason = callMediaFailed, "no-common-crypto"
732748
isError = false
749+
} else if e := (SDPError{}); errors.As(err, &e) {
750+
status, reason = callMediaFailed, "sdp-error"
751+
isError = false
733752
}
734753
if isError {
735-
c.log().Errorw("Cannot start media", err)
754+
log.Errorw("Cannot start media", err)
736755
} else {
737-
c.log().Warnw("Cannot start media", err)
756+
log.Warnw("Cannot start media", err)
738757
}
739758
c.cc.RespondAndDrop(sip.StatusInternalServerError, "")
740759
c.close(true, status, reason)
@@ -925,7 +944,7 @@ func (c *inboundCall) runMediaConn(tid traceid.ID, offerData []byte, enc livekit
925944

926945
answer, mconf, err := mp.SetOffer(offerData, e)
927946
if err != nil {
928-
return nil, err
947+
return nil, SDPError{Err: err}
929948
}
930949
answerData, err = answer.SDP.Marshal()
931950
if err != nil {

0 commit comments

Comments
 (0)