mirror of
https://github.com/bluenviron/mediamtx
synced 2025-02-08 07:28:01 +00:00
fix crash when udp is disabled (#69)
This commit is contained in:
parent
476262e02d
commit
1b8177eb96
16
main.go
16
main.go
@ -247,22 +247,22 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
|
||||
http.DefaultServeMux = http.NewServeMux()
|
||||
}
|
||||
|
||||
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
|
||||
p.serverRtp, err = newServerUdp(p, conf.RtpPort, gortsplib.StreamTypeRtp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
|
||||
p.serverRtcp, err = newServerUdp(p, conf.RtcpPort, gortsplib.StreamTypeRtcp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
p.serverRtsp, err = newServerTcp(p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for name, confp := range conf.Paths {
|
||||
if confp.RunOnInit != "" {
|
||||
@ -284,12 +284,18 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
|
||||
if p.metrics != nil {
|
||||
go p.metrics.run()
|
||||
}
|
||||
|
||||
if _, ok := conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
|
||||
go p.serverRtp.run()
|
||||
go p.serverRtcp.run()
|
||||
go p.serverRtsp.run()
|
||||
}
|
||||
|
||||
for _, s := range p.sources {
|
||||
go s.run()
|
||||
}
|
||||
|
||||
go p.serverRtsp.run()
|
||||
|
||||
go p.run()
|
||||
|
||||
return p, nil
|
||||
@ -541,13 +547,13 @@ outer:
|
||||
cmd.Wait()
|
||||
}
|
||||
|
||||
p.serverRtsp.close()
|
||||
|
||||
for _, s := range p.sources {
|
||||
s.events <- sourceEventTerminate{}
|
||||
<-s.done
|
||||
}
|
||||
|
||||
p.serverRtsp.close()
|
||||
|
||||
if _, ok := p.conf.protocolsParsed[gortsplib.StreamProtocolUdp]; ok {
|
||||
p.serverRtcp.close()
|
||||
p.serverRtp.close()
|
||||
|
35
main_test.go
35
main_test.go
@ -213,6 +213,41 @@ func TestRead(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTcpOnly(t *testing.T) {
|
||||
stdin := []byte("\n" +
|
||||
"protocols: [tcp]\n")
|
||||
p, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
||||
require.NoError(t, err)
|
||||
defer p.close()
|
||||
|
||||
time.Sleep(1 * time.Second)
|
||||
|
||||
cnt1, err := newContainer("ffmpeg", "publish", []string{
|
||||
"-re",
|
||||
"-stream_loop", "-1",
|
||||
"-i", "/emptyvideo.ts",
|
||||
"-c", "copy",
|
||||
"-f", "rtsp",
|
||||
"-rtsp_transport", "tcp",
|
||||
"rtsp://" + ownDockerIp + ":8554/teststream",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer cnt1.close()
|
||||
|
||||
cnt2, err := newContainer("ffmpeg", "read", []string{
|
||||
"-rtsp_transport", "tcp",
|
||||
"-i", "rtsp://" + ownDockerIp + ":8554/teststream",
|
||||
"-vframes", "1",
|
||||
"-f", "image2",
|
||||
"-y", "/dev/null",
|
||||
})
|
||||
require.NoError(t, err)
|
||||
defer cnt2.close()
|
||||
|
||||
code := cnt2.wait()
|
||||
require.Equal(t, 0, code)
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
t.Run("publish", func(t *testing.T) {
|
||||
stdin := []byte("\n" +
|
||||
|
Loading…
Reference in New Issue
Block a user