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:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user