fix remote track logging.

This commit is contained in:
Miroslav Šedivý 2022-01-06 20:41:44 +01:00
parent 6b14e01415
commit 0f9f9a376c

View File

@ -27,6 +27,9 @@ const failedTimeout = 6 * time.Second
// how often the ICE Agent sends extra traffic if there is no activity, if media is flowing no traffic will be sent. Default is 2 seconds // how often the ICE Agent sends extra traffic if there is no activity, if media is flowing no traffic will be sent. Default is 2 seconds
const keepAliveInterval = 2 * time.Second const keepAliveInterval = 2 * time.Second
// send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval
const rtcpPLIInterval = 3 * time.Second
func New(desktop types.DesktopManager, capture types.CaptureManager, config *config.WebRTC) *WebRTCManagerCtx { func New(desktop types.DesktopManager, capture types.CaptureManager, config *config.WebRTC) *WebRTCManagerCtx {
return &WebRTCManagerCtx{ return &WebRTCManagerCtx{
logger: log.With().Str("module", "webrtc").Logger(), logger: log.With().Str("module", "webrtc").Logger(),
@ -164,17 +167,17 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
Str("mime", track.Codec().RTPCodecCapability.MimeType). Str("mime", track.Codec().RTPCodecCapability.MimeType).
Logger() Logger()
logger.Info().Msgf("received new track") logger.Info().Msgf("received new remote track")
if !session.Profile().CanShareMedia { if !session.Profile().CanShareMedia {
logger.Warn().Msg("share media is disabled for this session") logger.Warn().Msg("media sharing is disabled for this session")
return return
} }
// parse codec // parse codec from remote track
codec, ok := codec.ParseRTC(track.Codec()) codec, ok := codec.ParseRTC(track.Codec())
if !ok { if !ok {
logger.Warn().Msg("unknown codec") logger.Warn().Msg("remote track with unknown codec")
return return
} }
@ -194,15 +197,14 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
} }
defer srcManager.Stop() defer srcManager.Stop()
// Send a PLI on an interval so that the publisher is pushing a keyframe every rtcpPLIInterval ticker := time.NewTicker(rtcpPLIInterval)
ticker := time.NewTicker(time.Second * 3)
defer ticker.Stop() defer ticker.Stop()
go func() { go func() {
for range ticker.C { for range ticker.C {
err := connection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}}) err := connection.WriteRTCP([]rtcp.Packet{&rtcp.PictureLossIndication{MediaSSRC: uint32(track.SSRC())}})
if err != nil { if err != nil {
logger.Err(err).Msg("rtcp send err") logger.Err(err).Msg("remote track rtcp send err")
} }
} }
}() }()
@ -211,14 +213,14 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
for { for {
i, _, err := track.Read(buf) i, _, err := track.Read(buf)
if err != nil { if err != nil {
logger.Warn().Err(err).Msg("failed read from track") logger.Warn().Err(err).Msg("failed read from remote track")
break break
} }
srcManager.Push(buf[:i]) srcManager.Push(buf[:i])
} }
logger.Info().Msg("track data finished") logger.Info().Msg("remote track data finished")
}) })
connection.OnDataChannel(func(dc *webrtc.DataChannel) { connection.OnDataChannel(func(dc *webrtc.DataChannel) {