fix: add OpenAL device open logging and nil pointer safety
Add info-level logging showing which device OpenAL opens and with what format. Also add nil checks for inputDevice/outputDevice pointers to prevent panics when config fields are unset.
This commit is contained in:
committed by
Brandon McGinty
parent
a24fca382d
commit
b2a1d2f846
@@ -85,19 +85,32 @@ func New(client *gumble.Client, inputDevice *string, outputDevice *string, test
|
|||||||
frmsz = client.Config.AudioFrameSize()
|
frmsz = client.Config.AudioFrameSize()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devName := ""
|
||||||
|
if inputDevice != nil {
|
||||||
|
devName = *inputDevice
|
||||||
|
}
|
||||||
|
log.Info("OpenAL capture: requested device=%q rate=%d frameSize=%d", devName, gumble.AudioSampleRate, frmsz)
|
||||||
|
|
||||||
inputFormat := openal.FormatStereo16
|
inputFormat := openal.FormatStereo16
|
||||||
sourceChannels := 2
|
sourceChannels := 2
|
||||||
idev := openal.CaptureOpenDevice(*inputDevice, gumble.AudioSampleRate, inputFormat, uint32(frmsz))
|
idev := openal.CaptureOpenDevice(devName, gumble.AudioSampleRate, inputFormat, uint32(frmsz))
|
||||||
if idev == nil {
|
if idev == nil {
|
||||||
|
log.Info("OpenAL capture: stereo failed, trying mono")
|
||||||
inputFormat = openal.FormatMono16
|
inputFormat = openal.FormatMono16
|
||||||
sourceChannels = 1
|
sourceChannels = 1
|
||||||
idev = openal.CaptureOpenDevice(*inputDevice, gumble.AudioSampleRate, inputFormat, uint32(frmsz))
|
idev = openal.CaptureOpenDevice(devName, gumble.AudioSampleRate, inputFormat, uint32(frmsz))
|
||||||
}
|
}
|
||||||
if idev == nil {
|
if idev == nil {
|
||||||
|
log.Error("OpenAL capture: failed to open device %q", devName)
|
||||||
return nil, ErrInputDevice
|
return nil, ErrInputDevice
|
||||||
}
|
}
|
||||||
|
log.Info("OpenAL capture: opened device %q format=%v channels=%d", devName, inputFormat, sourceChannels)
|
||||||
|
|
||||||
odev := openal.OpenDevice(*outputDevice)
|
outName := ""
|
||||||
|
if outputDevice != nil {
|
||||||
|
outName = *outputDevice
|
||||||
|
}
|
||||||
|
odev := openal.OpenDevice(outName)
|
||||||
if odev == nil {
|
if odev == nil {
|
||||||
idev.CaptureCloseDevice()
|
idev.CaptureCloseDevice()
|
||||||
return nil, ErrOutputDevice
|
return nil, ErrOutputDevice
|
||||||
@@ -486,14 +499,19 @@ func (s *Stream) sourceRoutine(inputDevice *string) {
|
|||||||
interval := s.client.Config.AudioInterval
|
interval := s.client.Config.AudioInterval
|
||||||
frameSize := s.client.Config.AudioFrameSize()
|
frameSize := s.client.Config.AudioFrameSize()
|
||||||
|
|
||||||
|
devName := ""
|
||||||
|
if inputDevice != nil {
|
||||||
|
devName = *inputDevice
|
||||||
|
}
|
||||||
|
|
||||||
if frameSize != s.sourceFrameSize {
|
if frameSize != s.sourceFrameSize {
|
||||||
s.deviceSource.CaptureCloseDevice()
|
s.deviceSource.CaptureCloseDevice()
|
||||||
s.sourceFrameSize = frameSize
|
s.sourceFrameSize = frameSize
|
||||||
s.deviceSource = openal.CaptureOpenDevice(*inputDevice, gumble.AudioSampleRate, s.sourceFormat, uint32(s.sourceFrameSize))
|
s.deviceSource = openal.CaptureOpenDevice(devName, gumble.AudioSampleRate, s.sourceFormat, uint32(s.sourceFrameSize))
|
||||||
if s.deviceSource == nil && s.sourceFormat == openal.FormatStereo16 {
|
if s.deviceSource == nil && s.sourceFormat == openal.FormatStereo16 {
|
||||||
s.sourceFormat = openal.FormatMono16
|
s.sourceFormat = openal.FormatMono16
|
||||||
s.sourceChannels = 1
|
s.sourceChannels = 1
|
||||||
s.deviceSource = openal.CaptureOpenDevice(*inputDevice, gumble.AudioSampleRate, s.sourceFormat, uint32(s.sourceFrameSize))
|
s.deviceSource = openal.CaptureOpenDevice(devName, gumble.AudioSampleRate, s.sourceFormat, uint32(s.sourceFrameSize))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if s.deviceSource == nil {
|
if s.deviceSource == nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user