Fix race on pcm pack backchannel #432
This commit is contained in:
+11
-2
@@ -3,15 +3,22 @@ package pcm
|
|||||||
import (
|
import (
|
||||||
"github.com/AlexxIT/go2rtc/pkg/core"
|
"github.com/AlexxIT/go2rtc/pkg/core"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RepackBackchannel(handler core.HandlerFunc) core.HandlerFunc {
|
func RepackBackchannel(handler core.HandlerFunc) core.HandlerFunc {
|
||||||
var buf []byte
|
var buf []byte
|
||||||
var seq uint16
|
var seq uint16
|
||||||
|
|
||||||
|
// fix https://github.com/AlexxIT/go2rtc/issues/432
|
||||||
|
var mu sync.Mutex
|
||||||
|
|
||||||
return func(packet *rtp.Packet) {
|
return func(packet *rtp.Packet) {
|
||||||
|
mu.Lock()
|
||||||
|
|
||||||
buf = append(buf, packet.Payload...)
|
buf = append(buf, packet.Payload...)
|
||||||
if len(buf) < 1024 {
|
if len(buf) < 1024 {
|
||||||
|
mu.Unlock()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,9 +34,11 @@ func RepackBackchannel(handler core.HandlerFunc) core.HandlerFunc {
|
|||||||
Payload: buf[:1024],
|
Payload: buf[:1024],
|
||||||
}
|
}
|
||||||
|
|
||||||
handler(pkt)
|
|
||||||
|
|
||||||
buf = buf[1024:]
|
buf = buf[1024:]
|
||||||
seq++
|
seq++
|
||||||
|
|
||||||
|
mu.Unlock()
|
||||||
|
|
||||||
|
handler(pkt)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user