|
|
@ -12,13 +12,12 @@ import (
|
|
|
|
type Pusher struct {
|
|
|
|
type Pusher struct {
|
|
|
|
*Session
|
|
|
|
*Session
|
|
|
|
*RTSPClient
|
|
|
|
*RTSPClient
|
|
|
|
players map[string]*Player //SessionID <-> Player
|
|
|
|
players map[string]*Player //SessionID <-> Player
|
|
|
|
playersLock sync.RWMutex
|
|
|
|
playersLock sync.RWMutex
|
|
|
|
gopCacheEnable bool
|
|
|
|
gopCacheEnable bool
|
|
|
|
gopCache []*RTPPack
|
|
|
|
gopCache []*RTPPack
|
|
|
|
gopCacheLock sync.RWMutex
|
|
|
|
gopCacheLock sync.RWMutex
|
|
|
|
UDPServer *UDPServer
|
|
|
|
UDPServer *UDPServer
|
|
|
|
|
|
|
|
|
|
|
|
spsppsInSTAPaPack bool
|
|
|
|
spsppsInSTAPaPack bool
|
|
|
|
cond *sync.Cond
|
|
|
|
cond *sync.Cond
|
|
|
|
queue []*RTPPack
|
|
|
|
queue []*RTPPack
|
|
|
@ -187,10 +186,24 @@ func NewPusher(session *Session) (pusher *Pusher) {
|
|
|
|
cond: sync.NewCond(&sync.Mutex{}),
|
|
|
|
cond: sync.NewCond(&sync.Mutex{}),
|
|
|
|
queue: make([]*RTPPack, 0),
|
|
|
|
queue: make([]*RTPPack, 0),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pusher.bindSession(session)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (pusher *Pusher) bindSession(session *Session) {
|
|
|
|
|
|
|
|
pusher.Session = session
|
|
|
|
session.RTPHandles = append(session.RTPHandles, func(pack *RTPPack) {
|
|
|
|
session.RTPHandles = append(session.RTPHandles, func(pack *RTPPack) {
|
|
|
|
|
|
|
|
if session != pusher.Session {
|
|
|
|
|
|
|
|
session.logger.Printf("Session recv rtp to pusher.but pusher got a new session[%v].", pusher.Session.ID)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
pusher.QueueRTP(pack)
|
|
|
|
pusher.QueueRTP(pack)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
session.StopHandles = append(session.StopHandles, func() {
|
|
|
|
session.StopHandles = append(session.StopHandles, func() {
|
|
|
|
|
|
|
|
if session != pusher.Session {
|
|
|
|
|
|
|
|
session.logger.Printf("Session stop to release pusher.but pusher got a new session[%v].", pusher.Session.ID)
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
pusher.ClearPlayer()
|
|
|
|
pusher.ClearPlayer()
|
|
|
|
pusher.Server().RemovePusher(pusher)
|
|
|
|
pusher.Server().RemovePusher(pusher)
|
|
|
|
pusher.cond.Broadcast()
|
|
|
|
pusher.cond.Broadcast()
|
|
|
@ -199,7 +212,37 @@ func NewPusher(session *Session) (pusher *Pusher) {
|
|
|
|
pusher.UDPServer = nil
|
|
|
|
pusher.UDPServer = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (pusher *Pusher) RebindSession(session *Session) bool {
|
|
|
|
|
|
|
|
if pusher.RTSPClient != nil {
|
|
|
|
|
|
|
|
pusher.Logger().Printf("call RebindSession[%s] to a Client-Pusher. got false", session.ID)
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := pusher.Session
|
|
|
|
|
|
|
|
pusher.bindSession(session)
|
|
|
|
|
|
|
|
session.Pusher = pusher
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pusher.gopCacheLock.Lock()
|
|
|
|
|
|
|
|
pusher.gopCache = make([]*RTPPack, 0)
|
|
|
|
|
|
|
|
pusher.gopCacheLock.Unlock()
|
|
|
|
|
|
|
|
if sess != nil {
|
|
|
|
|
|
|
|
sess.Stop()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (pusher *Pusher) RebindClient(client *RTSPClient) bool {
|
|
|
|
|
|
|
|
if pusher.Session != nil {
|
|
|
|
|
|
|
|
pusher.Logger().Printf("call RebindClient[%s] to a Session-Pusher. got false", client.ID)
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
sess := pusher.RTSPClient
|
|
|
|
|
|
|
|
pusher.RTSPClient = client
|
|
|
|
|
|
|
|
if sess != nil {
|
|
|
|
|
|
|
|
sess.Stop()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (pusher *Pusher) QueueRTP(pack *RTPPack) *Pusher {
|
|
|
|
func (pusher *Pusher) QueueRTP(pack *RTPPack) *Pusher {
|
|
|
@ -312,10 +355,11 @@ func (pusher *Pusher) ClearPlayer() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pusher.players = make(map[string]*Player)
|
|
|
|
pusher.players = make(map[string]*Player)
|
|
|
|
pusher.playersLock.Unlock()
|
|
|
|
pusher.playersLock.Unlock()
|
|
|
|
|
|
|
|
go func() { // do not block
|
|
|
|
for _, v := range players {
|
|
|
|
for _, v := range players {
|
|
|
|
v.Stop()
|
|
|
|
v.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (pusher *Pusher) shouldSequenceStart(rtp *RTPInfo) bool {
|
|
|
|
func (pusher *Pusher) shouldSequenceStart(rtp *RTPInfo) bool {
|
|
|
|