mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-21 00:59:22 +00:00
Allocation inplace
This commit is contained in:
parent
b3e9fd91e3
commit
edba449500
3 changed files with 12 additions and 2 deletions
|
|
@ -3,6 +3,7 @@ package room
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/giongto35/cloud-game/config"
|
||||
"github.com/giongto35/cloud-game/emulator"
|
||||
"github.com/giongto35/cloud-game/util"
|
||||
"gopkg.in/hraban/opus.v2"
|
||||
|
|
@ -77,6 +78,8 @@ func (r *Room) startAudio() {
|
|||
}
|
||||
|
||||
func (r *Room) startVideo() {
|
||||
size := int(float32(config.Width*config.Height) * 1.5)
|
||||
yuv := make([]byte, size, size)
|
||||
// fanout Screen
|
||||
for {
|
||||
image, ok := <-r.imageChannel
|
||||
|
|
@ -91,7 +94,7 @@ func (r *Room) startVideo() {
|
|||
}
|
||||
|
||||
// TODO: Use worker pool for encoding
|
||||
yuv := util.RgbaToYuv(image)
|
||||
util.RgbaToYuvInplace(image, yuv)
|
||||
// TODO: r.rtcSessions is rarely updated. Lock will hold down perf
|
||||
//r.sessionsLock.Lock()
|
||||
for _, webRTC := range r.rtcSessions {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ package util
|
|||
import (
|
||||
"image"
|
||||
"unsafe"
|
||||
|
||||
"github.com/giongto35/cloud-game/config"
|
||||
)
|
||||
|
||||
// https://stackoverflow.com/questions/9465815/rgb-to-yuv420-algorithm-efficiency
|
||||
|
|
@ -51,3 +53,9 @@ func RgbaToYuv(rgba *image.RGBA) []byte {
|
|||
C.rgba2yuv(unsafe.Pointer(&yuv[0]), unsafe.Pointer(&rgba.Pix[0]), C.int(w), C.int(h), C.int(stride))
|
||||
return yuv
|
||||
}
|
||||
|
||||
// RgbaToYuvInplace convert to yuv from rgba inplace to yuv. Avoid reallocation
|
||||
func RgbaToYuvInplace(rgba *image.RGBA, yuv []byte) {
|
||||
stride := rgba.Stride - config.Width*4
|
||||
C.rgba2yuv(unsafe.Pointer(&yuv[0]), unsafe.Pointer(&rgba.Pix[0]), C.int(config.Width), C.int(config.Height), C.int(stride))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -174,7 +174,6 @@ func (v *VpxEncoder) Release() {
|
|||
if v.IsRunning {
|
||||
v.IsRunning = false
|
||||
log.Println("Releasing encoder")
|
||||
log.Println("Close output", v.Output)
|
||||
C.vpx_img_free(&v.vpxImage)
|
||||
C.vpx_codec_destroy(&v.vpxCodexCtx)
|
||||
// TODO: Bug here, after close it will signal
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue