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
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/description"
"github.com/bluenviron/gortsplib/v4/pkg/format" "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/bluenviron/gortsplib/v4/pkg/rtptime"
"github.com/pion/rtcp" "github.com/pion/rtcp"
"github.com/pion/rtp" "github.com/pion/rtp"
"github.com/pion/webrtc/v3" "github.com/pion/webrtc/v3"
"github.com/bluenviron/mediamtx/internal/logger"
"github.com/bluenviron/mediamtx/internal/stream" "github.com/bluenviron/mediamtx/internal/stream"
) )
@@ -112,7 +115,8 @@ func (webrtcTrackWrapper) PTSEqualsDTS(*rtp.Packet) bool {
return true 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)} trackWrapper := &webrtcTrackWrapper{clockRate: int(t.track.Codec().ClockRate)}
go func() { go func() {
@@ -122,6 +126,12 @@ func (t *webRTCIncomingTrack) start(stream *stream.Stream, timeDecoder *rtptime.
return 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. // sometimes Chrome sends empty RTP packets. ignore them.
if len(pkt.Payload) == 0 { if len(pkt.Payload) == 0 {
continue continue

View File

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

View File

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