revid: added pkg name to logging messages in revid.go and senders.go

This commit is contained in:
saxon 2018-09-19 22:35:15 +09:30
parent 5c94f556b4
commit 0f24e19a2a
1 changed files with 38 additions and 38 deletions

View File

@ -153,7 +153,7 @@ func (r *Revid) reset(config Config) error {
if r.destination != nil {
err = r.destination.close()
if err != nil {
r.config.Logger.Log(smartlogger.Error, "Could not close destination", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"Could not close destination", "error", err.Error())
}
}
switch r.config.Output {
@ -187,10 +187,10 @@ func (r *Revid) reset(config Config) error {
}
switch r.config.InputCodec {
case H264:
r.config.Logger.Log(smartlogger.Info, "Using H264 lexer")
r.config.Logger.Log(smartlogger.Info, pkg+"Using H264 lexer")
r.lexTo = lex.H264
case Mjpeg:
r.config.Logger.Log(smartlogger.Info, "Using MJPEG lexer")
r.config.Logger.Log(smartlogger.Info, pkg+"Using MJPEG lexer")
r.lexTo = lex.MJPEG
}
@ -216,11 +216,11 @@ func (r *Revid) reset(config Config) error {
r.getFrame = r.getFrameNoPacketization
return nil
case Mpegts:
r.config.Logger.Log(smartlogger.Info, "Using MPEGTS packetisation")
r.config.Logger.Log(smartlogger.Info, pkg+"Using MPEGTS packetisation")
frameRate, _ := strconv.ParseFloat(r.config.FrameRate, 64)
r.encoder = mts.NewEncoder(frameRate)
case Flv:
r.config.Logger.Log(smartlogger.Info, "Using FLV packetisation")
r.config.Logger.Log(smartlogger.Info, pkg+"Using FLV packetisation")
frameRate, _ := strconv.Atoi(r.config.FrameRate)
r.encoder = flv.NewEncoder(true, true, frameRate)
}
@ -240,31 +240,31 @@ func (r *Revid) IsRunning() bool {
// and packetising (if theres packetization) to a defined output.
func (r *Revid) Start() {
if r.isRunning {
r.config.Logger.Log(smartlogger.Warning, "Revid.Start() called but revid already running!")
r.config.Logger.Log(smartlogger.Warning, pkg+"Revid.Start() called but revid already running!")
return
}
r.config.Logger.Log(smartlogger.Info, "Starting Revid")
r.config.Logger.Log(smartlogger.Debug, "Setting up output")
r.config.Logger.Log(smartlogger.Info, pkg+"Starting Revid")
r.config.Logger.Log(smartlogger.Debug, pkg+"Setting up output")
r.isRunning = true
r.config.Logger.Log(smartlogger.Info, "Starting output routine")
r.config.Logger.Log(smartlogger.Info, pkg+"Starting output routine")
go r.outputClips()
r.config.Logger.Log(smartlogger.Info, "Starting clip packing routine")
r.config.Logger.Log(smartlogger.Info, pkg+"Starting clip packing routine")
go r.packClips()
r.config.Logger.Log(smartlogger.Info, "Setting up input and receiving content")
r.config.Logger.Log(smartlogger.Info, pkg+"Setting up input and receiving content")
go r.setupInput()
}
// Stop halts any processing of video data from a camera or file
func (r *Revid) Stop() {
if !r.isRunning {
r.config.Logger.Log(smartlogger.Warning, "Revid.Stop() called but revid not running!")
r.config.Logger.Log(smartlogger.Warning, pkg+"Revid.Stop() called but revid not running!")
return
}
r.config.Logger.Log(smartlogger.Info, "Stopping revid!")
r.config.Logger.Log(smartlogger.Info, pkg+"Stopping revid!")
r.isRunning = false
r.config.Logger.Log(smartlogger.Info, "Killing input proccess!")
r.config.Logger.Log(smartlogger.Info, pkg+"Killing input proccess!")
// If a cmd process is running, we kill!
if r.cmd != nil && r.cmd.Process != nil {
r.cmd.Process.Kill()
@ -298,16 +298,16 @@ func (r *Revid) packClips() {
case frame := <-r.encoder.Stream():
lenOfFrame := len(frame)
if lenOfFrame > ringBufferElementSize {
r.config.Logger.Log(smartlogger.Warning, "Frame was too big", "frame size", lenOfFrame)
r.config.Logger.Log(smartlogger.Warning, pkg+"Frame was too big", "frame size", lenOfFrame)
frame = r.getFrame()
lenOfFrame = len(frame)
}
_, err := r.ringBuffer.Write(frame)
if err != nil {
if err == ring.ErrDropped {
r.config.Logger.Log(smartlogger.Warning, "dropped frame", "frame size", len(frame))
r.config.Logger.Log(smartlogger.Warning, pkg+"dropped frame", "frame size", len(frame))
} else {
r.config.Logger.Log(smartlogger.Error, "Unexpected ringbuffer write error",
r.config.Logger.Log(smartlogger.Error, pkg+"Unexpected ringbuffer write error",
"error", err.Error())
}
}
@ -351,51 +351,51 @@ func (r *Revid) outputClips() {
}
bytes += chunk.Len()
r.config.Logger.Log(smartlogger.Debug, "About to send")
r.config.Logger.Log(smartlogger.Debug, pkg+"About to send")
err = r.destination.load(chunk)
if err != nil {
r.config.Logger.Log(smartlogger.Error, "Failed to load clip")
r.config.Logger.Log(smartlogger.Error, pkg+"Failed to load clip")
}
err = r.destination.send()
if err == nil {
r.config.Logger.Log(smartlogger.Debug, "Sent clip")
r.config.Logger.Log(smartlogger.Debug, pkg+"Sent clip")
}
if r.isRunning && err != nil && chunk.Len() > 11 {
r.config.Logger.Log(smartlogger.Debug, "Send failed! Trying again")
r.config.Logger.Log(smartlogger.Debug, pkg+"Send failed! Trying again")
// Try and send again
err = r.destination.send()
r.config.Logger.Log(smartlogger.Error, "Destination send error", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"Destination send error", "error", err.Error())
// if there's still an error we try and reconnect, unless we're stopping
for r.isRunning && err != nil {
r.config.Logger.Log(smartlogger.Debug, "Send failed a again! Trying to reconnect...")
r.config.Logger.Log(smartlogger.Debug, pkg+"Send failed a again! Trying to reconnect...")
time.Sleep(time.Duration(sendFailedDelay) * time.Millisecond)
r.config.Logger.Log(smartlogger.Error, "Send failed with error", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"Send failed with error", "error", err.Error())
if rs, ok := r.destination.(restarter); ok {
r.config.Logger.Log(smartlogger.Debug, "restarting session", "session", rs)
r.config.Logger.Log(smartlogger.Debug, pkg+"restarting session", "session", rs)
err = rs.restart()
if err != nil {
// TODO(kortschak): Make this "Fatal" when that exists.
r.config.Logger.Log(smartlogger.Error, "failed to restart rtmp session", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"failed to restart rtmp session", "error", err.Error())
r.isRunning = false
return
}
r.config.Logger.Log(smartlogger.Info, "restarted rtmp session")
r.config.Logger.Log(smartlogger.Info, pkg+"restarted rtmp session")
}
r.config.Logger.Log(smartlogger.Debug, "Trying to send again with new connection...")
r.config.Logger.Log(smartlogger.Debug, pkg+"Trying to send again with new connection...")
err = r.destination.send()
if err != nil {
r.config.Logger.Log(smartlogger.Error, "Send failed with error", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"Send failed with error", "error", err.Error())
}
}
}
r.destination.release()
r.config.Logger.Log(smartlogger.Debug, "Done reading that clip from ringbuffer...")
r.config.Logger.Log(smartlogger.Debug, pkg+"Done reading that clip from ringbuffer...")
// Log some information regarding bitrate and ring buffer size if it's time
now = time.Now()
@ -403,23 +403,23 @@ func (r *Revid) outputClips() {
if deltaTime > bitrateTime {
// FIXME(kortschak): For subsecond deltaTime, this will give infinite bitrate.
r.bitrate = int(float64(bytes*8) / float64(deltaTime/time.Second))
r.config.Logger.Log(smartlogger.Debug, "Bitrate (bits/s)", "bitrate", r.bitrate)
r.config.Logger.Log(smartlogger.Debug, "Ring buffer size", "value", r.ringBuffer.Len())
r.config.Logger.Log(smartlogger.Debug, pkg+"Bitrate (bits/s)", "bitrate", r.bitrate)
r.config.Logger.Log(smartlogger.Debug, pkg+"Ring buffer size", "value", r.ringBuffer.Len())
prevTime = now
bytes = 0
}
}
r.config.Logger.Log(smartlogger.Info, "Not outputting clips anymore")
r.config.Logger.Log(smartlogger.Info, pkg+"Not outputting clips anymore")
err := r.destination.close()
if err != nil {
r.config.Logger.Log(smartlogger.Error, "Failed to close destination", "error", err.Error())
r.config.Logger.Log(smartlogger.Error, pkg+"Failed to close destination", "error", err.Error())
}
}
// startRaspivid sets up things for input from raspivid i.e. starts
// a raspivid process and pipes it's data output.
func (r *Revid) startRaspivid() error {
r.config.Logger.Log(smartlogger.Info, "Starting raspivid!")
r.config.Logger.Log(smartlogger.Info, pkg+"Starting raspivid!")
switch r.config.InputCodec {
case H264:
args := []string{
@ -446,7 +446,7 @@ func (r *Revid) startRaspivid() error {
}
// Log all the args and create []string
argsStr := strings.Join(args, " ")
r.config.Logger.Log(smartlogger.Info, "Raspivid args", "raspividArgs", argsStr)
r.config.Logger.Log(smartlogger.Info, pkg+"Raspivid args", "raspividArgs", argsStr)
r.cmd = exec.Command("raspivid", argsStr)
case Mjpeg:
@ -469,9 +469,9 @@ func (r *Revid) startRaspivid() error {
}
r.inputReader = stdout
go func() {
r.config.Logger.Log(smartlogger.Info, "Reading camera data!")
r.config.Logger.Log(smartlogger.Info, pkg+"Reading camera data!")
r.lexTo(r.encoder, r.inputReader, 0)
r.config.Logger.Log(smartlogger.Info, "Not trying to read from camera anymore!")
r.config.Logger.Log(smartlogger.Info, pkg+"Not trying to read from camera anymore!")
}()
return nil
}