Skip to content

Commit 95d1324

Browse files
authored
Stop RTP loop if the errors persist. (#354)
1 parent d980924 commit 95d1324

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

pkg/sip/media_port.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,13 @@ func (p *MediaPort) rtpLoop(sess rtp.Session) {
389389
}
390390

391391
func (p *MediaPort) rtpReadLoop(log logger.Logger, r rtp.ReadStream) {
392+
const maxErrors = 50 // 1 sec, given 20 ms frames
392393
buf := make([]byte, rtp.MTUSize+1)
393394
overflow := false
394395
var (
395396
h rtp.Header
396397
pipeline string
398+
errorCnt int
397399
)
398400
for {
399401
h = rtp.Header{}
@@ -426,14 +428,21 @@ func (p *MediaPort) rtpReadLoop(log logger.Logger, r rtp.ReadStream) {
426428
if pipeline == "" {
427429
pipeline = hnd.String()
428430
}
429-
log.Errorw("handle RTP failed", err,
430-
"payloadType", h.PayloadType,
431+
log := log.WithValues(
431432
"payloadSize", n,
432433
"rtpHeader", h,
433434
"pipeline", pipeline,
435+
"errorCount", errorCnt,
434436
)
437+
log.Debugw("handle RTP failed", "error", err)
438+
errorCnt++
439+
if errorCnt >= maxErrors {
440+
log.Errorw("killing RTP loop due to persisted errors", err)
441+
return
442+
}
435443
continue
436444
}
445+
errorCnt = 0
437446
pipeline = ""
438447
}
439448
}

0 commit comments

Comments
 (0)