mirror of https://bitbucket.org/ausocean/av.git
codec/mjpeg/jpeg.go: removing panics inside ParsePayload in favour of errors
This commit is contained in:
parent
803cdf0747
commit
f187af747b
|
@ -85,9 +85,12 @@ const (
|
||||||
sosComponentsInScan = 3 // Number of components in scan.
|
sosComponentsInScan = 3 // Number of components in scan.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Errors returned from ParsePayload.
|
||||||
var (
|
var (
|
||||||
errNoQTable = errors.New("no quantization table")
|
ErrNoQTable = errors.New("no quantization table")
|
||||||
errReservedQ = errors.New("q value is reserved")
|
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.
|
// Slices used in the creation of huffman tables.
|
||||||
|
@ -205,7 +208,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if t > 1 {
|
if t > 1 {
|
||||||
panic("unimplemented RTP/JPEG type")
|
return ErrUnimplementedType
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parse quantization table if our offset is 0.
|
// Parse quantization table if our offset is 0.
|
||||||
|
@ -220,7 +223,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
|
||||||
idx += 3
|
idx += 3
|
||||||
|
|
||||||
if prec != 0 {
|
if prec != 0 {
|
||||||
panic("unsupported precision")
|
return ErrUnsupportedPrecision
|
||||||
}
|
}
|
||||||
|
|
||||||
if qLen > 0 {
|
if qLen > 0 {
|
||||||
|
@ -233,7 +236,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if q == 255 {
|
if q == 255 {
|
||||||
return errNoQTable
|
return ErrNoQTable
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.qTablesLen[q-128] == 0 {
|
if c.qTablesLen[q-128] == 0 {
|
||||||
|
@ -245,7 +248,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
|
||||||
}
|
}
|
||||||
} else { // q <= 127
|
} else { // q <= 127
|
||||||
if q == 0 || q > 99 {
|
if q == 0 || q > 99 {
|
||||||
return errReservedQ
|
return ErrReservedQ
|
||||||
}
|
}
|
||||||
qTable = defaultQTable(int(q))
|
qTable = defaultQTable(int(q))
|
||||||
qLen = len(qTable)
|
qLen = len(qTable)
|
||||||
|
|
Loading…
Reference in New Issue