mirror of
https://github.com/aler9/rtsp-simple-server
synced 2025-11-02 03:52:41 +08:00
drop support for configuration through stdin
This commit is contained in:
10
conf.go
10
conf.go
@@ -57,19 +57,11 @@ type conf struct {
|
|||||||
Paths map[string]*pathConf `yaml:"paths"`
|
Paths map[string]*pathConf `yaml:"paths"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func loadConf(fpath string, stdin io.Reader) (*conf, error) {
|
func loadConf(fpath string) (*conf, error) {
|
||||||
conf := &conf{}
|
conf := &conf{}
|
||||||
|
|
||||||
// read from file or stdin
|
// read from file or stdin
|
||||||
err := func() error {
|
err := func() error {
|
||||||
if fpath == "stdin" {
|
|
||||||
err := yaml.NewDecoder(stdin).Decode(conf)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// rtsp-simple-server.yml is optional
|
// rtsp-simple-server.yml is optional
|
||||||
if fpath == "rtsp-simple-server.yml" {
|
if fpath == "rtsp-simple-server.yml" {
|
||||||
if _, err := os.Stat(fpath); err != nil {
|
if _, err := os.Stat(fpath); err != nil {
|
||||||
|
|||||||
4
main.go
4
main.go
@@ -63,7 +63,7 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
|
|||||||
"rtsp-simple-server "+Version+"\n\nRTSP server.")
|
"rtsp-simple-server "+Version+"\n\nRTSP server.")
|
||||||
|
|
||||||
argVersion := k.Flag("version", "print version").Bool()
|
argVersion := k.Flag("version", "print version").Bool()
|
||||||
argConfPath := k.Arg("confpath", "path to a config file. The default is rtsp-simple-server.yml. Use 'stdin' to read config from stdin").Default("rtsp-simple-server.yml").String()
|
argConfPath := k.Arg("confpath", "path to a config file. The default is rtsp-simple-server.yml.").Default("rtsp-simple-server.yml").String()
|
||||||
|
|
||||||
kingpin.MustParse(k.Parse(args))
|
kingpin.MustParse(k.Parse(args))
|
||||||
|
|
||||||
@@ -72,7 +72,7 @@ func newProgram(args []string, stdin io.Reader) (*program, error) {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
conf, err := loadConf(*argConfPath, stdin)
|
conf, err := loadConf(*argConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
69
main_test.go
69
main_test.go
@@ -1,7 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
@@ -99,6 +99,23 @@ func (c *container) ip() string {
|
|||||||
return string(out[:len(out)-1])
|
return string(out[:len(out)-1])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testProgram(conf string) (*program, error) {
|
||||||
|
if conf == "" {
|
||||||
|
return newProgram([]string{}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
|
tmpf, err := ioutil.TempFile(os.TempDir(), "rtsp-")
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer os.Remove(tmpf.Name())
|
||||||
|
|
||||||
|
tmpf.WriteString(conf)
|
||||||
|
tmpf.Close()
|
||||||
|
|
||||||
|
return newProgram([]string{tmpf.Name()}, nil)
|
||||||
|
}
|
||||||
|
|
||||||
func TestEnvironment(t *testing.T) {
|
func TestEnvironment(t *testing.T) {
|
||||||
// string
|
// string
|
||||||
os.Setenv("RTSP_RUNONCONNECT", "testcmd")
|
os.Setenv("RTSP_RUNONCONNECT", "testcmd")
|
||||||
@@ -130,7 +147,7 @@ func TestEnvironment(t *testing.T) {
|
|||||||
os.Setenv("RTSP_PATHS_TEST_SOURCEPROTOCOL", "tcp")
|
os.Setenv("RTSP_PATHS_TEST_SOURCEPROTOCOL", "tcp")
|
||||||
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCEPROTOCOL")
|
defer os.Unsetenv("RTSP_PATHS_TEST_SOURCEPROTOCOL")
|
||||||
|
|
||||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
p, err := testProgram("")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -174,7 +191,7 @@ func TestPublish(t *testing.T) {
|
|||||||
{"gstreamer", "tcp"},
|
{"gstreamer", "tcp"},
|
||||||
} {
|
} {
|
||||||
t.Run(conf.publishSoft+"_"+conf.publishProto, func(t *testing.T) {
|
t.Run(conf.publishSoft+"_"+conf.publishProto, func(t *testing.T) {
|
||||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
p, err := testProgram("")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -232,7 +249,7 @@ func TestRead(t *testing.T) {
|
|||||||
{"vlc", "tcp"},
|
{"vlc", "tcp"},
|
||||||
} {
|
} {
|
||||||
t.Run(conf.readSoft+"_"+conf.readProto, func(t *testing.T) {
|
t.Run(conf.readSoft+"_"+conf.readProto, func(t *testing.T) {
|
||||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
p, err := testProgram("")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -286,8 +303,8 @@ func TestRead(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestTCPOnly(t *testing.T) {
|
func TestTCPOnly(t *testing.T) {
|
||||||
stdin := []byte("protocols: [tcp]\n")
|
conf := "protocols: [tcp]\n"
|
||||||
p, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -320,7 +337,7 @@ func TestTCPOnly(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPathWithSlash(t *testing.T) {
|
func TestPathWithSlash(t *testing.T) {
|
||||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
p, err := testProgram("")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -353,7 +370,7 @@ func TestPathWithSlash(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestPathWithQuery(t *testing.T) {
|
func TestPathWithQuery(t *testing.T) {
|
||||||
p, err := newProgram([]string{}, bytes.NewBuffer(nil))
|
p, err := testProgram("")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -387,12 +404,12 @@ func TestPathWithQuery(t *testing.T) {
|
|||||||
|
|
||||||
func TestAuth(t *testing.T) {
|
func TestAuth(t *testing.T) {
|
||||||
t.Run("publish", func(t *testing.T) {
|
t.Run("publish", func(t *testing.T) {
|
||||||
stdin := []byte("paths:\n" +
|
conf := "paths:\n" +
|
||||||
" all:\n" +
|
" all:\n" +
|
||||||
" publishUser: testuser\n" +
|
" publishUser: testuser\n" +
|
||||||
" publishPass: testpass\n" +
|
" publishPass: testpass\n" +
|
||||||
" publishIps: [172.17.0.0/16]\n")
|
" publishIps: [172.17.0.0/16]\n"
|
||||||
p, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -431,12 +448,12 @@ func TestAuth(t *testing.T) {
|
|||||||
"vlc",
|
"vlc",
|
||||||
} {
|
} {
|
||||||
t.Run("read_"+soft, func(t *testing.T) {
|
t.Run("read_"+soft, func(t *testing.T) {
|
||||||
stdin := []byte("paths:\n" +
|
conf := "paths:\n" +
|
||||||
" all:\n" +
|
" all:\n" +
|
||||||
" readUser: testuser\n" +
|
" readUser: testuser\n" +
|
||||||
" readPass: testpass\n" +
|
" readPass: testpass\n" +
|
||||||
" readIps: [172.17.0.0/16]\n")
|
" readIps: [172.17.0.0/16]\n"
|
||||||
p, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -489,11 +506,11 @@ func TestSourceRtsp(t *testing.T) {
|
|||||||
"tcp",
|
"tcp",
|
||||||
} {
|
} {
|
||||||
t.Run(proto, func(t *testing.T) {
|
t.Run(proto, func(t *testing.T) {
|
||||||
stdin := []byte("paths:\n" +
|
conf := "paths:\n" +
|
||||||
" all:\n" +
|
" all:\n" +
|
||||||
" readUser: testuser\n" +
|
" readUser: testuser\n" +
|
||||||
" readPass: testpass\n")
|
" readPass: testpass\n"
|
||||||
p1, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p1, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p1.close()
|
defer p1.close()
|
||||||
|
|
||||||
@@ -513,7 +530,7 @@ func TestSourceRtsp(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
stdin = []byte("rtspPort: 8555\n" +
|
conf = "rtspPort: 8555\n" +
|
||||||
"rtpPort: 8100\n" +
|
"rtpPort: 8100\n" +
|
||||||
"rtcpPort: 8101\n" +
|
"rtcpPort: 8101\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
@@ -521,8 +538,8 @@ func TestSourceRtsp(t *testing.T) {
|
|||||||
" proxied:\n" +
|
" proxied:\n" +
|
||||||
" source: rtsp://testuser:testpass@localhost:8554/teststream\n" +
|
" source: rtsp://testuser:testpass@localhost:8554/teststream\n" +
|
||||||
" sourceProtocol: " + proto + "\n" +
|
" sourceProtocol: " + proto + "\n" +
|
||||||
" sourceOnDemand: yes\n")
|
" sourceOnDemand: yes\n"
|
||||||
p2, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p2, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p2.close()
|
defer p2.close()
|
||||||
|
|
||||||
@@ -564,11 +581,11 @@ func TestSourceRtmp(t *testing.T) {
|
|||||||
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
|
|
||||||
stdin := []byte("paths:\n" +
|
conf := "paths:\n" +
|
||||||
" proxied:\n" +
|
" proxied:\n" +
|
||||||
" source: rtmp://" + cnt1.ip() + "/stream/test\n" +
|
" source: rtmp://" + cnt1.ip() + "/stream/test\n" +
|
||||||
" sourceOnDemand: yes\n")
|
" sourceOnDemand: yes\n"
|
||||||
p, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p.close()
|
defer p.close()
|
||||||
|
|
||||||
@@ -589,10 +606,10 @@ func TestSourceRtmp(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRunOnDemand(t *testing.T) {
|
func TestRunOnDemand(t *testing.T) {
|
||||||
stdin := []byte("paths:\n" +
|
conf := "paths:\n" +
|
||||||
" all:\n" +
|
" all:\n" +
|
||||||
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:8554/$RTSP_SERVER_PATH\n")
|
" runOnDemand: ffmpeg -hide_banner -loglevel error -re -i testimages/ffmpeg/emptyvideo.ts -c copy -f rtsp rtsp://localhost:8554/$RTSP_SERVER_PATH\n"
|
||||||
p1, err := newProgram([]string{"stdin"}, bytes.NewBuffer(stdin))
|
p1, err := testProgram(conf)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
defer p1.close()
|
defer p1.close()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user