mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-07-25 02:57:24 +00:00
Optimize
This commit is contained in:
parent
713de84dc2
commit
ab06eb488d
5 changed files with 28 additions and 23 deletions
|
|
@ -1,6 +1,8 @@
|
|||
package nes
|
||||
|
||||
import "encoding/gob"
|
||||
import (
|
||||
"encoding/gob"
|
||||
)
|
||||
|
||||
const frameCounterRate = CPUFrequency / 240.0
|
||||
|
||||
|
|
|
|||
|
|
@ -148,18 +148,16 @@ func (v *VpxEncoder) startLooping() {
|
|||
v.frameCount++
|
||||
|
||||
// Get Frame
|
||||
for {
|
||||
goBytes := C.get_frame_buffer(&v.vpxCodexCtx, &v.vpxCodexIter)
|
||||
if goBytes.bs == nil {
|
||||
break
|
||||
}
|
||||
bs := C.GoBytes(goBytes.bs, goBytes.size)
|
||||
// if buffer is full skip frame
|
||||
if len(v.Output) >= cap(v.Output) {
|
||||
continue
|
||||
}
|
||||
v.Output <- bs
|
||||
goBytes := C.get_frame_buffer(&v.vpxCodexCtx, &v.vpxCodexIter)
|
||||
if goBytes.bs == nil {
|
||||
continue
|
||||
}
|
||||
bs := C.GoBytes(goBytes.bs, goBytes.size)
|
||||
// if buffer is full skip frame
|
||||
if len(v.Output) >= cap(v.Output) {
|
||||
continue
|
||||
}
|
||||
v.Output <- bs
|
||||
|
||||
if *config.IsMonitor {
|
||||
log.Println("Encoding time: ", time.Now().Sub(beginEncoding))
|
||||
|
|
|
|||
|
|
@ -59,9 +59,9 @@ func NewWebRTC() *WebRTC {
|
|||
w := &WebRTC{
|
||||
ID: uuid.Must(uuid.NewV4()).String(),
|
||||
|
||||
ImageChannel: make(chan []byte, 100),
|
||||
AudioChannel: make(chan []byte, 1000),
|
||||
InputChannel: make(chan int, 10),
|
||||
ImageChannel: make(chan []byte, 30),
|
||||
AudioChannel: make(chan []byte, 30),
|
||||
InputChannel: make(chan int, 100),
|
||||
}
|
||||
return w
|
||||
}
|
||||
|
|
@ -113,8 +113,12 @@ func (w *WebRTC) StartClient(remoteSession string, iceCandidates []string, width
|
|||
w.encoder = encoder
|
||||
|
||||
log.Println("=== StartClient ===")
|
||||
m := webrtc.MediaEngine{}
|
||||
m.RegisterCodec(webrtc.NewRTPOpusCodec(webrtc.DefaultPayloadTypeOpus, 48000))
|
||||
m.RegisterCodec(webrtc.NewRTPVP8Codec(webrtc.DefaultPayloadTypeVP8, 90000))
|
||||
api := webrtc.NewAPI(webrtc.WithMediaEngine(m))
|
||||
|
||||
w.connection, err = webrtc.NewPeerConnection(webrtcconfig)
|
||||
w.connection, err = api.NewPeerConnection(webrtcconfig)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,6 @@ package worker
|
|||
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/config"
|
||||
"github.com/giongto35/cloud-game/cws"
|
||||
|
|
@ -107,9 +105,6 @@ func (h *Handler) RouteOverlord() {
|
|||
if room.IsPCInRoom(session.peerconnection) {
|
||||
h.detachPeerConn(session.peerconnection)
|
||||
}
|
||||
start := time.Now()
|
||||
runtime.GC()
|
||||
log.Printf("GC takes %s\n", time.Since(start))
|
||||
|
||||
return cws.EmptyPacket
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,8 +6,10 @@ import (
|
|||
"log"
|
||||
"math/rand"
|
||||
"os"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
emulator "github.com/giongto35/cloud-game/emulator"
|
||||
"github.com/giongto35/cloud-game/webrtc"
|
||||
|
|
@ -46,8 +48,8 @@ func NewRoom(roomID, gamepath, gameName string, onlineStorage *storage.Client) *
|
|||
roomID = generateRoomID()
|
||||
}
|
||||
log.Println("Init new room", roomID, gameName)
|
||||
imageChannel := make(chan *image.RGBA, 100)
|
||||
audioChannel := make(chan float32, emulator.SampleRate)
|
||||
imageChannel := make(chan *image.RGBA, 30)
|
||||
audioChannel := make(chan float32, 30)
|
||||
inputChannel := make(chan int, 100)
|
||||
|
||||
// create director
|
||||
|
|
@ -88,6 +90,10 @@ func NewRoom(roomID, gamepath, gameName string, onlineStorage *storage.Client) *
|
|||
log.Printf("Room %s started", roomID)
|
||||
director.Start([]string{path})
|
||||
log.Printf("Room %s ended", roomID)
|
||||
|
||||
start := time.Now()
|
||||
runtime.GC()
|
||||
log.Printf("GC takes %s\n", time.Since(start))
|
||||
}(path, roomID)
|
||||
|
||||
return room
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue