-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
60 lines (52 loc) · 1.16 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"flag"
"io"
"log"
"net"
"net/http"
_ "net/http/pprof"
"os"
"time"
)
var (
addr = flag.String("l", "127.0.0.1:18090", "Listening address")
iface = flag.String("i", "eth0", "Listening multicast interface")
timeout = flag.Duration("o", time.Second, "rtp read timeout")
debug = flag.Bool("d", false, "enable debug log")
)
var inf *net.Interface
var debugLog *log.Logger
func main() {
if os.Getppid() == 1 {
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))
} else {
log.SetFlags(log.Lshortfile | log.LstdFlags)
}
flag.Parse()
if *debug {
debugLog = log.New(os.Stderr, "", log.Flags())
} else {
debugLog = log.New(io.Discard, "", log.Flags())
}
var err error
inf, err = net.InterfaceByName(*iface)
if err != nil {
log.Printf("multicast disabled: %v", err)
}
var mux http.ServeMux
mux.HandleFunc("/r/", handleHLS)
mux.HandleFunc("/rtp/", handleRTP)
if *debug {
mux.HandleFunc("/debug/pprof/", http.DefaultServeMux.ServeHTTP)
}
SdNotify("READY=1")
go func() {
for {
updateStatus()
time.Sleep(5 * time.Second)
}
}()
log.Printf("Listening on %s", *addr)
log.Fatal(http.ListenAndServe(*addr, &mux))
}