Commit c4284a45 authored by Juliusz Chroboczek's avatar Juliusz Chroboczek

Delay rtcpUpSender until the connection is complete.

This avoids locking in sendRR.
parent 7786aa12
...@@ -336,8 +336,6 @@ func addUpConn(c *webClient, id string) (*upConnection, error) { ...@@ -336,8 +336,6 @@ func addUpConn(c *webClient, id string) (*upConnection, error) {
sendICE(c, id, candidate) sendICE(c, id, candidate)
}) })
go rtcpUpSender(c, conn)
pc.OnTrack(func(remote *webrtc.Track, receiver *webrtc.RTPReceiver) { pc.OnTrack(func(remote *webrtc.Track, receiver *webrtc.RTPReceiver) {
c.mu.Lock() c.mu.Lock()
u, ok := c.up[id] u, ok := c.up[id]
...@@ -395,6 +393,7 @@ func addUpConn(c *webClient, id string) (*upConnection, error) { ...@@ -395,6 +393,7 @@ func addUpConn(c *webClient, id string) (*upConnection, error) {
for _, cc := range clients { for _, cc := range clients {
cc.pushConn(u, tracks, u.label) cc.pushConn(u, tracks, u.label)
} }
go rtcpUpSender(conn)
} }
}) })
...@@ -569,10 +568,8 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) { ...@@ -569,10 +568,8 @@ func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
} }
} }
func sendRR(c *webClient, conn *upConnection) error { func sendRR(conn *upConnection) error {
c.mu.Lock()
if len(conn.tracks) == 0 { if len(conn.tracks) == 0 {
c.mu.Unlock()
return nil return nil
} }
...@@ -600,25 +597,23 @@ func sendRR(c *webClient, conn *upConnection) error { ...@@ -600,25 +597,23 @@ func sendRR(c *webClient, conn *upConnection) error {
Delay: delay, Delay: delay,
}) })
} }
c.mu.Unlock()
return conn.pc.WriteRTCP([]rtcp.Packet{ return conn.pc.WriteRTCP([]rtcp.Packet{
&rtcp.ReceiverReport{ &rtcp.ReceiverReport{
SSRC: 1,
Reports: reports, Reports: reports,
}, },
}) })
} }
func rtcpUpSender(c *webClient, conn *upConnection) { func rtcpUpSender(conn *upConnection) {
for { for {
time.Sleep(time.Second) time.Sleep(time.Second)
err := sendRR(c, conn) err := sendRR(conn)
if err != nil { if err != nil {
if err == io.EOF || err == io.ErrClosedPipe { if err == io.EOF || err == io.ErrClosedPipe {
return return
} }
log.Printf("WriteRTCP: %v", err) log.Printf("sendRR: %v", err)
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment