From a26777b697df9de84619ebbb639ae3f4b579cfbc Mon Sep 17 00:00:00 2001 From: Saxon Date: Fri, 17 Jan 2020 16:02:51 +1030 Subject: [PATCH] codec/h264&h265/lex.go: returning errors even if io.EOF, and not bothering to return what's currently in buffer if error --- codec/h264/lex.go | 24 +++++------------------- codec/h265/lex.go | 2 -- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/codec/h264/lex.go b/codec/h264/lex.go index 176c8b3b..1f169afe 100644 --- a/codec/h264/lex.go +++ b/codec/h264/lex.go @@ -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 } diff --git a/codec/h265/lex.go b/codec/h265/lex.go index 55db6be6..6534e571 100644 --- a/codec/h265/lex.go +++ b/codec/h265/lex.go @@ -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) }