From 4c04cc033a5c6b7ba9c79717dfb4cb117de9d4bc Mon Sep 17 00:00:00 2001 From: Saxon Date: Sun, 29 Dec 2019 22:52:53 +1030 Subject: [PATCH] codec/mjpeg/jpeg.go: renamed fields of putBuffer struct --- codec/mjpeg/jpeg.go | 6 +++--- codec/mjpeg/utils.go | 34 +++++++++++++++------------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/codec/mjpeg/jpeg.go b/codec/mjpeg/jpeg.go index 0f240c5e..d1da4fcf 100644 --- a/codec/mjpeg/jpeg.go +++ b/codec/mjpeg/jpeg.go @@ -222,7 +222,7 @@ func (c *Context) ParsePayload(p []byte, m bool) error { writeHeader(c.buf, t, width, height, qLen/64, dri, qTable) } - if c.buf.len() == 0 { + if c.buf.len == 0 { // Must have missed start of frame? So ignore and wait for start. return nil } @@ -292,13 +292,13 @@ func writeHeader(p *putBuffer, _type, width, height, nbqTab, dri int, qtable []b // Define huffman table. mark(p, codeDHT) - lenIdx := p.len() + lenIdx := p.len p.put16(0) writeHuffman(p, 0, 0, bitsDCLum, valDC) writeHuffman(p, 0, 1, bitsDCChr, valDC) writeHuffman(p, 1, 0, bitsACLum, valACLum) writeHuffman(p, 1, 1, bitsACChr, valACChr) - p.put16At(uint16(p.len()-lenIdx), lenIdx) + p.put16At(uint16(p.len-lenIdx), lenIdx) // Start of frame. mark(p, codeSOF0) diff --git a/codec/mjpeg/utils.go b/codec/mjpeg/utils.go index 511a9da3..12ff01ea 100644 --- a/codec/mjpeg/utils.go +++ b/codec/mjpeg/utils.go @@ -30,49 +30,45 @@ import ( ) type putBuffer struct { - i int - b []byte + len int + bytes []byte } -func newPutBuffer(b []byte) *putBuffer { return &putBuffer{b: b} } +func newPutBuffer(b []byte) *putBuffer { return &putBuffer{bytes: b} } func (p *putBuffer) Write(b []byte) (int, error) { - copy(p.b[p.i:], b) - p.i += len(b) + copy(p.bytes[p.len:], b) + p.len += len(b) return len(b), nil } func (p *putBuffer) writeTo(d io.Writer) (int, error) { - n, err := d.Write(p.b[0:p.i]) - p.i -= n + n, err := d.Write(p.bytes[0:p.len]) + p.len -= n return n, err } func (p *putBuffer) put16(v uint16) { - binary.BigEndian.PutUint16(p.b[p.i:], v) - p.i += 2 + binary.BigEndian.PutUint16(p.bytes[p.len:], v) + p.len += 2 } func (p *putBuffer) put8(v uint8) { - p.b[p.i] = byte(v) - p.i++ + p.bytes[p.len] = byte(v) + p.len++ } func (p *putBuffer) putBuf(src []byte) { - copy(p.b[p.i:], src) - p.i += len(src) + copy(p.bytes[p.len:], src) + p.len += len(src) } func (p *putBuffer) put16At(v uint16, i int) { - binary.BigEndian.PutUint16(p.b[i:], v) + binary.BigEndian.PutUint16(p.bytes[i:], v) } func (p *putBuffer) reset() { - p.i = 0 -} - -func (p *putBuffer) len() int { - return p.i + p.len = 0 } type byteStream struct {