Fix deadlock on write to track channel

This commit is contained in:
Alex X
2025-04-08 11:33:04 +03:00
parent ce02b03a73
commit 699a995e8c

View File

@@ -97,8 +97,9 @@ func NewSender(media *Media, codec *Codec) *Sender {
buf: buf,
}
s.Input = func(packet *Packet) {
// writing to nil chan - OK, writing to closed chan - panic
s.mu.Lock()
if s.buf != nil {
// unblocked write to channel
select {
case s.buf <- packet:
s.Bytes += len(packet.Payload)
@@ -106,6 +107,9 @@ func NewSender(media *Media, codec *Codec) *Sender {
default:
s.Drops++
}
} else {
s.Drops++
}
s.mu.Unlock()
}
s.Output = func(packet *Packet) {