optimize remote desktop, hvnc and webcam stuff. Fix issues with webcam frames getting super slow out of nowhere because of backup. Also remove compression since we rarely use it + H264 already compresses. Most things we send either way are so small where compression just adds CPU overhead that isn't needed.
This commit is contained in:
@@ -4,13 +4,26 @@ import (
|
||||
"bytes"
|
||||
"image"
|
||||
"image/jpeg"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var jpegBufPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
b := bytes.NewBuffer(make([]byte, 0, 128*1024))
|
||||
return b
|
||||
},
|
||||
}
|
||||
|
||||
func encodeJPEG(img image.Image, quality int) ([]byte, error) {
|
||||
buf := bytes.Buffer{}
|
||||
err := jpeg.Encode(&buf, img, &jpeg.Options{Quality: quality})
|
||||
buf := jpegBufPool.Get().(*bytes.Buffer)
|
||||
buf.Reset()
|
||||
err := jpeg.Encode(buf, img, &jpeg.Options{Quality: quality})
|
||||
if err != nil {
|
||||
jpegBufPool.Put(buf)
|
||||
return nil, err
|
||||
}
|
||||
return buf.Bytes(), nil
|
||||
out := make([]byte, buf.Len())
|
||||
copy(out, buf.Bytes())
|
||||
jpegBufPool.Put(buf)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user