mirror of https://bitbucket.org/ausocean/av.git
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:
parent
28eba2ad60
commit
6320011190
|
@ -197,16 +197,16 @@ func (a *AudioInput) open() error {
|
|||
log.Log(logger.Debug, "Sample rate set", "rate", defaultSampleRate)
|
||||
}
|
||||
|
||||
var fmt alsa.FormatType
|
||||
var aFmt alsa.FormatType
|
||||
switch a.BitDepth {
|
||||
case 16:
|
||||
fmt = alsa.S16_LE
|
||||
aFmt = alsa.S16_LE
|
||||
case 32:
|
||||
fmt = alsa.S32_LE
|
||||
aFmt = alsa.S32_LE
|
||||
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 {
|
||||
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.
|
||||
// Any errors returned are unexpected and should be considered fatal.
|
||||
func (a *AudioInput) Read(p []byte) (n int, err error) {
|
||||
fmt.Println("Performing AudioInput read...")
|
||||
chunk, err := a.rb.Next(rbNextTimeout)
|
||||
switch err {
|
||||
case nil:
|
||||
|
|
|
@ -2,28 +2,28 @@ package revid
|
|||
|
||||
import (
|
||||
"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
|
||||
// ns, err := netsender.New(&logger, nil, nil, nil)
|
||||
// if err != nil {
|
||||
// t.Errorf("netsender.New failed with error %v", err)
|
||||
// }
|
||||
var c Config
|
||||
c.Logger = &logger
|
||||
c.Input = Audio
|
||||
|
||||
// var c Config
|
||||
// c.Logger = &logger
|
||||
// c.Input = Audio
|
||||
// c.Outputs = make([]uint8, 1)
|
||||
rv, err := New(c, ns)
|
||||
if err != nil {
|
||||
t.Errorf("revid.New failed with error %v", err)
|
||||
}
|
||||
|
||||
// rv, err := New(c, ns)
|
||||
// if err != nil {
|
||||
// t.Errorf("revid.New failed with error %v", err)
|
||||
// }
|
||||
|
||||
// err = rv.Start()
|
||||
// if err != nil {
|
||||
// t.Errorf("revid.Start failed with error %v", err)
|
||||
// }
|
||||
err = rv.Start()
|
||||
if err != nil {
|
||||
t.Errorf("revid.Start failed with error %v", err)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -164,6 +164,7 @@ const (
|
|||
defaultExposure = "auto"
|
||||
defaultAutoWhiteBalance = "auto"
|
||||
|
||||
defaultAudioInputCodec = ADPCM
|
||||
defaultSampleRate = 48000
|
||||
defaultBitDepth = 16
|
||||
defaultChannels = 1
|
||||
|
@ -211,10 +212,16 @@ func (c *Config) Validate(r *Revid) error {
|
|||
}
|
||||
case PCM, ADPCM:
|
||||
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.InputCodec = defaultInputCodec
|
||||
c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization)
|
||||
c.Quantization = defaultQuantization
|
||||
}
|
||||
default:
|
||||
return errors.New("bad input codec defined in config")
|
||||
}
|
||||
|
@ -285,6 +292,26 @@ func (c *Config) Validate(r *Revid) error {
|
|||
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 {
|
||||
c.Logger.Log(logger.Info, pkg+"no bitrate defined, defaulting", "bitrate", defaultBitrate)
|
||||
c.Bitrate = defaultBitrate
|
||||
|
|
Loading…
Reference in New Issue