From 0dd99f6a69dea54199a622ecfe1a9e6e92d4fa6e Mon Sep 17 00:00:00 2001 From: giongto35 Date: Sat, 6 Apr 2019 01:05:07 +0800 Subject: [PATCH] Remove unnecessary code --- main.go | 11 ----------- ui/director.go | 5 +++-- ui/font.go | 9 +-------- ui/gameview.go | 1 + ui/run.go | 2 ++ ui/util.go | 9 +-------- util/util.go | 1 + webrtc/webrtc.go | 15 +++++---------- 8 files changed, 14 insertions(+), 39 deletions(-) diff --git a/main.go b/main.go index 16a87b74..a908cadd 100644 --- a/main.go +++ b/main.go @@ -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) } } diff --git a/ui/director.go b/ui/director.go index 6afcd6f3..85857bcd 100644 --- a/ui/director.go +++ b/ui/director.go @@ -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 diff --git a/ui/font.go b/ui/font.go index 10291bc4..882b3a68 100644 --- a/ui/font.go +++ b/ui/font.go @@ -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) diff --git a/ui/gameview.go b/ui/gameview.go index 313b3173..205be30b 100644 --- a/ui/gameview.go +++ b/ui/gameview.go @@ -1,3 +1,4 @@ +// credit to https://github.com/fogleman/nes package ui import ( diff --git a/ui/run.go b/ui/run.go index 047edf25..d5712d16 100644 --- a/ui/run.go +++ b/ui/run.go @@ -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() diff --git a/ui/util.go b/ui/util.go index dc0e20eb..53815df5 100644 --- a/ui/util.go +++ b/ui/util.go @@ -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" } diff --git a/util/util.go b/util/util.go index a218574d..0a9fc15e 100644 --- a/util/util.go +++ b/util/util.go @@ -1,3 +1,4 @@ +// credit to https://github.com/poi5305/go-yuv2webRTC/blob/master/webrtc/webrtc.go package util import ( diff --git a/webrtc/webrtc.go b/webrtc/webrtc.go index 095109af..74ef67e2 100644 --- a/webrtc/webrtc.go +++ b/webrtc/webrtc.go @@ -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)