mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 02:34:42 +00:00
Try YUV without the mem pool
This commit is contained in:
parent
954bb23bb8
commit
a7acebc5d0
2 changed files with 13 additions and 9 deletions
|
|
@ -80,7 +80,7 @@ func (v *Video) Encode(frame InFrame) OutFrame {
|
|||
}
|
||||
|
||||
yCbCr := v.y.Process(yuv.RawFrame(frame), v.rot, v.pf)
|
||||
defer v.y.Put(&yCbCr)
|
||||
//defer v.y.Put(&yCbCr)
|
||||
if bytes := v.codec.Encode(yCbCr); len(bytes) > 0 {
|
||||
return bytes
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,12 @@ import (
|
|||
)
|
||||
|
||||
type Conv struct {
|
||||
w, h int
|
||||
sw, sh int
|
||||
scale float64
|
||||
pool sync.Pool
|
||||
w, h int
|
||||
sw, sh int
|
||||
scale float64
|
||||
pool sync.Pool
|
||||
frame []byte
|
||||
frameSc []byte
|
||||
}
|
||||
|
||||
type RawFrame struct {
|
||||
|
|
@ -35,7 +37,9 @@ func NewYuvConv(w, h int, scale float64) Conv {
|
|||
bufSize := int(float64(sw) * float64(sh) * 1.5)
|
||||
return Conv{
|
||||
w: w, h: h, sw: sw, sh: sh, scale: scale,
|
||||
pool: sync.Pool{New: func() any { b := make([]byte, bufSize); return &b }},
|
||||
pool: sync.Pool{New: func() any { b := make([]byte, bufSize); return &b }},
|
||||
frame: make([]byte, bufSize),
|
||||
frameSc: make([]byte, bufSize),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,13 +56,13 @@ func (c *Conv) Process(frame RawFrame, rot uint, pf PixFmt) []byte {
|
|||
stride = frame.Stride >> 1
|
||||
}
|
||||
|
||||
buf := *c.pool.Get().(*[]byte)
|
||||
buf := c.frame //*c.pool.Get().(*[]byte)
|
||||
libyuv.Y420(frame.Data, buf, frame.W, frame.H, stride, dx, dy, rot, uint32(pf), cx, cy)
|
||||
|
||||
if c.scale > 1 {
|
||||
dstBuf := *c.pool.Get().(*[]byte)
|
||||
dstBuf := c.frameSc //*c.pool.Get().(*[]byte)
|
||||
libyuv.Y420Scale(buf, dstBuf, dx, dy, c.sw, c.sh)
|
||||
c.pool.Put(&buf)
|
||||
//c.pool.Put(&buf)
|
||||
return dstBuf
|
||||
}
|
||||
return buf
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue