From 62af00ff4f6d6cbf54f78c5d91a51f4cf538548e Mon Sep 17 00:00:00 2001 From: Scott Date: Tue, 31 Dec 2019 10:54:13 +1030 Subject: [PATCH] PR changes #1 --- filter/{variable_fps.go => vfps.go} | 29 ++++++++++++++--------------- revid/revid.go | 2 +- 2 files changed, 15 insertions(+), 16 deletions(-) rename filter/{variable_fps.go => vfps.go} (68%) diff --git a/filter/variable_fps.go b/filter/vfps.go similarity index 68% rename from filter/variable_fps.go rename to filter/vfps.go index 606b3656..93b6f543 100644 --- a/filter/variable_fps.go +++ b/filter/vfps.go @@ -8,7 +8,7 @@ AUTHORS Scott Barnard LICENSE - variable_fps.go is Copyright (C) 2019 the Australian Ocean Lab (AusOcean) + vfps.go is Copyright (C) 2019 the Australian Ocean Lab (AusOcean) 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 @@ -30,39 +30,38 @@ import ( "io" ) -// VariableFps is a filter that has a variable frame rate. When motion is +// VariableFPSFilter is a filter that has a variable frame rate. When motion is // detected, the filter sends all frames and when it is not, the filter // sends frames at a reduced framerate. -type VariableFps struct { - motionFilter Filter - dst io.WriteCloser - frames uint - count uint +type VariableFPSFilter struct { + filter Filter + dst io.WriteCloser + frames uint + count uint } -// NewVariableFps returns a pointer to a new VariableFps filter. -func NewVariableFps(dst io.WriteCloser, minFPS float64, debug bool) *VariableFps { +// NewVariableFPSFilter returns a pointer to a new VariableFPSFilter struct. +func NewVariableFPSFilter(dst io.WriteCloser, minFPS float64, filter Filter) *VariableFPSFilter { frames := uint(25 / minFPS) - mf := NewMOGFilter(dst, 25, 20, 500, 3, debug) - return &VariableFps{mf, dst, frames, 0} + return &VariableFPSFilter{filter, dst, frames, 0} } // Implements io.Writer. // Write applies the motion filter to the video stream. Frames are sent // at a reduced frame rate, except when motion is detected, then all frames // with motion are sent. -func (v *VariableFps) Write(f []byte) (int, error) { +func (v *VariableFPSFilter) Write(f []byte) (int, error) { v.count = (v.count + 1) % v.frames if v.count == 0 { return v.dst.Write(f) } - return v.motionFilter.Write(f) + return v.filter.Write(f) } // Implements io.Closer. // Close calls the motion filter's Close method. -func (v *VariableFps) Close() error { - return v.motionFilter.Close() +func (v *VariableFPSFilter) Close() error { + return v.filter.Close() } diff --git a/revid/revid.go b/revid/revid.go index 74bbe65a..073c4348 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -334,7 +334,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.FilterMOG: r.filter = filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true) case config.FilterVariableFPS: - r.filter = filter.NewVariableFps(r.encoders, 1.0, true) + r.filter = filter.NewVariableFPSFilter(r.encoders, 1.0, filter.NewMOGFilter(r.encoders, 25, 20, 500, 3, true)) default: panic("Undefined Filter") }