codec/mjpeg/jpeg.go: improve Context struct field names

This commit is contained in:
Saxon 2019-12-29 22:47:38 +10:30
parent ef699451d5
commit 029a59fc78
1 changed files with 11 additions and 11 deletions

View File

@ -139,15 +139,15 @@ var (
type Context struct { type Context struct {
qTables [128][128]byte qTables [128][128]byte
qTablesLen [128]byte qTablesLen [128]byte
p *putBuffer buf *putBuffer
d io.Writer dst io.Writer
} }
// NewContext will return a new Context. // NewContext will return a new Context with destination d.
func NewContext(d io.Writer) *Context { func NewContext(d io.Writer) *Context {
return &Context{ return &Context{
d: d, dst: d,
p: newPutBuffer(make([]byte, maxJPEG)), buf: newPutBuffer(make([]byte, maxJPEG)),
} }
} }
@ -217,12 +217,12 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
qLen = len(qTable) qLen = len(qTable)
} }
c.p.reset() c.buf.reset()
writeHeader(c.p, t, width, height, qLen/64, dri, qTable) writeHeader(c.buf, t, width, height, qLen/64, dri, qTable)
} }
if c.p.len() == 0 { if c.buf.len() == 0 {
// Must have missed start of frame? So ignore and wait for start. // Must have missed start of frame? So ignore and wait for start.
return nil return nil
} }
@ -234,16 +234,16 @@ func (c *Context) ParsePayload(p []byte, m bool) error {
// to determine if there are missing frames. // to determine if there are missing frames.
// Write frame data // Write frame data
err := b.writeTo(c.p, b.remaining()) err := b.writeTo(c.buf, b.remaining())
if err != nil { if err != nil {
return fmt.Errorf("could not write remaining frame data to output buffer: %w", err) return fmt.Errorf("could not write remaining frame data to output buffer: %w", err)
} }
if m { if m {
// End of image marker. // End of image marker.
mark(c.p, codeEOI) mark(c.buf, codeEOI)
_, err = c.p.writeTo(c.d) _, err = c.buf.writeTo(c.dst)
if err != nil { if err != nil {
return fmt.Errorf("could not write JPEG to dst: %w", err) return fmt.Errorf("could not write JPEG to dst: %w", err)
} }