Report OpenAL device names in startup errors
This commit is contained in:
committed by
Brandon McGinty
parent
3448ed5802
commit
0712e3150c
@@ -17,6 +17,21 @@ import (
|
|||||||
"git.stormux.org/storm/barnard/noise"
|
"git.stormux.org/storm/barnard/noise"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func deviceName(name string) string {
|
||||||
|
if name == "" {
|
||||||
|
return "default"
|
||||||
|
}
|
||||||
|
return name
|
||||||
|
}
|
||||||
|
|
||||||
|
func openInputDeviceError(name string, format openal.Format) error {
|
||||||
|
return fmt.Errorf("%w: could not open capture device %q (format=%v, rate=%d)", ErrInputDevice, deviceName(name), format, gumble.AudioSampleRate)
|
||||||
|
}
|
||||||
|
|
||||||
|
func openOutputDeviceError(name string) error {
|
||||||
|
return fmt.Errorf("%w: could not open playback device %q", ErrOutputDevice, deviceName(name))
|
||||||
|
}
|
||||||
|
|
||||||
// NoiseProcessor interface for noise suppression
|
// NoiseProcessor interface for noise suppression
|
||||||
type NoiseProcessor interface {
|
type NoiseProcessor interface {
|
||||||
ProcessSamples(samples []int16)
|
ProcessSamples(samples []int16)
|
||||||
@@ -109,11 +124,11 @@ func New(client *gumble.Client, inputDevice *string, outputDevice *string, test
|
|||||||
}
|
}
|
||||||
if idev == nil {
|
if idev == nil {
|
||||||
log.Error("OpenAL capture: failed to open device %q", devName)
|
log.Error("OpenAL capture: failed to open device %q", devName)
|
||||||
return nil, ErrInputDevice
|
return nil, openInputDeviceError(devName, inputFormat)
|
||||||
}
|
}
|
||||||
if err := idev.Err(); err != nil {
|
if err := idev.Err(); err != nil {
|
||||||
idev.CaptureCloseDevice()
|
idev.CaptureCloseDevice()
|
||||||
return nil, fmt.Errorf("%w: %v", ErrInputDevice, err)
|
return nil, fmt.Errorf("%w: capture device %q: %v", ErrInputDevice, deviceName(devName), err)
|
||||||
}
|
}
|
||||||
log.Info("OpenAL capture: opened device %q format=%v channels=%d", devName, inputFormat, sourceChannels)
|
log.Info("OpenAL capture: opened device %q format=%v channels=%d", devName, inputFormat, sourceChannels)
|
||||||
|
|
||||||
@@ -124,12 +139,12 @@ func New(client *gumble.Client, inputDevice *string, outputDevice *string, test
|
|||||||
odev := openal.OpenDevice(outName)
|
odev := openal.OpenDevice(outName)
|
||||||
if odev == nil {
|
if odev == nil {
|
||||||
idev.CaptureCloseDevice()
|
idev.CaptureCloseDevice()
|
||||||
return nil, ErrOutputDevice
|
return nil, openOutputDeviceError(outName)
|
||||||
}
|
}
|
||||||
if err := odev.Err(); err != nil {
|
if err := odev.Err(); err != nil {
|
||||||
idev.CaptureCloseDevice()
|
idev.CaptureCloseDevice()
|
||||||
odev.CloseDevice()
|
odev.CloseDevice()
|
||||||
return nil, fmt.Errorf("%w: %v", ErrOutputDevice, err)
|
return nil, fmt.Errorf("%w: playback device %q: %v", ErrOutputDevice, deviceName(outName), err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if test {
|
if test {
|
||||||
|
|||||||
@@ -1,11 +1,30 @@
|
|||||||
package gumbleopenal
|
package gumbleopenal
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"git.stormux.org/storm/barnard/gumble/go-openal/openal"
|
||||||
|
)
|
||||||
|
|
||||||
// Regression: audio cleanup could send a final render command after Destroy
|
// Regression: audio cleanup could send a final render command after Destroy
|
||||||
// had closed renderCh, panicking instead of safely discarding that work.
|
// had closed renderCh, panicking instead of safely discarding that work.
|
||||||
// Regression: StopSource returned before the capture worker ended, allowing
|
// Regression: StopSource returned before the capture worker ended, allowing
|
||||||
// Destroy to close the device while that worker still used it.
|
// Destroy to close the device while that worker still used it.
|
||||||
|
// Regression: OpenAL returned only a generic input/output error, hiding the
|
||||||
|
// actual configured device that a user must correct.
|
||||||
|
func TestDeviceOpenErrorsIncludeConfiguredDevice(t *testing.T) {
|
||||||
|
input := openInputDeviceError("virtual_mic.monitor", openal.FormatMono16)
|
||||||
|
if !errors.Is(input, ErrInputDevice) || !strings.Contains(input.Error(), "virtual_mic.monitor") {
|
||||||
|
t.Fatalf("input error %q", input)
|
||||||
|
}
|
||||||
|
output := openOutputDeviceError("")
|
||||||
|
if !errors.Is(output, ErrOutputDevice) || !strings.Contains(output.Error(), "default") {
|
||||||
|
t.Fatalf("output error %q", output)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestStopSourceWaitsForWorker(t *testing.T) {
|
func TestStopSourceWaitsForWorker(t *testing.T) {
|
||||||
stop, done := make(chan bool), make(chan struct{})
|
stop, done := make(chan bool), make(chan struct{})
|
||||||
s := &Stream{sourceStop: stop, sourceDone: done}
|
s := &Stream{sourceStop: stop, sourceDone: done}
|
||||||
|
|||||||
Reference in New Issue
Block a user