Replacing hand rolled ion-sfu atomic with uber/atomic (#465)
* Replacing hand rolled ion-sfu atomic with uber/atomic * Remove another hand rolled atomic
This commit is contained in:
+9
-9
@@ -4,7 +4,6 @@ import (
|
||||
"io"
|
||||
"runtime"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/go-logr/logr"
|
||||
@@ -13,6 +12,7 @@ import (
|
||||
"github.com/pion/rtcp"
|
||||
"github.com/pion/webrtc/v3"
|
||||
"github.com/rs/zerolog/log"
|
||||
"go.uber.org/atomic"
|
||||
|
||||
"github.com/livekit/livekit-server/pkg/config"
|
||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||
@@ -58,7 +58,7 @@ type WebRTCReceiver struct {
|
||||
isSimulcast bool
|
||||
onCloseHandler func()
|
||||
closeOnce sync.Once
|
||||
closed atomicBool
|
||||
closed atomic.Bool
|
||||
useTrackers bool
|
||||
|
||||
rtcpCh chan []rtcp.Packet
|
||||
@@ -239,7 +239,7 @@ func (w *WebRTCReceiver) Kind() webrtc.RTPCodecType {
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) AddUpTrack(track *webrtc.TrackRemote, buff *buffer.Buffer) {
|
||||
if w.closed.get() {
|
||||
if w.closed.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ func (w *WebRTCReceiver) SetUpTrackPaused(paused bool) {
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) AddDownTrack(track TrackSender) {
|
||||
if w.closed.get() {
|
||||
if w.closed.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ func (w *WebRTCReceiver) OnCloseHandler(fn func()) {
|
||||
|
||||
// DeleteDownTrack removes a DownTrack from a Receiver
|
||||
func (w *WebRTCReceiver) DeleteDownTrack(peerID livekit.ParticipantID) {
|
||||
if w.closed.get() {
|
||||
if w.closed.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -368,7 +368,7 @@ func (w *WebRTCReceiver) DeleteDownTrack(peerID livekit.ParticipantID) {
|
||||
}
|
||||
|
||||
func (w *WebRTCReceiver) sendRTCP(packets []rtcp.Packet) {
|
||||
if w.closed.get() {
|
||||
if w.closed.Load() {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -446,7 +446,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
||||
|
||||
defer func() {
|
||||
w.closeOnce.Do(func() {
|
||||
w.closed.set(true)
|
||||
w.closed.Store(true)
|
||||
w.closeTracks()
|
||||
})
|
||||
|
||||
@@ -479,7 +479,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
||||
}
|
||||
} else {
|
||||
// parallel - enables much more efficient multi-core utilization
|
||||
start := uint64(0)
|
||||
start := atomic.NewUint64(0)
|
||||
end := uint64(len(downTracks))
|
||||
|
||||
// 100µs is enough to amortize the overhead and provide sufficient load balancing.
|
||||
@@ -492,7 +492,7 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
for {
|
||||
n := atomic.AddUint64(&start, step)
|
||||
n := start.Add(step)
|
||||
if n >= end+step {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user