Merged in fix-loop (pull request #483)

revid & device/file: removing Loop mode which was conflicting with Loop variable, and improve file input with logging and robustness

Resolves issue #374

Approved-by: Trek Hopton
This commit is contained in:
Saxon Milton 2022-09-01 05:58:45 +00:00
commit f9fddcf0e8
3 changed files with 20 additions and 20 deletions

View File

@ -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,10 +85,14 @@ 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)
@ -98,7 +104,6 @@ func (m *AVFile) Read(p []byte) (int, error) {
return n, fmt.Errorf("could not read after start seek: %w", err)
}
}
}
return n, err
}
return 0, errors.New("AV file is closed")

View File

@ -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,

View File

@ -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: