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)
|
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:
|
||||||
|
|
|
@ -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)
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,10 +164,11 @@ const (
|
||||||
defaultExposure = "auto"
|
defaultExposure = "auto"
|
||||||
defaultAutoWhiteBalance = "auto"
|
defaultAutoWhiteBalance = "auto"
|
||||||
|
|
||||||
defaultSampleRate = 48000
|
defaultAudioInputCodec = ADPCM
|
||||||
defaultBitDepth = 16
|
defaultSampleRate = 48000
|
||||||
defaultChannels = 1
|
defaultBitDepth = 16
|
||||||
defaultRecPeriod = 1
|
defaultChannels = 1
|
||||||
|
defaultRecPeriod = 1
|
||||||
)
|
)
|
||||||
|
|
||||||
// Validate checks for any errors in the config fields and defaults settings
|
// Validate checks for any errors in the config fields and defaults settings
|
||||||
|
@ -211,10 +212,16 @@ func (c *Config) Validate(r *Revid) error {
|
||||||
}
|
}
|
||||||
case PCM, ADPCM:
|
case PCM, ADPCM:
|
||||||
case NothingDefined:
|
case NothingDefined:
|
||||||
c.Logger.Log(logger.Info, pkg+"no input codec defined, defaulting", "inputCodec", defaultInputCodec)
|
switch c.Input {
|
||||||
c.InputCodec = defaultInputCodec
|
case Audio:
|
||||||
c.Logger.Log(logger.Info, pkg+"defaulting quantization", "quantization", defaultQuantization)
|
c.Logger.Log(logger.Info, pkg+"input is audio but no codec defined, defaulting", "inputCodec", defaultAudioInputCodec)
|
||||||
c.Quantization = defaultQuantization
|
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:
|
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
|
||||||
|
|
Loading…
Reference in New Issue