From d0e356314d474d60205e56de47454ec0fe8bc51f Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 7 Jan 2020 13:06:56 +1030 Subject: [PATCH] codec/mjpeg/jpeg.go: moved get24 to bottom of file and gave comment. --- codec/mjpeg/extract.go | 4 +++- codec/mjpeg/jpeg.go | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/codec/mjpeg/extract.go b/codec/mjpeg/extract.go index 39e4ec57..d0e515f2 100644 --- a/codec/mjpeg/extract.go +++ b/codec/mjpeg/extract.go @@ -73,7 +73,9 @@ func (e *Extractor) Extract(dst io.Writer, src io.Reader, delay time.Duration) e } err = ctx.ParsePayload(p, m) - if err != nil { + switch err { + case ErrNoFrameStart: // If no frame start then we continue until we get one. + default: return fmt.Errorf("could not parse JPEG scan: %w", err) } } diff --git a/codec/mjpeg/jpeg.go b/codec/mjpeg/jpeg.go index da15f64d..91f691f6 100644 --- a/codec/mjpeg/jpeg.go +++ b/codec/mjpeg/jpeg.go @@ -91,6 +91,7 @@ var ( ErrReservedQ = errors.New("q value is reserved") ErrUnimplementedType = errors.New("unimplemented RTP/JPEG type") ErrUnsupportedPrecision = errors.New("unsupported precision") + ErrNoFrameStart = errors.New("missing start of frame") ) // Slices used in the creation of huffman tables. @@ -260,7 +261,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { if c.blen == 0 { // Must have missed start of frame? So ignore and wait for start. - return nil + return ErrNoFrameStart } // TODO: check that timestamp is consistent @@ -290,10 +291,6 @@ func (c *Context) ParsePayload(p []byte, m bool) error { return nil } -func get24(p []byte) int { - return int(p[0]<<16) | int(p[1]<<8) | int(p[2]) -} - // writeHeader writes a JPEG header to the writer w. func writeHeader(p []byte, _type, width, height, nbqTab int, dri uint16, qtable []byte) int { width <<= 3 @@ -451,3 +448,8 @@ func clip(v, min, max int) int { return v } + +// get24 parses an int24 from p using big endian order. +func get24(p []byte) int { + return int(p[0]<<16) | int(p[1]<<8) | int(p[2]) +}