mirror of https://bitbucket.org/ausocean/av.git
Merge branch 'master' into m3u-packages
This commit is contained in:
commit
0cbe77c205
|
@ -1,12 +1,9 @@
|
||||||
/*
|
/*
|
||||||
NAME
|
|
||||||
lex-mjpeg.js
|
|
||||||
|
|
||||||
AUTHOR
|
AUTHOR
|
||||||
Trek Hopton <trek@ausocean.org>
|
Trek Hopton <trek@ausocean.org>
|
||||||
|
|
||||||
LICENSE
|
LICENSE
|
||||||
This file is Copyright (C) 2019 the Australian Ocean Lab (AusOcean)
|
This file is Copyright (C) 2020 the Australian Ocean Lab (AusOcean)
|
||||||
|
|
||||||
It is free software: you can redistribute it and/or modify them
|
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
|
under the terms of the GNU General Public License as published by the
|
||||||
|
@ -24,11 +21,14 @@ LICENSE
|
||||||
|
|
||||||
// MJPEGLexer lexes a byte array containing MJPEG into individual JPEGs.
|
// MJPEGLexer lexes a byte array containing MJPEG into individual JPEGs.
|
||||||
class MJPEGLexer {
|
class MJPEGLexer {
|
||||||
constructor(src) {
|
constructor() {
|
||||||
this.src = src;
|
|
||||||
this.off = 0;
|
this.off = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
append(data) {
|
||||||
|
this.src = new Uint8Array(data);
|
||||||
|
}
|
||||||
|
|
||||||
// read returns the next single frame.
|
// read returns the next single frame.
|
||||||
read() {
|
read() {
|
||||||
// Check if the src can contain at least the start and end flags (4B).
|
// Check if the src can contain at least the start and end flags (4B).
|
||||||
|
|
|
@ -32,7 +32,9 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
"runtime/pprof"
|
"runtime/pprof"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -44,10 +46,11 @@ import (
|
||||||
"bitbucket.org/ausocean/av/device/raspivid"
|
"bitbucket.org/ausocean/av/device/raspivid"
|
||||||
"bitbucket.org/ausocean/av/revid"
|
"bitbucket.org/ausocean/av/revid"
|
||||||
"bitbucket.org/ausocean/av/revid/config"
|
"bitbucket.org/ausocean/av/revid/config"
|
||||||
|
"bitbucket.org/ausocean/iot/pi/netlogger"
|
||||||
"bitbucket.org/ausocean/iot/pi/netsender"
|
"bitbucket.org/ausocean/iot/pi/netsender"
|
||||||
"bitbucket.org/ausocean/iot/pi/sds"
|
"bitbucket.org/ausocean/iot/pi/sds"
|
||||||
"bitbucket.org/ausocean/iot/pi/smartlogger"
|
|
||||||
"bitbucket.org/ausocean/utils/logger"
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Revid modes
|
// Revid modes
|
||||||
|
@ -72,7 +75,10 @@ const (
|
||||||
var canProfile = true
|
var canProfile = true
|
||||||
|
|
||||||
// The logger that will be used throughout.
|
// The logger that will be used throughout.
|
||||||
var log *logger.Logger
|
var (
|
||||||
|
netLog *netlogger.Logger
|
||||||
|
log *logger.Logger
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
metaPreambleKey = "copyright"
|
metaPreambleKey = "copyright"
|
||||||
|
@ -160,7 +166,20 @@ func handleFlags() config.Config {
|
||||||
cfg.LogLevel = defaultLogVerbosity
|
cfg.LogLevel = defaultLogVerbosity
|
||||||
}
|
}
|
||||||
|
|
||||||
log = logger.New(cfg.LogLevel, &smartlogger.New(*logPathPtr).LogRoller, true)
|
netLog = netlogger.New()
|
||||||
|
log = logger.New(
|
||||||
|
cfg.LogLevel,
|
||||||
|
io.MultiWriter(
|
||||||
|
&lumberjack.Logger{
|
||||||
|
Filename: filepath.Join(*logPathPtr, "netsender.log"),
|
||||||
|
MaxSize: 500, // MB
|
||||||
|
MaxBackups: 10,
|
||||||
|
MaxAge: 28, // days
|
||||||
|
},
|
||||||
|
netLog,
|
||||||
|
),
|
||||||
|
true,
|
||||||
|
)
|
||||||
|
|
||||||
cfg.Logger = log
|
cfg.Logger = log
|
||||||
|
|
||||||
|
@ -296,6 +315,11 @@ func run(cfg config.Config) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = netLog.Send(ns)
|
||||||
|
if err != nil {
|
||||||
|
log.Log(logger.Warning, pkg+"Logs could not be sent", "error", err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
// If var sum hasn't changed we continue.
|
// If var sum hasn't changed we continue.
|
||||||
var vars map[string]string
|
var vars map[string]string
|
||||||
newVs := ns.VarSum()
|
newVs := ns.VarSum()
|
||||||
|
|
|
@ -66,7 +66,7 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
||||||
buf := make([]byte, len(h264Prefix), bufSize)
|
buf := make([]byte, len(h264Prefix), bufSize)
|
||||||
copy(buf, h264Prefix[:])
|
copy(buf, h264Prefix[:])
|
||||||
writeOut := false
|
writeOut := false
|
||||||
outer:
|
|
||||||
for {
|
for {
|
||||||
var b byte
|
var b byte
|
||||||
var err error
|
var err error
|
||||||
|
@ -75,7 +75,10 @@ outer:
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
break
|
if len(buf) != 0 {
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return io.EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
for n := 1; b == 0x0 && n < 4; n++ {
|
for n := 1; b == 0x0 && n < 4; n++ {
|
||||||
|
@ -84,7 +87,7 @@ outer:
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
break outer
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
buf = append(buf, b)
|
buf = append(buf, b)
|
||||||
|
|
||||||
|
@ -109,7 +112,7 @@ outer:
|
||||||
if err != io.EOF {
|
if err != io.EOF {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
break outer
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
buf = append(buf, b)
|
buf = append(buf, b)
|
||||||
|
|
||||||
|
@ -127,10 +130,4 @@ outer:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(buf) == len(h264Prefix) {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
<-tick
|
|
||||||
_, err := dst.Write(buf)
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,10 +76,14 @@ func (l *Lexer) Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
||||||
n, err := src.Read(buf)
|
n, err := src.Read(buf)
|
||||||
switch err {
|
switch err {
|
||||||
case nil: // Do nothing.
|
case nil: // Do nothing.
|
||||||
case io.EOF:
|
|
||||||
return nil
|
|
||||||
default:
|
default:
|
||||||
return fmt.Errorf("source read error: %w\n", err)
|
if err == io.EOF {
|
||||||
|
if l.buf.Len() == 0 {
|
||||||
|
return io.EOF
|
||||||
|
}
|
||||||
|
return io.ErrUnexpectedEOF
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get payload from RTP packet.
|
// Get payload from RTP packet.
|
||||||
|
@ -181,7 +185,7 @@ func (l *Lexer) handleFragmentation(d []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// handlePACI will handl PACI packets
|
// handlePACI will handle PACI packets
|
||||||
//
|
//
|
||||||
// TODO: complete this
|
// TODO: complete this
|
||||||
func (l *Lexer) handlePACI(d []byte) {
|
func (l *Lexer) handlePACI(d []byte) {
|
||||||
|
|
|
@ -247,7 +247,9 @@ func TestLex(t *testing.T) {
|
||||||
r := &rtpReader{packets: test.packets}
|
r := &rtpReader{packets: test.packets}
|
||||||
d := &destination{}
|
d := &destination{}
|
||||||
err := NewLexer(test.donl).Lex(d, r, 0)
|
err := NewLexer(test.donl).Lex(d, r, 0)
|
||||||
if err != nil {
|
switch err {
|
||||||
|
case nil, io.EOF: // Do nothing
|
||||||
|
default:
|
||||||
t.Fatalf("error lexing: %v\n", err)
|
t.Fatalf("error lexing: %v\n", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,12 +60,9 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
||||||
buf := make([]byte, 2, 4<<10)
|
buf := make([]byte, 2, 4<<10)
|
||||||
n, err := r.Read(buf)
|
n, err := r.Read(buf)
|
||||||
if n < 2 {
|
if n < 2 {
|
||||||
return nil
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if !bytes.Equal(buf, []byte{0xff, 0xd8}) {
|
if !bytes.Equal(buf, []byte{0xff, 0xd8}) {
|
||||||
|
@ -76,7 +73,7 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
||||||
b, err := r.ReadByte()
|
b, err := r.ReadByte()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == io.EOF {
|
if err == io.EOF {
|
||||||
return nil
|
return io.ErrUnexpectedEOF
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,10 +32,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewMOGFilter returns a pointer to a new NoOp struct for testing purposes only.
|
// NewMOGFilter returns a pointer to a new NoOp struct for testing purposes only.
|
||||||
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool) *NoOp {
|
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *NoOp {
|
||||||
return &NoOp{dst: dst}
|
return &NoOp{dst: dst}
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool) *NoOp {
|
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *NoOp {
|
||||||
return &NoOp{dst: dst}
|
return &NoOp{dst: dst}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,23 +40,26 @@ import (
|
||||||
// KNNFilter is a filter that provides basic motion detection. KNN is short for
|
// KNNFilter is a filter that provides basic motion detection. KNN is short for
|
||||||
// K-Nearest Neighbours method.
|
// K-Nearest Neighbours method.
|
||||||
type KNNFilter struct {
|
type KNNFilter struct {
|
||||||
dst io.WriteCloser
|
dst io.WriteCloser // Destination to which motion containing frames go.
|
||||||
area float64
|
area float64 // The minimum area that a contour can be found in.
|
||||||
bs *gocv.BackgroundSubtractorKNN
|
bs *gocv.BackgroundSubtractorKNN // Uses the KNN algorithm to find the difference between the current and background frame.
|
||||||
knl gocv.Mat
|
knl gocv.Mat // Matrix that is used for calculations.
|
||||||
debug bool
|
debug bool // If true then debug windows with the bounding boxes and difference will be shown on the screen.
|
||||||
windows []*gocv.Window
|
windows []*gocv.Window // Holds debug windows.
|
||||||
|
hold [][]byte // Will hold all frames up to hf (so only every hf frame is motion detected).
|
||||||
|
hf int // The number of frames to be held.
|
||||||
|
hfCount int // Counter for the hold array.
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewKNNFilter returns a pointer to a new KNNFilter.
|
// NewKNNFilter returns a pointer to a new KNNFilter.
|
||||||
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool) *KNNFilter {
|
func NewKNNFilter(dst io.WriteCloser, area, threshold float64, history, kernelSize int, debug bool, hf int) *KNNFilter {
|
||||||
bs := gocv.NewBackgroundSubtractorKNNWithParams(history, threshold, false)
|
bs := gocv.NewBackgroundSubtractorKNNWithParams(history, threshold, false)
|
||||||
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize))
|
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(kernelSize, kernelSize))
|
||||||
var windows []*gocv.Window
|
var windows []*gocv.Window
|
||||||
if debug {
|
if debug {
|
||||||
windows = []*gocv.Window{gocv.NewWindow("KNN: Bounding boxes"), gocv.NewWindow("KNN: Motion")}
|
windows = []*gocv.Window{gocv.NewWindow("KNN: Bounding boxes"), gocv.NewWindow("KNN: Motion")}
|
||||||
}
|
}
|
||||||
return &KNNFilter{dst, area, &bs, k, debug, windows}
|
return &KNNFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements io.Closer.
|
// Implements io.Closer.
|
||||||
|
@ -75,6 +78,13 @@ func (m *KNNFilter) Close() error {
|
||||||
// Write applies the motion filter to the video stream. Only frames with motion
|
// Write applies the motion filter to the video stream. Only frames with motion
|
||||||
// are written to the destination encoder, frames without are discarded.
|
// are written to the destination encoder, frames without are discarded.
|
||||||
func (m *KNNFilter) Write(f []byte) (int, error) {
|
func (m *KNNFilter) Write(f []byte) (int, error) {
|
||||||
|
if m.hfCount < (m.hf - 1) {
|
||||||
|
m.hold[m.hfCount] = f
|
||||||
|
m.hfCount++
|
||||||
|
return len(f), nil
|
||||||
|
}
|
||||||
|
m.hfCount = 0
|
||||||
|
|
||||||
img, err := gocv.IMDecode(f, gocv.IMReadColor)
|
img, err := gocv.IMDecode(f, gocv.IMReadColor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("can't decode image: %w", err)
|
return 0, fmt.Errorf("can't decode image: %w", err)
|
||||||
|
@ -125,9 +135,16 @@ func (m *KNNFilter) Write(f []byte) (int, error) {
|
||||||
|
|
||||||
// Don't write to destination if there is no motion.
|
// Don't write to destination if there is no motion.
|
||||||
if len(contours) == 0 {
|
if len(contours) == 0 {
|
||||||
return -1, nil
|
return len(f), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to destination.
|
// Write to destination, past 4 frames then current frame.
|
||||||
|
for i, h := range m.hold {
|
||||||
|
_, err := m.dst.Write(h)
|
||||||
|
m.hold[i] = nil
|
||||||
|
if err != nil {
|
||||||
|
return len(f), fmt.Errorf("could not write previous frames: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return m.dst.Write(f)
|
return m.dst.Write(f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,23 +40,26 @@ import (
|
||||||
// MOGFilter is a filter that provides basic motion detection. MoG is short for
|
// MOGFilter is a filter that provides basic motion detection. MoG is short for
|
||||||
// Mixture of Gaussians method.
|
// Mixture of Gaussians method.
|
||||||
type MOGFilter struct {
|
type MOGFilter struct {
|
||||||
dst io.WriteCloser
|
dst io.WriteCloser // Destination to which motion containing frames go.
|
||||||
area float64
|
area float64 // The minimum area that a contour can be found in.
|
||||||
bs *gocv.BackgroundSubtractorMOG2
|
bs *gocv.BackgroundSubtractorMOG2 // Uses the MOG algorithm to find the difference between the current and background frame.
|
||||||
knl gocv.Mat
|
knl gocv.Mat // Matrix that is used for calculations.
|
||||||
debug bool
|
debug bool // If true then debug windows with the bounding boxes and difference will be shown on the screen.
|
||||||
windows []*gocv.Window
|
windows []*gocv.Window // Holds debug windows.
|
||||||
|
hold [][]byte // Will hold all frames up to hf (so only every hf frame is motion detected).
|
||||||
|
hf int // The number of frames to be held.
|
||||||
|
hfCount int // Counter for the hold array.
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewMOGFilter returns a pointer to a new MOGFilter struct.
|
// NewMOGFilter returns a pointer to a new MOGFilter struct.
|
||||||
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool) *MOGFilter {
|
func NewMOGFilter(dst io.WriteCloser, area, threshold float64, history int, debug bool, hf int) *MOGFilter {
|
||||||
bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false)
|
bs := gocv.NewBackgroundSubtractorMOG2WithParams(history, threshold, false)
|
||||||
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3))
|
k := gocv.GetStructuringElement(gocv.MorphRect, image.Pt(3, 3))
|
||||||
var windows []*gocv.Window
|
var windows []*gocv.Window
|
||||||
if debug {
|
if debug {
|
||||||
windows = []*gocv.Window{gocv.NewWindow("MOG: Bounding boxes"), gocv.NewWindow("MOG: Motion")}
|
windows = []*gocv.Window{gocv.NewWindow("MOG: Bounding boxes"), gocv.NewWindow("MOG: Motion")}
|
||||||
}
|
}
|
||||||
return &MOGFilter{dst, area, &bs, k, debug, windows}
|
return &MOGFilter{dst, area, &bs, k, debug, windows, make([][]byte, hf-1), hf, 0}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements io.Closer.
|
// Implements io.Closer.
|
||||||
|
@ -75,6 +78,13 @@ func (m *MOGFilter) Close() error {
|
||||||
// Write applies the motion filter to the video stream. Only frames with motion
|
// Write applies the motion filter to the video stream. Only frames with motion
|
||||||
// are written to the destination encoder, frames without are discarded.
|
// are written to the destination encoder, frames without are discarded.
|
||||||
func (m *MOGFilter) Write(f []byte) (int, error) {
|
func (m *MOGFilter) Write(f []byte) (int, error) {
|
||||||
|
if m.hfCount < (m.hf - 1) {
|
||||||
|
m.hold[m.hfCount] = f
|
||||||
|
m.hfCount++
|
||||||
|
return len(f), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
m.hfCount = 0
|
||||||
img, err := gocv.IMDecode(f, gocv.IMReadColor)
|
img, err := gocv.IMDecode(f, gocv.IMReadColor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("image can't be decoded: %w", err)
|
return 0, fmt.Errorf("image can't be decoded: %w", err)
|
||||||
|
@ -125,9 +135,16 @@ func (m *MOGFilter) Write(f []byte) (int, error) {
|
||||||
|
|
||||||
// Don't write to destination if there is no motion.
|
// Don't write to destination if there is no motion.
|
||||||
if len(contours) == 0 {
|
if len(contours) == 0 {
|
||||||
return 0, nil
|
return len(f), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write to destination.
|
// Write to destination, past 4 frames then current frame.
|
||||||
|
for i, h := range m.hold {
|
||||||
|
_, err := m.dst.Write(h)
|
||||||
|
m.hold[i] = nil
|
||||||
|
if err != nil {
|
||||||
|
return len(f), fmt.Errorf("could not write previous frames: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
return m.dst.Write(f)
|
return m.dst.Write(f)
|
||||||
}
|
}
|
||||||
|
|
3
go.mod
3
go.mod
|
@ -3,7 +3,7 @@ module bitbucket.org/ausocean/av
|
||||||
go 1.13
|
go 1.13
|
||||||
|
|
||||||
require (
|
require (
|
||||||
bitbucket.org/ausocean/iot v1.2.11
|
bitbucket.org/ausocean/iot v1.2.13
|
||||||
bitbucket.org/ausocean/utils v1.2.12
|
bitbucket.org/ausocean/utils v1.2.12
|
||||||
github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7
|
github.com/Comcast/gots v0.0.0-20190305015453-8d56e473f0f7
|
||||||
github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480
|
github.com/go-audio/audio v0.0.0-20181013203223-7b2a6ca21480
|
||||||
|
@ -12,4 +12,5 @@ require (
|
||||||
github.com/pkg/errors v0.8.1
|
github.com/pkg/errors v0.8.1
|
||||||
github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e
|
github.com/yobert/alsa v0.0.0-20180630182551-d38d89fa843e
|
||||||
gocv.io/x/gocv v0.21.0
|
gocv.io/x/gocv v0.21.0
|
||||||
|
gopkg.in/natefinch/lumberjack.v2 v2.0.0
|
||||||
)
|
)
|
||||||
|
|
4
go.sum
4
go.sum
|
@ -4,6 +4,10 @@ bitbucket.org/ausocean/iot v1.2.10 h1:TTu+ykH5gQA8wU/pN0aS55ySQ/XcGxV4s4LKx3Wye5
|
||||||
bitbucket.org/ausocean/iot v1.2.10/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
bitbucket.org/ausocean/iot v1.2.10/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
||||||
bitbucket.org/ausocean/iot v1.2.11 h1:MwYQK1F2ESA5jPVSCB0lBUN8HBiNDHGkh/OMGJKw8Oc=
|
bitbucket.org/ausocean/iot v1.2.11 h1:MwYQK1F2ESA5jPVSCB0lBUN8HBiNDHGkh/OMGJKw8Oc=
|
||||||
bitbucket.org/ausocean/iot v1.2.11/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
bitbucket.org/ausocean/iot v1.2.11/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
||||||
|
bitbucket.org/ausocean/iot v1.2.12 h1:Ixf0CTmWOMJVrJ6IYMEluTrCLlu9LM1eNSBZ+ZUnDmU=
|
||||||
|
bitbucket.org/ausocean/iot v1.2.12/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
||||||
|
bitbucket.org/ausocean/iot v1.2.13 h1:E9LcW3HYqRgJqxNhPJUCfVRvoV2IAU4B7JSDNxB/x2k=
|
||||||
|
bitbucket.org/ausocean/iot v1.2.13/go.mod h1:Q5FwaOKnCty3dVeVtki6DLwYa5vhNpOaeu1lwLyPCg8=
|
||||||
bitbucket.org/ausocean/utils v1.2.11 h1:zA0FOaPjN960ryp8PKCkV5y50uWBYrIxCVnXjwbvPqg=
|
bitbucket.org/ausocean/utils v1.2.11 h1:zA0FOaPjN960ryp8PKCkV5y50uWBYrIxCVnXjwbvPqg=
|
||||||
bitbucket.org/ausocean/utils v1.2.11/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8=
|
bitbucket.org/ausocean/utils v1.2.11/go.mod h1:uXzX9z3PLemyURTMWRhVI8uLhPX4uuvaaO85v2hcob8=
|
||||||
bitbucket.org/ausocean/utils v1.2.12 h1:VnskjWTDM475TnQRhBQE0cNp9D6Y6OELrd4UkD2VVIQ=
|
bitbucket.org/ausocean/utils v1.2.12 h1:VnskjWTDM475TnQRhBQE0cNp9D6Y6OELrd4UkD2VVIQ=
|
||||||
|
|
|
@ -85,6 +85,7 @@ const (
|
||||||
defaultClipDuration = 0
|
defaultClipDuration = 0
|
||||||
defaultAudioInputCodec = codecutil.ADPCM
|
defaultAudioInputCodec = codecutil.ADPCM
|
||||||
defaultPSITime = 2
|
defaultPSITime = 2
|
||||||
|
defaultMotionInterval = 5
|
||||||
|
|
||||||
// Ring buffer defaults.
|
// Ring buffer defaults.
|
||||||
defaultRBMaxElements = 10000
|
defaultRBMaxElements = 10000
|
||||||
|
@ -275,6 +276,7 @@ type Config struct {
|
||||||
HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input.
|
HorizontalFlip bool // HorizontalFlip flips video horizontally for Raspivid input.
|
||||||
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
VerticalFlip bool // VerticalFlip flips video vertically for Raspivid input.
|
||||||
Filters []int // Defines the methods of filtering to be used in between lexing and encoding.
|
Filters []int // Defines the methods of filtering to be used in between lexing and encoding.
|
||||||
|
MotionInterval int // Sets the number of frames that are held before the filter is used (on the nth frame)
|
||||||
PSITime int // Sets the time between a packet being sent.
|
PSITime int // Sets the time between a packet being sent.
|
||||||
|
|
||||||
// Ring buffer parameters.
|
// Ring buffer parameters.
|
||||||
|
@ -328,6 +330,7 @@ var TypeData = map[string]string{
|
||||||
"MOGHistory": "uint",
|
"MOGHistory": "uint",
|
||||||
"MOGMinArea": "float",
|
"MOGMinArea": "float",
|
||||||
"MOGThreshold": "float",
|
"MOGThreshold": "float",
|
||||||
|
"MotionInterval": "int",
|
||||||
"RBCapacity": "uint",
|
"RBCapacity": "uint",
|
||||||
"RBMaxElements": "uint",
|
"RBMaxElements": "uint",
|
||||||
"RBWriteTimeout": "uint",
|
"RBWriteTimeout": "uint",
|
||||||
|
@ -462,6 +465,10 @@ func (c *Config) Validate() error {
|
||||||
c.Logger.Log(logger.Info, pkg+"PSITime bad or unset, defaulting", "PSITime", defaultPSITime)
|
c.Logger.Log(logger.Info, pkg+"PSITime bad or unset, defaulting", "PSITime", defaultPSITime)
|
||||||
c.PSITime = defaultPSITime
|
c.PSITime = defaultPSITime
|
||||||
}
|
}
|
||||||
|
if c.MotionInterval <= 0 {
|
||||||
|
c.Logger.Log(logger.Info, pkg+"MotionInterval bad or unset, defaulting", "MotionInterval", defaultMotionInterval)
|
||||||
|
c.MotionInterval = defaultMotionInterval
|
||||||
|
}
|
||||||
|
|
||||||
if c.MinFPS <= 0 {
|
if c.MinFPS <= 0 {
|
||||||
c.Logger.Log(logger.Info, pkg+"MinFPS bad or unset, defaulting", "MinFPS", defaultMinFPS)
|
c.Logger.Log(logger.Info, pkg+"MinFPS bad or unset, defaulting", "MinFPS", defaultMinFPS)
|
||||||
|
|
|
@ -337,11 +337,11 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
|
||||||
case config.FilterNoOp:
|
case config.FilterNoOp:
|
||||||
r.filters[i] = filter.NewNoOp(dst)
|
r.filters[i] = filter.NewNoOp(dst)
|
||||||
case config.FilterMOG:
|
case config.FilterMOG:
|
||||||
r.filters[i] = filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows)
|
r.filters[i] = filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval)
|
||||||
case config.FilterVariableFPS:
|
case config.FilterVariableFPS:
|
||||||
r.filters[i] = filter.NewVariableFPSFilter(dst, r.cfg.MinFPS, filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows))
|
r.filters[i] = filter.NewVariableFPSFilter(dst, r.cfg.MinFPS, filter.NewMOGFilter(dst, r.cfg.MOGMinArea, r.cfg.MOGThreshold, int(r.cfg.MOGHistory), r.cfg.ShowWindows, r.cfg.MotionInterval))
|
||||||
case config.FilterKNN:
|
case config.FilterKNN:
|
||||||
r.filters[i] = filter.NewKNNFilter(dst, r.cfg.KNNMinArea, r.cfg.KNNThreshold, int(r.cfg.KNNHistory), int(r.cfg.KNNKernel), r.cfg.ShowWindows)
|
r.filters[i] = filter.NewKNNFilter(dst, r.cfg.KNNMinArea, r.cfg.KNNThreshold, int(r.cfg.KNNHistory), int(r.cfg.KNNKernel), r.cfg.ShowWindows, r.cfg.MotionInterval)
|
||||||
default:
|
default:
|
||||||
panic("Undefined Filter")
|
panic("Undefined Filter")
|
||||||
}
|
}
|
||||||
|
@ -671,6 +671,13 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
}
|
}
|
||||||
r.cfg.Filters[i] = v
|
r.cfg.Filters[i] = v
|
||||||
}
|
}
|
||||||
|
case "MotionInterval":
|
||||||
|
v, err := strconv.Atoi(value)
|
||||||
|
if err != nil || v < 0 {
|
||||||
|
r.cfg.Logger.Log(logger.Warning, pkg+"invalid MotionInterval var", "value", value)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
r.cfg.MotionInterval = v
|
||||||
case "PSITime":
|
case "PSITime":
|
||||||
v, err := strconv.Atoi(value)
|
v, err := strconv.Atoi(value)
|
||||||
if err != nil || v < 0 {
|
if err != nil || v < 0 {
|
||||||
|
@ -847,7 +854,13 @@ func (r *Revid) Update(vars map[string]string) error {
|
||||||
// processFrom is run as a routine to read from a input data source, lex and
|
// processFrom is run as a routine to read from a input data source, lex and
|
||||||
// then send individual access units to revid's encoders.
|
// then send individual access units to revid's encoders.
|
||||||
func (r *Revid) processFrom(read io.Reader, delay time.Duration) {
|
func (r *Revid) processFrom(read io.Reader, delay time.Duration) {
|
||||||
r.err <- r.lexTo(r.filters[0], read, delay)
|
err := r.lexTo(r.filters[0], read, delay)
|
||||||
r.cfg.Logger.Log(logger.Info, pkg+"finished lexing")
|
r.cfg.Logger.Log(logger.Debug, pkg+"finished lexing")
|
||||||
|
switch err {
|
||||||
|
case nil: // Do nothing.
|
||||||
|
case io.EOF: // TODO: handle this depending on loop mode.
|
||||||
|
default:
|
||||||
|
r.err <- err
|
||||||
|
}
|
||||||
r.wg.Done()
|
r.wg.Done()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue