diff --git a/cmd/revid-cli/main.go b/cmd/revid-cli/main.go index 5b826b91..826cb2a4 100644 --- a/cmd/revid-cli/main.go +++ b/cmd/revid-cli/main.go @@ -72,23 +72,22 @@ func main() { cfg := handleFlags() if !*useNetsender { - // run revid for the specified duration - rv, _, err := startRevid(nil, cfg) + rv, err := revid.New(cfg, nil) if err != nil { + cfg.Logger.Log(logger.Fatal, pkg+"failed to initialiase revid", "error", err.Error()) + } + if err = rv.Start(); err != nil { cfg.Logger.Log(logger.Fatal, pkg+"failed to start revid", "error", err.Error()) } time.Sleep(*runDurationPtr) - err = stopRevid(rv) - if err != nil { + if err = rv.Stop(); err != nil { cfg.Logger.Log(logger.Error, pkg+"failed to stop revid before program termination", "error", err.Error()) } return } - err := run(nil, cfg) - if err != nil { + if err := run(cfg); err != nil { log.Log(logger.Fatal, pkg+"failed to run revid", "error", err.Error()) - os.Exit(1) } } @@ -244,27 +243,20 @@ func handleFlags() revid.Config { } // initialize then run the main NetSender client -func run(rv *revid.Revid, cfg revid.Config) error { +func run(cfg revid.Config) error { // initialize NetSender and use NetSender's logger - //config.Logger = netsender.Logger() log.Log(logger.Info, pkg+"running in NetSender mode") var ns netsender.Sender - err := ns.Init(log, nil, nil, nil) - if err != nil { + if err := ns.Init(log, nil, nil, nil); err != nil { return err } vars, _ := ns.Vars() vs := ns.VarSum() - paused := false - if vars["mode"] == "Paused" { - paused = true - } - if !paused { - rv, cfg, err = updateRevid(&ns, rv, cfg, vars, false) - if err != nil { - return err - } + + rv, cfg, err = updateRevid(&ns, rv, cfg, vars, false) + if err != nil { + return err } for { @@ -331,28 +323,6 @@ func send(ns *netsender.Sender, rv *revid.Revid) error { return nil } -// wrappers for stopping and starting revid -func startRevid(ns *netsender.Sender, cfg revid.Config) (*revid.Revid, revid.Config, error) { - rv, err := revid.New(cfg, ns) - if err != nil { - return nil, cfg, err - } - err = rv.Start() - return rv, cfg, err -} - -func stopRevid(rv *revid.Revid) error { - err := rv.Stop() - if err != nil { - return err - } - - // FIXME(kortschak): Is this waiting on completion of work? - // Use a wait group and Wait method if it is. - time.Sleep(revidStopTime) - return nil -} - func updateRevid(ns *netsender.Sender, rv *revid.Revid, cfg revid.Config, vars map[string]string, stop bool) (*revid.Revid, revid.Config, error) { if stop { err := stopRevid(rv) diff --git a/revid/revid.go b/revid/revid.go index 6833ec2b..81546ead 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -40,6 +40,7 @@ import ( "sync" "time" + "bitbucket.org/ausocean/av/revid" "bitbucket.org/ausocean/av/stream" "bitbucket.org/ausocean/av/stream/flv" "bitbucket.org/ausocean/av/stream/lex" @@ -326,6 +327,13 @@ func (r *Revid) IsRunning() bool { return ret } +func (r *Revid) Config() Config { + r.mu.Lock() + ret := r.config + r.mu.Unlock() + return ret +} + // setIsRunning sets revid.isRunning using b. func (r *Revid) setIsRunning(b bool) { r.mu.Lock() @@ -366,6 +374,113 @@ func (r *Revid) Stop() error { return nil } +func (r *Revid) Update(vars map[string]string) error { + if r.IsRunning() { + r.Stop() + } + //look through the vars and update revid where needed + for key, value := range vars { + switch key { + case "Output": + // FIXME(kortschak): There can be only one! + // How do we specify outputs after the first? + // + // Maybe we shouldn't be doing this! + switch value { + case "File": + cfg.Outputs[0] = revid.File + case "Http": + cfg.Outputs[0] = revid.Http + case "Rtmp": + cfg.Outputs[0] = revid.Rtmp + case "FfmpegRtmp": + cfg.Outputs[0] = revid.FfmpegRtmp + default: + log.Log(logger.Warning, pkg+"invalid Output1 param", "value", value) + continue + } + case "FramesPerClip": + f, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid framesperclip param", "value", value) + break + } + cfg.FramesPerClip = uint(f) + case "RtmpUrl": + cfg.RtmpUrl = value + case "Bitrate": + r, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid framerate param", "value", value) + break + } + cfg.Bitrate = uint(r) + case "OutputFileName": + cfg.OutputFileName = value + case "InputFileName": + cfg.InputFileName = value + case "Height": + h, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid height param", "value", value) + break + } + cfg.Height = uint(h) + case "Width": + w, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid width param", "value", value) + break + } + cfg.Width = uint(w) + case "FrameRate": + r, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid framerate param", "value", value) + break + } + cfg.FrameRate = uint(r) + case "HttpAddress": + cfg.HttpAddress = value + case "Quantization": + q, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid quantization param", "value", value) + break + } + cfg.Quantization = uint(q) + case "IntraRefreshPeriod": + p, err := strconv.ParseUint(value, 10, 0) + if err != nil { + log.Log(logger.Warning, pkg+"invalid intrarefreshperiod param", "value", value) + break + } + cfg.IntraRefreshPeriod = uint(p) + case "HorizontalFlip": + switch strings.ToLower(value) { + case "true": + cfg.FlipHorizontal = true + case "false": + cfg.FlipHorizontal = false + default: + log.Log(logger.Warning, pkg+"invalid HorizontalFlip param", "value", value) + } + case "VerticalFlip": + switch strings.ToLower(value) { + case "true": + cfg.FlipVertical = true + case "false": + cfg.FlipVertical = false + default: + log.Log(logger.Warning, pkg+"invalid VerticalFlip param", "value", value) + } + default: + } + } + + return startRevid(ns, cfg) +} + // outputClips takes the clips produced in the packClips method and outputs them // to the desired output defined in the revid config func (r *Revid) outputClips() {