mirror of https://bitbucket.org/ausocean/av.git
Merged in alsa-pause (pull request #473)
alsa: close pool buffer on stop, handle EOF from next Approved-by: Saxon Milton
This commit is contained in:
commit
3db7d1b1f3
|
@ -69,8 +69,11 @@ func (l *ByteLexer) Lex(dst io.Writer, src io.Reader, d time.Duration) error {
|
|||
for {
|
||||
<-ticker.C
|
||||
off, err := src.Read(buf)
|
||||
if err != nil {
|
||||
// The only error that will stop the lexer is an EOF.
|
||||
if err == io.EOF {
|
||||
return err
|
||||
} else if err != nil {
|
||||
continue
|
||||
}
|
||||
_, err = dst.Write(buf[:off])
|
||||
if err != nil {
|
||||
|
|
|
@ -377,6 +377,10 @@ func (d *ALSA) input() {
|
|||
d.dev.Close()
|
||||
d.dev = nil
|
||||
}
|
||||
err := d.buf.Close()
|
||||
if err != nil {
|
||||
d.l.Log(logger.Error, "unable to close pool buffer", "error", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
@ -417,15 +421,15 @@ func (d *ALSA) Read(p []byte) (int, error) {
|
|||
_, err := d.buf.Next(rbNextTimeout)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case nil, io.EOF:
|
||||
d.l.Log(logger.Debug, pkg+"EOF")
|
||||
return 0, nil
|
||||
case io.EOF:
|
||||
d.l.Log(logger.Debug, pkg+"EOF from Next")
|
||||
return 0, err
|
||||
case pool.ErrTimeout:
|
||||
d.l.Log(logger.Debug, pkg+"pool buffer timeout")
|
||||
return 0, nil
|
||||
return 0, err
|
||||
default:
|
||||
d.l.Log(logger.Error, pkg+"unexpected error from Next", "error", err.Error())
|
||||
return 0, nil
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -434,12 +438,12 @@ func (d *ALSA) Read(p []byte) (int, error) {
|
|||
n, err := d.buf.Read(p)
|
||||
if err != nil {
|
||||
switch err {
|
||||
case nil, io.EOF:
|
||||
d.l.Log(logger.Debug, pkg+"EOF from Read, stopping")
|
||||
case io.EOF:
|
||||
d.l.Log(logger.Debug, pkg+"EOF from Read")
|
||||
return n, err
|
||||
default:
|
||||
d.l.Log(logger.Error, pkg+"unexpected error from Read", "error", err.Error())
|
||||
return n, nil
|
||||
return n, err
|
||||
}
|
||||
}
|
||||
d.l.Log(logger.Debug, fmt.Sprintf("%v read %v bytes", pkg, n))
|
||||
|
|
Loading…
Reference in New Issue