2018-04-19 10:03:12 +03:00
|
|
|
/*
|
|
|
|
NAME
|
2018-06-27 01:20:05 +03:00
|
|
|
revid-cli - command line interface for Revid.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
See Readme.md
|
|
|
|
|
|
|
|
AUTHORS
|
2018-06-20 08:08:34 +03:00
|
|
|
Saxon A. Nelson-Milton <saxon@ausocean.org>
|
|
|
|
Jack Richardson <jack@ausocean.org>
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
LICENSE
|
2018-06-27 01:20:05 +03:00
|
|
|
revid-cli is Copyright (C) 2017-2018 the Australian Ocean Lab (AusOcean)
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
It is free software: you can redistribute it and/or modify them
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
Free Software Foundation, either version 3 of the License, or (at your
|
|
|
|
option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
2018-06-20 08:08:34 +03:00
|
|
|
for more details.
|
2018-04-19 10:03:12 +03:00
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-06-20 08:08:34 +03:00
|
|
|
along with revid in gpl.txt. If not, see http://www.gnu.org/licenses.
|
2018-04-19 10:03:12 +03:00
|
|
|
*/
|
2018-07-05 14:24:10 +03:00
|
|
|
|
2018-04-15 13:42:06 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
2018-06-09 03:46:04 +03:00
|
|
|
"os"
|
2018-07-05 14:24:10 +03:00
|
|
|
"runtime/pprof"
|
2018-04-19 09:42:07 +03:00
|
|
|
"strconv"
|
2018-04-19 11:19:36 +03:00
|
|
|
"time"
|
2018-04-19 08:58:16 +03:00
|
|
|
|
2018-04-19 11:19:36 +03:00
|
|
|
"bitbucket.org/ausocean/av/revid"
|
2018-05-03 06:51:28 +03:00
|
|
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
2018-05-24 06:35:29 +03:00
|
|
|
"bitbucket.org/ausocean/utils/smartlogger"
|
2018-04-15 13:42:06 +03:00
|
|
|
)
|
|
|
|
|
2018-06-08 15:44:23 +03:00
|
|
|
const (
|
|
|
|
// progName is the program name for logging purposes.
|
|
|
|
progName = "revid-cli"
|
|
|
|
|
|
|
|
// Logging is set to INFO level.
|
2018-09-11 02:25:45 +03:00
|
|
|
defaultLogVerbosity = smartlogger.Info
|
2018-06-08 15:44:23 +03:00
|
|
|
)
|
|
|
|
|
2018-04-19 09:42:07 +03:00
|
|
|
// Other misc consts
|
|
|
|
const (
|
2018-06-08 15:22:11 +03:00
|
|
|
netSendRetryTime = 5 * time.Second
|
|
|
|
defaultRunDuration = 24 * time.Hour
|
|
|
|
revidStopTime = 5 * time.Second
|
2018-12-05 11:44:36 +03:00
|
|
|
defaultLogPath = "/var/log/netsender"
|
2018-09-20 04:48:11 +03:00
|
|
|
pkg = "revid-cli:"
|
2018-04-19 09:42:07 +03:00
|
|
|
)
|
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
// canProfile is set to false with revid-cli is built with "-tags profile".
|
|
|
|
var canProfile = true
|
|
|
|
|
2018-09-10 12:19:09 +03:00
|
|
|
// The logger that will be used throughout
|
|
|
|
var logger *smartlogger.Logger
|
|
|
|
|
2018-04-19 09:42:07 +03:00
|
|
|
// Globals
|
2018-12-06 06:34:55 +03:00
|
|
|
var rv *revid.Revid
|
2018-04-15 13:42:06 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
func main() {
|
2018-12-05 12:24:52 +03:00
|
|
|
useNetsender := flag.Bool("NetSender", false, "Are we checking vars through netsender?")
|
|
|
|
runDurationPtr := flag.Duration("runDuration", defaultRunDuration, "How long do you want revid to run for?")
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg := handleFlags()
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
if !*useNetsender {
|
|
|
|
// run revid for the specified duration
|
2018-12-06 06:34:55 +03:00
|
|
|
startRevid(nil, cfg)
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(*runDurationPtr)
|
|
|
|
stopRevid()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
err := run(cfg)
|
2018-09-11 02:25:45 +03:00
|
|
|
if err != nil {
|
2018-09-20 05:10:12 +03:00
|
|
|
logger.Log(smartlogger.Fatal, pkg+"failed to run revid", "error", err.Error())
|
2018-09-11 02:25:45 +03:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
// handleFlags parses command line flags and returns a revid configuration
|
|
|
|
// based on them.
|
|
|
|
func handleFlags() revid.Config {
|
|
|
|
var cfg revid.Config
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
var (
|
|
|
|
cpuprofile = flag.String("cpuprofile", "", "write cpu profile to `file`")
|
|
|
|
|
|
|
|
inputPtr = flag.String("Input", "", "The input type: Raspivid, File")
|
|
|
|
inputCodecPtr = flag.String("InputCodec", "", "The codec of the input: H264, Mjpeg")
|
|
|
|
output1Ptr = flag.String("Output1", "", "The first output type: Http, Rtmp, File, Udp, Rtp")
|
|
|
|
output2Ptr = flag.String("Output2", "", "The second output type: Http, Rtmp, File, Udp, Rtp")
|
|
|
|
rtmpMethodPtr = flag.String("RtmpMethod", "", "The method used to send over rtmp: Ffmpeg, Librtmp")
|
|
|
|
packetizationPtr = flag.String("Packetization", "", "The method of data packetisation: Flv, Mpegts, None")
|
|
|
|
quantizationModePtr = flag.String("QuantizationMode", "", "Whether quantization if on or off (variable bitrate): On, Off")
|
|
|
|
verbosityPtr = flag.String("Verbosity", "", "Verbosity: Info, Warning, Error, Fatal")
|
|
|
|
framesPerClipPtr = flag.String("FramesPerClip", "", "Number of frames per clip sent")
|
|
|
|
rtmpUrlPtr = flag.String("RtmpUrl", "", "Url of rtmp endpoint")
|
|
|
|
bitratePtr = flag.String("Bitrate", "", "Bitrate of recorded video")
|
|
|
|
outputFileNamePtr = flag.String("OutputFileName", "", "The directory of the output file")
|
|
|
|
inputFileNamePtr = flag.String("InputFileName", "", "The directory of the input file")
|
|
|
|
heightPtr = flag.String("Height", "", "Height in pixels")
|
|
|
|
widthPtr = flag.String("Width", "", "Width in pixels")
|
|
|
|
frameRatePtr = flag.String("FrameRate", "", "Frame rate of captured video")
|
|
|
|
httpAddressPtr = flag.String("HttpAddress", "", "Destination address of http posts")
|
|
|
|
quantizationPtr = flag.String("Quantization", "", "Desired quantization value: 0-40")
|
|
|
|
timeoutPtr = flag.String("Timeout", "", "Http timeout in seconds")
|
|
|
|
intraRefreshPeriodPtr = flag.String("IntraRefreshPeriod", "", "The IntraRefreshPeriod i.e. how many keyframes we send")
|
|
|
|
verticalFlipPtr = flag.String("VerticalFlip", "", "Flip video vertically: Yes, No")
|
|
|
|
horizontalFlipPtr = flag.String("HorizontalFlip", "", "Flip video horizontally: Yes, No")
|
|
|
|
logPathPtr = flag.String("LogPath", defaultLogPath, "Path for logging files (default is /var/log/netsender/)")
|
|
|
|
rtpAddrPtr = flag.String("RtpAddr", "", "Rtp destination address: <IP>:<port> (port is generally 6970-6999)")
|
|
|
|
)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2018-09-12 04:30:04 +03:00
|
|
|
flag.Parse()
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
logger = smartlogger.New(defaultLogVerbosity, *logPathPtr)
|
2018-09-11 02:25:45 +03:00
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Logger = logger
|
2018-09-12 04:27:56 +03:00
|
|
|
|
2018-07-05 14:24:10 +03:00
|
|
|
if *cpuprofile != "" {
|
|
|
|
if canProfile {
|
|
|
|
f, err := os.Create(*cpuprofile)
|
|
|
|
if err != nil {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Fatal, pkg+"could not create CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
if err := pprof.StartCPUProfile(f); err != nil {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Fatal, pkg+"could not start CPU profile", "error", err.Error())
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
defer pprof.StopCPUProfile()
|
|
|
|
} else {
|
2018-09-19 15:59:10 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"ignoring cpuprofile flag - http/pprof built in.")
|
2018-07-05 14:24:10 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Raspivid":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Input = revid.Raspivid
|
2018-04-15 13:42:06 +03:00
|
|
|
case "File":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Input = revid.File
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad input argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *inputCodecPtr {
|
2018-11-18 10:43:38 +03:00
|
|
|
case "H264":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.InputCodec = revid.H264
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad input codec argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *output1Ptr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "File":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.File
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Http":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Http
|
2018-06-25 04:23:26 +03:00
|
|
|
case "Rtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Rtmp
|
2018-04-19 12:39:48 +03:00
|
|
|
case "FfmpegRtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.FfmpegRtmp
|
2018-11-18 05:53:14 +03:00
|
|
|
case "Udp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Udp
|
2018-11-21 10:44:36 +03:00
|
|
|
case "Rtp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Rtp
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-11-25 15:54:03 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad output 1 argument")
|
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *output2Ptr {
|
2018-11-25 15:54:03 +03:00
|
|
|
case "File":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.File
|
2018-11-25 15:54:03 +03:00
|
|
|
case "Http":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.Http
|
2018-11-25 15:54:03 +03:00
|
|
|
case "Rtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.Rtmp
|
2018-11-25 15:54:03 +03:00
|
|
|
case "FfmpegRtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.FfmpegRtmp
|
2018-11-25 15:54:03 +03:00
|
|
|
case "Udp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.Udp
|
2018-11-25 15:54:03 +03:00
|
|
|
case "Rtp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output2 = revid.Rtp
|
2018-11-25 15:54:03 +03:00
|
|
|
case "":
|
|
|
|
default:
|
|
|
|
logger.Log(smartlogger.Error, pkg+"bad output 2 argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *rtmpMethodPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Ffmpeg":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpMethod = revid.Ffmpeg
|
2018-04-15 13:42:06 +03:00
|
|
|
case "LibRtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpMethod = revid.LibRtmp
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad rtmp method argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *packetizationPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "None":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.None
|
2018-06-30 15:20:55 +03:00
|
|
|
case "Mpegts":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.Mpegts
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Flv":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Packetization = revid.Flv
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad packetization argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *quantizationModePtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "QuantizationOn":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.QuantizationMode = revid.QuantizationOn
|
2018-04-15 13:42:06 +03:00
|
|
|
case "QuantizationOff":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.QuantizationMode = revid.QuantizationOff
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad quantization mode argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *verbosityPtr {
|
2018-04-15 13:42:06 +03:00
|
|
|
case "No":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.LogLevel = smartlogger.Fatal
|
2018-04-15 13:42:06 +03:00
|
|
|
case "Yes":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.LogLevel = smartlogger.Debug
|
2018-04-19 12:37:25 +03:00
|
|
|
case "":
|
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad verbosity argument")
|
2018-04-15 13:42:06 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *horizontalFlipPtr {
|
2018-05-03 11:32:36 +03:00
|
|
|
case "No":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = false
|
2018-05-03 11:32:36 +03:00
|
|
|
case "Yes":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = true
|
2018-05-03 11:32:36 +03:00
|
|
|
case "":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = false
|
2018-05-03 11:32:36 +03:00
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad horizontal flip option")
|
2018-05-03 15:36:17 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
switch *verticalFlipPtr {
|
2018-05-03 15:36:17 +03:00
|
|
|
case "No":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = false
|
2018-05-03 15:36:17 +03:00
|
|
|
case "Yes":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = true
|
2018-05-03 15:36:17 +03:00
|
|
|
case "":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = false
|
2018-05-03 15:36:17 +03:00
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"bad vertical flip option")
|
2018-05-03 11:32:36 +03:00
|
|
|
}
|
|
|
|
|
2018-12-05 12:24:52 +03:00
|
|
|
fpc, err := strconv.Atoi(*framesPerClipPtr)
|
2018-06-20 08:08:34 +03:00
|
|
|
if err == nil && fpc > 0 {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FramesPerClip = fpc
|
2018-06-20 08:08:34 +03:00
|
|
|
}
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpUrl = *rtmpUrlPtr
|
|
|
|
cfg.Bitrate = *bitratePtr
|
|
|
|
cfg.OutputFileName = *outputFileNamePtr
|
|
|
|
cfg.InputFileName = *inputFileNamePtr
|
|
|
|
cfg.Height = *heightPtr
|
|
|
|
cfg.Width = *widthPtr
|
|
|
|
cfg.FrameRate = *frameRatePtr
|
|
|
|
cfg.HttpAddress = *httpAddressPtr
|
|
|
|
cfg.Quantization = *quantizationPtr
|
|
|
|
cfg.Timeout = *timeoutPtr
|
|
|
|
cfg.IntraRefreshPeriod = *intraRefreshPeriodPtr
|
|
|
|
cfg.RtpAddress = *rtpAddrPtr
|
|
|
|
|
|
|
|
return cfg
|
2018-09-12 04:41:48 +03:00
|
|
|
}
|
2018-04-19 09:42:07 +03:00
|
|
|
|
2018-09-12 04:41:48 +03:00
|
|
|
// initialize then run the main NetSender client
|
2018-12-06 06:34:55 +03:00
|
|
|
func run(cfg revid.Config) error {
|
2018-09-12 04:41:48 +03:00
|
|
|
// initialize NetSender and use NetSender's logger
|
|
|
|
//config.Logger = netsender.Logger()
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Info, pkg+"running in NetSender mode")
|
2018-09-12 04:41:48 +03:00
|
|
|
|
|
|
|
var ns netsender.Sender
|
2018-09-21 08:12:50 +03:00
|
|
|
err := ns.Init(logger, nil, nil, nil)
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
vars, _ := ns.Vars()
|
|
|
|
vs := ns.VarSum()
|
|
|
|
paused := false
|
|
|
|
if vars["mode"] == "Paused" {
|
|
|
|
paused = true
|
|
|
|
}
|
|
|
|
if !paused {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg, err = updateRevid(&ns, cfg, vars, false)
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
if err := send(&ns); err != nil {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"polling failed", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
|
|
|
if vs != ns.VarSum() {
|
|
|
|
// vars changed
|
|
|
|
vars, err := ns.Vars()
|
|
|
|
if err != nil {
|
2018-09-19 15:59:10 +03:00
|
|
|
logger.Log(smartlogger.Error, pkg+"netSender failed to get vars", "error", err.Error())
|
2018-09-12 04:41:48 +03:00
|
|
|
time.Sleep(netSendRetryTime)
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
vs = ns.VarSum()
|
|
|
|
if vars["mode"] == "Paused" {
|
|
|
|
if !paused {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Info, pkg+"pausing revid")
|
2018-09-12 04:41:48 +03:00
|
|
|
stopRevid()
|
|
|
|
paused = true
|
|
|
|
}
|
|
|
|
} else {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg, err = updateRevid(&ns, cfg, vars, !paused)
|
2018-09-12 04:41:48 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if paused {
|
|
|
|
paused = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sleepTime, _ := strconv.Atoi(ns.Param("mp"))
|
|
|
|
time.Sleep(time.Duration(sleepTime) * time.Second)
|
2018-04-20 05:20:33 +03:00
|
|
|
}
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
|
2018-06-26 09:23:55 +03:00
|
|
|
// send implements our main NetSender client and handles NetReceiver configuration
|
2018-06-15 10:59:59 +03:00
|
|
|
// (as distinct from httpSender which just sends video data).
|
2018-06-26 09:23:55 +03:00
|
|
|
func send(ns *netsender.Sender) error {
|
2018-06-14 10:07:57 +03:00
|
|
|
// populate input values, if any
|
2018-06-25 03:40:37 +03:00
|
|
|
inputs := netsender.MakePins(ns.Param("ip"), "X")
|
2018-06-28 09:43:06 +03:00
|
|
|
if rv != nil {
|
|
|
|
for i, pin := range inputs {
|
|
|
|
if pin.Name == "X23" {
|
|
|
|
inputs[i].Value = rv.Bitrate()
|
|
|
|
}
|
2018-06-14 10:07:57 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-16 12:34:32 +03:00
|
|
|
_, reconfig, err := ns.Send(netsender.RequestPoll, inputs)
|
2018-06-08 15:45:14 +03:00
|
|
|
if err != nil {
|
2018-06-01 14:20:56 +03:00
|
|
|
return err
|
2018-06-08 15:45:14 +03:00
|
|
|
}
|
|
|
|
if reconfig {
|
|
|
|
return ns.Config()
|
2018-04-19 09:42:07 +03:00
|
|
|
}
|
2018-06-01 14:20:56 +03:00
|
|
|
return nil
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// wrappers for stopping and starting revid
|
2018-12-06 06:34:55 +03:00
|
|
|
func startRevid(ns *netsender.Sender, cfg revid.Config) (revid.Config, error) {
|
|
|
|
var err error
|
|
|
|
rv, err = revid.New(cfg, ns)
|
2018-06-26 09:23:55 +03:00
|
|
|
if err != nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
return cfg, err
|
2018-06-08 15:56:20 +03:00
|
|
|
}
|
2018-06-26 09:23:55 +03:00
|
|
|
rv.Start()
|
2018-12-06 06:34:55 +03:00
|
|
|
return cfg, nil
|
2018-06-08 15:56:20 +03:00
|
|
|
}
|
|
|
|
|
2018-05-07 04:16:44 +03:00
|
|
|
func stopRevid() {
|
2018-06-26 09:23:55 +03:00
|
|
|
rv.Stop()
|
2018-06-07 14:50:57 +03:00
|
|
|
|
|
|
|
// FIXME(kortschak): Is this waiting on completion of work?
|
|
|
|
// Use a wait group and Wait method if it is.
|
2018-06-08 15:22:11 +03:00
|
|
|
time.Sleep(revidStopTime)
|
2018-05-07 04:16:44 +03:00
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
func updateRevid(ns *netsender.Sender, cfg revid.Config, vars map[string]string, stop bool) (revid.Config, error) {
|
2018-05-07 04:16:44 +03:00
|
|
|
if stop {
|
|
|
|
stopRevid()
|
|
|
|
}
|
2018-04-20 11:23:59 +03:00
|
|
|
|
2018-06-01 14:20:56 +03:00
|
|
|
//look through the vars and update revid where needed
|
2018-04-19 08:58:16 +03:00
|
|
|
for key, value := range vars {
|
|
|
|
switch key {
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Output":
|
|
|
|
switch value {
|
|
|
|
case "File":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.File
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Http":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Http
|
2018-06-25 04:39:56 +03:00
|
|
|
case "Rtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.Rtmp
|
2018-06-25 04:39:56 +03:00
|
|
|
case "FfmpegRtmp":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Output1 = revid.FfmpegRtmp
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2018-11-25 15:54:03 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid Output1 param", "value", value)
|
2018-06-25 04:39:56 +03:00
|
|
|
continue
|
|
|
|
}
|
2018-05-06 11:38:45 +03:00
|
|
|
case "FramesPerClip":
|
2018-06-20 08:08:34 +03:00
|
|
|
fpc, err := strconv.Atoi(value)
|
|
|
|
if fpc > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FramesPerClip = fpc
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid FramesPerClip param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "RtmpUrl":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.RtmpUrl = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Bitrate":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Bitrate = value
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid Bitrate param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "OutputFileName":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.OutputFileName = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "InputFileName":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.InputFileName = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Height":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Height = value
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid Height param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "Width":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Width = value
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid Width param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "FrameRate":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FrameRate = value
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid FrameRate param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "HttpAddress":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.HttpAddress = value
|
2018-05-06 11:38:45 +03:00
|
|
|
case "Quantization":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Quantization = value
|
2018-06-25 04:39:56 +03:00
|
|
|
} else {
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid Quantization param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "Timeout":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.Timeout = value
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "IntraRefreshPeriod":
|
|
|
|
asInt, err := strconv.Atoi(value)
|
|
|
|
if asInt > 0 && err == nil {
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.IntraRefreshPeriod = value
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "HorizontalFlip":
|
|
|
|
switch value {
|
|
|
|
case "Yes":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = true
|
2018-05-06 11:38:45 +03:00
|
|
|
case "No":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipHorizontal = false
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid HorizontalFlip param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
|
|
|
case "VerticalFlip":
|
|
|
|
switch value {
|
|
|
|
case "Yes":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = true
|
2018-05-06 11:38:45 +03:00
|
|
|
case "No":
|
2018-12-06 06:34:55 +03:00
|
|
|
cfg.FlipVertical = false
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2018-09-20 05:08:08 +03:00
|
|
|
logger.Log(smartlogger.Warning, pkg+"invalid VerticalFlip param", "value", value)
|
2018-05-06 11:38:45 +03:00
|
|
|
}
|
2018-06-25 04:39:56 +03:00
|
|
|
default:
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-06 06:34:55 +03:00
|
|
|
return startRevid(ns, cfg)
|
2018-04-19 08:58:16 +03:00
|
|
|
}
|