mirror of https://bitbucket.org/ausocean/av.git
codec/h264&h265/lex.go: returning errors even if io.EOF, and not bothering to return what's currently in buffer if error
This commit is contained in:
parent
3a743ea917
commit
a26777b697
|
@ -31,6 +31,7 @@ LICENSE
|
|||
package h264
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
|
@ -66,25 +67,19 @@ func Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
buf := make([]byte, len(h264Prefix), bufSize)
|
||||
copy(buf, h264Prefix[:])
|
||||
writeOut := false
|
||||
outer:
|
||||
|
||||
for {
|
||||
var b byte
|
||||
var err error
|
||||
buf, b, err = c.ScanUntil(buf, 0x00)
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
return err
|
||||
}
|
||||
break
|
||||
return fmt.Errorf("can't scan until: %w", err)
|
||||
}
|
||||
|
||||
for n := 1; b == 0x0 && n < 4; n++ {
|
||||
b, err = c.ReadByte()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
return err
|
||||
}
|
||||
break outer
|
||||
return fmt.Errorf("can't read byte: %w", err)
|
||||
}
|
||||
buf = append(buf, b)
|
||||
|
||||
|
@ -106,10 +101,7 @@ outer:
|
|||
|
||||
b, err = c.ReadByte()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
return err
|
||||
}
|
||||
break outer
|
||||
return fmt.Errorf("can't read byte: %w", err)
|
||||
}
|
||||
buf = append(buf, b)
|
||||
|
||||
|
@ -127,10 +119,4 @@ outer:
|
|||
}
|
||||
}
|
||||
}
|
||||
if len(buf) == len(h264Prefix) {
|
||||
return nil
|
||||
}
|
||||
<-tick
|
||||
_, err := dst.Write(buf)
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -76,8 +76,6 @@ func (l *Lexer) Lex(dst io.Writer, src io.Reader, delay time.Duration) error {
|
|||
n, err := src.Read(buf)
|
||||
switch err {
|
||||
case nil: // Do nothing.
|
||||
case io.EOF:
|
||||
return nil
|
||||
default:
|
||||
return fmt.Errorf("source read error: %w\n", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue