Skip to content

Commit

Permalink
move test into gortsplib
Browse files Browse the repository at this point in the history
  • Loading branch information
aler9 committed Nov 6, 2021
1 parent 9645d18 commit d5c55a8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 126 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
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-20211106110157-ee767bfdefbe
github.com/aler9/gortsplib v0.0.0-20211106122816-6e38851a096e
github.com/asticode/go-astits v1.10.0
github.com/fsnotify/fsnotify v1.4.9
github.com/gin-gonic/gin v1.7.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20211106110157-ee767bfdefbe h1:UuS+N7mG8uCvYGC92wR3OtFcys2keSeeMGkJgG5tWcM=
github.com/aler9/gortsplib v0.0.0-20211106110157-ee767bfdefbe/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc=
github.com/aler9/gortsplib v0.0.0-20211106122816-6e38851a096e h1:qSjVAaIvJukmEuLxV0agmQ5KmBabBK+jzb+eNqG3Z+w=
github.com/aler9/gortsplib v0.0.0-20211106122816-6e38851a096e/go.mod h1:fyQrQyHo8QvdR/h357tkv1g36VesZlzEPsdAu2VrHHc=
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=
Expand Down
123 changes: 0 additions & 123 deletions internal/core/rtsp_server_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package core

import (
"bytes"
"os"
"testing"
"time"
Expand Down Expand Up @@ -467,128 +466,6 @@ func TestRTSPServerPublisherOverride(t *testing.T) {
}
}

func TestRTSPServerNonCompliantFrameSize(t *testing.T) {
t.Run("publish", func(t *testing.T) {
p, ok := newInstance(
"rtmpDisable: yes\n" +
"hlsDisable: yes\n" +
"readBufferSize: 4500\n" +
"paths:\n" +
" all:\n")
require.Equal(t, true, ok)
defer p.close()

track, err := gortsplib.NewTrackH264(96,
&gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)

client := &gortsplib.Client{
Transport: func() *gortsplib.Transport {
v := gortsplib.TransportTCP
return &v
}(),
ReadBufferSize: 4500,
}

source, err := client.DialPublish("rtsp://localhost:8554/teststream",
gortsplib.Tracks{track})
require.NoError(t, err)
defer source.Close()

dest, err := client.DialRead("rtsp://localhost:8554/teststream")
require.NoError(t, err)
defer dest.Close()

input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)

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(frameRecv)
})
}()

err = source.WriteFrame(0, gortsplib.StreamTypeRTP, input)
require.NoError(t, err)

<-frameRecv

dest.Close()
<-readDone
})

t.Run("proxy", func(t *testing.T) {
p1, ok := newInstance("rtmpDisable: yes\n" +
"hlsDisable: yes\n" +
"protocols: [tcp]\n" +
"readBufferSize: 4500\n" +
"paths:\n" +
" all:\n")
require.Equal(t, true, ok)
defer p1.close()

track, err := gortsplib.NewTrackH264(96,
&gortsplib.TrackConfigH264{SPS: []byte{0x01, 0x02, 0x03, 0x04}, PPS: []byte{0x01, 0x02, 0x03, 0x04}})
require.NoError(t, err)

client := &gortsplib.Client{
Transport: func() *gortsplib.Transport {
v := gortsplib.TransportTCP
return &v
}(),
ReadBufferSize: 4500,
}

source, err := client.DialPublish("rtsp://localhost:8554/teststream",
gortsplib.Tracks{track})
require.NoError(t, err)
defer source.Close()

p2, ok := newInstance("rtmpDisable: yes\n" +
"hlsDisable: yes\n" +
"protocols: [tcp]\n" +
"readBufferSize: 4500\n" +
"rtspAddress: :8555\n" +
"paths:\n" +
" teststream:\n" +
" source: rtsp://localhost:8554/teststream\n" +
" sourceProtocol: tcp\n")
require.Equal(t, true, ok)
defer p2.close()

time.Sleep(100 * time.Millisecond)

dest, err := client.DialRead("rtsp://localhost:8555/teststream")
require.NoError(t, err)
defer dest.Close()

input := bytes.Repeat([]byte{0x01, 0x02, 0x03, 0x04, 0x05}, 4096/5)

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(frameRecv)
})
}()

err = source.WriteFrame(0, gortsplib.StreamTypeRTP, input)
require.NoError(t, err)

<-frameRecv

dest.Close()
<-readDone
})
}

func TestRTSPServerRedirect(t *testing.T) {
p1, ok := newInstance("rtmpDisable: yes\n" +
"hlsDisable: yes\n" +
Expand Down

0 comments on commit d5c55a8

Please sign in to comment.