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 9b3e9f15..d879c208 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: