Remove unnecessary code

This commit is contained in:
giongto35 2019-04-06 01:05:07 +08:00
parent 47de10c465
commit 0dd99f6a69
8 changed files with 14 additions and 39 deletions

11
main.go
View file

@ -30,22 +30,13 @@ func startGame(path string, imageChannel chan *image.RGBA, inputChannel chan int
}
func main() {
// imageChannel := make(chan *image.RGBA, 100)
fmt.Println("http://localhost:8000")
// webRTC = webrtc.NewWebRTC()
router := mux.NewRouter()
router.HandleFunc("/", getWeb).Methods("GET")
router.HandleFunc("/session", postSession).Methods("POST")
// go http.ListenAndServe(":8000", router)
http.ListenAndServe(":8000", router)
// start screenshot loop, wait for connection
// go screenshotLoop(imageChannel)
// startGame("games/"+gameName, imageChannel, webRTC.InputChannel)
// time.Sleep(time.Minute)
}
func getWeb(w http.ResponseWriter, r *http.Request) {
@ -90,7 +81,5 @@ func screenshotLoop(imageChannel chan *image.RGBA, webRTC *webrtc.WebRTC) {
yuv := util.RgbaToYuv(image)
webRTC.ImageChannel <- yuv
}
// time.Sleep(10 * time.Millisecond)
// time.Sleep(time.Duration(1000 / FPS) * time.Millisecond)
}
}

View file

@ -1,3 +1,4 @@
// credit to https://github.com/fogleman/nes
package ui
import (
@ -21,11 +22,11 @@ type Director struct {
timestamp float64
imageChannel chan *image.RGBA
inputChannel chan int
webRTC *webrtc.WebRTC
webRTC *webrtc.WebRTC
}
func NewDirector(imageChannel chan *image.RGBA, inputChannel chan int, webRTC *webrtc.WebRTC) *Director {
// func NewDirector(audio *Audio, imageChannel chan *image.RGBA, inputChannel chan int) *Director {
// func NewDirector(audio *Audio, imageChannel chan *image.RGBA, inputChannel chan int) *Director {
director := Director{}
// director.audio = audio
director.imageChannel = imageChannel

View file

@ -1,3 +1,4 @@
// credit to https://github.com/fogleman/nes
package ui
import (
@ -30,14 +31,6 @@ func init() {
fontMask = mask
}
func CreateGenericThumbnail(text string) image.Image {
im := image.NewRGBA(image.Rect(0, 0, 256, 240))
draw.Draw(im, im.Rect, &image.Uniform{color.Black}, image.ZP, draw.Src)
DrawCenteredText(im, text, 1, 2, color.RGBA{128, 128, 128, 255})
DrawCenteredText(im, text, 0, 0, color.White)
return im
}
func WordWrap(text string, maxLength int) []string {
var rows []string
words := strings.Fields(text)

View file

@ -1,3 +1,4 @@
// credit to https://github.com/fogleman/nes
package ui
import (

View file

@ -1,3 +1,4 @@
// credit to https://github.com/fogleman/nes
package ui
import (
@ -22,6 +23,7 @@ func init() {
}
func Run(paths []string, imageChannel chan *image.RGBA, inputChannel chan int, webRTC *webrtc.WebRTC) {
// TODO: stream audio
// initialize audio
// portaudio.Initialize()
// defer portaudio.Terminate()

View file

@ -1,3 +1,4 @@
// credit to https://github.com/fogleman/nes
package ui
import (
@ -28,14 +29,6 @@ func init() {
homeDir = u.HomeDir
}
func thumbnailURL(hash string) string {
return "http://www.michaelfogleman.com/static/nes/" + hash + ".png"
}
func thumbnailPath(hash string) string {
return homeDir + "/.nes/thumbnail/" + hash + ".png"
}
func sramPath(hash string) string {
return homeDir + "/.nes/sram/" + hash + ".dat"
}

View file

@ -1,3 +1,4 @@
// credit to https://github.com/poi5305/go-yuv2webRTC/blob/master/webrtc/webrtc.go
package util
import (

View file

@ -1,3 +1,4 @@
// credit to https://github.com/poi5305/go-yuv2webRTC/blob/master/webrtc/webrtc.go
package webrtc
import (
@ -9,7 +10,6 @@ import (
"io/ioutil"
"math/rand"
"strconv"
"time"
vpxEncoder "github.com/giongto35/game-online/vpx-encoder"
"github.com/pions/webrtc"
@ -21,11 +21,6 @@ var config = webrtc.Configuration{ICEServers: []webrtc.ICEServer{{URLs: []string
// Allows compressing offer/answer to bypass terminal input limits.
const compress = false
func init() {
//api.mediaEngine.RegisterDefaultCodecs()
//webrtc.RegisterDefaultCodecs()
}
func zip(in []byte) []byte {
var b bytes.Buffer
gz := gzip.NewWriter(&b)
@ -97,8 +92,8 @@ func Decode(in string, obj interface{}) {
// NewWebRTC create
func NewWebRTC() *WebRTC {
w := &WebRTC{
ImageChannel: make(chan []byte, 2),
InputChannel: make(chan int, 2),
ImageChannel: make(chan []byte, 100),
InputChannel: make(chan int, 100),
}
return w
}
@ -108,7 +103,7 @@ type WebRTC struct {
connection *webrtc.PeerConnection
encoder *vpxEncoder.VpxEncoder
isConnected bool
isClosed bool
isClosed bool
// for yuvI420 image
ImageChannel chan []byte
InputChannel chan int
@ -126,7 +121,7 @@ func (w *WebRTC) StartClient(remoteSession string, width, height int) (string, e
// reset client
if w.isConnected {
w.StopClient()
time.Sleep(2 * time.Second)
//time.Sleep(2 * time.Second)
}
encoder, err := vpxEncoder.NewVpxEncoder(width, height, 20, 1200, 5)