From f187af747be95c93443b2f6a553d141490122130 Mon Sep 17 00:00:00 2001 From: Saxon Date: Tue, 7 Jan 2020 12:52:31 +1030 Subject: [PATCH] codec/mjpeg/jpeg.go: removing panics inside ParsePayload in favour of errors --- codec/mjpeg/jpeg.go | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/codec/mjpeg/jpeg.go b/codec/mjpeg/jpeg.go index c3277b9f..be3c648c 100644 --- a/codec/mjpeg/jpeg.go +++ b/codec/mjpeg/jpeg.go @@ -85,9 +85,12 @@ const ( sosComponentsInScan = 3 // Number of components in scan. ) +// Errors returned from ParsePayload. var ( - errNoQTable = errors.New("no quantization table") - errReservedQ = errors.New("q value is reserved") + ErrNoQTable = errors.New("no quantization table") + ErrReservedQ = errors.New("q value is reserved") + ErrUnimplementedType = errors.New("unimplemented RTP/JPEG type") + ErrUnsupportedPrecision = errors.New("unsupported precision") ) // Slices used in the creation of huffman tables. @@ -205,7 +208,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { } if t > 1 { - panic("unimplemented RTP/JPEG type") + return ErrUnimplementedType } // Parse quantization table if our offset is 0. @@ -220,7 +223,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { idx += 3 if prec != 0 { - panic("unsupported precision") + return ErrUnsupportedPrecision } if qLen > 0 { @@ -233,7 +236,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { } } else { if q == 255 { - return errNoQTable + return ErrNoQTable } if c.qTablesLen[q-128] == 0 { @@ -245,7 +248,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { } } else { // q <= 127 if q == 0 || q > 99 { - return errReservedQ + return ErrReservedQ } qTable = defaultQTable(int(q)) qLen = len(qTable)