mirror of https://bitbucket.org/ausocean/av.git
revid & device/file: removing Loop mode which was conflicting with Loop variable, and improve file input with logging and robustness
This commit is contained in:
parent
f1b1d5c880
commit
862c06b5f3
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue