|
|
|
@ -21,6 +21,13 @@ const ( |
|
|
|
pprofAddress = ":9999" |
|
|
|
pprofAddress = ":9999" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type logDestination int |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
|
|
|
logDestinationStdout logDestination = iota |
|
|
|
|
|
|
|
logDestinationFile |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
type programEvent interface { |
|
|
|
type programEvent interface { |
|
|
|
isProgramEvent() |
|
|
|
isProgramEvent() |
|
|
|
} |
|
|
|
} |
|
|
|
@ -161,6 +168,7 @@ func (programEventTerminate) isProgramEvent() {} |
|
|
|
|
|
|
|
|
|
|
|
type program struct { |
|
|
|
type program struct { |
|
|
|
conf *conf |
|
|
|
conf *conf |
|
|
|
|
|
|
|
logFile *os.File |
|
|
|
metrics *metrics |
|
|
|
metrics *metrics |
|
|
|
serverRtsp *serverTcp |
|
|
|
serverRtsp *serverTcp |
|
|
|
serverRtp *serverUdp |
|
|
|
serverRtp *serverUdp |
|
|
|
@ -202,6 +210,15 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { |
|
|
|
done: make(chan struct{}), |
|
|
|
done: make(chan struct{}), |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, ok := p.conf.logDestinationsParsed[logDestinationFile]; ok { |
|
|
|
|
|
|
|
p.logFile, err = os.OpenFile(p.conf.LogFile, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
log.Fatal("ERR:", err) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
p.log("rtsp-simple-server %s", Version) |
|
|
|
|
|
|
|
|
|
|
|
for path, confp := range conf.Paths { |
|
|
|
for path, confp := range conf.Paths { |
|
|
|
if path == "all" { |
|
|
|
if path == "all" { |
|
|
|
continue |
|
|
|
continue |
|
|
|
@ -216,8 +233,6 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
p.log("rtsp-simple-server %s", Version) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if conf.Metrics { |
|
|
|
if conf.Metrics { |
|
|
|
p.metrics = newMetrics(p) |
|
|
|
p.metrics = newMetrics(p) |
|
|
|
} |
|
|
|
} |
|
|
|
@ -263,8 +278,15 @@ func newProgram(args []string, stdin io.Reader) (*program, error) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p *program) log(format string, args ...interface{}) { |
|
|
|
func (p *program) log(format string, args ...interface{}) { |
|
|
|
log.Printf("[%d/%d/%d] "+format, append([]interface{}{len(p.clients), |
|
|
|
line := fmt.Sprintf("[%d/%d/%d] "+format, append([]interface{}{len(p.clients), |
|
|
|
p.publisherCount, p.readerCount}, args...)...) |
|
|
|
p.publisherCount, p.readerCount}, args...)...) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _, ok := p.conf.logDestinationsParsed[logDestinationStdout]; ok { |
|
|
|
|
|
|
|
log.Println(line) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := p.conf.logDestinationsParsed[logDestinationFile]; ok { |
|
|
|
|
|
|
|
p.logFile.WriteString(line + "\n") |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (p *program) run() { |
|
|
|
func (p *program) run() { |
|
|
|
@ -491,6 +513,10 @@ outer: |
|
|
|
p.metrics.close() |
|
|
|
p.metrics.close() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if p.logFile != nil { |
|
|
|
|
|
|
|
p.logFile.Close() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
close(p.events) |
|
|
|
close(p.events) |
|
|
|
close(p.done) |
|
|
|
close(p.done) |
|
|
|
} |
|
|
|
} |
|
|
|
|