revid: added audio input start test

test written and passing for revid with AudioInput starting
unset audio parameters in config now default.
This commit is contained in:
Trek H 2019-05-09 12:11:02 +09:30
parent 28eba2ad60
commit 6320011190
3 changed files with 59 additions and 33 deletions

View File

@ -197,16 +197,16 @@ func (a *AudioInput) open() error {
log.Log(logger.Debug, "Sample rate set", "rate", defaultSampleRate) log.Log(logger.Debug, "Sample rate set", "rate", defaultSampleRate)
} }
var fmt alsa.FormatType var aFmt alsa.FormatType
switch a.BitDepth { switch a.BitDepth {
case 16: case 16:
fmt = alsa.S16_LE aFmt = alsa.S16_LE
case 32: case 32:
fmt = alsa.S32_LE aFmt = alsa.S32_LE
default: default:
return errors.New("Unsupported sample bits") return fmt.Errorf("Unsupported sample bits %v\n", a.BitDepth)
} }
_, err = a.dev.NegotiateFormat(fmt) _, err = a.dev.NegotiateFormat(aFmt)
if err != nil { if err != nil {
return err return err
} }
@ -274,7 +274,6 @@ func (a *AudioInput) input() {
// Read reads a full PCM chunk from the ringbuffer, returning the number of bytes read upon success. // Read reads a full PCM chunk from the ringbuffer, returning the number of bytes read upon success.
// Any errors returned are unexpected and should be considered fatal. // Any errors returned are unexpected and should be considered fatal.
func (a *AudioInput) Read(p []byte) (n int, err error) { func (a *AudioInput) Read(p []byte) (n int, err error) {
fmt.Println("Performing AudioInput read...")
chunk, err := a.rb.Next(rbNextTimeout) chunk, err := a.rb.Next(rbNextTimeout)
switch err { switch err {
case nil: case nil:

View File

@ -2,28 +2,28 @@ package revid
import ( import (
"testing" "testing"
"bitbucket.org/ausocean/iot/pi/netsender"
) )
func TestAudioInput(t *testing.T) { func TestAudioInputStart(t *testing.T) {
var logger testLogger
ns, err := netsender.New(&logger, nil, nil, nil)
if err != nil {
t.Errorf("netsender.New failed with error %v", err)
}
// var logger testLogger var c Config
// ns, err := netsender.New(&logger, nil, nil, nil) c.Logger = &logger
// if err != nil { c.Input = Audio
// t.Errorf("netsender.New failed with error %v", err)
// }
// var c Config rv, err := New(c, ns)
// c.Logger = &logger if err != nil {
// c.Input = Audio t.Errorf("revid.New failed with error %v", err)
// c.Outputs = make([]uint8, 1) }
// rv, err := New(c, ns) err = rv.Start()
// if err != nil { if err != nil {
// t.Errorf("revid.New failed with error %v", err) t.Errorf("revid.Start failed with error %v", err)
// } }
// err = rv.Start()
// if err != nil {
// t.Errorf("revid.Start failed with error %v", err)
// }
} }

View File

@ -164,6 +164,7 @@ const (
defaultExposure = "auto" defaultExposure = "auto"
defaultAutoWhiteBalance = "auto" defaultAutoWhiteBalance = "auto"
defaultAudioInputCodec = ADPCM
defaultSampleRate = 48000 defaultSampleRate = 48000
defaultBitDepth = 16 defaultBitDepth = 16
defaultChannels = 1 defaultChannels = 1
@ -211,10 +212,16 @@ func (c *Config) Validate(r *Revid) error {
} }
case PCM, ADPCM: case PCM, ADPCM:
case NothingDefined: case NothingDefined:
switch c.Input {
case Audio:
c.Logger.Log(logger.Info, pkg+"input is audio but no codec defined, defaulting", "inputCodec", defaultAudioInputCodec)
c.InputCodec = defaultAudioInputCodec
default:
c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec) c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec)
c.InputCodec = defaultInputCodec c.InputCodec = defaultInputCodec
c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization) c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization)
c.Quantization = defaultQuantization c.Quantization = defaultQuantization
}
default: default:
return errors.New("bad input codec defined in config") return errors.New("bad input codec defined in config")
} }
@ -285,6 +292,26 @@ func (c *Config) Validate(r *Revid) error {
c.SampleRate = defaultSampleRate c.SampleRate = defaultSampleRate
} }
if c.Channels == 0 {
c.Logger.Log(logger.Info, pkg+"no number of channels defined, defaulting", "Channels", defaultChannels)
c.Channels = defaultChannels
}
if c.BitDepth == 0 {
c.Logger.Log(logger.Info, pkg+"no bit depth defined, defaulting", "BitDepth", defaultBitDepth)
c.BitDepth = defaultBitDepth
}
if c.RecPeriod == 0 {
c.Logger.Log(logger.Info, pkg+"no record period defined, defaulting", "recPeriod", defaultRecPeriod)
c.RecPeriod = defaultRecPeriod
}
if c.WriteRate == 0 {
c.Logger.Log(logger.Info, pkg+"no write rate defined, defaulting", "writeRate", defaultWriteRate)
c.WriteRate = defaultWriteRate
}
if c.Bitrate == 0 { if c.Bitrate == 0 {
c.Logger.Log(logger.Info, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate) c.Logger.Log(logger.Info, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate)
c.Bitrate = defaultBitrate c.Bitrate = defaultBitrate