diff --git a/device/alsa/alsa.go b/device/alsa/alsa.go index 970a325f..0ebfa931 100644 --- a/device/alsa/alsa.go +++ b/device/alsa/alsa.go @@ -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) } diff --git a/device/alsa/alsa_test.go b/device/alsa/alsa_test.go index aeeb6ac9..918a022a 100644 --- a/device/alsa/alsa_test.go +++ b/device/alsa/alsa_test.go @@ -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, diff --git a/revid/audio_linux.go b/revid/audio_linux.go index 4c128922..d3d08a58 100644 --- a/revid/audio_linux.go +++ b/revid/audio_linux.go @@ -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) } diff --git a/revid/revid.go b/revid/revid.go index 383e3253..41b83602 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -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")