Browse Source

update gortsplib

pull/169/head
aler9 6 years ago
parent
commit
cbab55af4c
  1. 2
      go.mod
  2. 4
      go.sum
  3. 31
      internal/client/client.go
  4. 2
      internal/clientman/clientman.go
  5. 2
      internal/conf/conf.go
  6. 2
      internal/conf/pathconf.go
  7. 2
      internal/path/path.go
  8. 2
      internal/path/readersmap.go
  9. 4
      internal/pathman/pathman.go
  10. 4
      internal/serverudp/server.go
  11. 4
      internal/sourcertmp/source.go
  12. 95
      internal/sourcertsp/source.go

2
go.mod

@ -5,7 +5,7 @@ go 1.15 @@ -5,7 +5,7 @@ go 1.15
require (
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751 // indirect
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d // indirect
github.com/aler9/gortsplib v0.0.0-20201112104820-ad96344f01fe
github.com/aler9/gortsplib v0.0.0-20201115164941-3f45d21f1132
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9
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 @@ -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/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/aler9/gortsplib v0.0.0-20201112104820-ad96344f01fe h1:se/lGBXWvJzIhUCKfvH/FDJQ4aFzbC/782fnIOcXK8A=
github.com/aler9/gortsplib v0.0.0-20201112104820-ad96344f01fe/go.mod h1:6yKsTNIrCapRz90WHQtyFV/rKK0TT+QapxUXNqSJi9M=
github.com/aler9/gortsplib v0.0.0-20201115164941-3f45d21f1132 h1:yPtvZE/tfSPkQn7R2TkBv0I9t318yKDgCwynHzuCK5E=
github.com/aler9/gortsplib v0.0.0-20201115164941-3f45d21f1132/go.mod h1:6yKsTNIrCapRz90WHQtyFV/rKK0TT+QapxUXNqSJi9M=
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.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=

31
internal/client/client.go

@ -12,10 +12,10 @@ import ( @@ -12,10 +12,10 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/auth"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/headers"
"github.com/aler9/gortsplib/rtcpreceiver"
"github.com/aler9/gortsplib/pkg/auth"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/gortsplib/pkg/rtcpreceiver"
"github.com/aler9/rtsp-simple-server/internal/conf"
"github.com/aler9/rtsp-simple-server/internal/externalcmd"
@ -56,27 +56,22 @@ const ( @@ -56,27 +56,22 @@ const (
stateRecord
)
func (cs state) String() string {
switch cs {
func (s state) String() string {
switch s {
case stateInitial:
return "Initial"
return "initial"
case stateWaitingDescribe:
return "WaitingDescribe"
return "waitingDescribe"
case statePrePlay:
return "PrePlay"
return "prePlay"
case statePlay:
return "Play"
return "play"
case statePreRecord:
return "PreRecord"
return "preRecord"
case stateRecord:
return "Record"
return "record"
}
return "Invalid"
return "invalid"
}
// Path is implemented by path.Path.

2
internal/clientman/clientman.go

@ -5,7 +5,7 @@ import ( @@ -5,7 +5,7 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/pathman"

2
internal/conf/conf.go

@ -6,7 +6,7 @@ import ( @@ -6,7 +6,7 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/headers"
"github.com/aler9/gortsplib/pkg/headers"
"gopkg.in/yaml.v2"
"github.com/aler9/rtsp-simple-server/internal/confenv"

2
internal/conf/pathconf.go

@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/pkg/base"
)
var reUserPass = regexp.MustCompile("^[a-zA-Z0-9!\\$\\(\\)\\*\\+\\.;<=>\\[\\]\\^_\\-\\{\\}]+$")

2
internal/path/path.go

@ -9,7 +9,7 @@ import ( @@ -9,7 +9,7 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/conf"

2
internal/path/readersmap.go

@ -4,7 +4,7 @@ import ( @@ -4,7 +4,7 @@ import (
"sync"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/pkg/base"
)
type reader interface {

4
internal/pathman/pathman.go

@ -6,8 +6,8 @@ import ( @@ -6,8 +6,8 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/headers"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/headers"
"github.com/aler9/rtsp-simple-server/internal/client"
"github.com/aler9/rtsp-simple-server/internal/conf"

4
internal/serverudp/server.go

@ -6,8 +6,8 @@ import ( @@ -6,8 +6,8 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/base"
"github.com/aler9/gortsplib/multibuffer"
"github.com/aler9/gortsplib/pkg/base"
"github.com/aler9/gortsplib/pkg/multibuffer"
)
const (

4
internal/sourcertmp/source.go

@ -8,8 +8,8 @@ import ( @@ -8,8 +8,8 @@ import (
"time"
"github.com/aler9/gortsplib"
"github.com/aler9/gortsplib/rtpaac"
"github.com/aler9/gortsplib/rtph264"
"github.com/aler9/gortsplib/pkg/rtpaac"
"github.com/aler9/gortsplib/pkg/rtph264"
"github.com/notedit/rtmp/av"
"github.com/notedit/rtmp/codec/h264"
"github.com/notedit/rtmp/format/rtmp"

95
internal/sourcertsp/source.go

@ -113,11 +113,14 @@ func (s *Source) runInner() bool { @@ -113,11 +113,14 @@ func (s *Source) runInner() bool {
dialDone := make(chan struct{}, 1)
go func() {
defer close(dialDone)
conn, err = gortsplib.Dialer{
dialer := gortsplib.Dialer{
StreamProtocol: s.proto,
ReadTimeout: s.readTimeout,
WriteTimeout: s.writeTimeout,
ReadBufferCount: 2,
}.DialRead(s.ur, s.proto)
}
conn, err = dialer.DialRead(s.ur)
}()
select {
@ -136,89 +139,12 @@ func (s *Source) runInner() bool { @@ -136,89 +139,12 @@ func (s *Source) runInner() bool {
s.parent.Log("rtsp source ready")
s.parent.OnSourceSetReady(tracks)
var ret bool
if s.proto == gortsplib.StreamProtocolUDP {
ret = s.runUDP(conn, tracks)
} else {
ret = s.runTCP(conn, tracks)
}
s.parent.OnSourceSetNotReady()
return ret
}
func (s *Source) runUDP(conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool {
var wg sync.WaitGroup
// receive RTP packets
for trackId := range tracks {
wg.Add(1)
go func(trackId int) {
defer wg.Done()
for {
buf, err := conn.ReadFrameUDP(trackId, gortsplib.StreamTypeRtp)
if err != nil {
break
}
s.parent.OnFrame(trackId, gortsplib.StreamTypeRtp, buf)
}
}(trackId)
}
// receive RTCP packets
for trackId := range tracks {
wg.Add(1)
go func(trackId int) {
defer wg.Done()
for {
buf, err := conn.ReadFrameUDP(trackId, gortsplib.StreamTypeRtcp)
if err != nil {
break
}
s.parent.OnFrame(trackId, gortsplib.StreamTypeRtcp, buf)
}
}(trackId)
}
tcpConnDone := make(chan error)
go func() {
tcpConnDone <- conn.LoopUDP()
}()
var ret bool
outer:
for {
select {
case <-s.terminate:
conn.Close()
<-tcpConnDone
ret = false
break outer
case err := <-tcpConnDone:
conn.Close()
s.parent.Log("rtsp source ERR: %s", err)
ret = true
break outer
}
}
wg.Wait()
return ret
}
func (s *Source) runTCP(conn *gortsplib.ConnClient, tracks gortsplib.Tracks) bool {
tcpConnDone := make(chan error)
readDone := make(chan error)
go func() {
for {
trackId, streamType, content, err := conn.ReadFrameTCP()
trackId, streamType, content, err := conn.ReadFrame()
if err != nil {
tcpConnDone <- err
readDone <- err
return
}
@ -233,11 +159,11 @@ outer: @@ -233,11 +159,11 @@ outer:
select {
case <-s.terminate:
conn.Close()
<-tcpConnDone
<-readDone
ret = false
break outer
case err := <-tcpConnDone:
case err := <-readDone:
conn.Close()
s.parent.Log("rtsp source ERR: %s", err)
ret = true
@ -245,5 +171,6 @@ outer: @@ -245,5 +171,6 @@ outer:
}
}
s.parent.OnSourceSetNotReady()
return ret
}

Loading…
Cancel
Save