mirror of
https://github.com/giongto35/cloud-game.git
synced 2026-01-23 02:34:42 +00:00
Migrate to v2 suffix (#231)
This commit is contained in:
parent
dbdb99f19e
commit
a42aebec88
33 changed files with 850 additions and 194 deletions
2
.github/workflows/build.yml
vendored
2
.github/workflows/build.yml
vendored
|
|
@ -14,7 +14,7 @@ on:
|
|||
branches:
|
||||
- master
|
||||
env:
|
||||
go-version: 1.13
|
||||
go-version: 1.14
|
||||
jobs:
|
||||
build:
|
||||
name: Build
|
||||
|
|
|
|||
2
.github/workflows/release.yml.disabled
vendored
2
.github/workflows/release.yml.disabled
vendored
|
|
@ -24,7 +24,7 @@ on:
|
|||
tags:
|
||||
- 'v*'
|
||||
env:
|
||||
go-version: 1.13
|
||||
go-version: 1.14
|
||||
app-name: cloud-game
|
||||
app-arch: x86_64
|
||||
jobs:
|
||||
|
|
|
|||
|
|
@ -7,8 +7,8 @@ import (
|
|||
"os/signal"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/coordinator"
|
||||
"github.com/giongto35/cloud-game/pkg/util/logging"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/coordinator"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util/logging"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/faiface/mainthread"
|
||||
config "github.com/giongto35/cloud-game/pkg/config/worker"
|
||||
"github.com/giongto35/cloud-game/pkg/util/logging"
|
||||
"github.com/giongto35/cloud-game/pkg/worker"
|
||||
config "github.com/giongto35/cloud-game/v2/pkg/config/worker"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util/logging"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/worker"
|
||||
"github.com/golang/glog"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
|
|
|||
39
go.mod
vendored
39
go.mod
vendored
|
|
@ -1,24 +1,35 @@
|
|||
module github.com/giongto35/cloud-game
|
||||
module github.com/giongto35/cloud-game/v2
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.43.0
|
||||
cloud.google.com/go v0.67.0 // indirect
|
||||
cloud.google.com/go/storage v1.12.0
|
||||
github.com/disintegration/imaging v1.6.2
|
||||
github.com/faiface/mainthread v0.0.0-20171120011319-8b78f0a41ae3
|
||||
github.com/gen2brain/x264-go v0.0.0-20200517120223-c08131f6fc8a
|
||||
github.com/gen2brain/x264-go v0.0.0-20200605131102-0523307cbe23
|
||||
github.com/go-gl/gl v0.0.0-20190320180904-bf2b1f2f34d7
|
||||
github.com/gofrs/uuid v3.2.0+incompatible
|
||||
github.com/gofrs/uuid v3.3.0+incompatible
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gorilla/websocket v1.4.0
|
||||
github.com/pion/webrtc/v2 v2.2.0
|
||||
github.com/prometheus/client_golang v1.1.0
|
||||
github.com/spf13/pflag v1.0.3
|
||||
github.com/google/uuid v1.1.2 // indirect
|
||||
github.com/gorilla/mux v1.8.0
|
||||
github.com/gorilla/websocket v1.4.2
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.1 // indirect
|
||||
github.com/pion/dtls/v2 v2.0.3 // indirect
|
||||
github.com/pion/quic v0.1.4 // indirect
|
||||
github.com/pion/sctp v1.7.11 // indirect
|
||||
github.com/pion/srtp v1.5.2 // indirect
|
||||
github.com/pion/webrtc/v2 v2.2.26
|
||||
github.com/prometheus/client_golang v1.7.1
|
||||
github.com/prometheus/common v0.14.0 // indirect
|
||||
github.com/prometheus/procfs v0.2.0 // indirect
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/veandco/go-sdl2 v0.4.4
|
||||
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
|
||||
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8
|
||||
golang.org/x/sys v0.0.0-20191218084908-4a24b4065292 // indirect
|
||||
golang.org/x/tools/gopls v0.4.2 // indirect
|
||||
gopkg.in/hraban/opus.v2 v2.0.0-20180426093920-0f2e0b4fc6cd
|
||||
golang.org/x/crypto v0.0.0-20200930160638-afb6bcd081ae
|
||||
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5
|
||||
golang.org/x/net v0.0.0-20200930145003-4acb6c075d10 // indirect
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f // indirect
|
||||
golang.org/x/tools v0.0.0-20200930213115-e57f6d466a48 // indirect
|
||||
google.golang.org/genproto v0.0.0-20200930140634-01fc692af84b // indirect
|
||||
gopkg.in/hraban/opus.v2 v2.0.0-20200710132758-e28f8214483b
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,9 @@ package config
|
|||
|
||||
import (
|
||||
"flag"
|
||||
"github.com/giongto35/cloud-game/pkg/emulator/libretro/image"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/v2/pkg/emulator/libretro/image"
|
||||
)
|
||||
|
||||
const DefaultSTUNTURN = `[{"urls":"stun:stun-turn.webgame2d.com:3478"},{"urls":"turn:stun-turn.webgame2d.com:3478","username":"root","credential":"root"}]`
|
||||
|
|
@ -81,9 +82,9 @@ var EmulatorConfig = map[string]EmulatorMeta{
|
|||
Height: 240,
|
||||
},
|
||||
"snes": {
|
||||
Path: "assets/emulator/libretro/cores/snes9x_libretro",
|
||||
Width: 256,
|
||||
Height: 224,
|
||||
Path: "assets/emulator/libretro/cores/snes9x_libretro",
|
||||
Width: 256,
|
||||
Height: 224,
|
||||
HasMultitap: true,
|
||||
},
|
||||
"mame": {
|
||||
|
|
@ -92,12 +93,12 @@ var EmulatorConfig = map[string]EmulatorMeta{
|
|||
Height: 160,
|
||||
},
|
||||
"n64": {
|
||||
Path: "assets/emulator/libretro/cores/mupen64plus_next_libretro",
|
||||
Config: "assets/emulator/libretro/cores/mupen64plus_next_libretro.cfg",
|
||||
Width: 320,
|
||||
Height: 240,
|
||||
Path: "assets/emulator/libretro/cores/mupen64plus_next_libretro",
|
||||
Config: "assets/emulator/libretro/cores/mupen64plus_next_libretro.cfg",
|
||||
Width: 320,
|
||||
Height: 240,
|
||||
IsGlAllowed: true,
|
||||
UsesLibCo: true,
|
||||
UsesLibCo: true,
|
||||
},
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package worker
|
||||
|
||||
import (
|
||||
"github.com/giongto35/cloud-game/pkg/monitoring"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/monitoring"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/cws"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
package coordinator
|
||||
|
||||
import (
|
||||
"github.com/giongto35/cloud-game/pkg/monitoring"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/monitoring"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ func NewDefaultConfig() Config {
|
|||
return Config{
|
||||
Port: 8800,
|
||||
PublicDomain: "http://localhost:8000",
|
||||
PingServer: "",
|
||||
PingServer: "",
|
||||
|
||||
MonitoringConfig: monitoring.ServerMonitoringConfig{
|
||||
Port: 6601,
|
||||
|
|
|
|||
|
|
@ -8,8 +8,8 @@ import (
|
|||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/monitoring"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/monitoring"
|
||||
"github.com/golang/glog"
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import (
|
|||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/pkg/util/gamelist"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util/gamelist"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/cws"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import (
|
|||
|
||||
type imageCache struct {
|
||||
image *image.RGBA
|
||||
w int
|
||||
h int
|
||||
w int
|
||||
h int
|
||||
}
|
||||
|
||||
var canvas = imageCache{
|
||||
|
|
@ -57,4 +57,3 @@ func getCanvas(w, h int) *image.RGBA {
|
|||
|
||||
return canvas.image
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -251,4 +251,3 @@ func BenchmarkNewMapDirect(b *testing.B) {
|
|||
p1, p2 = p2, p1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
package image
|
||||
|
||||
import (
|
||||
"golang.org/x/image/draw"
|
||||
"image"
|
||||
|
||||
"golang.org/x/image/draw"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ package nanoarch
|
|||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"log"
|
||||
)
|
||||
|
||||
import "C"
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
)
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ import (
|
|||
|
||||
"github.com/disintegration/imaging"
|
||||
"github.com/faiface/mainthread"
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/emulator/libretro/image"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/emulator/libretro/image"
|
||||
"github.com/go-gl/gl/v4.1-core/gl"
|
||||
"github.com/veandco/go-sdl2/sdl"
|
||||
)
|
||||
|
|
@ -148,9 +148,9 @@ func coreVideoRefresh(data unsafe.Pointer, width C.unsigned, height C.unsigned,
|
|||
return
|
||||
}
|
||||
// divide by 8333 to give us the equivalent of a 120fps resolution
|
||||
timestamp := uint32(time.Now().UnixNano() / 8333) + seed
|
||||
timestamp := uint32(time.Now().UnixNano()/8333) + seed
|
||||
|
||||
if (data == C.RETRO_HW_FRAME_BUFFER_VALID) {
|
||||
if data == C.RETRO_HW_FRAME_BUFFER_VALID {
|
||||
im := stdimage.NewNRGBA(stdimage.Rect(0, 0, int(width), int(height)))
|
||||
gl.BindFramebuffer(gl.FRAMEBUFFER, video.fbo)
|
||||
gl.ReadPixels(0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(im.Pix))
|
||||
|
|
@ -161,7 +161,7 @@ func coreVideoRefresh(data unsafe.Pointer, width C.unsigned, height C.unsigned,
|
|||
Stride: im.Stride,
|
||||
Rect: im.Rect,
|
||||
}
|
||||
NAEmulator.imageChannel <- GameFrame{ Image: rgba, Timestamp: timestamp }
|
||||
NAEmulator.imageChannel <- GameFrame{Image: rgba, Timestamp: timestamp}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -184,7 +184,7 @@ func coreVideoRefresh(data unsafe.Pointer, width C.unsigned, height C.unsigned,
|
|||
|
||||
// the image is pushed into a channel
|
||||
// where it will be distributed with fan-out
|
||||
NAEmulator.imageChannel <- GameFrame{ Image: outputImg, Timestamp: timestamp }
|
||||
NAEmulator.imageChannel <- GameFrame{Image: outputImg, Timestamp: timestamp}
|
||||
}
|
||||
|
||||
//export coreInputPoll
|
||||
|
|
@ -197,7 +197,7 @@ func coreInputState(port C.unsigned, device C.unsigned, index C.unsigned, id C.u
|
|||
if index > C.RETRO_DEVICE_INDEX_ANALOG_RIGHT || id > C.RETRO_DEVICE_ID_ANALOG_Y {
|
||||
return 0
|
||||
}
|
||||
axis := index * 2 + id
|
||||
axis := index*2 + id
|
||||
for k := range NAEmulator.controllersMap {
|
||||
value := NAEmulator.controllersMap[k][port].axes[axis]
|
||||
if value != 0 {
|
||||
|
|
@ -265,7 +265,7 @@ func coreGetCurrentFramebuffer() C.uintptr_t {
|
|||
|
||||
//export coreGetProcAddress
|
||||
func coreGetProcAddress(sym *C.char) C.retro_proc_address_t {
|
||||
return (C.retro_proc_address_t) (sdl.GLGetProcAddress(C.GoString(sym)))
|
||||
return (C.retro_proc_address_t)(sdl.GLGetProcAddress(C.GoString(sym)))
|
||||
}
|
||||
|
||||
//export coreEnvironment
|
||||
|
|
@ -327,7 +327,7 @@ func coreEnvironment(cmd C.unsigned, data unsafe.Pointer) C.bool {
|
|||
// fmt.Printf("[Env]: get variable: key:%v not found\n", key)
|
||||
return false
|
||||
case C.RETRO_ENVIRONMENT_SET_HW_RENDER:
|
||||
if (isGlAllowed) {
|
||||
if isGlAllowed {
|
||||
video.isGl = true
|
||||
// runtime.LockOSThread()
|
||||
video.hw = (*C.struct_retro_hw_render_callback)(data)
|
||||
|
|
@ -337,14 +337,14 @@ func coreEnvironment(cmd C.unsigned, data unsafe.Pointer) C.bool {
|
|||
}
|
||||
return false
|
||||
case C.RETRO_ENVIRONMENT_SET_CONTROLLER_INFO:
|
||||
if (multitap.supported) {
|
||||
if multitap.supported {
|
||||
info := (*[100]C.struct_retro_controller_info)(data)
|
||||
var i C.unsigned
|
||||
for i = 0; unsafe.Pointer(info[i].types) != nil; i++ {
|
||||
var j C.unsigned
|
||||
types := (*[100]C.struct_retro_controller_description)(unsafe.Pointer(info[i].types))
|
||||
for j = 0; j < info[i].num_types; j++ {
|
||||
if (C.GoString(types[j].desc) == "Multitap") {
|
||||
if C.GoString(types[j].desc) == "Multitap" {
|
||||
multitap.value = types[j].id
|
||||
return true
|
||||
}
|
||||
|
|
@ -363,6 +363,7 @@ func init() {
|
|||
}
|
||||
|
||||
var sdlInitialized = false
|
||||
|
||||
//export initVideo
|
||||
func initVideo() {
|
||||
// create_window()
|
||||
|
|
@ -442,14 +443,14 @@ func initVideo() {
|
|||
gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, video.tex, 0)
|
||||
|
||||
if video.hw.depth {
|
||||
gl.GenRenderbuffers(1, &video.rbo);
|
||||
gl.GenRenderbuffers(1, &video.rbo)
|
||||
gl.BindRenderbuffer(gl.RENDERBUFFER, video.rbo)
|
||||
if video.hw.stencil {
|
||||
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, video.base_width, video.base_height);
|
||||
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, video.rbo);
|
||||
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH24_STENCIL8, video.base_width, video.base_height)
|
||||
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_STENCIL_ATTACHMENT, gl.RENDERBUFFER, video.rbo)
|
||||
} else {
|
||||
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, video.base_width, video.base_height);
|
||||
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, video.rbo);
|
||||
gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT24, video.base_width, video.base_height)
|
||||
gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, video.rbo)
|
||||
}
|
||||
gl.BindRenderbuffer(gl.RENDERBUFFER, 0)
|
||||
}
|
||||
|
|
@ -469,7 +470,7 @@ func initVideo() {
|
|||
func deinitVideo() {
|
||||
C.bridge_context_reset(video.hw.context_destroy)
|
||||
if video.hw.depth {
|
||||
gl.DeleteRenderbuffers(1, &video.rbo);
|
||||
gl.DeleteRenderbuffers(1, &video.rbo)
|
||||
}
|
||||
gl.DeleteFramebuffers(1, &video.fbo)
|
||||
gl.DeleteTextures(1, &video.tex)
|
||||
|
|
@ -665,9 +666,9 @@ func coreLoadGame(filename string) {
|
|||
fmt.Println(" FPS: ", avi.timing.fps) /* FPS of video content. */
|
||||
fmt.Println("-----------------------------------")
|
||||
|
||||
video.max_width = int32(avi.geometry.max_width)
|
||||
video.max_height = int32(avi.geometry.max_height)
|
||||
video.base_width = int32(avi.geometry.base_width)
|
||||
video.max_width = int32(avi.geometry.max_width)
|
||||
video.max_height = int32(avi.geometry.max_height)
|
||||
video.base_width = int32(avi.geometry.base_width)
|
||||
video.base_height = int32(avi.geometry.base_height)
|
||||
if video.isGl {
|
||||
if usesLibCo {
|
||||
|
|
@ -681,12 +682,12 @@ func coreLoadGame(filename string) {
|
|||
}
|
||||
|
||||
func toggleMultitap() {
|
||||
if (multitap.supported && multitap.value != 0) {
|
||||
if multitap.supported && multitap.value != 0 {
|
||||
// Official SNES games only support a single multitap device
|
||||
// Most require it to be plugged in player 2 port
|
||||
// And Snes9X requires it to be "plugged" after the game is loaded
|
||||
// Control this from the browser since player 2 will stop working in some games if multitap is "plugged" in
|
||||
if (multitap.enabled) {
|
||||
if multitap.enabled {
|
||||
C.bridge_retro_set_controller_port_device(retroSetControllerPortDevice, 1, C.RETRO_DEVICE_JOYPAD)
|
||||
} else {
|
||||
C.bridge_retro_set_controller_port_device(retroSetControllerPortDevice, 1, multitap.value)
|
||||
|
|
@ -806,5 +807,5 @@ func setRotation(rotation int) {
|
|||
video.rotation = image.Angle(rotation)
|
||||
rotationFn = image.GetRotation(video.rotation)
|
||||
NAEmulator.meta.Rotation = rotationFn
|
||||
log.Printf("[Env]: the game video is rotated %v°", map[int]int{0: 0, 1: 90, 2: 180, 3: 270}[rotation])
|
||||
log.Printf("[Env]: the game video is rotated %v°", map[int]int{0: 0, 1: 90, 2: 180, 3: 270}[rotation])
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package emulator
|
||||
|
||||
import "github.com/giongto35/cloud-game/pkg/config"
|
||||
import "github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
|
||||
// CloudEmulator is the interface of cloud emulator. Currently NES emulator and RetroArch implements this in codebase
|
||||
type CloudEmulator interface {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import (
|
|||
"runtime/debug"
|
||||
|
||||
"github.com/gen2brain/x264-go"
|
||||
"github.com/giongto35/cloud-game/pkg/encoder"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/encoder"
|
||||
)
|
||||
|
||||
const chanSize = 2
|
||||
|
|
@ -30,7 +30,7 @@ type H264Encoder struct {
|
|||
func NewH264Encoder(width, height, fps int) (encoder.Encoder, error) {
|
||||
v := &H264Encoder{
|
||||
Output: make(chan encoder.OutFrame, 5*chanSize),
|
||||
Input: make(chan encoder.InFrame, chanSize),
|
||||
Input: make(chan encoder.InFrame, chanSize),
|
||||
done: make(chan struct{}),
|
||||
|
||||
buf: bytes.NewBuffer(make([]byte, 0)),
|
||||
|
|
@ -80,7 +80,7 @@ func (v *H264Encoder) startLooping() {
|
|||
if err != nil {
|
||||
log.Println("err encoding ", img.Image, " using h264")
|
||||
}
|
||||
v.Output <- encoder.OutFrame{ Data: v.buf.Bytes(), Timestamp: img.Timestamp }
|
||||
v.Output <- encoder.OutFrame{Data: v.buf.Bytes(), Timestamp: img.Timestamp}
|
||||
v.buf.Reset()
|
||||
}
|
||||
close(v.Output)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ type OutFrame struct {
|
|||
}
|
||||
|
||||
type Encoder interface {
|
||||
GetInputChan() chan InFrame
|
||||
GetInputChan() chan InFrame
|
||||
GetOutputChan() chan OutFrame
|
||||
Stop()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"log"
|
||||
"unsafe"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/encoder"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/encoder"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
)
|
||||
|
||||
// https://chromium.googlesource.com/webm/libvpx/+/master/examples/simple_encoder.c
|
||||
|
|
@ -65,7 +65,7 @@ type VpxEncoder struct {
|
|||
func NewVpxEncoder(w, h, fps, bitrate, keyframe int) (encoder.Encoder, error) {
|
||||
v := &VpxEncoder{
|
||||
Output: make(chan encoder.OutFrame, 5*chanSize),
|
||||
Input: make(chan encoder.InFrame, chanSize),
|
||||
Input: make(chan encoder.InFrame, chanSize),
|
||||
done: make(chan struct{}),
|
||||
|
||||
// C
|
||||
|
|
@ -152,7 +152,7 @@ func (v *VpxEncoder) startLooping() {
|
|||
if len(v.Output) >= cap(v.Output) {
|
||||
continue
|
||||
}
|
||||
v.Output <- encoder.OutFrame{ Data: bs, Timestamp: img.Timestamp }
|
||||
v.Output <- encoder.OutFrame{Data: bs, Timestamp: img.Timestamp}
|
||||
}
|
||||
close(v.Output)
|
||||
close(v.done)
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"os/user"
|
||||
"unsafe"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
)
|
||||
|
||||
// https://stackoverflow.com/questions/9465815/rgb-to-yuv420-algorithm-efficiency
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
)
|
||||
|
||||
type GameInfo struct {
|
||||
|
|
|
|||
|
|
@ -10,8 +10,8 @@ import (
|
|||
"runtime/debug"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/pion/webrtc/v2"
|
||||
"github.com/pion/webrtc/v2/pkg/media"
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import (
|
|||
"log"
|
||||
"strconv"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/pkg/webrtc"
|
||||
"github.com/giongto35/cloud-game/pkg/worker/room"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/cws"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/webrtc"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/worker/room"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
|
|
@ -265,25 +265,25 @@ func (h *Handler) RouteCoordinator() {
|
|||
return req
|
||||
})
|
||||
|
||||
oClient.Receive(
|
||||
"multitap",
|
||||
func(resp cws.WSPacket) (req cws.WSPacket) {
|
||||
log.Println("Received a multitap toggle from coordinator")
|
||||
req.ID = "multitap"
|
||||
req.Data = "ok"
|
||||
if resp.RoomID != "" {
|
||||
room := h.getRoom(resp.RoomID)
|
||||
err := room.ToggleMultitap()
|
||||
if err != nil {
|
||||
log.Println("[!] Could not toggle multitap state: ", err)
|
||||
req.Data = "error"
|
||||
}
|
||||
} else {
|
||||
oClient.Receive(
|
||||
"multitap",
|
||||
func(resp cws.WSPacket) (req cws.WSPacket) {
|
||||
log.Println("Received a multitap toggle from coordinator")
|
||||
req.ID = "multitap"
|
||||
req.Data = "ok"
|
||||
if resp.RoomID != "" {
|
||||
room := h.getRoom(resp.RoomID)
|
||||
err := room.ToggleMultitap()
|
||||
if err != nil {
|
||||
log.Println("[!] Could not toggle multitap state: ", err)
|
||||
req.Data = "error"
|
||||
}
|
||||
} else {
|
||||
req.Data = "error"
|
||||
}
|
||||
|
||||
return req
|
||||
})
|
||||
return req
|
||||
})
|
||||
|
||||
oClient.Receive(
|
||||
"terminateSession",
|
||||
|
|
|
|||
|
|
@ -8,13 +8,13 @@ import (
|
|||
"path"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/config/worker"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config/worker"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/pkg/webrtc"
|
||||
storage "github.com/giongto35/cloud-game/pkg/worker/cloud-storage"
|
||||
"github.com/giongto35/cloud-game/pkg/worker/room"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/webrtc"
|
||||
storage "github.com/giongto35/cloud-game/v2/pkg/worker/cloud-storage"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/worker/room"
|
||||
"github.com/gorilla/websocket"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,12 +4,12 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/encoder"
|
||||
"github.com/giongto35/cloud-game/pkg/encoder/h264encoder"
|
||||
vpxencoder "github.com/giongto35/cloud-game/pkg/encoder/vpx-encoder"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/pkg/webrtc"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/encoder"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/encoder/h264encoder"
|
||||
vpxencoder "github.com/giongto35/cloud-game/v2/pkg/encoder/vpx-encoder"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/webrtc"
|
||||
"gopkg.in/hraban/opus.v2"
|
||||
)
|
||||
|
||||
|
|
@ -165,7 +165,7 @@ func (r *Room) startVideo(width, height int, videoEncoderType string) {
|
|||
// fanout imageChannel
|
||||
if webRTC.IsConnected() {
|
||||
// NOTE: can block here
|
||||
webRTC.ImageChannel <- webrtc.WebFrame{ Data: data.Data, Timestamp: data.Timestamp }
|
||||
webRTC.ImageChannel <- webrtc.WebFrame{Data: data.Data, Timestamp: data.Timestamp}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -173,7 +173,7 @@ func (r *Room) startVideo(width, height int, videoEncoderType string) {
|
|||
|
||||
for image := range r.imageChannel {
|
||||
if len(einput) < cap(einput) {
|
||||
einput <- encoder.InFrame{ Image: image.Image, Timestamp: image.Timestamp }
|
||||
einput <- encoder.InFrame{Image: image.Image, Timestamp: image.Timestamp}
|
||||
}
|
||||
}
|
||||
log.Println("Room ", r.ID, " video channel closed")
|
||||
|
|
|
|||
|
|
@ -16,15 +16,15 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config/worker"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config/worker"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/emulator"
|
||||
"github.com/giongto35/cloud-game/pkg/emulator/libretro/nanoarch"
|
||||
"github.com/giongto35/cloud-game/pkg/util"
|
||||
"github.com/giongto35/cloud-game/pkg/util/gamelist"
|
||||
"github.com/giongto35/cloud-game/pkg/webrtc"
|
||||
storage "github.com/giongto35/cloud-game/pkg/worker/cloud-storage"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/emulator"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/emulator/libretro/nanoarch"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/util/gamelist"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/webrtc"
|
||||
storage "github.com/giongto35/cloud-game/v2/pkg/worker/cloud-storage"
|
||||
)
|
||||
|
||||
// Room is a game session. multi webRTC sessions can connect to a same game.
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package worker
|
||||
|
||||
import "github.com/giongto35/cloud-game/pkg/webrtc"
|
||||
import "github.com/giongto35/cloud-game/v2/pkg/webrtc"
|
||||
|
||||
// Session represents a session connected from the browser to the current server
|
||||
// It requires one connection to browser and one connection to the coordinator
|
||||
|
|
|
|||
|
|
@ -10,12 +10,12 @@ import (
|
|||
"strconv"
|
||||
"time"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/config"
|
||||
"github.com/giongto35/cloud-game/pkg/config/worker"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/config/worker"
|
||||
"golang.org/x/crypto/acme"
|
||||
"golang.org/x/crypto/acme/autocert"
|
||||
|
||||
"github.com/giongto35/cloud-game/pkg/monitoring"
|
||||
"github.com/giongto35/cloud-game/v2/pkg/monitoring"
|
||||
"github.com/golang/glog"
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue