codec/mjpeg/jpeg.go: removing panics inside ParsePayload in favour of errors

This commit is contained in:
Saxon 2020-01-07 12:52:31 +10:30
parent 803cdf0747
commit f187af747b
1 changed files with 9 additions and 6 deletions

View File

@ -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)