Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2] DRAFT: This is the branch tracking v2 Work #66

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ingest/src/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ pub fn read_stream_key(startup: bool, stream_key_env: Option<&str>) -> Vec<u8> {
if !stream_key.is_empty() {
let key = stream_key.as_bytes().to_vec();
print_stream_key(key.to_vec());
fs::write("hash", hex::encode(&stream_key))
fs::write("hash", hex::encode(stream_key))
.expect("Unable to write stream key to hash file");
return key;
}
Expand Down
2 changes: 1 addition & 1 deletion webrtc/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ vendor/
# ide
/.idea/
# actual binary
/lightspeed-webrtc
/webrtc
2 changes: 1 addition & 1 deletion webrtc/go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/GRVYDEV/lightspeed-webrtc
module github.com/GRVYDEV/Project-Lightspeed/webrtc

go 1.15

Expand Down
73 changes: 73 additions & 0 deletions webrtc/ingest/ingest.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package ingest

import (
"fmt"
"io"
"log"
"os/exec"
)

type IngestServer struct {
cmd *exec.Cmd
}

type IngestServerConfig struct {
Path string
Addr string
StreamKey string
LogFile string
}

func NewIngestServer(config IngestServerConfig) *IngestServer {
args := make([]string, 0)
if config.Addr != "" {
args = append(args, fmt.Sprintf("-a=%s", config.Addr))
}
if config.StreamKey != "" {
args = append(args, fmt.Sprintf("-k=%s", config.StreamKey))
}
if config.LogFile != "" {
args = append(args, fmt.Sprintf("-l=%s", config.LogFile))
}

return &IngestServer{
cmd: exec.Command(config.Path, args...),
}
}

// StartIngest tries to start the ingest server and logs its stdout
func (s *IngestServer) Start() error {
stdout, err := s.cmd.StdoutPipe()
if err != nil {
return err
}
err = s.cmd.Start()
if err != nil {
return err
}

//TODO Handle shutdown logic
go s.logger(stdout)
go s.waitForExit()
return nil
}

func (s *IngestServer) logger(stdout io.ReadCloser) {
for {
buf := make([]byte, 1096)
_, err := stdout.Read(buf)
if err == io.EOF {
break
}
line := string(buf)
fmt.Print(line)
}
}

func (s *IngestServer) waitForExit() error {
err := s.cmd.Wait()
if err != nil {
log.Fatal(err)
}
return err
}
35 changes: 27 additions & 8 deletions webrtc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import (
"strings"
"sync"

"github.com/GRVYDEV/lightspeed-webrtc/ws"
"github.com/GRVYDEV/Project-Lightspeed/webrtc/ingest"
"github.com/GRVYDEV/Project-Lightspeed/webrtc/ws"
"github.com/gorilla/websocket"

"github.com/pion/interceptor"
Expand All @@ -23,13 +24,19 @@ import (
)

var (
addr = flag.String("addr", "localhost", "http service address")
ip = flag.String("ip", "none", "IP address for webrtc")
wsPort = flag.Int("ws-port", 8080, "Port for websocket")
rtpPort = flag.Int("rtp-port", 65535, "Port for RTP")
ports = flag.String("ports", "20000-20500", "Port range for webrtc")
sslCert = flag.String("ssl-cert", "", "Ssl cert for websocket (optional)")
sslKey = flag.String("ssl-key", "", "Ssl key for websocket (optional)")
addr = flag.String("addr", "localhost", "http service address")
ip = flag.String("ip", "none", "IP address for webrtc")
wsPort = flag.Int("ws-port", 8080, "Port for websocket")
rtpPort = flag.Int("rtp-port", 65535, "Port for RTP")
ports = flag.String("ports", "20000-20500", "Port range for webrtc")
sslCert = flag.String("ssl-cert", "", "Ssl cert for websocket (optional)")
sslKey = flag.String("ssl-key", "", "Ssl key for websocket (optional)")

ingestPath = flag.String("ingest-path", "lightspeed-ingest", "Path to the lightspeed-ingest binary")
ingestAddr = flag.String("ingest-addr", "", "The address for the ingest server to bind to default 0.0.0.0")
ingestStreamKey = flag.String("ingest-stream-key", "", "The stream key for the ingest server to use")
ingestLogFile = flag.String("ingest-log-file", "", "A path to store ingest logs")

upgrader = websocket.Upgrader{
CheckOrigin: func(r *http.Request) bool { return true },
}
Expand All @@ -45,6 +52,18 @@ func main() {
flag.Parse()
log.SetFlags(0)

iServer := ingest.NewIngestServer(ingest.IngestServerConfig{
Path: *ingestPath,
Addr: *ingestAddr,
StreamKey: *ingestStreamKey,
LogFile: *ingestLogFile,
})

err := iServer.Start()
if err != nil {
log.Fatalf("error starting ingest server %v", err)
}

// Open a UDP Listener for RTP Packets on port 65535
listener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP(*addr), Port: *rtpPort})
if err != nil {
Expand Down