mirror of https://bitbucket.org/ausocean/av.git
device/alsa/alsa.go: removed OpenError
This commit is contained in:
parent
e4e03b4ed1
commit
67a0771c32
|
@ -105,9 +105,6 @@ type Logger interface {
|
||||||
Log(level int8, message string, params ...interface{})
|
Log(level int8, message string, params ...interface{})
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenError is used to determine whether an error has originated from attempting to open a device.
|
|
||||||
type OpenError error
|
|
||||||
|
|
||||||
// New initializes and returns an ALSA device which has its logger set as the given logger.
|
// New initializes and returns an ALSA device which has its logger set as the given logger.
|
||||||
func New(l Logger) *ALSA { return &ALSA{l: l} }
|
func New(l Logger) *ALSA { return &ALSA{l: l} }
|
||||||
|
|
||||||
|
@ -239,7 +236,7 @@ func (d *ALSA) open() error {
|
||||||
d.l.Log(logger.Debug, "opening sound card")
|
d.l.Log(logger.Debug, "opening sound card")
|
||||||
cards, err := yalsa.OpenCards()
|
cards, err := yalsa.OpenCards()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OpenError(err)
|
return err
|
||||||
}
|
}
|
||||||
defer yalsa.CloseCards(cards)
|
defer yalsa.CloseCards(cards)
|
||||||
|
|
||||||
|
@ -260,13 +257,13 @@ func (d *ALSA) open() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if d.dev == nil {
|
if d.dev == nil {
|
||||||
return OpenError(errors.New("no ALSA device found"))
|
return errors.New("no ALSA device found")
|
||||||
}
|
}
|
||||||
|
|
||||||
d.l.Log(logger.Debug, "opening ALSA device", "title", d.dev.Title)
|
d.l.Log(logger.Debug, "opening ALSA device", "title", d.dev.Title)
|
||||||
err = d.dev.Open()
|
err = d.dev.Open()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OpenError(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to configure device with chosen channels.
|
// Try to configure device with chosen channels.
|
||||||
|
@ -276,7 +273,7 @@ func (d *ALSA) open() error {
|
||||||
channels, err = d.dev.NegotiateChannels(2)
|
channels, err = d.dev.NegotiateChannels(2)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OpenError(fmt.Errorf("device is unable to record with requested number of channels: %w", err))
|
return fmt.Errorf("device is unable to record with requested number of channels: %w", err)
|
||||||
}
|
}
|
||||||
d.l.Log(logger.Debug, "alsa device channels set", "channels", channels)
|
d.l.Log(logger.Debug, "alsa device channels set", "channels", channels)
|
||||||
|
|
||||||
|
@ -309,7 +306,7 @@ func (d *ALSA) open() error {
|
||||||
d.l.Log(logger.Warning, "unable to sample at requested rate, default used.", "rateRequested", d.SampleRate)
|
d.l.Log(logger.Warning, "unable to sample at requested rate, default used.", "rateRequested", d.SampleRate)
|
||||||
rate, err = d.dev.NegotiateRate(defaultSampleRate)
|
rate, err = d.dev.NegotiateRate(defaultSampleRate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OpenError(err)
|
return err
|
||||||
}
|
}
|
||||||
d.l.Log(logger.Debug, "alsa device sample rate set", "rate", rate)
|
d.l.Log(logger.Debug, "alsa device sample rate set", "rate", rate)
|
||||||
}
|
}
|
||||||
|
@ -321,7 +318,7 @@ func (d *ALSA) open() error {
|
||||||
case 32:
|
case 32:
|
||||||
aFmt = yalsa.S32_LE
|
aFmt = yalsa.S32_LE
|
||||||
default:
|
default:
|
||||||
return OpenError(fmt.Errorf("unsupported sample bits %v", d.BitDepth))
|
return fmt.Errorf("unsupported sample bits %v", d.BitDepth)
|
||||||
}
|
}
|
||||||
devFmt, err := d.dev.NegotiateFormat(aFmt)
|
devFmt, err := d.dev.NegotiateFormat(aFmt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -334,7 +331,7 @@ func (d *ALSA) open() error {
|
||||||
case yalsa.S32_LE:
|
case yalsa.S32_LE:
|
||||||
bitdepth = 32
|
bitdepth = 32
|
||||||
default:
|
default:
|
||||||
return OpenError(fmt.Errorf("unsupported sample bits %v", d.BitDepth))
|
return fmt.Errorf("unsupported sample bits %v", d.BitDepth)
|
||||||
}
|
}
|
||||||
d.l.Log(logger.Debug, "alsa device bit depth set", "bitdepth", bitdepth)
|
d.l.Log(logger.Debug, "alsa device bit depth set", "bitdepth", bitdepth)
|
||||||
|
|
||||||
|
@ -349,12 +346,12 @@ func (d *ALSA) open() error {
|
||||||
// At least two period sizes should fit within the buffer.
|
// At least two period sizes should fit within the buffer.
|
||||||
bufSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2)
|
bufSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return OpenError(err)
|
return err
|
||||||
}
|
}
|
||||||
d.l.Log(logger.Debug, "alsa device buffer size set", "buffersize", bufSize)
|
d.l.Log(logger.Debug, "alsa device buffer size set", "buffersize", bufSize)
|
||||||
|
|
||||||
if err = d.dev.Prepare(); err != nil {
|
if err = d.dev.Prepare(); err != nil {
|
||||||
return OpenError(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
d.l.Log(logger.Debug, "successfully negotiated device params")
|
d.l.Log(logger.Debug, "successfully negotiated device params")
|
||||||
|
|
Loading…
Reference in New Issue