Browse Source

fix freeze

pull/169/head
aler9 5 years ago
parent
commit
9887abc51a
  1. 2
      go.mod
  2. 4
      go.sum
  3. 41
      internal/client/client.go

2
go.mod

@ -5,7 +5,7 @@ go 1.15
require ( require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20201214220650-27636bc8102d github.com/aler9/gortsplib v0.0.0-20201215190704-e5b126007572
github.com/davecgh/go-spew v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51

4
go.sum

@ -2,8 +2,8 @@ github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 h1:JYp7IbQjafo
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc= github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2cI+DC1Mbh0TJxzA3RcLoMsFw+aXw7E=
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho= github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/gortsplib v0.0.0-20201214220650-27636bc8102d h1:2ZoBLngSzfy/n4FawfA//Gbwu7xkIswOo7trGKtSZyU= github.com/aler9/gortsplib v0.0.0-20201215190704-e5b126007572 h1:7tZCOaqiBURhVXE0xR6jNz6T7UX/LUKUKl0qsZBQwGU=
github.com/aler9/gortsplib v0.0.0-20201214220650-27636bc8102d/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I= github.com/aler9/gortsplib v0.0.0-20201215190704-e5b126007572/go.mod h1:8P09VjpiPJFyfkVosyF5/TY82jNwkMN165NS/7sc32I=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

41
internal/client/client.go

@ -113,8 +113,6 @@ type Client struct {
streamTracks map[int]*streamTrack streamTracks map[int]*streamTrack
rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver rtcpReceivers map[int]*rtcpreceiver.RtcpReceiver
udpLastFrameTimes []*int64 udpLastFrameTimes []*int64
writeFrameEnable bool
writeFrameMutex sync.Mutex
onReadCmd *externalcmd.Cmd onReadCmd *externalcmd.Cmd
onPublishCmd *externalcmd.Cmd onPublishCmd *externalcmd.Cmd
@ -775,10 +773,17 @@ func (c *Client) run() {
switch c.state { switch c.state {
case statePlay: case statePlay:
if c.streamProtocol == gortsplib.StreamProtocolTCP {
c.conn.EnableFrames(false)
}
c.stopPlay() c.stopPlay()
c.state = statePrePlay c.state = statePrePlay
case stateRecord: case stateRecord:
if c.streamProtocol == gortsplib.StreamProtocolTCP {
c.conn.EnableFrames(false)
c.conn.EnableReadTimeout(false)
}
c.stopRecord() c.stopRecord()
c.state = statePreRecord c.state = statePreRecord
} }
@ -951,10 +956,6 @@ func (c *Client) checkState(allowed map[state]struct{}) error {
} }
func (c *Client) startPlay() { func (c *Client) startPlay() {
if c.streamProtocol == gortsplib.StreamProtocolTCP {
c.writeFrameEnable = true
}
c.state = statePlay c.state = statePlay
c.path.OnClientPlay(c) c.path.OnClientPlay(c)
@ -973,25 +974,11 @@ func (c *Client) startPlay() {
} }
if c.streamProtocol == gortsplib.StreamProtocolTCP { if c.streamProtocol == gortsplib.StreamProtocolTCP {
c.writeFrameMutex.Lock() c.conn.EnableFrames(true)
c.writeFrameEnable = true
c.writeFrameMutex.Unlock()
c.conn.EnableReadFrames(true)
c.conn.EnableReadTimeout(false)
} }
} }
func (c *Client) stopPlay() { func (c *Client) stopPlay() {
if c.streamProtocol == gortsplib.StreamProtocolTCP {
c.conn.EnableReadFrames(false)
c.conn.EnableReadTimeout(false)
c.writeFrameMutex.Lock()
c.writeFrameEnable = false
c.writeFrameMutex.Unlock()
}
if c.path.Conf().RunOnRead != "" { if c.path.Conf().RunOnRead != "" {
c.onReadCmd.Close() c.onReadCmd.Close()
} }
@ -1053,7 +1040,7 @@ func (c *Client) startRecord() {
if c.streamProtocol == gortsplib.StreamProtocolUDP { if c.streamProtocol == gortsplib.StreamProtocolUDP {
go c.backgroundRecordUDP() go c.backgroundRecordUDP()
} else { } else {
c.conn.EnableReadFrames(true) c.conn.EnableFrames(true)
c.conn.EnableReadTimeout(true) c.conn.EnableReadTimeout(true)
go c.backgroundRecordTCP() go c.backgroundRecordTCP()
} }
@ -1068,10 +1055,6 @@ func (c *Client) stopRecord() {
c.serverUDPRtp.RemovePublisher(c.ip(), track.rtpPort, c) c.serverUDPRtp.RemovePublisher(c.ip(), track.rtpPort, c)
c.serverUDPRtcp.RemovePublisher(c.ip(), track.rtcpPort, c) c.serverUDPRtcp.RemovePublisher(c.ip(), track.rtcpPort, c)
} }
} else {
c.conn.EnableReadFrames(false)
c.conn.EnableReadTimeout(false)
} }
if c.path.Conf().RunOnPublish != "" { if c.path.Conf().RunOnPublish != "" {
@ -1173,11 +1156,7 @@ func (c *Client) OnReaderFrame(trackID int, streamType base.StreamType, buf []by
} }
} else { } else {
c.writeFrameMutex.Lock() c.conn.WriteFrame(trackID, streamType, buf)
if c.writeFrameEnable {
c.conn.WriteFrame(trackID, streamType, buf)
}
c.writeFrameMutex.Unlock()
} }
} }

Loading…
Cancel
Save