Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions pkg/media/webrtc_sink.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"context"
"math"
"sync"
"sync/atomic"
"time"

"github.com/frostbyte73/core"
"github.com/go-gst/go-gst/gst"
Expand Down Expand Up @@ -52,18 +54,23 @@ type WebRTCSink struct {
outputSync *utils.OutputSynchronizer
spliceProcessor *SpliceProcessor
statsGatherer *stats.LocalMediaStatsGatherer

// logging
tooSlowThrottle core.Throttle
tooSlowLogEvents atomic.Int32
}

func NewWebRTCSink(ctx context.Context, p *params.Params, onFailure func(), statsGatherer *stats.LocalMediaStatsGatherer) (*WebRTCSink, error) {
ctx, span := tracer.Start(ctx, "media.NewWebRTCSink")
defer span.End()

s := &WebRTCSink{
params: p,
onFailure: onFailure,
errChan: make(chan error),
outputSync: utils.NewOutputSynchronizer(),
statsGatherer: statsGatherer,
params: p,
onFailure: onFailure,
errChan: make(chan error),
outputSync: utils.NewOutputSynchronizer(),
statsGatherer: statsGatherer,
tooSlowThrottle: core.NewThrottle(5 * time.Second),
}

go func() {
Expand Down Expand Up @@ -164,7 +171,12 @@ func (s *WebRTCSink) isPlayingTooSlow() bool {
}

if minQueueLength > targetMinQueueLength {
logger.Debugw("playing too slow", "minQueueLength", minQueueLength)
s.tooSlowLogEvents.Add(1)

s.tooSlowThrottle(func() {
logger.Debugw("playing too slow", "minQueueLength", minQueueLength, "eventCount", s.tooSlowLogEvents.Swap(0))
})

return true
}

Expand Down