codec/mjpeg/jpeg.go: moved get24 to bottom of file and gave comment.

This commit is contained in:
Saxon 2020-01-07 13:06:56 +10:30
parent 86e215f913
commit d0e356314d
2 changed files with 10 additions and 6 deletions

View File

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

View File

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