mirror of
https://github.com/jech/galene.git
synced 2024-11-22 16:45:58 +01:00
Signal new tracks explicitly.
This commit is contained in:
parent
5916028edd
commit
5a2dbf36b9
2 changed files with 50 additions and 31 deletions
25
client.go
25
client.go
|
@ -353,6 +353,8 @@ func addUpConn(c *client, id string) (*upConnection, error) {
|
||||||
rate: estimator.New(time.Second),
|
rate: estimator.New(time.Second),
|
||||||
jitter: jitter.New(remote.Codec().ClockRate),
|
jitter: jitter.New(remote.Codec().ClockRate),
|
||||||
maxBitrate: ^uint64(0),
|
maxBitrate: ^uint64(0),
|
||||||
|
localCh: make(chan struct{}, 2),
|
||||||
|
writerDone: make(chan struct{}),
|
||||||
}
|
}
|
||||||
u.tracks = append(u.tracks, track)
|
u.tracks = append(u.tracks, track)
|
||||||
var tracks []*upTrack
|
var tracks []*upTrack
|
||||||
|
@ -432,20 +434,18 @@ func readLoop(conn *upConnection, track *upTrack) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) {
|
func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) {
|
||||||
var localTime uint64
|
defer close(track.writerDone)
|
||||||
var local []*downTrack
|
|
||||||
|
|
||||||
buf := make([]byte, packetcache.BufSize)
|
buf := make([]byte, packetcache.BufSize)
|
||||||
var packet rtp.Packet
|
var packet rtp.Packet
|
||||||
|
|
||||||
for {
|
local := track.getLocal()
|
||||||
now := mono.Microseconds()
|
|
||||||
if now < localTime || now > localTime+500000 {
|
|
||||||
local = track.getLocal()
|
|
||||||
localTime = now
|
|
||||||
}
|
|
||||||
|
|
||||||
pi, ok := <-ch
|
for {
|
||||||
|
select {
|
||||||
|
case <-track.localCh:
|
||||||
|
local = track.getLocal()
|
||||||
|
case pi, ok := <-ch:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -469,6 +469,7 @@ func writeLoop(conn *upConnection, track *upTrack, ch <-chan packetIndex) {
|
||||||
l.rate.Add(uint32(bytes))
|
l.rate.Add(uint32(bytes))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
|
func rtcpUpListener(conn *upConnection, track *upTrack, r *webrtc.RTPReceiver) {
|
||||||
|
@ -637,7 +638,11 @@ func addDownConn(c *client, id string, remote *upConnection) (*downConnection, e
|
||||||
if c.down == nil {
|
if c.down == nil {
|
||||||
c.down = make(map[string]*downConnection)
|
c.down = make(map[string]*downConnection)
|
||||||
}
|
}
|
||||||
conn := &downConnection{id: id, pc: pc, remote: remote}
|
conn := &downConnection{
|
||||||
|
id: id,
|
||||||
|
pc: pc,
|
||||||
|
remote: remote,
|
||||||
|
}
|
||||||
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
defer c.mu.Unlock()
|
||||||
|
|
18
group.go
18
group.go
|
@ -35,25 +35,39 @@ type upTrack struct {
|
||||||
lastSenderReport uint32
|
lastSenderReport uint32
|
||||||
lastSenderReportTime uint32
|
lastSenderReportTime uint32
|
||||||
|
|
||||||
|
localCh chan struct{} // signals that local has changed
|
||||||
|
writerDone chan struct{} // closed when the loop dies
|
||||||
|
|
||||||
mu sync.Mutex
|
mu sync.Mutex
|
||||||
local []*downTrack
|
local []*downTrack
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (up *upTrack) notifyLocal() {
|
||||||
|
var s struct{}
|
||||||
|
select {
|
||||||
|
case up.localCh <- s:
|
||||||
|
case <-up.writerDone:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (up *upTrack) addLocal(local *downTrack) {
|
func (up *upTrack) addLocal(local *downTrack) {
|
||||||
up.mu.Lock()
|
up.mu.Lock()
|
||||||
defer up.mu.Unlock()
|
|
||||||
up.local = append(up.local, local)
|
up.local = append(up.local, local)
|
||||||
|
up.mu.Unlock()
|
||||||
|
up.notifyLocal()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (up *upTrack) delLocal(local *downTrack) bool {
|
func (up *upTrack) delLocal(local *downTrack) bool {
|
||||||
up.mu.Lock()
|
up.mu.Lock()
|
||||||
defer up.mu.Unlock()
|
|
||||||
for i, l := range up.local {
|
for i, l := range up.local {
|
||||||
if l == local {
|
if l == local {
|
||||||
up.local = append(up.local[:i], up.local[i+1:]...)
|
up.local = append(up.local[:i], up.local[i+1:]...)
|
||||||
|
up.mu.Unlock()
|
||||||
|
up.notifyLocal()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
up.mu.Unlock()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue