From 862c06b5f3e7b4b22bb6521ca62200d4cf3540e4 Mon Sep 17 00:00:00 2001 From: Saxon Nelson-Milton Date: Wed, 31 Aug 2022 16:58:40 +0930 Subject: [PATCH] revid & device/file: removing Loop mode which was conflicting with Loop variable, and improve file input with logging and robustness --- device/file/file.go | 29 +++++++++++++++++------------ revid/config/variables.go | 9 ++------- revid/pipeline.go | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/device/file/file.go b/device/file/file.go index a0e9f455..bb211782 100644 --- a/device/file/file.go +++ b/device/file/file.go @@ -32,6 +32,7 @@ import ( "os" "bitbucket.org/ausocean/av/revid/config" + "bitbucket.org/ausocean/utils/logging" ) // AVFile is an implementation of the AVDevice interface for a file containg @@ -40,10 +41,11 @@ type AVFile struct { f *os.File cfg config.Config isRunning bool + log logging.Logger } // NewAVFile returns a new AVFile. -func New() *AVFile { return &AVFile{} } +func New(l logging.Logger) *AVFile { return &AVFile{log: l} } // Name returns the name of the device. func (m *AVFile) Name() string { @@ -83,20 +85,23 @@ func (m *AVFile) Stop() error { func (m *AVFile) Read(p []byte) (int, error) { if m.f != nil { n, err := m.f.Read(p) - if err != nil { + if err != nil && err != io.EOF { + return n, err + } + + if (n < len(p) || err == io.EOF) && m.cfg.Loop { + m.log.Info("looping input file") // In the case that we reach end of file but loop is true, we want to // seek to start and keep reading from there. - if err == io.EOF && m.cfg.Loop { - _, err = m.f.Seek(0, io.SeekStart) - if err != nil { - return 0, fmt.Errorf("could not seek to start of file for input loop: %w", err) - } + _, err = m.f.Seek(0, io.SeekStart) + if err != nil { + return 0, fmt.Errorf("could not seek to start of file for input loop: %w", err) + } - // Now that we've seeked to start, let's try reading again. - n, err = m.f.Read(p) - if err != nil { - return n, fmt.Errorf("could not read after start seek: %w", err) - } + // Now that we've seeked to start, let's try reading again. + n, err = m.f.Read(p) + if err != nil { + return n, fmt.Errorf("could not read after start seek: %w", err) } } return n, err diff --git a/revid/config/variables.go b/revid/config/variables.go index 478f72c3..644cb0f4 100644 --- a/revid/config/variables.go +++ b/revid/config/variables.go @@ -418,13 +418,8 @@ var Variables = []struct { }, { Name: KeyMode, - Type: "enum:Normal,Paused,Burst,Loop", - Update: func(c *Config, v string) { - c.Loop = false - if v == KeyLoop { - c.Loop = true - } - }, + Type: "enum:Normal,Paused,Burst", + Update: func(c *Config, v string) {}, }, { Name: KeyMotionDownscaling, diff --git a/revid/pipeline.go b/revid/pipeline.go index 39665a47..ca171617 100644 --- a/revid/pipeline.go +++ b/revid/pipeline.go @@ -301,7 +301,7 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io. case config.InputFile: r.cfg.Logger.Debug("using file input") - r.input = file.New() + r.input = file.New(r.cfg.Logger) err = r.setLexer(r.cfg.InputCodec, false) case config.InputRTSP: