Browse Source

update gortsplib

pull/442/head
aler9 5 years ago
parent
commit
6d02ec9478
  1. 2
      go.mod
  2. 4
      go.sum
  3. 29
      internal/rtspsource/source.go
  4. 51
      main_clientrtsp_test.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-20210509121021-994cd442e361
github.com/aler9/gortsplib v0.0.0-20210510211300-0d6385640fad
github.com/asticode/go-astits v0.0.0-00010101000000-000000000000
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.4.9

4
go.sum

@ -4,8 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c @@ -4,8 +4,8 @@ github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d h1:UQZhZ2O0vMHr2c
github.com/alecthomas/units v0.0.0-20190924025748-f65c72e2690d/go.mod h1:rBZYJk541a8SKzHPHnH3zbiI+7dagKZ0cgpgrD7Fyho=
github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04 h1:CXgQLsU4uxWAmsXNOjGLbj0A+0IlRcpZpMgI13fmVwo=
github.com/aler9/go-astits v0.0.0-20210423195926-582b09ed7c04/go.mod h1:DkOWmBNQpnr9mv24KfZjq4JawCFX1FCqjLVGvO0DygQ=
github.com/aler9/gortsplib v0.0.0-20210509121021-994cd442e361 h1:GZCzLl3MiMCgQdiC+xU+eUqJ2/x8ZKba55TJhzgTNnY=
github.com/aler9/gortsplib v0.0.0-20210509121021-994cd442e361/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY=
github.com/aler9/gortsplib v0.0.0-20210510211300-0d6385640fad h1:u6DNZKoG3gm5pMz+K1duYS5pqbrq6iuiDB1kJc4N0d4=
github.com/aler9/gortsplib v0.0.0-20210510211300-0d6385640fad/go.mod h1:zVCg+TQX445hh1pC5QgAuuBvvXZMWLY1XYz626dGFqY=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927 h1:95mXJ5fUCYpBRdSOnLAQAdJHHKxxxJrVCiaqDi965YQ=
github.com/aler9/rtmp v0.0.0-20210403095203-3be4a5535927/go.mod h1:vzuE21rowz+lT1NGsWbreIvYulgBpCGnQyeTyFblUHc=
github.com/asticode/go-astikit v0.20.0 h1:+7N+J4E4lWx2QOkRdOf6DafWJMv6O4RRfgClwQokrH8=

29
internal/rtspsource/source.go

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
package rtspsource
import (
"context"
"crypto/sha256"
"crypto/tls"
"encoding/hex"
@ -123,12 +124,6 @@ func (s *Source) run() { @@ -123,12 +124,6 @@ func (s *Source) run() {
func (s *Source) runInner() bool {
s.log(logger.Debug, "connecting")
var conn *gortsplib.ClientConn
var err error
dialDone := make(chan struct{}, 1)
go func() {
defer close(dialDone)
client := &gortsplib.Client{
StreamProtocol: s.proto,
TLSConfig: &tls.Config{
@ -159,13 +154,24 @@ func (s *Source) runInner() bool { @@ -159,13 +154,24 @@ func (s *Source) runInner() bool {
},
}
conn, err = client.DialRead(s.ur)
ctx, ctxCancel := context.WithCancel(context.Background())
var conn *gortsplib.ClientConn
var err error
dialDone := make(chan struct{})
go func() {
defer close(dialDone)
conn, err = client.DialReadContext(ctx, s.ur)
}()
select {
case <-s.terminate:
ctxCancel()
<-dialDone
return false
case <-dialDone:
ctxCancel()
}
if err != nil {
@ -190,17 +196,20 @@ func (s *Source) runInner() bool { @@ -190,17 +196,20 @@ func (s *Source) runInner() bool {
<-res
}()
done := conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
readErr := make(chan error)
go func() {
readErr <- conn.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
res.SP.OnFrame(trackID, streamType, payload)
})
}()
select {
case <-s.terminate:
conn.Close()
<-done
<-readErr
return false
case err := <-done:
case err := <-readErr:
s.log(logger.Info, "ERR: %s", err)
conn.Close()
return true

51
main_clientrtsp_test.go

@ -452,15 +452,19 @@ func TestClientRTSPPublisherOverride(t *testing.T) { @@ -452,15 +452,19 @@ func TestClientRTSPPublisherOverride(t *testing.T) {
require.NoError(t, err)
defer d1.Close()
recv := make(chan struct{})
readDone := make(chan struct{})
frameRecv := make(chan struct{})
go func() {
defer close(readDone)
d1.ReadFrames(func(trackID int, streamType base.StreamType, payload []byte) {
if ca == "enabled" {
require.Equal(t, []byte{0x05, 0x06, 0x07, 0x08}, payload)
} else {
require.Equal(t, []byte{0x01, 0x02, 0x03, 0x04}, payload)
}
close(recv)
close(frameRecv)
})
}()
err = s1.WriteFrame(track.ID, gortsplib.StreamTypeRTP,
[]byte{0x01, 0x02, 0x03, 0x04})
@ -476,7 +480,10 @@ func TestClientRTSPPublisherOverride(t *testing.T) { @@ -476,7 +480,10 @@ func TestClientRTSPPublisherOverride(t *testing.T) {
require.NoError(t, err)
}
<-recv
<-frameRecv
d1.Close()
<-readDone
})
}
}
@ -511,21 +518,24 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) { @@ -511,21 +518,24 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)
recvDone := make(chan struct{})
recvErr := dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
readDone := make(chan struct{})
frameRecv := make(chan struct{})
go func() {
defer close(readDone)
dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
require.Equal(t, gortsplib.StreamTypeRTP, streamType)
require.Equal(t, input, payload)
close(recvDone)
close(frameRecv)
})
}()
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, input)
require.NoError(t, err)
select {
case <-recvDone:
case err := <-recvErr:
t.Error(err)
}
<-frameRecv
dest.Close()
<-readDone
})
t.Run("proxy", func(t *testing.T) {
@ -572,21 +582,24 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) { @@ -572,21 +582,24 @@ func TestClientRTSPNonCompliantFrameSize(t *testing.T) {
input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)
recvDone := make(chan struct{})
recvErr := dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
readDone := make(chan struct{})
frameRecv := make(chan struct{})
go func() {
defer close(readDone)
dest.ReadFrames(func(trackID int, streamType gortsplib.StreamType, payload []byte) {
require.Equal(t, gortsplib.StreamTypeRTP, streamType)
require.Equal(t, input, payload)
close(recvDone)
close(frameRecv)
})
}()
err = source.WriteFrame(track.ID, gortsplib.StreamTypeRTP, input)
require.NoError(t, err)
select {
case <-recvDone:
case err := <-recvErr:
t.Error(err)
}
<-frameRecv
dest.Close()
<-readDone
})
}

Loading…
Cancel
Save