Merge branch 'master' into audio-fixes

This commit is contained in:
Trek H 2020-08-13 16:26:25 +09:30
commit 42bf1a379a
4 changed files with 16 additions and 12 deletions

View File

@ -116,11 +116,11 @@ func (d *ALSA) Name() string {
return "ALSA"
}
// Set will take a Config struct, check the validity of the relevant fields
// and then performs any configuration necessary. If fields are not valid,
// Setup will take a Config struct, check the validity of the relevant fields
// and then perform any configuration necessary. If fields are not valid,
// an error is added to the multiError and a default value is used.
// It then initialises the ALSA device which can then be started, read from, and stopped.
func (d *ALSA) Set(c config.Config) error {
func (d *ALSA) Setup(c config.Config) error {
var errs device.MultiError
if c.SampleRate <= 0 {
errs = append(errs, errInvalidSampleRate)
@ -185,6 +185,14 @@ func (d *ALSA) Set(c config.Config) error {
return nil
}
// Set exists to satisfy the implementation of the Device interface that revid uses.
// Everything that would usually be in Set is in the Setup function.
// This is because an ALSA device is different to other devices in that it
// outputs binary non-packetised data and it requires a different configuration procedure.
func (d *ALSA) Set(c config.Config) error {
return nil
}
// Start will start recording audio and writing to the ringbuffer.
// Once an ALSA device has been stopped it cannot be started again. This is likely to change in future.
func (d *ALSA) Start() error {
@ -458,6 +466,8 @@ func (d *ALSA) formatBuffer() pcm.Buffer {
return formatted
}
// DataSize returns the size in bytes of the data ALSA device d will
// output in the duration of a single recording period.
func (d *ALSA) DataSize() int {
return pcm.DataSize(d.SampleRate, d.Channels, d.BitDepth, d.RecPeriod, d.Codec)
}

View File

@ -53,7 +53,7 @@ func TestDevice(t *testing.T) {
// Create a new ALSA device, start, read/lex, and then stop it.
l := logger.New(logger.Debug, os.Stderr, true)
ai := New(l)
err := ai.Set(c)
err := ai.Setup(c)
// If there was an error opening the device, skip this test.
if _, ok := err.(OpenError); ok {
t.Skip(err)
@ -119,7 +119,7 @@ func TestIsRunning(t *testing.T) {
l := logger.New(logger.Debug, &bytes.Buffer{}, true) // Discard logs.
d := New(l)
err := d.Set(config.Config{
err := d.Setup(config.Config{
SampleRate: sampleRate,
Channels: channels,
BitDepth: bitDepth,

View File

@ -41,7 +41,7 @@ func (r *Revid) setupAudio() error {
// Configure ALSA device.
r.cfg.Logger.Log(logger.Debug, "configuring input device")
err := r.input.Set(r.cfg)
err := d.Setup(r.cfg)
if err != nil {
r.cfg.Logger.Log(logger.Warning, "errors from configuring input device", "errors", err)
}

View File

@ -393,12 +393,6 @@ func (r *Revid) setupPipeline(mtsEnc func(dst io.WriteCloser, rate float64) (io.
}
}
// input.Set does not need to be called for InputAudio since it is called
// in setupAudio above, so we can return here.
if r.cfg.Input == config.InputAudio {
return nil
}
// Configure the input device. We know that defaults are set, so no need to
// return error, but we should log.
r.cfg.Logger.Log(logger.Debug, "configuring input device")