mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 19:42:20 +00:00
Make telnet output configurable
This commit is contained in:
parent
e640450d98
commit
61ae490a5d
@ -68,6 +68,23 @@ srt:
|
|||||||
# Max number of active SRT connections
|
# Max number of active SRT connections
|
||||||
#maxClients: 64
|
#maxClients: 64
|
||||||
|
|
||||||
|
## Telnet server ##
|
||||||
|
# The telnet server receive the stream and emit the stream as ASCII-art.
|
||||||
|
telnet:
|
||||||
|
# By default, this easter egg is disabled.
|
||||||
|
# You must enable it to use it.
|
||||||
|
#enable: false
|
||||||
|
|
||||||
|
#listenAddress: :4242
|
||||||
|
|
||||||
|
# Size is in characters. It is recommended to keep a 16x9 format.
|
||||||
|
#width: 80
|
||||||
|
#height: 45
|
||||||
|
|
||||||
|
# Time in milliseconds that we should sleep between two images. By default, 20 FPS. Displaying text takes time...
|
||||||
|
#delay: 50
|
||||||
|
|
||||||
|
|
||||||
## Web server ##
|
## Web server ##
|
||||||
# The web server serves a WebRTC player.
|
# The web server serves a WebRTC player.
|
||||||
web:
|
web:
|
||||||
|
@ -3,6 +3,7 @@ package config
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
|
"gitlab.crans.org/nounous/ghostream/stream/telnet"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
@ -25,6 +26,7 @@ type Config struct {
|
|||||||
Forwarding forwarding.Options
|
Forwarding forwarding.Options
|
||||||
Monitoring monitoring.Options
|
Monitoring monitoring.Options
|
||||||
Srt srt.Options
|
Srt srt.Options
|
||||||
|
Telnet telnet.Options
|
||||||
Web web.Options
|
Web web.Options
|
||||||
WebRTC webrtc.Options
|
WebRTC webrtc.Options
|
||||||
}
|
}
|
||||||
@ -56,6 +58,13 @@ func New() *Config {
|
|||||||
ListenAddress: ":9710",
|
ListenAddress: ":9710",
|
||||||
MaxClients: 64,
|
MaxClients: 64,
|
||||||
},
|
},
|
||||||
|
Telnet: telnet.Options{
|
||||||
|
Enabled: false,
|
||||||
|
ListenAddress: ":4242",
|
||||||
|
Width: 80,
|
||||||
|
Height: 45,
|
||||||
|
Delay: 50,
|
||||||
|
},
|
||||||
Web: web.Options{
|
Web: web.Options{
|
||||||
Enabled: true,
|
Enabled: true,
|
||||||
Favicon: "/static/img/favicon.svg",
|
Favicon: "/static/img/favicon.svg",
|
||||||
|
2
main.go
2
main.go
@ -5,6 +5,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"gitlab.crans.org/nounous/ghostream/stream/telnet"
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"gitlab.crans.org/nounous/ghostream/auth"
|
"gitlab.crans.org/nounous/ghostream/auth"
|
||||||
@ -50,6 +51,7 @@ func main() {
|
|||||||
go forwarding.Serve(forwardingChannel, cfg.Forwarding)
|
go forwarding.Serve(forwardingChannel, cfg.Forwarding)
|
||||||
go monitoring.Serve(&cfg.Monitoring)
|
go monitoring.Serve(&cfg.Monitoring)
|
||||||
go srt.Serve(&cfg.Srt, authBackend, forwardingChannel, webrtcChannel)
|
go srt.Serve(&cfg.Srt, authBackend, forwardingChannel, webrtcChannel)
|
||||||
|
go telnet.Serve(&cfg.Telnet)
|
||||||
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
|
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
|
||||||
go webrtc.Serve(remoteSdpChan, localSdpChan, webrtcChannel, &cfg.WebRTC)
|
go webrtc.Serve(remoteSdpChan, localSdpChan, webrtcChannel, &cfg.WebRTC)
|
||||||
|
|
||||||
|
@ -8,20 +8,34 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func asciiChar(pixel byte) string {
|
var (
|
||||||
asciiChars := []string{"@", "#", "$", "%", "?", "*", "+", ";", ":", ",", "."}
|
Cfg *Options
|
||||||
return asciiChars[pixel/25]
|
currentMessage *string
|
||||||
|
)
|
||||||
|
|
||||||
|
// Options holds telnet package configuration
|
||||||
|
type Options struct {
|
||||||
|
Enabled bool
|
||||||
|
ListenAddress string
|
||||||
|
Width int
|
||||||
|
Height int
|
||||||
|
Delay int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ServeAsciiArt starts a telnet server that send all packets as ASCII Art
|
func Serve(config *Options) {
|
||||||
func ServeAsciiArt(reader io.Reader) {
|
Cfg = config
|
||||||
listener, err := net.Listen("tcp", ":4242")
|
|
||||||
if err != nil {
|
if !Cfg.Enabled {
|
||||||
log.Printf("Error while listening to the port 4242: %s", err)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
currentMessage := ""
|
listener, err := net.Listen("tcp", Cfg.ListenAddress)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error while listening to the address %s: %s", Cfg.ListenAddress, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
currentMessage = new(string)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
@ -32,7 +46,7 @@ func ServeAsciiArt(reader io.Reader) {
|
|||||||
}
|
}
|
||||||
go func(s net.Conn) {
|
go func(s net.Conn) {
|
||||||
for {
|
for {
|
||||||
n, err := s.Write([]byte(currentMessage))
|
n, err := s.Write([]byte(*currentMessage))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error while sending TCP data: %s", err)
|
log.Printf("Error while sending TCP data: %s", err)
|
||||||
_ = s.Close()
|
_ = s.Close()
|
||||||
@ -42,13 +56,28 @@ func ServeAsciiArt(reader io.Reader) {
|
|||||||
_ = s.Close()
|
_ = s.Close()
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
time.Sleep(time.Duration(Cfg.Delay) * time.Millisecond)
|
||||||
}
|
}
|
||||||
}(s)
|
}(s)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
buff := make([]byte, 2048)
|
log.Println("Telnet server initialized")
|
||||||
|
}
|
||||||
|
|
||||||
|
func asciiChar(pixel byte) string {
|
||||||
|
asciiChars := []string{"@", "#", "$", "%", "?", "*", "+", ";", ":", ",", ".", " "}
|
||||||
|
return asciiChars[(255-pixel)/23]
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeAsciiArt starts a telnet server that send all packets as ASCII Art
|
||||||
|
func ServeAsciiArt(reader io.ReadCloser) {
|
||||||
|
if !Cfg.Enabled {
|
||||||
|
_ = reader.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
buff := make([]byte, Cfg.Width*Cfg.Height)
|
||||||
header := "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
header := "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||||
for {
|
for {
|
||||||
n, _ := reader.Read(buff)
|
n, _ := reader.Read(buff)
|
||||||
@ -56,13 +85,13 @@ func ServeAsciiArt(reader io.Reader) {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
imageStr := ""
|
imageStr := ""
|
||||||
for j := 0; j < 18; j++ {
|
for j := 0; j < Cfg.Height; j++ {
|
||||||
for i := 0; i < 32; i++ {
|
for i := 0; i < Cfg.Width; i++ {
|
||||||
pixel := buff[32*j+i]
|
pixel := buff[Cfg.Width*j+i]
|
||||||
imageStr += asciiChar(pixel) + asciiChar(pixel)
|
imageStr += asciiChar(pixel) + asciiChar(pixel)
|
||||||
}
|
}
|
||||||
imageStr += "\n"
|
imageStr += "\n"
|
||||||
}
|
}
|
||||||
currentMessage = header + imageStr
|
*currentMessage = header + imageStr
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package webrtc
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"fmt"
|
||||||
"gitlab.crans.org/nounous/ghostream/stream/telnet"
|
"gitlab.crans.org/nounous/ghostream/stream/telnet"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
@ -53,7 +54,7 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
"-f", "rtp", "rtp://127.0.0.1:5004",
|
"-f", "rtp", "rtp://127.0.0.1:5004",
|
||||||
"-vn", "-acodec", "libopus", "-cpu-used", "5", "-deadline", "1", "-qmin", "10", "-qmax", "42", "-error-resilient", "1", "-auto-alt-ref", "1",
|
"-vn", "-acodec", "libopus", "-cpu-used", "5", "-deadline", "1", "-qmin", "10", "-qmax", "42", "-error-resilient", "1", "-auto-alt-ref", "1",
|
||||||
"-f", "rtp", "rtp://127.0.0.1:5005",
|
"-f", "rtp", "rtp://127.0.0.1:5005",
|
||||||
"-an", "-f", "rawvideo", "-vf", "scale=32x18", "-pix_fmt", "gray", "pipe:1")
|
"-an", "-f", "rawvideo", "-vf", fmt.Sprintf("scale=%dx%d", telnet.Cfg.Width, telnet.Cfg.Height), "-pix_fmt", "gray", "pipe:1")
|
||||||
|
|
||||||
input, err := ffmpeg.StdinPipe()
|
input, err := ffmpeg.StdinPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user