Skip to content

Commit bed388d

Browse files
committed
add gstreamer to tests and readme (#40)
1 parent e42b135 commit bed388d

File tree

8 files changed

+119
-25
lines changed

8 files changed

+119
-25
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Features:
3030
ffmpeg -re -stream_loop -1 -i file.ts -c copy -f rtsp rtsp://localhost:8554/mystream
3131
```
3232

33+
or _GStreamer_:
34+
```
35+
gst-launch-1.0 filesrc location=file.mp4 ! qtdemux ! rtspclientsink location=rtsp://localhost:8554/mystream
36+
```
37+
3338
4. Open the stream. For instance, you can open the stream with _VLC_:
3439
```
3540
vlc rtsp://localhost:8554/mystream

main_test.go

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"os"
77
"os/exec"
88
"strconv"
9-
"strings"
109
"testing"
1110
"time"
1211

@@ -92,43 +91,107 @@ func (c *container) wait() int {
9291
return int(code)
9392
}
9493

95-
func TestPublishRead(t *testing.T) {
96-
for _, conf := range [][3]string{
97-
{"udp", "udp", "ffmpeg"},
98-
{"udp", "tcp", "ffmpeg"},
99-
{"tcp", "udp", "ffmpeg"},
100-
{"tcp", "tcp", "ffmpeg"},
101-
{"tcp", "udp", "vlc"},
102-
{"tcp", "tcp", "vlc"},
94+
func TestPublish(t *testing.T) {
95+
for _, conf := range []struct {
96+
publishSoft string
97+
publishProto string
98+
}{
99+
{"ffmpeg", "udp"},
100+
{"ffmpeg", "tcp"},
101+
{"gstreamer", "udp"},
102+
{"gstreamer", "tcp"},
103103
} {
104-
t.Run(strings.Join(conf[:], "_"), func(t *testing.T) {
104+
t.Run(conf.publishSoft+"_"+conf.publishProto, func(t *testing.T) {
105105
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
106106
require.NoError(t, err)
107107
defer p.close()
108108

109109
time.Sleep(1 * time.Second)
110110

111-
cnt1, err := newContainer("ffmpeg", "source", []string{
111+
switch conf.publishSoft {
112+
case "ffmpeg":
113+
cnt1, err := newContainer("ffmpeg", "publish", []string{
114+
"-hide_banner",
115+
"-loglevel", "panic",
116+
"-re",
117+
"-stream_loop", "-1",
118+
"-i", "/emptyvideo.ts",
119+
"-c", "copy",
120+
"-f", "rtsp",
121+
"-rtsp_transport", conf.publishProto,
122+
"rtsp://" + ownDockerIp + ":8554/teststream",
123+
})
124+
require.NoError(t, err)
125+
defer cnt1.close()
126+
127+
default:
128+
cnt1, err := newContainer("gstreamer", "source", []string{
129+
"filesrc location=emptyvideo.ts ! tsdemux ! rtspclientsink " +
130+
"location=rtsp://" + ownDockerIp + ":8554/teststream protocols=" + conf.publishProto,
131+
})
132+
require.NoError(t, err)
133+
defer cnt1.close()
134+
}
135+
136+
time.Sleep(1 * time.Second)
137+
138+
cnt2, err := newContainer("ffmpeg", "read", []string{
139+
"-hide_banner",
140+
"-loglevel", "panic",
141+
"-rtsp_transport", "udp",
142+
"-i", "rtsp://" + ownDockerIp + ":8554/teststream",
143+
"-vframes", "1",
144+
"-f", "image2",
145+
"-y", "/dev/null",
146+
})
147+
require.NoError(t, err)
148+
defer cnt2.close()
149+
150+
code := cnt2.wait()
151+
require.Equal(t, 0, code)
152+
})
153+
}
154+
}
155+
156+
func TestRead(t *testing.T) {
157+
for _, conf := range []struct {
158+
readSoft string
159+
readProto string
160+
}{
161+
{"ffmpeg", "udp"},
162+
{"ffmpeg", "tcp"},
163+
{"vlc", "udp"},
164+
{"vlc", "tcp"},
165+
} {
166+
t.Run(conf.readSoft+"_"+conf.readProto, func(t *testing.T) {
167+
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
168+
require.NoError(t, err)
169+
defer p.close()
170+
171+
time.Sleep(1 * time.Second)
172+
173+
cnt1, err := newContainer("ffmpeg", "publish", []string{
112174
"-hide_banner",
113175
"-loglevel", "panic",
114176
"-re",
115177
"-stream_loop", "-1",
116178
"-i", "/emptyvideo.ts",
117179
"-c", "copy",
118180
"-f", "rtsp",
119-
"-rtsp_transport", conf[0],
181+
"-rtsp_transport", "udp",
120182
"rtsp://" + ownDockerIp + ":8554/teststream",
121183
})
122184
require.NoError(t, err)
123185
defer cnt1.close()
124186

125187
time.Sleep(1 * time.Second)
126188

127-
if conf[2] == "ffmpeg" {
128-
cnt2, err := newContainer("ffmpeg", "dest", []string{
189+
switch conf.readSoft {
190+
case "ffmpeg":
191+
cnt2, err := newContainer("ffmpeg", "read", []string{
129192
"-hide_banner",
130193
"-loglevel", "panic",
131-
"-rtsp_transport", conf[1],
194+
"-rtsp_transport", conf.readProto,
132195
"-i", "rtsp://" + ownDockerIp + ":8554/teststream",
133196
"-vframes", "1",
134197
"-f", "image2",
@@ -140,9 +203,9 @@ func TestPublishRead(t *testing.T) {
140203
code := cnt2.wait()
141204
require.Equal(t, 0, code)
142205

143-
} else {
206+
default:
144207
args := []string{}
145-
if conf[1] == "tcp" {
208+
if conf.readProto == "tcp" {
146209
args = append(args, "--rtsp-tcp")
147210
}
148211
args = append(args, "rtsp://"+ownDockerIp+":8554/teststream")

test-images/ffmpeg/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM amd64/alpine:3.11
1+
FROM amd64/alpine:3.12
22

33
RUN apk add --no-cache \
44
ffmpeg

test-images/ffmpeg/start.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh -e
22

3-
ffmpeg $@
3+
exec ffmpeg $@

test-images/gstreamer/Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM amd64/alpine:3.12
2+
3+
RUN apk add --no-cache \
4+
gstreamer-tools \
5+
gst-plugins-good \
6+
gst-plugins-bad \
7+
&& apk add --no-cache \
8+
-X http://dl-cdn.alpinelinux.org/alpine/edge/testing \
9+
gst-rtsp-server
10+
11+
COPY emptyvideo.ts /
12+
13+
COPY start.sh /
14+
RUN chmod +x /start.sh
15+
16+
ENTRYPOINT [ "/start.sh" ]
63.5 KB
Binary file not shown.

test-images/gstreamer/start.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh -e
2+
3+
exec gst-launch-1.0 $@

test-images/vlc/start.sh

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,17 @@ chown user:user /out
66
CMD="cvlc --play-and-exit --no-audio --no-video --sout file/ts:/out/stream.ts -vvv $@"
77
su - user -c "$CMD" 2>&1 &
88

9-
sleep 10
9+
COUNTER=0
10+
while true; do
11+
sleep 1
1012

11-
if [ $(stat -c "%s" /out/stream.ts) -gt 0 ]; then
12-
exit 0
13-
else
14-
exit 1
15-
fi
13+
if [ $(stat -c "%s" /out/stream.ts) -gt 0 ]; then
14+
exit 0
15+
fi
16+
17+
COUNTER=$(($COUNTER + 1))
18+
19+
if [ $COUNTER -ge 15 ]; then
20+
exit 1
21+
fi
22+
done

0 commit comments

Comments
 (0)