mirror of https://bitbucket.org/ausocean/av.git
Merge branch 'master' into audio-order
This commit is contained in:
commit
53a55cc477
|
@ -49,7 +49,6 @@ const (
|
|||
rbTimeout = 100 * time.Millisecond
|
||||
rbNextTimeout = 2000 * time.Millisecond
|
||||
rbLen = 200
|
||||
defaultSampleRate = 48000
|
||||
)
|
||||
|
||||
// "running" means the input goroutine is reading from the ALSA device and writing to the ringbuffer.
|
||||
|
@ -61,6 +60,23 @@ const (
|
|||
stopped
|
||||
)
|
||||
|
||||
const (
|
||||
defaultSampleRate = 48000
|
||||
defaultBitDepth = 16
|
||||
defaultChannels = 1
|
||||
defaultRecPeriod = 1.0
|
||||
defaultCodec = codecutil.PCM
|
||||
)
|
||||
|
||||
// Configuration field errors.
|
||||
var (
|
||||
errInvalidSampleRate = errors.New("invalid sample rate, defaulting")
|
||||
errInvalidChannels = errors.New("invalid number of channels, defaulting")
|
||||
errInvalidBitDepth = errors.New("invalid bitdepth, defaulting")
|
||||
errInvalidRecPeriod = errors.New("invalid record period, defaulting")
|
||||
errInvalidCodec = errors.New("invalid audio codec, defaulting")
|
||||
)
|
||||
|
||||
// An ALSA device holds everything we need to know about the audio input stream and implements io.Reader and device.AVDevice.
|
||||
type ALSA struct {
|
||||
l Logger // Logger for device's routines to log to.
|
||||
|
@ -107,19 +123,24 @@ func (d *ALSA) Name() string {
|
|||
func (d *ALSA) Set(c config.Config) error {
|
||||
var errs device.MultiError
|
||||
if c.SampleRate <= 0 {
|
||||
errs = append(errs, fmt.Errorf("invalid sample rate: %v", c.SampleRate))
|
||||
errs = append(errs, errInvalidSampleRate)
|
||||
c.SampleRate = defaultSampleRate
|
||||
}
|
||||
if c.Channels <= 0 {
|
||||
errs = append(errs, fmt.Errorf("invalid number of channels: %v", c.Channels))
|
||||
errs = append(errs, errInvalidChannels)
|
||||
c.Channels = defaultChannels
|
||||
}
|
||||
if c.BitDepth <= 0 {
|
||||
errs = append(errs, fmt.Errorf("invalid bitdepth: %v", c.BitDepth))
|
||||
errs = append(errs, errInvalidBitDepth)
|
||||
c.BitDepth = defaultBitDepth
|
||||
}
|
||||
if c.RecPeriod <= 0 {
|
||||
errs = append(errs, fmt.Errorf("invalid recording period: %v", c.RecPeriod))
|
||||
errs = append(errs, errInvalidRecPeriod)
|
||||
c.RecPeriod = defaultRecPeriod
|
||||
}
|
||||
if !codecutil.IsValid(c.InputCodec) {
|
||||
errs = append(errs, errors.New("invalid codec"))
|
||||
if c.InputCodec != codecutil.ADPCM && c.InputCodec != codecutil.PCM {
|
||||
errs = append(errs, errInvalidCodec)
|
||||
c.InputCodec = defaultCodec
|
||||
}
|
||||
d.Config = Config{
|
||||
SampleRate: c.SampleRate,
|
||||
|
|
|
@ -50,7 +50,6 @@ const (
|
|||
InputAudio
|
||||
|
||||
// Outputs.
|
||||
OutputAudio
|
||||
OutputRTMP
|
||||
OutputRTP
|
||||
OutputHTTP
|
||||
|
|
|
@ -51,7 +51,6 @@ const (
|
|||
defaultFrameRate = 25
|
||||
defaultWriteRate = 25
|
||||
defaultClipDuration = 0
|
||||
defaultAudioInputCodec = codecutil.ADPCM
|
||||
defaultPSITime = 2
|
||||
defaultFileFPS = 0
|
||||
|
||||
|
@ -138,6 +137,11 @@ var Variables = []struct {
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Channels",
|
||||
Type_: "uint",
|
||||
Update: func(c *Config, v string) { c.Channels = parseUint("Channels", v, c) },
|
||||
},
|
||||
{
|
||||
Name: "Exposure",
|
||||
Type_: "enum:auto,night,nightpreview,backlight,spotlight,sports,snow,beach,verylong,fixedfps,antishake,fireworks",
|
||||
|
@ -242,16 +246,10 @@ var Variables = []struct {
|
|||
Validate: func(c *Config) {
|
||||
switch c.InputCodec {
|
||||
case codecutil.H264, codecutil.MJPEG, codecutil.PCM, codecutil.ADPCM:
|
||||
default:
|
||||
switch c.Input {
|
||||
case OutputAudio:
|
||||
c.LogInvalidField("InputCodec", defaultAudioInputCodec)
|
||||
c.InputCodec = defaultAudioInputCodec
|
||||
default:
|
||||
c.LogInvalidField("InputCodec", defaultInputCodec)
|
||||
c.InputCodec = defaultInputCodec
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
|
@ -449,6 +447,17 @@ var Variables = []struct {
|
|||
c.RBWriteTimeout = lessThanOrEqual("RBWriteTimeout", c.RBWriteTimeout, 0, c, defaultRBWriteTimeout)
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "RecPeriod",
|
||||
Type_: "float",
|
||||
Update: func(c *Config, v string) {
|
||||
_v, err := strconv.ParseFloat(v, 64)
|
||||
if err != nil {
|
||||
c.Logger.Log(logger.Warning, fmt.Sprintf("invalid %s param", "RecPeriod"), "value", v)
|
||||
}
|
||||
c.RecPeriod = _v
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "Rotation",
|
||||
Type_: "uint",
|
||||
|
@ -470,6 +479,11 @@ var Variables = []struct {
|
|||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
Name: "SampleRate",
|
||||
Type_: "uint",
|
||||
Update: func(c *Config, v string) { c.SampleRate = parseUint("SampleRate", v, c) },
|
||||
},
|
||||
{
|
||||
Name: "Saturation",
|
||||
Type_: "int",
|
||||
|
|
Loading…
Reference in New Issue