Skip to content

Commit

Permalink
Merge pull request #8 from prlanzarin/u27/fix/cpu-lock-jbread
Browse files Browse the repository at this point in the history
fix: CPU lock when reading packets from JB
  • Loading branch information
prlanzarin authored May 11, 2023
2 parents 6fedd96 + 2d93ad6 commit 2368e36
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2 1
0.3 1
31 changes: 16 additions & 15 deletions internal/webrtc/webrtc.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ func (w WebRTC) Init(
}

jb := utils.NewJitterBuffer(w.cfg.JitterBuffer)
var s1, s2 uint16

if true {
done := make(chan bool)
Expand All @@ -185,7 +186,6 @@ func (w WebRTC) Init(
go func() {
ticker := time.NewTicker(time.Millisecond * 100)
var wasFlowing, isFlowing bool
var s1, s2 uint16
for {
select {
case <-done:
Expand All @@ -212,20 +212,6 @@ func (w WebRTC) Init(
}
}
wasFlowing = isFlowing
default:
packets := jb.NextPackets()
if packets == nil {
continue
}
for _, p := range packets {
s2 = p.SequenceNumber
switch {
case isAudio:
r.PushAudio(p)
case isVideo:
r.PushVideo(p)
}
}
}
}
}()
Expand All @@ -249,6 +235,21 @@ func (w WebRTC) Init(
seq = su.Unwrap(uint64(rtp.SequenceNumber))
jb.Add(seq, rtp)
rl.Add(rtp.SequenceNumber)
packets := jb.NextPackets()

if packets == nil {
continue
}

for _, p := range packets {
s2 = p.SequenceNumber
switch {
case isAudio:
r.PushAudio(p)
case isVideo:
r.PushVideo(p)
}
}
}
})

Expand Down

0 comments on commit 2368e36

Please sign in to comment.