mirror of https://bitbucket.org/ausocean/av.git
Merged in remove-alsa-openerror (pull request #431)
device/alsa/alsa.go: removed OpenError
This commit is contained in:
commit
e318690e83
|
@ -105,9 +105,6 @@ type Logger 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.
|
||||
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")
|
||||
cards, err := yalsa.OpenCards()
|
||||
if err != nil {
|
||||
return OpenError(err)
|
||||
return err
|
||||
}
|
||||
defer yalsa.CloseCards(cards)
|
||||
|
||||
|
@ -260,13 +257,13 @@ func (d *ALSA) open() error {
|
|||
}
|
||||
}
|
||||
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)
|
||||
err = d.dev.Open()
|
||||
if err != nil {
|
||||
return OpenError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
// Try to configure device with chosen channels.
|
||||
|
@ -276,7 +273,7 @@ func (d *ALSA) open() error {
|
|||
channels, err = d.dev.NegotiateChannels(2)
|
||||
}
|
||||
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)
|
||||
|
||||
|
@ -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)
|
||||
rate, err = d.dev.NegotiateRate(defaultSampleRate)
|
||||
if err != nil {
|
||||
return OpenError(err)
|
||||
return err
|
||||
}
|
||||
d.l.Log(logger.Debug, "alsa device sample rate set", "rate", rate)
|
||||
}
|
||||
|
@ -321,7 +318,7 @@ func (d *ALSA) open() error {
|
|||
case 32:
|
||||
aFmt = yalsa.S32_LE
|
||||
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)
|
||||
if err != nil {
|
||||
|
@ -334,7 +331,7 @@ func (d *ALSA) open() error {
|
|||
case yalsa.S32_LE:
|
||||
bitdepth = 32
|
||||
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)
|
||||
|
||||
|
@ -349,12 +346,12 @@ func (d *ALSA) open() error {
|
|||
// At least two period sizes should fit within the buffer.
|
||||
bufSize, err := d.dev.NegotiateBufferSize(nearWantPeriodSize * 2)
|
||||
if err != nil {
|
||||
return OpenError(err)
|
||||
return err
|
||||
}
|
||||
d.l.Log(logger.Debug, "alsa device buffer size set", "buffersize", bufSize)
|
||||
|
||||
if err = d.dev.Prepare(); err != nil {
|
||||
return OpenError(err)
|
||||
return err
|
||||
}
|
||||
|
||||
d.l.Log(logger.Debug, "successfully negotiated device params")
|
||||
|
|
Loading…
Reference in New Issue