add server test with gstreamer

This commit is contained in:
aler9
2020-12-13 22:23:16 +01:00
parent 0674c08d2b
commit d30dbb38f9
3 changed files with 46 additions and 30 deletions

View File

@@ -74,7 +74,7 @@ func TestClientDialRead(t *testing.T) {
cnt2, err := newContainer("ffmpeg", "publish", []string{ cnt2, err := newContainer("ffmpeg", "publish", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
"-i", "/emptyvideo.ts", "-i", "emptyvideo.ts",
"-c", "copy", "-c", "copy",
"-f", "rtsp", "-f", "rtsp",
"-rtsp_transport", "udp", "-rtsp_transport", "udp",
@@ -131,7 +131,7 @@ func TestClientDialReadAutomaticProtocol(t *testing.T) {
cnt2, err := newContainer("ffmpeg", "publish", []string{ cnt2, err := newContainer("ffmpeg", "publish", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
"-i", "/emptyvideo.ts", "-i", "emptyvideo.ts",
"-c", "copy", "-c", "copy",
"-f", "rtsp", "-f", "rtsp",
"-rtsp_transport", "tcp", "-rtsp_transport", "tcp",
@@ -176,7 +176,7 @@ func TestClientDialReadRedirect(t *testing.T) {
cnt2, err := newContainer("ffmpeg", "publish", []string{ cnt2, err := newContainer("ffmpeg", "publish", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
"-i", "/emptyvideo.ts", "-i", "emptyvideo.ts",
"-c", "copy", "-c", "copy",
"-f", "rtsp", "-f", "rtsp",
"-rtsp_transport", "udp", "-rtsp_transport", "udp",
@@ -218,7 +218,7 @@ func TestClientDialReadPause(t *testing.T) {
cnt2, err := newContainer("ffmpeg", "publish", []string{ cnt2, err := newContainer("ffmpeg", "publish", []string{
"-re", "-re",
"-stream_loop", "-1", "-stream_loop", "-1",
"-i", "/emptyvideo.ts", "-i", "emptyvideo.ts",
"-c", "copy", "-c", "copy",
"-f", "rtsp", "-f", "rtsp",
"-rtsp_transport", "udp", "-rtsp_transport", "udp",

View File

@@ -14,7 +14,7 @@ import (
) )
// This example shows how to // This example shows how to
// 1. create a RTSP server which accept only connections encrypted with TLS (RTSPS) // 1. create a RTSP server which accepts only connections encrypted with TLS (RTSPS)
// 2. allow a single client to publish a stream with TCP // 2. allow a single client to publish a stream with TCP
// 3. allow multiple clients to read that stream with TCP // 3. allow multiple clients to read that stream with TCP

View File

@@ -272,10 +272,13 @@ y++U32uuSFiXDcSLarfIsE992MEJLSAynbF1Rsgsr3gXbGiuToJRyxbIeVy7gwzD
func TestServerPublishReadTCP(t *testing.T) { func TestServerPublishReadTCP(t *testing.T) {
for _, ca := range []struct { for _, ca := range []struct {
publisher string publisher string
reader string
encrypted bool encrypted bool
}{ }{
{"ffmpeg", false}, {"ffmpeg", "ffmpeg", false},
{"ffmpeg", true}, {"ffmpeg", "ffmpeg", true},
{"gstreamer", "ffmpeg", false},
{"gstreamer", "ffmpeg", true},
} { } {
encryptedStr := func() string { encryptedStr := func() string {
if ca.encrypted { if ca.encrypted {
@@ -284,7 +287,7 @@ func TestServerPublishReadTCP(t *testing.T) {
return "plain" return "plain"
}() }()
t.Run(ca.publisher+"_"+encryptedStr, func(t *testing.T) { t.Run(ca.publisher+"_"+ca.reader+"_"+encryptedStr, func(t *testing.T) {
var proto string var proto string
var tlsConf *tls.Config var tlsConf *tls.Config
if !ca.encrypted { if !ca.encrypted {
@@ -302,31 +305,44 @@ func TestServerPublishReadTCP(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
defer ts.close() defer ts.close()
cnt1, err := newContainer("ffmpeg", "publish", []string{ switch ca.publisher {
"-re", case "ffmpeg":
"-stream_loop", "-1", cnt1, err := newContainer("ffmpeg", "publish", []string{
"-i", "/emptyvideo.ts", "-re",
"-c", "copy", "-stream_loop", "-1",
"-f", "rtsp", "-i", "emptyvideo.ts",
"-rtsp_transport", "tcp", "-c", "copy",
proto + "://localhost:8554/teststream", "-f", "rtsp",
}) "-rtsp_transport", "tcp",
require.NoError(t, err) proto + "://localhost:8554/teststream",
defer cnt1.close() })
require.NoError(t, err)
defer cnt1.close()
case "gstreamer":
cnt1, err := newContainer("gstreamer", "publish", []string{
"filesrc location=emptyvideo.ts ! tsdemux ! queue ! video/x-h264 ! h264parse config-interval=1 ! rtspclientsink " +
"location=" + proto + "://127.0.0.1:8554/teststream protocols=tcp tls-validation-flags=0 latency=0 timeout=0 rtx-time=0",
})
require.NoError(t, err)
defer cnt1.close()
}
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)
cnt2, err := newContainer("ffmpeg", "read", []string{ switch ca.reader {
"-rtsp_transport", "tcp", case "ffmpeg":
"-i", proto + "://localhost:8554/teststream", cnt2, err := newContainer("ffmpeg", "read", []string{
"-vframes", "1", "-rtsp_transport", "tcp",
"-f", "image2", "-i", proto + "://localhost:8554/teststream",
"-y", "/dev/null", "-vframes", "1",
}) "-f", "image2",
require.NoError(t, err) "-y", "/dev/null",
defer cnt2.close() })
require.NoError(t, err)
require.Equal(t, 0, cnt2.wait()) defer cnt2.close()
require.Equal(t, 0, cnt2.wait())
}
}) })
} }
} }