webrtc: print lost packets (#2468)

This commit is contained in:
Alessandro Ros 2023-10-06 21:06:29 +02:00 committed by GitHub
parent a6f929d111
commit c37fd38f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -7,11 +7,14 @@ import (
"github.com/bluenviron/gortsplib/v4/pkg/description"
"github.com/bluenviron/gortsplib/v4/pkg/format"
"github.com/bluenviron/gortsplib/v4/pkg/liberrors"
"github.com/bluenviron/gortsplib/v4/pkg/rtplossdetector"
"github.com/bluenviron/gortsplib/v4/pkg/rtptime"
"github.com/pion/rtcp"
"github.com/pion/rtp"
"github.com/pion/webrtc/v3"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/stream"
)
@ -112,7 +115,8 @@ func (webrtcTrackWrapper) PTSEqualsDTS(*rtp.Packet) bool {
return true
}
func (t *webRTCIncomingTrack) start(stream *stream.Stream, timeDecoder *rtptime.GlobalDecoder) {
func (t *webRTCIncomingTrack) start(stream *stream.Stream, timeDecoder *rtptime.GlobalDecoder, log logger.Writer) {
lossDetector := rtplossdetector.New()
trackWrapper := &webrtcTrackWrapper{clockRate: int(t.track.Codec().ClockRate)}
go func() {
@ -122,6 +126,12 @@ func (t *webRTCIncomingTrack) start(stream *stream.Stream, timeDecoder *rtptime.
return
}
lost := lossDetector.Process(pkt)
if lost != 0 {
log.Log(logger.Warn, (liberrors.ErrClientRTPPacketsLost{Lost: lost}).Error())
// do not return
}
// sometimes Chrome sends empty RTP packets. ignore them.
if len(pkt.Payload) == 0 {
continue

View File

@ -410,7 +410,7 @@ func (s *webRTCSession) runPublish() (int, error) {
timeDecoder := rtptime.NewGlobalDecoder()
for _, track := range tracks {
track.start(rres.stream, timeDecoder)
track.start(rres.stream, timeDecoder, s)
}
select {

View File

@ -158,7 +158,7 @@ func (s *webRTCSource) run(ctx context.Context, cnf *conf.PathConf, _ chan *conf
timeDecoder := rtptime.NewGlobalDecoder()
for _, track := range tracks {
track.start(rres.stream, timeDecoder)
track.start(rres.stream, timeDecoder, s)
}
select {