mirror of https://bitbucket.org/ausocean/av.git
Improving error checking further
This commit is contained in:
parent
535d898a3c
commit
a07953042c
|
@ -32,6 +32,7 @@ package revid
|
|||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
|
@ -41,7 +42,6 @@ import (
|
|||
"os/exec"
|
||||
"strconv"
|
||||
"time"
|
||||
"errors"
|
||||
|
||||
//"bitbucket.org/ausocean/av/h264"
|
||||
//"bitbucket.org/ausocean/av/tsgenerator"
|
||||
|
@ -50,8 +50,8 @@ import (
|
|||
|
||||
//"bitbucket.org/ausocean/av/ringbuffer"
|
||||
//"bitbucket.org/ausocean/utils/smartLogger"
|
||||
"../ringbuffer"
|
||||
"../../utils/smartLogger"
|
||||
"../ringbuffer"
|
||||
)
|
||||
|
||||
// Misc constants
|
||||
|
@ -100,15 +100,16 @@ type Config struct {
|
|||
|
||||
// Enums for config struct
|
||||
const (
|
||||
raspivid = 1
|
||||
rtp = 2
|
||||
h264Codec = 3
|
||||
file = 4
|
||||
httpOut = 5
|
||||
h264 = 6
|
||||
mjpeg = 7
|
||||
none = 8
|
||||
mpegts = 9
|
||||
NothingDefined = 0
|
||||
Raspivid = 1
|
||||
Rtp = 2
|
||||
H264Codec = 3
|
||||
File = 4
|
||||
HttpOut = 5
|
||||
H264 = 6
|
||||
Mjpeg = 7
|
||||
None = 8
|
||||
Mpegts = 9
|
||||
)
|
||||
|
||||
// Default config settings
|
||||
|
@ -130,7 +131,6 @@ type RevidInst interface {
|
|||
IsRunning() bool
|
||||
}
|
||||
|
||||
|
||||
// The revidInst struct provides fields to describe the state of a RevidInst.
|
||||
type revidInst struct {
|
||||
ffmpegPath string
|
||||
|
@ -198,50 +198,67 @@ func (r *revidInst) GetConfigRef() *Config {
|
|||
// ChangeState swaps the current config of a revidInst with the passed
|
||||
// configuration; checking validity and returning errors if not valid.
|
||||
func (r *revidInst) ChangeState(config Config) error {
|
||||
r.config.Logger = config.Logger
|
||||
switch config.Input {
|
||||
case rtp:
|
||||
case raspivid:
|
||||
case file:
|
||||
case Rtp:
|
||||
case Raspivid:
|
||||
case File:
|
||||
case NothingDefined:
|
||||
r.Log(Warning, "No input type defined, defaulting to raspivid!")
|
||||
config.Input = Raspivid
|
||||
default:
|
||||
return errors.New("Bad input type defined in config!")
|
||||
}
|
||||
|
||||
switch config.InputCodec {
|
||||
case h264:
|
||||
case mjpeg:
|
||||
case H264:
|
||||
case Mjpeg:
|
||||
case NothingDefined:
|
||||
r.Log(Warning,"No input codec defined, defaulting to h264!")
|
||||
config.InputCodec = H264
|
||||
default:
|
||||
return errors.New("Bad input format defined in config!")
|
||||
return errors.New("Bad input codec defined in config!")
|
||||
}
|
||||
|
||||
switch config.Output {
|
||||
case httpOut:
|
||||
case file:
|
||||
case HttpOut:
|
||||
case File:
|
||||
case NothingDefine:
|
||||
r.Log(Warning, "No output defined, defaulting to httpOut!")
|
||||
config.Output = HttpOut
|
||||
default:
|
||||
return errors.New("Bad output type defined in config!")
|
||||
}
|
||||
|
||||
if integer, err := strconv.Atoi(config.Width); integer < 0 || err != nil {
|
||||
return errors.New("Bad width defined in config!")
|
||||
}
|
||||
if integer, _ := strconv.Atoi(config.Width); integer == 0 {
|
||||
r.Log(Warning, "No width defined, defaulting to 1280!")
|
||||
config.Width = defaultWidth
|
||||
}
|
||||
if integer, err := strconv.Atoi(config.Height); integer < 0 || err != nil {
|
||||
return errors.New("Bad height defined in config!")
|
||||
}
|
||||
if integer, _ := strconv.Atoi(config.Height); integer == 0 {
|
||||
r.Log(Warning, "No height defined, defaulting to 720!")
|
||||
config.Height = defaultHeight
|
||||
}
|
||||
if integer, err := strconv.Atoi(config.FrameRate); integer < 0 || err != nil {
|
||||
return errors.New("Bad FrameRate defined in config!")
|
||||
}
|
||||
if integer, _ := strconv.Atoi(config.FrameRate); integer == 0 {
|
||||
r.Log(Warning, "No FrameRate defined, defaulting to 25!")
|
||||
config.FrameRate = defaultFrameRate
|
||||
}
|
||||
if integer, err := strconv.Atoi(config.Timeout); integer < 0 || err != nil {
|
||||
return errors.New("Bad timeout define in config!")
|
||||
return errors.New("Bad timeout defined in config!")
|
||||
}
|
||||
if integer, err := strconv.Atoi(config.IntraRefreshPeriod); integer < 0 || err != nil {
|
||||
return errors.New("Bad intra refresh period defined in config!")
|
||||
}
|
||||
if integer, _ := strconv.Atoi(config.IntraRefreshPeriod); integer == 0 {
|
||||
r.Log(Warning, "No intra refresh period defined, defaulting to 100!")
|
||||
config.IntraRefreshPeriod = defaultIntraRefreshPeriod
|
||||
}
|
||||
if integer, err := strconv.Atoi(config.Quantization); integer <= 0 || integer > 51 || err != nil {
|
||||
|
|
|
@ -33,11 +33,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
* Testing with file input
|
||||
*
|
||||
*/
|
||||
/*
|
||||
// Test revidInst with a file input
|
||||
func TestFileInput(t *testing.T){
|
||||
config := Config{
|
||||
Input: file,
|
||||
|
@ -53,13 +49,9 @@ func TestFileInput(t *testing.T){
|
|||
time.Sleep(100*time.Second)
|
||||
revidInst.Stop()
|
||||
}
|
||||
* */
|
||||
|
||||
|
||||
/*
|
||||
Testing use with raspivid
|
||||
*/
|
||||
func TestRaspividInput(t *testing.T){
|
||||
// Test revidInst with a Raspivid h264 input
|
||||
func TestRaspividH264Input(t *testing.T){
|
||||
config := Config{
|
||||
Input: Raspivid,
|
||||
Output: File,
|
||||
|
@ -78,6 +70,24 @@ func TestRaspividInput(t *testing.T){
|
|||
revidInst.Stop()
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Test revidInst with a raspivid mjpeg input
|
||||
func TestRaspividMJPEGInput(t *testing.T){
|
||||
config := Config{
|
||||
Input: Raspivid,
|
||||
InputCodec: mjpeg,
|
||||
Output: File,
|
||||
OutputFileName: "output/TestRaspividMjpegOutput.mjpeg",
|
||||
Width: "1280",
|
||||
Height: "720",
|
||||
Bitrate: "0",
|
||||
Quantization: "35",
|
||||
FrameRate: "25",
|
||||
}
|
||||
revidInst, err := NewRevidInstance(config)
|
||||
if err != nil {
|
||||
t.Errorf("Should not of have got an error!")
|
||||
}
|
||||
revidInst.Start()
|
||||
time.Sleep(100*time.Second)
|
||||
revidInst.Stop()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue