From d30dbb38f9ee2fa22caa6ee1561adc9e574ac39e Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Sun, 13 Dec 2020 22:23:16 +0100 Subject: [PATCH] add server test with gstreamer --- clientconf_test.go | 8 ++--- examples/server-tls.go | 2 +- serverconf_test.go | 66 ++++++++++++++++++++++++++---------------- 3 files changed, 46 insertions(+), 30 deletions(-) diff --git a/clientconf_test.go b/clientconf_test.go index 476bac53..24cb51b1 100644 --- a/clientconf_test.go +++ b/clientconf_test.go @@ -74,7 +74,7 @@ func TestClientDialRead(t *testing.T) { cnt2, err := newContainer("ffmpeg", "publish", []string{ "-re", "-stream_loop", "-1", - "-i", "/emptyvideo.ts", + "-i", "emptyvideo.ts", "-c", "copy", "-f", "rtsp", "-rtsp_transport", "udp", @@ -131,7 +131,7 @@ func TestClientDialReadAutomaticProtocol(t *testing.T) { cnt2, err := newContainer("ffmpeg", "publish", []string{ "-re", "-stream_loop", "-1", - "-i", "/emptyvideo.ts", + "-i", "emptyvideo.ts", "-c", "copy", "-f", "rtsp", "-rtsp_transport", "tcp", @@ -176,7 +176,7 @@ func TestClientDialReadRedirect(t *testing.T) { cnt2, err := newContainer("ffmpeg", "publish", []string{ "-re", "-stream_loop", "-1", - "-i", "/emptyvideo.ts", + "-i", "emptyvideo.ts", "-c", "copy", "-f", "rtsp", "-rtsp_transport", "udp", @@ -218,7 +218,7 @@ func TestClientDialReadPause(t *testing.T) { cnt2, err := newContainer("ffmpeg", "publish", []string{ "-re", "-stream_loop", "-1", - "-i", "/emptyvideo.ts", + "-i", "emptyvideo.ts", "-c", "copy", "-f", "rtsp", "-rtsp_transport", "udp", diff --git a/examples/server-tls.go b/examples/server-tls.go index 10ff29b8..6e8706bb 100644 --- a/examples/server-tls.go +++ b/examples/server-tls.go @@ -14,7 +14,7 @@ import ( ) // 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 // 3. allow multiple clients to read that stream with TCP diff --git a/serverconf_test.go b/serverconf_test.go index 790789ac..80acc7ae 100644 --- a/serverconf_test.go +++ b/serverconf_test.go @@ -272,10 +272,13 @@ y++U32uuSFiXDcSLarfIsE992MEJLSAynbF1Rsgsr3gXbGiuToJRyxbIeVy7gwzD func TestServerPublishReadTCP(t *testing.T) { for _, ca := range []struct { publisher string + reader string encrypted bool }{ - {"ffmpeg", false}, - {"ffmpeg", true}, + {"ffmpeg", "ffmpeg", false}, + {"ffmpeg", "ffmpeg", true}, + {"gstreamer", "ffmpeg", false}, + {"gstreamer", "ffmpeg", true}, } { encryptedStr := func() string { if ca.encrypted { @@ -284,7 +287,7 @@ func TestServerPublishReadTCP(t *testing.T) { 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 tlsConf *tls.Config if !ca.encrypted { @@ -302,31 +305,44 @@ func TestServerPublishReadTCP(t *testing.T) { require.NoError(t, err) defer ts.close() - cnt1, err := newContainer("ffmpeg", "publish", []string{ - "-re", - "-stream_loop", "-1", - "-i", "/emptyvideo.ts", - "-c", "copy", - "-f", "rtsp", - "-rtsp_transport", "tcp", - proto + "://localhost:8554/teststream", - }) - require.NoError(t, err) - defer cnt1.close() + switch ca.publisher { + case "ffmpeg": + cnt1, err := newContainer("ffmpeg", "publish", []string{ + "-re", + "-stream_loop", "-1", + "-i", "emptyvideo.ts", + "-c", "copy", + "-f", "rtsp", + "-rtsp_transport", "tcp", + proto + "://localhost:8554/teststream", + }) + 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) - cnt2, err := newContainer("ffmpeg", "read", []string{ - "-rtsp_transport", "tcp", - "-i", proto + "://localhost:8554/teststream", - "-vframes", "1", - "-f", "image2", - "-y", "/dev/null", - }) - require.NoError(t, err) - defer cnt2.close() - - require.Equal(t, 0, cnt2.wait()) + switch ca.reader { + case "ffmpeg": + cnt2, err := newContainer("ffmpeg", "read", []string{ + "-rtsp_transport", "tcp", + "-i", proto + "://localhost:8554/teststream", + "-vframes", "1", + "-f", "image2", + "-y", "/dev/null", + }) + require.NoError(t, err) + defer cnt2.close() + require.Equal(t, 0, cnt2.wait()) + } }) } }