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" )
0 commit comments