utils.AtomicFlag -> atomic.Bool (#466)
* Replacing hand rolled ion-sfu atomic with uber/atomic * Remove another hand rolled atomic * utils.AtomicFlag -> atomic.Bool
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -18,7 +18,7 @@ type LocalRouter struct {
|
||||
// channels for each participant
|
||||
requestChannels map[string]*MessageChannel
|
||||
responseChannels map[string]*MessageChannel
|
||||
isStarted utils.AtomicFlag
|
||||
isStarted atomic.Bool
|
||||
|
||||
rtcMessageChan *MessageChannel
|
||||
|
||||
@@ -147,7 +147,7 @@ func (r *LocalRouter) OnRTCMessage(callback RTCMessageCallback) {
|
||||
}
|
||||
|
||||
func (r *LocalRouter) Start() error {
|
||||
if !r.isStarted.TrySet(true) {
|
||||
if r.isStarted.Swap(true) {
|
||||
return nil
|
||||
}
|
||||
go r.statsWorker()
|
||||
@@ -166,7 +166,7 @@ func (r *LocalRouter) Stop() {
|
||||
|
||||
func (r *LocalRouter) statsWorker() {
|
||||
for {
|
||||
if !r.isStarted.Get() {
|
||||
if !r.isStarted.Load() {
|
||||
return
|
||||
}
|
||||
// update every 10 seconds
|
||||
@@ -179,7 +179,7 @@ func (r *LocalRouter) statsWorker() {
|
||||
|
||||
func (r *LocalRouter) rtcMessageWorker() {
|
||||
// is a new channel available? if so swap to that one
|
||||
if !r.isStarted.Get() {
|
||||
if !r.isStarted.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
|
||||
"github.com/go-redis/redis/v8"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -96,7 +96,7 @@ type RTCNodeSink struct {
|
||||
rc *redis.Client
|
||||
nodeID livekit.NodeID
|
||||
participantKey livekit.ParticipantKey
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
onClose func()
|
||||
}
|
||||
|
||||
@@ -109,14 +109,14 @@ func NewRTCNodeSink(rc *redis.Client, nodeID livekit.NodeID, participantKey live
|
||||
}
|
||||
|
||||
func (s *RTCNodeSink) WriteMessage(msg proto.Message) error {
|
||||
if s.isClosed.Get() {
|
||||
if s.isClosed.Load() {
|
||||
return ErrChannelClosed
|
||||
}
|
||||
return publishRTCMessage(s.rc, s.nodeID, s.participantKey, msg)
|
||||
}
|
||||
|
||||
func (s *RTCNodeSink) Close() {
|
||||
if !s.isClosed.TrySet(true) {
|
||||
if s.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
if s.onClose != nil {
|
||||
@@ -132,7 +132,7 @@ type SignalNodeSink struct {
|
||||
rc *redis.Client
|
||||
nodeID livekit.NodeID
|
||||
connectionID livekit.ConnectionID
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
onClose func()
|
||||
}
|
||||
|
||||
@@ -145,14 +145,14 @@ func NewSignalNodeSink(rc *redis.Client, nodeID livekit.NodeID, connectionID liv
|
||||
}
|
||||
|
||||
func (s *SignalNodeSink) WriteMessage(msg proto.Message) error {
|
||||
if s.isClosed.Get() {
|
||||
if s.isClosed.Load() {
|
||||
return ErrChannelClosed
|
||||
}
|
||||
return publishSignalMessage(s.rc, s.nodeID, s.connectionID, msg)
|
||||
}
|
||||
|
||||
func (s *SignalNodeSink) Close() {
|
||||
if !s.isClosed.TrySet(true) {
|
||||
if s.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
_ = publishSignalMessage(s.rc, s.nodeID, s.connectionID, &livekit.EndSession{})
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/routing/selector"
|
||||
@@ -31,7 +32,7 @@ type RedisRouter struct {
|
||||
|
||||
rc *redis.Client
|
||||
ctx context.Context
|
||||
isStarted utils.AtomicFlag
|
||||
isStarted atomic.Bool
|
||||
|
||||
pubsub *redis.PubSub
|
||||
cancel func()
|
||||
@@ -278,7 +279,7 @@ func (r *RedisRouter) startParticipantRTC(ss *livekit.StartSession, participantK
|
||||
}
|
||||
|
||||
func (r *RedisRouter) Start() error {
|
||||
if !r.isStarted.TrySet(true) {
|
||||
if r.isStarted.Swap(true) {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -303,7 +304,7 @@ func (r *RedisRouter) Drain() {
|
||||
}
|
||||
|
||||
func (r *RedisRouter) Stop() {
|
||||
if !r.isStarted.TrySet(false) {
|
||||
if !r.isStarted.Swap(false) {
|
||||
return
|
||||
}
|
||||
logger.Debugw("stopping RedisRouter")
|
||||
|
||||
@@ -36,7 +36,7 @@ func TestTrackInfo(t *testing.T) {
|
||||
require.Equal(t, ti.Simulcast, outInfo.Simulcast)
|
||||
|
||||
// make it simulcasted
|
||||
mt.simulcasted.TrySet(true)
|
||||
mt.simulcasted.Store(true)
|
||||
require.True(t, mt.ToProto().Simulcast)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,10 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/rtcp"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
@@ -25,8 +25,8 @@ const (
|
||||
|
||||
type MediaTrackReceiver struct {
|
||||
params MediaTrackReceiverParams
|
||||
muted utils.AtomicFlag
|
||||
simulcasted utils.AtomicFlag
|
||||
muted atomic.Bool
|
||||
simulcasted atomic.Bool
|
||||
|
||||
lock sync.RWMutex
|
||||
receiver sfu.TrackReceiver
|
||||
@@ -140,11 +140,11 @@ func (t *MediaTrackReceiver) PublisherIdentity() livekit.ParticipantIdentity {
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) IsSimulcast() bool {
|
||||
return t.simulcasted.Get()
|
||||
return t.simulcasted.Load()
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) SetSimulcast(simulcast bool) {
|
||||
t.simulcasted.TrySet(simulcast)
|
||||
t.simulcasted.Store(simulcast)
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) Name() string {
|
||||
@@ -152,11 +152,11 @@ func (t *MediaTrackReceiver) Name() string {
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) IsMuted() bool {
|
||||
return t.muted.Get()
|
||||
return t.muted.Load()
|
||||
}
|
||||
|
||||
func (t *MediaTrackReceiver) SetMuted(muted bool) {
|
||||
t.muted.TrySet(muted)
|
||||
t.muted.Store(muted)
|
||||
|
||||
receiver := t.Receiver()
|
||||
if receiver != nil {
|
||||
@@ -339,7 +339,7 @@ func (t *MediaTrackReceiver) DebugInfo() map[string]interface{} {
|
||||
info := map[string]interface{}{
|
||||
"ID": t.ID(),
|
||||
"Kind": t.Kind().String(),
|
||||
"PubMuted": t.muted.Get(),
|
||||
"PubMuted": t.muted.Load(),
|
||||
}
|
||||
|
||||
info["DownTracks"] = t.MediaTrackSubscriptions.DebugInfo()
|
||||
|
||||
@@ -392,8 +392,8 @@ func (t *MediaTrackSubscriptions) DebugInfo() []map[string]interface{} {
|
||||
for _, val := range t.getAllSubscribedTracks() {
|
||||
if st, ok := val.(*SubscribedTrack); ok {
|
||||
dt := st.DownTrack().DebugInfo()
|
||||
dt["PubMuted"] = st.pubMuted.Get()
|
||||
dt["SubMuted"] = st.subMuted.Get()
|
||||
dt["PubMuted"] = st.pubMuted.Load()
|
||||
dt["SubMuted"] = st.subMuted.Load()
|
||||
subscribedTrackInfo = append(subscribedTrackInfo, dt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"io"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
lru "github.com/hashicorp/golang-lru"
|
||||
@@ -17,6 +16,7 @@ import (
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/pkg/errors"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
@@ -66,7 +66,7 @@ type ParticipantImpl struct {
|
||||
params ParticipantParams
|
||||
publisher *PCTransport
|
||||
subscriber *PCTransport
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
permission *livekit.ParticipantPermission
|
||||
state atomic.Value // livekit.ParticipantInfo_State
|
||||
updateCache *lru.Cache
|
||||
@@ -304,7 +304,7 @@ func (p *ParticipantImpl) ToProto() *livekit.ParticipantInfo {
|
||||
JoinedAt: p.ConnectedAt().Unix(),
|
||||
Hidden: p.Hidden(),
|
||||
Recorder: p.IsRecorder(),
|
||||
Version: atomic.AddUint32(&p.version, 1),
|
||||
Version: atomic.NewUint32(p.version).Inc(),
|
||||
}
|
||||
info.Tracks = p.UpTrackManager.ToProto()
|
||||
if p.params.Grants != nil {
|
||||
@@ -478,7 +478,7 @@ func (p *ParticipantImpl) Start() {
|
||||
}
|
||||
|
||||
func (p *ParticipantImpl) Close(sendLeave bool) error {
|
||||
if !p.isClosed.TrySet(true) {
|
||||
if p.isClosed.Swap(true) {
|
||||
// already closed
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package rtc
|
||||
|
||||
import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/bep/debounce"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc/types"
|
||||
"github.com/livekit/livekit-server/pkg/sfu"
|
||||
@@ -26,8 +25,8 @@ type SubscribedTrackParams struct {
|
||||
}
|
||||
type SubscribedTrack struct {
|
||||
params SubscribedTrackParams
|
||||
subMuted utils.AtomicFlag
|
||||
pubMuted utils.AtomicFlag
|
||||
subMuted atomic.Bool
|
||||
pubMuted atomic.Bool
|
||||
settings atomic.Value // *livekit.UpdateTrackSettings
|
||||
|
||||
onBind func()
|
||||
@@ -78,19 +77,19 @@ func (t *SubscribedTrack) MediaTrack() types.MediaTrack {
|
||||
|
||||
// has subscriber indicated it wants to mute this track
|
||||
func (t *SubscribedTrack) IsMuted() bool {
|
||||
return t.subMuted.Get()
|
||||
return t.subMuted.Load()
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) SetPublisherMuted(muted bool) {
|
||||
t.pubMuted.TrySet(muted)
|
||||
t.pubMuted.Store(muted)
|
||||
t.updateDownTrackMute()
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) UpdateSubscriberSettings(settings *livekit.UpdateTrackSettings) {
|
||||
visibilityChanged := t.subMuted.TrySet(settings.Disabled)
|
||||
prevDisabled := t.subMuted.Swap(settings.Disabled)
|
||||
t.settings.Store(settings)
|
||||
// avoid frequent changes to mute & video layers, unless it became visible
|
||||
if visibilityChanged && !settings.Disabled {
|
||||
if prevDisabled != settings.Disabled && !settings.Disabled {
|
||||
t.UpdateVideoLayer()
|
||||
} else {
|
||||
t.debouncer(t.UpdateVideoLayer)
|
||||
@@ -116,6 +115,6 @@ func (t *SubscribedTrack) UpdateVideoLayer() {
|
||||
}
|
||||
|
||||
func (t *SubscribedTrack) updateDownTrackMute() {
|
||||
muted := t.subMuted.Get() || t.pubMuted.Get()
|
||||
muted := t.subMuted.Load() || t.pubMuted.Load()
|
||||
t.DownTrack().Mute(muted)
|
||||
}
|
||||
|
||||
@@ -13,11 +13,11 @@ import (
|
||||
"github.com/livekit/protocol/auth"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/turn/v2"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"github.com/rs/cors"
|
||||
"github.com/urfave/negroni"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/routing"
|
||||
@@ -35,7 +35,7 @@ type LivekitServer struct {
|
||||
roomManager *RoomManager
|
||||
turnServer *turn.Server
|
||||
currentNode routing.LocalNode
|
||||
running utils.AtomicFlag
|
||||
running atomic.Bool
|
||||
doneChan chan struct{}
|
||||
closedChan chan struct{}
|
||||
}
|
||||
@@ -127,11 +127,11 @@ func (s *LivekitServer) HTTPPort() int {
|
||||
}
|
||||
|
||||
func (s *LivekitServer) IsRunning() bool {
|
||||
return s.running.Get()
|
||||
return s.running.Load()
|
||||
}
|
||||
|
||||
func (s *LivekitServer) Start() error {
|
||||
if s.running.Get() {
|
||||
if s.running.Load() {
|
||||
return errors.New("already running")
|
||||
}
|
||||
s.doneChan = make(chan struct{})
|
||||
@@ -203,7 +203,7 @@ func (s *LivekitServer) Start() error {
|
||||
// give time for Serve goroutine to start
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
|
||||
s.running.TrySet(true)
|
||||
s.running.Store(true)
|
||||
|
||||
<-s.doneChan
|
||||
|
||||
@@ -238,7 +238,7 @@ func (s *LivekitServer) Stop(force bool) {
|
||||
}
|
||||
partTicker.Stop()
|
||||
|
||||
if !s.running.TrySet(false) {
|
||||
if !s.running.Swap(false) {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ import (
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -43,7 +43,7 @@ type ConnectionStats struct {
|
||||
qualityWindows map[uint32]*qualityWindow
|
||||
|
||||
done chan struct{}
|
||||
isClosed utils.AtomicFlag
|
||||
isClosed atomic.Bool
|
||||
}
|
||||
|
||||
func NewConnectionStats(params ConnectionStatsParams) *ConnectionStats {
|
||||
@@ -60,7 +60,7 @@ func (cs *ConnectionStats) Start() {
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) Close() {
|
||||
if !cs.isClosed.TrySet(true) {
|
||||
if cs.isClosed.Swap(true) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ func (cs *ConnectionStats) GetScore() float32 {
|
||||
}
|
||||
|
||||
func (cs *ConnectionStats) UpdateWindow(ssrc uint32, extHighestSeqNum uint32, packetsLost uint32, rtt uint32, jitter uint32) {
|
||||
if cs.isClosed.Get() {
|
||||
if cs.isClosed.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -9,10 +9,10 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/interceptor/pkg/cc"
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
)
|
||||
@@ -153,7 +153,7 @@ type StreamAllocator struct {
|
||||
eventChMu sync.RWMutex
|
||||
eventCh chan Event
|
||||
|
||||
isStopped utils.AtomicFlag
|
||||
isStopped atomic.Bool
|
||||
}
|
||||
|
||||
func NewStreamAllocator(params StreamAllocatorParams) *StreamAllocator {
|
||||
@@ -182,7 +182,7 @@ func (s *StreamAllocator) Start() {
|
||||
|
||||
func (s *StreamAllocator) Stop() {
|
||||
s.eventChMu.Lock()
|
||||
if !s.isStopped.TrySet(true) {
|
||||
if s.isStopped.Swap(true) {
|
||||
s.eventChMu.Unlock()
|
||||
return
|
||||
}
|
||||
@@ -320,7 +320,7 @@ func (s *StreamAllocator) onProbeClusterDone(info ProbeClusterInfo) {
|
||||
|
||||
func (s *StreamAllocator) postEvent(event Event) {
|
||||
s.eventChMu.RLock()
|
||||
if s.isStopped.Get() {
|
||||
if s.isStopped.Load() {
|
||||
s.eventChMu.RUnlock()
|
||||
return
|
||||
}
|
||||
@@ -340,7 +340,7 @@ func (s *StreamAllocator) ping() {
|
||||
|
||||
for {
|
||||
<-ticker.C
|
||||
if s.isStopped.Get() {
|
||||
if s.isStopped.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,6 @@ import (
|
||||
"time"
|
||||
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/protocol/utils"
|
||||
)
|
||||
|
||||
type StreamStatus int32
|
||||
@@ -54,7 +52,7 @@ type StreamTracker struct {
|
||||
// only access by the same goroutine as Observe
|
||||
lastSN uint16
|
||||
|
||||
isStopped utils.AtomicFlag
|
||||
isStopped atomic.Bool
|
||||
}
|
||||
|
||||
func NewStreamTracker(samplesRequired uint32, cyclesRequired uint64, cycleDuration time.Duration) *StreamTracker {
|
||||
@@ -110,7 +108,7 @@ func (s *StreamTracker) Start() {
|
||||
}
|
||||
|
||||
func (s *StreamTracker) Stop() {
|
||||
if !s.isStopped.TrySet(true) {
|
||||
if s.isStopped.Swap(true) {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -119,7 +117,7 @@ func (s *StreamTracker) Stop() {
|
||||
}
|
||||
|
||||
func (s *StreamTracker) Reset() {
|
||||
if s.isStopped.Get() {
|
||||
if s.isStopped.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+22
-22
@@ -14,11 +14,11 @@ import (
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/rtp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/thoas/go-funk"
|
||||
"go.uber.org/atomic"
|
||||
"google.golang.org/protobuf/proto"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/rtc"
|
||||
@@ -40,8 +40,8 @@ type RTCClient struct {
|
||||
wsLock sync.Mutex
|
||||
ctx context.Context
|
||||
cancel context.CancelFunc
|
||||
connected utils.AtomicFlag
|
||||
iceConnected utils.AtomicFlag
|
||||
connected atomic.Bool
|
||||
iceConnected atomic.Bool
|
||||
me *webrtc.MediaEngine // optional, populated only when receiving tracks
|
||||
subscribedTracks map[livekit.ParticipantID][]*webrtc.TrackRemote
|
||||
localParticipant *livekit.ParticipantInfo
|
||||
@@ -51,8 +51,8 @@ type RTCClient struct {
|
||||
reliableDCSub *webrtc.DataChannel
|
||||
lossyDC *webrtc.DataChannel
|
||||
lossyDCSub *webrtc.DataChannel
|
||||
publisherConnected utils.AtomicFlag
|
||||
publisherNegotiated utils.AtomicFlag
|
||||
publisherConnected atomic.Bool
|
||||
publisherNegotiated atomic.Bool
|
||||
|
||||
// tracks waiting to be acked, cid => trackInfo
|
||||
pendingPublishedTracks map[string]*livekit.TrackInfo
|
||||
@@ -216,9 +216,9 @@ func NewRTCClient(conn *websocket.Conn) (*RTCClient, error) {
|
||||
}
|
||||
}
|
||||
|
||||
initialConnect := !c.iceConnected.Get()
|
||||
initialConnect := !c.iceConnected.Load()
|
||||
c.pendingTrackWriters = nil
|
||||
c.iceConnected.TrySet(true)
|
||||
c.iceConnected.Store(true)
|
||||
|
||||
if initialConnect && c.OnConnected != nil {
|
||||
go c.OnConnected()
|
||||
@@ -231,13 +231,13 @@ func NewRTCClient(conn *websocket.Conn) (*RTCClient, error) {
|
||||
"participant", c.localParticipant.Identity)
|
||||
|
||||
if state == webrtc.ICEConnectionStateConnected {
|
||||
c.publisherConnected.TrySet(true)
|
||||
c.publisherConnected.Store(true)
|
||||
// check if publisher triggered negotiate (!subscriberPrimary)
|
||||
if c.publisherNegotiated.Get() {
|
||||
c.iceConnected.TrySet(true)
|
||||
if c.publisherNegotiated.Load() {
|
||||
c.iceConnected.Store(true)
|
||||
}
|
||||
} else {
|
||||
c.publisherConnected.TrySet(false)
|
||||
c.publisherConnected.Store(false)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -277,7 +277,7 @@ func (c *RTCClient) Run() error {
|
||||
c.lock.Unlock()
|
||||
// if publish only, negotiate
|
||||
if !msg.Join.SubscriberPrimary {
|
||||
c.publisherNegotiated.TrySet(true)
|
||||
c.publisherNegotiated.Store(true)
|
||||
c.publisher.Negotiate()
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ func (c *RTCClient) WaitUntilConnected() error {
|
||||
}
|
||||
return fmt.Errorf("%s could not connect after timeout", id)
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
if c.iceConnected.Get() {
|
||||
if c.iceConnected.Load() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -409,8 +409,8 @@ func (c *RTCClient) Stop() {
|
||||
Leave: &livekit.LeaveRequest{},
|
||||
},
|
||||
})
|
||||
c.connected.TrySet(false)
|
||||
c.iceConnected.TrySet(false)
|
||||
c.connected.Store(false)
|
||||
c.iceConnected.Store(false)
|
||||
_ = c.conn.Close()
|
||||
c.publisher.Close()
|
||||
c.subscriber.Close()
|
||||
@@ -486,7 +486,7 @@ func (c *RTCClient) AddTrack(track *webrtc.TrackLocalStaticSample, path string)
|
||||
writer = NewTrackWriter(c.ctx, track, path)
|
||||
|
||||
// write tracks only after ICE connectivity
|
||||
if c.iceConnected.Get() {
|
||||
if c.iceConnected.Load() {
|
||||
err = writer.Start()
|
||||
} else {
|
||||
c.pendingTrackWriters = append(c.pendingTrackWriters, writer)
|
||||
@@ -578,7 +578,7 @@ func (c *RTCClient) GetPublishedTrackIDs() []string {
|
||||
}
|
||||
|
||||
func (c *RTCClient) ensurePublisherConnected() error {
|
||||
if c.publisherConnected.Get() {
|
||||
if c.publisherConnected.Load() {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -587,12 +587,12 @@ func (c *RTCClient) ensurePublisherConnected() error {
|
||||
c.publisher.Negotiate()
|
||||
}
|
||||
|
||||
dcOpen := utils.AtomicFlag{}
|
||||
dcOpen := atomic.NewBool(false)
|
||||
c.reliableDC.OnOpen(func() {
|
||||
dcOpen.TrySet(true)
|
||||
dcOpen.Store(true)
|
||||
})
|
||||
if c.reliableDC.ReadyState() == webrtc.DataChannelStateOpen {
|
||||
dcOpen.TrySet(true)
|
||||
dcOpen.Store(true)
|
||||
}
|
||||
|
||||
// wait until connected, increase wait time since it takes more than 10s sometimes on GH
|
||||
@@ -603,7 +603,7 @@ func (c *RTCClient) ensurePublisherConnected() error {
|
||||
case <-ctx.Done():
|
||||
return fmt.Errorf("could not connect publisher after timeout")
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
if c.publisherConnected.Get() && dcOpen.Get() {
|
||||
if c.publisherConnected.Load() && dcOpen.Load() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -660,7 +660,7 @@ func (c *RTCClient) handleAnswer(desc webrtc.SessionDescription) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if !c.connected.TrySet(true) {
|
||||
if c.connected.Swap(true) {
|
||||
// already connected
|
||||
return nil
|
||||
}
|
||||
|
||||
+4
-4
@@ -7,8 +7,8 @@ import (
|
||||
|
||||
"github.com/livekit/protocol/livekit"
|
||||
"github.com/livekit/protocol/logger"
|
||||
"github.com/livekit/protocol/utils"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/testutils"
|
||||
testclient "github.com/livekit/livekit-server/test/client"
|
||||
@@ -127,17 +127,17 @@ func scenarioDataPublish(t *testing.T) {
|
||||
|
||||
payload := "test bytes"
|
||||
|
||||
received := utils.AtomicFlag{}
|
||||
received := atomic.NewBool(false)
|
||||
c2.OnDataReceived = func(data []byte, sid string) {
|
||||
if string(data) == payload && livekit.ParticipantID(sid) == c1.ID() {
|
||||
received.TrySet(true)
|
||||
received.Store(true)
|
||||
}
|
||||
}
|
||||
|
||||
require.NoError(t, c1.PublishData([]byte(payload), livekit.DataPacket_RELIABLE))
|
||||
|
||||
testutils.WithTimeout(t, func() string {
|
||||
if received.Get() {
|
||||
if received.Load() {
|
||||
return ""
|
||||
} else {
|
||||
return "c2 did not receive published data"
|
||||
|
||||
Reference in New Issue
Block a user