From 3f375c037f6f4b00aee39de42bd27d9a26442ee4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Mon, 17 Apr 2023 01:21:20 +0200 Subject: [PATCH] fix track rtcp & paused. --- internal/webrtc/track.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/internal/webrtc/track.go b/internal/webrtc/track.go index 886de03f..dd528bda 100644 --- a/internal/webrtc/track.go +++ b/internal/webrtc/track.go @@ -33,33 +33,31 @@ type Track struct { videoChange func(string) (bool, error) } -type option func(*Track) +type trackOption func(*Track) -func WithVideoAuto(auto bool) option { +func WithVideoAuto(auto bool) trackOption { return func(t *Track) { t.videoAuto = auto } } -func WithRtcpChan(rtcp chan []rtcp.Packet) option { +func WithRtcpChan(rtcp chan []rtcp.Packet) trackOption { return func(t *Track) { t.rtcpCh = rtcp } } -func NewTrack(logger zerolog.Logger, codec codec.RTPCodec, connection *webrtc.PeerConnection, opts ...option) (*Track, error) { +func NewTrack(logger zerolog.Logger, codec codec.RTPCodec, connection *webrtc.PeerConnection, opts ...trackOption) (*Track, error) { id := codec.Type.String() track, err := webrtc.NewTrackLocalStaticSample(codec.Capability, id, "stream") if err != nil { return nil, err } - logger = logger.With().Str("id", id).Logger() - t := &Track{ - logger: logger, + logger: logger.With().Str("id", id).Logger(), track: track, - rtcpCh: make(chan []rtcp.Packet), + rtcpCh: nil, sample: make(chan types.Sample), } @@ -155,8 +153,9 @@ func (t *Track) RemoveStream() { t.streamMu.Lock() defer t.streamMu.Unlock() - // if there is no stream, or paused, do nothing + // if there is no stream, or paused we don't need to remove the listener if t.stream == nil || t.paused { + t.stream = nil return }