mirror of https://bitbucket.org/ausocean/av.git
Merged in remove-logging-pkg-prefix (pull request #393)
revid: no longer prepending package name before log messagges Approved-by: Trek Hopton <trek.hopton@gmail.com>
This commit is contained in:
commit
f9dc1d0139
|
@ -47,7 +47,7 @@ func (r *Revid) setupAudio() error {
|
||||||
case codecutil.ADPCM:
|
case codecutil.ADPCM:
|
||||||
mts.Meta.Add("codec", "adpcm")
|
mts.Meta.Add("codec", "adpcm")
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Fatal, pkg+"no audio codec set in config")
|
r.cfg.Logger.Log(logger.Fatal, "no audio codec set in config")
|
||||||
}
|
}
|
||||||
|
|
||||||
r.input = alsa.New(r.cfg.Logger)
|
r.input = alsa.New(r.cfg.Logger)
|
||||||
|
|
|
@ -34,8 +34,6 @@ import (
|
||||||
"bitbucket.org/ausocean/utils/logger"
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
)
|
)
|
||||||
|
|
||||||
const pkg = "config: "
|
|
||||||
|
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
SetLevel(int8)
|
SetLevel(int8)
|
||||||
Log(level int8, message string, params ...interface{})
|
Log(level int8, message string, params ...interface{})
|
||||||
|
@ -390,7 +388,7 @@ func (c *Config) Validate() error {
|
||||||
case OutputFile, OutputHTTP, OutputRTP:
|
case OutputFile, OutputHTTP, OutputRTP:
|
||||||
case OutputRTMP:
|
case OutputRTMP:
|
||||||
if c.RTMPURL == "" {
|
if c.RTMPURL == "" {
|
||||||
c.Logger.Log(logger.Info, pkg+"no RTMP URL: falling back to HTTP")
|
c.Logger.Log(logger.Info, "no RTMP URL: falling back to HTTP")
|
||||||
c.Outputs[i] = OutputHTTP
|
c.Outputs[i] = OutputHTTP
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
@ -469,7 +467,7 @@ func (c *Config) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Config) LogInvalidField(name string, def interface{}) {
|
func (c *Config) LogInvalidField(name string, def interface{}) {
|
||||||
c.Logger.Log(logger.Info, pkg+name+" bad or unset, defaulting", name, def)
|
c.Logger.Log(logger.Info, name+" bad or unset, defaulting", name, def)
|
||||||
}
|
}
|
||||||
|
|
||||||
// stringInSlice returns true if want is in slice.
|
// stringInSlice returns true if want is in slice.
|
||||||
|
|
108
revid/revid.go
108
revid/revid.go
|
@ -64,8 +64,6 @@ const (
|
||||||
rtmpConnectionTimeout = 10
|
rtmpConnectionTimeout = 10
|
||||||
)
|
)
|
||||||
|
|
||||||
const pkg = "revid: "
|
|
||||||
|
|
||||||
type Logger interface {
|
type Logger interface {
|
||||||
SetLevel(int8)
|
SetLevel(int8)
|
||||||
Log(level int8, message string, params ...interface{})
|
Log(level int8, message string, params ...interface{})
|
||||||
|
@ -140,7 +138,7 @@ func (r *Revid) handleErrors() {
|
||||||
for {
|
for {
|
||||||
err := <-r.err
|
err := <-r.err
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Error, pkg+"async error", "error", err.Error())
|
r.cfg.Logger.Log(logger.Error, "async error", "error", err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -277,7 +275,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
||||||
r.cfg.Logger.Log(logger.Debug, "using RTP output")
|
r.cfg.Logger.Log(logger.Debug, "using RTP output")
|
||||||
w, err := newRtpSender(r.cfg.RTPAddress, r.cfg.Logger.Log, r.cfg.FrameRate, r.bitrate.Report)
|
w, err := newRtpSender(r.cfg.RTPAddress, r.cfg.Logger.Log, r.cfg.FrameRate, r.bitrate.Report)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"rtp connect error", "error", err.Error())
|
r.cfg.Logger.Log(logger.Warning, "rtp connect error", "error", err.Error())
|
||||||
}
|
}
|
||||||
mtsSenders = append(mtsSenders, w)
|
mtsSenders = append(mtsSenders, w)
|
||||||
case config.OutputFile:
|
case config.OutputFile:
|
||||||
|
@ -302,7 +300,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
||||||
r.bitrate.Report,
|
r.bitrate.Report,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"rtmp connect error", "error", err.Error())
|
r.cfg.Logger.Log(logger.Warning, "rtmp connect error", "error", err.Error())
|
||||||
}
|
}
|
||||||
flvSenders = append(flvSenders, w)
|
flvSenders = append(flvSenders, w)
|
||||||
}
|
}
|
||||||
|
@ -400,7 +398,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
||||||
r.cfg.Logger.Log(logger.Debug, "configuring input device")
|
r.cfg.Logger.Log(logger.Debug, "configuring input device")
|
||||||
err := r.input.Set(r.cfg)
|
err := r.input.Set(r.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"errors from configuring input device", "errors", err)
|
r.cfg.Logger.Log(logger.Warning, "errors from configuring input device", "errors", err)
|
||||||
}
|
}
|
||||||
r.cfg.Logger.Log(logger.Info, "input device configured")
|
r.cfg.Logger.Log(logger.Info, "input device configured")
|
||||||
|
|
||||||
|
@ -440,14 +438,14 @@ func (r *Revid) setLexer(c uint8, isRTSP bool) {
|
||||||
// Start is safe for concurrent use.
|
// Start is safe for concurrent use.
|
||||||
func (r *Revid) Start() error {
|
func (r *Revid) Start() error {
|
||||||
if r.IsRunning() {
|
if r.IsRunning() {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"start called, but revid already running")
|
r.cfg.Logger.Log(logger.Warning, "start called, but revid already running")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
r.mu.Lock()
|
r.mu.Lock()
|
||||||
defer r.mu.Unlock()
|
defer r.mu.Unlock()
|
||||||
|
|
||||||
r.cfg.Logger.Log(logger.Debug, pkg+"resetting revid")
|
r.cfg.Logger.Log(logger.Debug, "resetting revid")
|
||||||
err := r.reset(r.cfg)
|
err := r.reset(r.cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.Stop()
|
r.Stop()
|
||||||
|
@ -475,7 +473,7 @@ func (r *Revid) Start() error {
|
||||||
// Stop is safe for concurrent use.
|
// Stop is safe for concurrent use.
|
||||||
func (r *Revid) Stop() {
|
func (r *Revid) Stop() {
|
||||||
if !r.IsRunning() {
|
if !r.IsRunning() {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"stop called but revid isn't running")
|
r.cfg.Logger.Log(logger.Warning, "stop called but revid isn't running")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -485,7 +483,7 @@ func (r *Revid) Stop() {
|
||||||
r.cfg.Logger.Log(logger.Debug, "stopping input")
|
r.cfg.Logger.Log(logger.Debug, "stopping input")
|
||||||
err := r.input.Stop()
|
err := r.input.Stop()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Error, pkg+"could not stop input", "error", err.Error())
|
r.cfg.Logger.Log(logger.Error, "could not stop input", "error", err.Error())
|
||||||
} else {
|
} else {
|
||||||
r.cfg.Logger.Log(logger.Info, "input stopped")
|
r.cfg.Logger.Log(logger.Info, "input stopped")
|
||||||
}
|
}
|
||||||
|
@ -493,7 +491,7 @@ func (r *Revid) Stop() {
|
||||||
r.cfg.Logger.Log(logger.Debug, "closing pipeline")
|
r.cfg.Logger.Log(logger.Debug, "closing pipeline")
|
||||||
err = r.encoders.Close()
|
err = r.encoders.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Error, pkg+"failed to close pipeline", "error", err.Error())
|
r.cfg.Logger.Log(logger.Error, "failed to close pipeline", "error", err.Error())
|
||||||
} else {
|
} else {
|
||||||
r.cfg.Logger.Log(logger.Info, "pipeline closed")
|
r.cfg.Logger.Log(logger.Info, "pipeline closed")
|
||||||
}
|
}
|
||||||
|
@ -501,7 +499,7 @@ func (r *Revid) Stop() {
|
||||||
for _, filter := range r.filters {
|
for _, filter := range r.filters {
|
||||||
err = filter.Close()
|
err = filter.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Error, pkg+"failed to close filters", "error", err.Error())
|
r.cfg.Logger.Log(logger.Error, "failed to close filters", "error", err.Error())
|
||||||
} else {
|
} else {
|
||||||
r.cfg.Logger.Log(logger.Info, "filters closed")
|
r.cfg.Logger.Log(logger.Info, "filters closed")
|
||||||
}
|
}
|
||||||
|
@ -559,21 +557,21 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Input":
|
case "Input":
|
||||||
v, ok := map[string]uint8{"raspivid": config.InputRaspivid, "rtsp": config.InputRTSP, "v4l": config.InputV4L, "file": config.InputFile}[strings.ToLower(value)]
|
v, ok := map[string]uint8{"raspivid": config.InputRaspivid, "rtsp": config.InputRTSP, "v4l": config.InputV4L, "file": config.InputFile}[strings.ToLower(value)]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid input var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid input var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Input = v
|
r.cfg.Input = v
|
||||||
case "Saturation":
|
case "Saturation":
|
||||||
s, err := strconv.Atoi(value)
|
s, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid saturation param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid saturation param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Saturation = int(s)
|
r.cfg.Saturation = int(s)
|
||||||
case "Brightness":
|
case "Brightness":
|
||||||
b, err := strconv.Atoi(value)
|
b, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid brightness param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid brightness param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Brightness = uint(b)
|
r.cfg.Brightness = uint(b)
|
||||||
|
@ -588,7 +586,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "MJPEG":
|
case "MJPEG":
|
||||||
r.cfg.InputCodec = codecutil.MJPEG
|
r.cfg.InputCodec = codecutil.MJPEG
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid InputCodec variable value", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid InputCodec variable value", "value", value)
|
||||||
}
|
}
|
||||||
case "Outputs":
|
case "Outputs":
|
||||||
outputs := strings.Split(value, ",")
|
outputs := strings.Split(value, ",")
|
||||||
|
@ -605,7 +603,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Rtp":
|
case "Rtp":
|
||||||
r.cfg.Outputs[i] = config.OutputRTP
|
r.cfg.Outputs[i] = config.OutputRTP
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid outputs param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid outputs param", "value", value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -621,7 +619,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "rtp":
|
case "rtp":
|
||||||
r.cfg.Outputs[0] = config.OutputRTP
|
r.cfg.Outputs[0] = config.OutputRTP
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid output param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid output param", "value", value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -632,7 +630,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Bitrate":
|
case "Bitrate":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid framerate param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid framerate param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Bitrate = uint(v)
|
r.cfg.Bitrate = uint(v)
|
||||||
|
@ -643,28 +641,28 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Height":
|
case "Height":
|
||||||
h, err := strconv.Atoi(value)
|
h, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid height param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid height param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Height = uint(h)
|
r.cfg.Height = uint(h)
|
||||||
case "Width":
|
case "Width":
|
||||||
w, err := strconv.Atoi(value)
|
w, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid width param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid width param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Width = uint(w)
|
r.cfg.Width = uint(w)
|
||||||
case "FrameRate":
|
case "FrameRate":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid framerate param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid framerate param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.FrameRate = uint(v)
|
r.cfg.FrameRate = uint(v)
|
||||||
case "Rotation":
|
case "Rotation":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v > 359 {
|
if err != nil || v > 359 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid rotation param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid rotation param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Rotation = uint(v)
|
r.cfg.Rotation = uint(v)
|
||||||
|
@ -673,14 +671,14 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Quantization":
|
case "Quantization":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid quantization param", "value", v)
|
r.cfg.Logger.Log(logger.Warning, "invalid quantization param", "value", v)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.Quantization = uint(v)
|
r.cfg.Quantization = uint(v)
|
||||||
case "MinFrames":
|
case "MinFrames":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MinFrames param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MinFrames param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MinFrames = uint(v)
|
r.cfg.MinFrames = uint(v)
|
||||||
|
@ -688,7 +686,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "ClipDuration":
|
case "ClipDuration":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid ClipDuration param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid ClipDuration param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.ClipDuration = time.Duration(v) * time.Second
|
r.cfg.ClipDuration = time.Duration(v) * time.Second
|
||||||
|
@ -700,7 +698,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "false":
|
case "false":
|
||||||
r.cfg.HorizontalFlip = false
|
r.cfg.HorizontalFlip = false
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid HorizontalFlip param", "value", value)
|
||||||
}
|
}
|
||||||
case "VerticalFlip":
|
case "VerticalFlip":
|
||||||
switch strings.ToLower(value) {
|
switch strings.ToLower(value) {
|
||||||
|
@ -709,7 +707,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "false":
|
case "false":
|
||||||
r.cfg.VerticalFlip = false
|
r.cfg.VerticalFlip = false
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid VerticalFlip param", "value", value)
|
||||||
}
|
}
|
||||||
case "Filters":
|
case "Filters":
|
||||||
filters := strings.Split(value, ",")
|
filters := strings.Split(value, ",")
|
||||||
|
@ -718,21 +716,21 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
for i, filter := range filters {
|
for i, filter := range filters {
|
||||||
v, ok := m[filter]
|
v, ok := m[filter]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid Filters param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid Filters param", "value", value)
|
||||||
}
|
}
|
||||||
r.cfg.Filters[i] = v
|
r.cfg.Filters[i] = v
|
||||||
}
|
}
|
||||||
case "PSITime":
|
case "PSITime":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid PSITime var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid PSITime var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.PSITime = v
|
r.cfg.PSITime = v
|
||||||
case "BurstPeriod":
|
case "BurstPeriod":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid BurstPeriod param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid BurstPeriod param", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.BurstPeriod = uint(v)
|
r.cfg.BurstPeriod = uint(v)
|
||||||
|
@ -749,54 +747,54 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "Fatal":
|
case "Fatal":
|
||||||
r.cfg.LogLevel = logger.Fatal
|
r.cfg.LogLevel = logger.Fatal
|
||||||
default:
|
default:
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid Logging param", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid Logging param", "value", value)
|
||||||
}
|
}
|
||||||
case "RTMPRBMaxElements":
|
case "RTMPRBMaxElements":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid RTMPRBMaxElements var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid RTMPRBMaxElements var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBMaxElements = v
|
r.cfg.RBMaxElements = v
|
||||||
case "RTMPRBCapacity":
|
case "RTMPRBCapacity":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid RTMPRBCapacity var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid RTMPRBCapacity var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBCapacity = v
|
r.cfg.RBCapacity = v
|
||||||
case "RTMPRBWriteTimeout":
|
case "RTMPRBWriteTimeout":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v <= 0 {
|
if err != nil || v <= 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid RTMPRBWriteTimeout var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid RTMPRBWriteTimeout var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBWriteTimeout = v
|
r.cfg.RBWriteTimeout = v
|
||||||
case "MTSRBMaxElements":
|
case "MTSRBMaxElements":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MTSRBMaxElements var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MTSRBMaxElements var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBMaxElements = v
|
r.cfg.RBMaxElements = v
|
||||||
case "MTSRBCapacity":
|
case "MTSRBCapacity":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MTSRBCapacity var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MTSRBCapacity var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBCapacity = v
|
r.cfg.RBCapacity = v
|
||||||
case "MTSRBWriteTimeout":
|
case "MTSRBWriteTimeout":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v <= 0 {
|
if err != nil || v <= 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MTSRBWriteTimeout var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MTSRBWriteTimeout var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.RBWriteTimeout = v
|
r.cfg.RBWriteTimeout = v
|
||||||
case "CBR":
|
case "CBR":
|
||||||
v, ok := map[string]bool{"true": true, "false": false}[strings.ToLower(value)]
|
v, ok := map[string]bool{"true": true, "false": false}[strings.ToLower(value)]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid CBR var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid CBR var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.CBR = v
|
r.cfg.CBR = v
|
||||||
|
@ -805,91 +803,91 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
case "VBRQuality":
|
case "VBRQuality":
|
||||||
v, ok := map[string]config.Quality{"standard": config.QualityStandard, "fair": config.QualityFair, "good": config.QualityGood, "great": config.QualityGreat, "excellent": config.QualityExcellent}[strings.ToLower(value)]
|
v, ok := map[string]config.Quality{"standard": config.QualityStandard, "fair": config.QualityFair, "good": config.QualityGood, "great": config.QualityGreat, "excellent": config.QualityExcellent}[strings.ToLower(value)]
|
||||||
if !ok {
|
if !ok {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid VBRQuality var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid VBRQuality var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.VBRQuality = v
|
r.cfg.VBRQuality = v
|
||||||
case "VBRBitrate":
|
case "VBRBitrate":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v <= 0 {
|
if err != nil || v <= 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid VBRBitrate var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid VBRBitrate var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.VBRBitrate = v
|
r.cfg.VBRBitrate = v
|
||||||
case "CameraChan":
|
case "CameraChan":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || (v != 1 && v != 2) {
|
if err != nil || (v != 1 && v != 2) {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid CameraChan var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid CameraChan var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.CameraChan = v
|
r.cfg.CameraChan = v
|
||||||
case "MinFPS":
|
case "MinFPS":
|
||||||
v, err := strconv.ParseFloat(value, 64)
|
v, err := strconv.ParseFloat(value, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MinFPS var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MinFPS var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MinFPS = v
|
r.cfg.MinFPS = v
|
||||||
case "MotionMinArea":
|
case "MotionMinArea":
|
||||||
v, err := strconv.ParseFloat(value, 64)
|
v, err := strconv.ParseFloat(value, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionMinArea var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionMinArea var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionMinArea = v
|
r.cfg.MotionMinArea = v
|
||||||
case "MotionThreshold":
|
case "MotionThreshold":
|
||||||
v, err := strconv.ParseFloat(value, 64)
|
v, err := strconv.ParseFloat(value, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionThreshold var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionThreshold var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionThreshold = v
|
r.cfg.MotionThreshold = v
|
||||||
case "MotionKernel":
|
case "MotionKernel":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionKernel var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionKernel var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionKernel = uint(v)
|
r.cfg.MotionKernel = uint(v)
|
||||||
case "MotionHistory":
|
case "MotionHistory":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v <= 0 {
|
if err != nil || v <= 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionHistory var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionHistory var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionHistory = uint(v)
|
r.cfg.MotionHistory = uint(v)
|
||||||
case "MotionPadding":
|
case "MotionPadding":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v <= 0 {
|
if err != nil || v <= 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionPadding var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionPadding var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionPadding = uint(v)
|
r.cfg.MotionPadding = uint(v)
|
||||||
case "MotionPixels":
|
case "MotionPixels":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionPixels var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionPixels var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionPixels = v
|
r.cfg.MotionPixels = v
|
||||||
case "MotionDownscaling":
|
case "MotionDownscaling":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionDownscaling var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionDownscaling var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionDownscaling = v
|
r.cfg.MotionDownscaling = v
|
||||||
case "MotionInterval":
|
case "MotionInterval":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionInterval var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid MotionInterval var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.MotionInterval = v
|
r.cfg.MotionInterval = v
|
||||||
case "FileFPS":
|
case "FileFPS":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
r.cfg.Logger.Log(logger.Warning, pkg+"invalid FileFPS var", "value", value)
|
r.cfg.Logger.Log(logger.Warning, "invalid FileFPS var", "value", value)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
r.cfg.FileFPS = v
|
r.cfg.FileFPS = v
|
||||||
|
@ -901,7 +899,7 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
r.cfg.Logger.Log(logger.Info, "finished reconfig")
|
r.cfg.Logger.Log(logger.Info, "finished reconfig")
|
||||||
r.cfg.Logger.Log(logger.Debug, pkg+"config changed", "config", r.cfg)
|
r.cfg.Logger.Log(logger.Debug, "config changed", "config", r.cfg)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -920,13 +918,13 @@ func (r *Revid) processFrom(in device.AVDevice, delay time.Duration) {
|
||||||
// Lex data from input device, in, until finished or an error is encountered.
|
// Lex data from input device, in, until finished or an error is encountered.
|
||||||
// For a continuous source e.g. a camera or microphone, we should remain
|
// For a continuous source e.g. a camera or microphone, we should remain
|
||||||
// in this call indefinitely unless in.Stop() is called and an io.EOF is forced.
|
// in this call indefinitely unless in.Stop() is called and an io.EOF is forced.
|
||||||
r.cfg.Logger.Log(logger.Debug, pkg+"lexing")
|
r.cfg.Logger.Log(logger.Debug, "lexing")
|
||||||
err = r.lexTo(r.filters[0], in, delay)
|
err = r.lexTo(r.filters[0], in, delay)
|
||||||
switch err {
|
switch err {
|
||||||
case nil, io.EOF:
|
case nil, io.EOF:
|
||||||
r.cfg.Logger.Log(logger.Info, "end of file")
|
r.cfg.Logger.Log(logger.Info, "end of file")
|
||||||
case io.ErrUnexpectedEOF:
|
case io.ErrUnexpectedEOF:
|
||||||
r.cfg.Logger.Log(logger.Info, pkg+"unexpected EOF from input")
|
r.cfg.Logger.Log(logger.Info, "unexpected EOF from input")
|
||||||
default:
|
default:
|
||||||
r.err <- err
|
r.err <- err
|
||||||
}
|
}
|
||||||
|
|
|
@ -127,18 +127,18 @@ func extractMeta(r string, log func(lvl int8, msg string, args ...interface{}))
|
||||||
// Extract time from reply
|
// Extract time from reply
|
||||||
t, err := dec.Int("ts")
|
t, err := dec.Int("ts")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(logger.Warning, pkg+"No timestamp in reply")
|
log(logger.Warning, "No timestamp in reply")
|
||||||
} else {
|
} else {
|
||||||
log(logger.Debug, fmt.Sprintf("%v got timestamp: %v", pkg, t))
|
log(logger.Debug, fmt.Sprintf("got timestamp: %v", t))
|
||||||
mts.RealTime.Set(time.Unix(int64(t), 0))
|
mts.RealTime.Set(time.Unix(int64(t), 0))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract location from reply
|
// Extract location from reply
|
||||||
g, err := dec.String("ll")
|
g, err := dec.String("ll")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log(logger.Debug, pkg+"No location in reply")
|
log(logger.Debug, "No location in reply")
|
||||||
} else {
|
} else {
|
||||||
log(logger.Debug, fmt.Sprintf("%v got location: %v", pkg, g))
|
log(logger.Debug, fmt.Sprintf("got location: %v", g))
|
||||||
mts.Meta.Add("loc", g)
|
mts.Meta.Add("loc", g)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ func (s *mtsSender) output() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.done:
|
case <-s.done:
|
||||||
s.log(logger.Info, pkg+"terminating sender output routine")
|
s.log(logger.Info, "terminating sender output routine")
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
|
@ -218,10 +218,10 @@ func (s *mtsSender) output() {
|
||||||
case nil, io.EOF:
|
case nil, io.EOF:
|
||||||
continue
|
continue
|
||||||
case vring.ErrNextTimeout:
|
case vring.ErrNextTimeout:
|
||||||
s.log(logger.Debug, pkg+"ring buffer read timeout")
|
s.log(logger.Debug, "ring buffer read timeout")
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
s.log(logger.Error, pkg+"unexpected error", "error", err.Error())
|
s.log(logger.Error, "unexpected error", "error", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -231,7 +231,7 @@ func (s *mtsSender) output() {
|
||||||
elem = nil
|
elem = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
s.log(logger.Debug, pkg+"writing")
|
s.log(logger.Debug, "writing")
|
||||||
_, err = s.dst.Write(elem.Bytes())
|
_, err = s.dst.Write(elem.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(logger.Debug, "failed write, repairing MTS", "error", err)
|
s.log(logger.Debug, "failed write, repairing MTS", "error", err)
|
||||||
|
@ -267,7 +267,7 @@ func (s *mtsSender) Write(d []byte) (int, error) {
|
||||||
s.ring.Flush()
|
s.ring.Flush()
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(logger.Warning, pkg+"ringBuffer write error", "error", err.Error(), "n", n, "size", len(s.buf))
|
s.log(logger.Warning, "ringBuffer write error", "error", err.Error(), "n", n, "size", len(s.buf))
|
||||||
}
|
}
|
||||||
s.buf = s.buf[:0]
|
s.buf = s.buf[:0]
|
||||||
}
|
}
|
||||||
|
@ -306,7 +306,7 @@ func newRtmpSender(url string, timeout uint, retries int, rb *vring.Buffer, log
|
||||||
}
|
}
|
||||||
log(logger.Error, "dial error", "error", err)
|
log(logger.Error, "dial error", "error", err)
|
||||||
if n < retries-1 {
|
if n < retries-1 {
|
||||||
log(logger.Info, pkg+"retrying dial")
|
log(logger.Info, "retrying dial")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s := &rtmpSender{
|
s := &rtmpSender{
|
||||||
|
@ -330,7 +330,7 @@ func (s *rtmpSender) output() {
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-s.done:
|
case <-s.done:
|
||||||
s.log(logger.Info, pkg+"terminating sender output routine")
|
s.log(logger.Info, "terminating sender output routine")
|
||||||
defer s.wg.Done()
|
defer s.wg.Done()
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
|
@ -342,18 +342,18 @@ func (s *rtmpSender) output() {
|
||||||
case nil, io.EOF:
|
case nil, io.EOF:
|
||||||
continue
|
continue
|
||||||
case vring.ErrNextTimeout:
|
case vring.ErrNextTimeout:
|
||||||
s.log(logger.Debug, pkg+"ring buffer read timeout")
|
s.log(logger.Debug, "ring buffer read timeout")
|
||||||
continue
|
continue
|
||||||
default:
|
default:
|
||||||
s.log(logger.Error, pkg+"unexpected error", "error", err.Error())
|
s.log(logger.Error, "unexpected error", "error", err.Error())
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.conn == nil {
|
if s.conn == nil {
|
||||||
s.log(logger.Warning, pkg+"no rtmp connection, re-dialing")
|
s.log(logger.Warning, "no rtmp connection, re-dialing")
|
||||||
err := s.restart()
|
err := s.restart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(logger.Warning, pkg+"could not restart connection", "error", err)
|
s.log(logger.Warning, "could not restart connection", "error", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -364,10 +364,10 @@ func (s *rtmpSender) output() {
|
||||||
case nil, rtmp.ErrInvalidFlvTag:
|
case nil, rtmp.ErrInvalidFlvTag:
|
||||||
s.log(logger.Debug, "good write to conn")
|
s.log(logger.Debug, "good write to conn")
|
||||||
default:
|
default:
|
||||||
s.log(logger.Warning, pkg+"send error, re-dialing", "error", err)
|
s.log(logger.Warning, "send error, re-dialing", "error", err)
|
||||||
err = s.restart()
|
err = s.restart()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(logger.Warning, pkg+"could not restart connection", "error", err)
|
s.log(logger.Warning, "could not restart connection", "error", err)
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -385,7 +385,7 @@ func (s *rtmpSender) Write(d []byte) (int, error) {
|
||||||
s.ring.Flush()
|
s.ring.Flush()
|
||||||
s.log(logger.Debug, "good ring buffer write", "len", len(d))
|
s.log(logger.Debug, "good ring buffer write", "len", len(d))
|
||||||
} else {
|
} else {
|
||||||
s.log(logger.Warning, pkg+"ring buffer write error", "error", err.Error())
|
s.log(logger.Warning, "ring buffer write error", "error", err.Error())
|
||||||
}
|
}
|
||||||
s.report(len(d))
|
s.report(len(d))
|
||||||
return len(d), nil
|
return len(d), nil
|
||||||
|
@ -402,7 +402,7 @@ func (s *rtmpSender) restart() error {
|
||||||
}
|
}
|
||||||
s.log(logger.Error, "dial error", "error", err)
|
s.log(logger.Error, "dial error", "error", err)
|
||||||
if n < s.retries-1 {
|
if n < s.retries-1 {
|
||||||
s.log(logger.Info, pkg+"retry rtmp connection")
|
s.log(logger.Info, "retry rtmp connection")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
@ -454,7 +454,7 @@ func (s *rtpSender) Write(d []byte) (int, error) {
|
||||||
copy(s.data, d)
|
copy(s.data, d)
|
||||||
_, err := s.encoder.Write(s.data)
|
_, err := s.encoder.Write(s.data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.log(logger.Warning, pkg+"rtpSender: write error", err.Error())
|
s.log(logger.Warning, "rtpSender: write error", err.Error())
|
||||||
}
|
}
|
||||||
s.report(len(d))
|
s.report(len(d))
|
||||||
return len(d), nil
|
return len(d), nil
|
||||||
|
|
Loading…
Reference in New Issue