Skip to content
Open
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
13 changes: 11 additions & 2 deletions server/internal/webrtc/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ func NewTrack(logger zerolog.Logger, codec codec.RTPCodec, connection *webrtc.Pe
logger: logger.With().Str("id", id).Logger(),
track: track,
rtcpCh: nil,
sample: make(chan types.Sample),
// buffer of 1: allows WriteSample to return immediately if sampleReader
// is busy with the previous frame. A stalled peer will drop frames
// rather than blocking the pipeline dispatcher (which holds listenersMu).
sample: make(chan types.Sample, 1),
}

for _, opt := range opts {
Expand Down Expand Up @@ -110,7 +113,13 @@ func (t *Track) sampleReader() {
}

func (t *Track) WriteSample(sample types.Sample) {
t.sample <- sample
select {
case t.sample <- sample:
default:
// drop frame: peer is too slow or stalled; don't block the pipeline
// dispatch goroutine (which holds listenersMu) and starve other viewers
t.logger.Trace().Msg("dropping sample: track channel full")
}
}

// --- stream ---
Expand Down
Loading