-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.go
76 lines (59 loc) · 1.58 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
import (
"crypto/rand"
"flag"
"fmt"
"io"
"log"
"os"
// TODO: switch to joy5?
"github.com/geekgonecrazy/prismplus/helpers"
"github.com/geekgonecrazy/prismplus/streamers"
rtmp "github.com/geekgonecrazy/rtmp-lib"
)
var (
bind = flag.String("bind", ":1935", "bind address")
adminKey = flag.String("adminKey", "", "Admin key. If none passed one will be created")
dataPath = flag.String("dataPath", "", "Path for data")
)
func main() {
flag.Parse()
if *adminKey == "" {
uuid, err := helpers.NewUUID()
if err != nil {
fmt.Println("Can't generate admin authorization key:", err)
os.Exit(1)
}
*adminKey = uuid
log.Println("Admin Authorization Key Generated:", *adminKey)
}
streamers.Setup(*dataPath)
fmt.Println("Starting RTMP server...")
config := &rtmp.Config{
ChunkSize: 128,
BufferSize: 0,
}
server := rtmp.NewServer(config)
server.Addr = *bind
server.HandlePublish = rtmpConnectionHandler
go apiServer()
fmt.Println("Waiting for incoming connection...")
err := server.ListenAndServe()
if err != nil {
fmt.Println(err)
os.Exit(1)
}
}
// newUUID generates a random UUID according to the RFC 4122, https://play.golang.org/p/4FkNSiUDMg
func newUUID() (string, error) {
uuid := make([]byte, 16)
n, err := io.ReadFull(rand.Reader, uuid)
if n != len(uuid) || err != nil {
return "", err
}
// variant bits; see section 4.1.1
uuid[8] = uuid[8]&^0xc0 | 0x80
// version 4 (pseudo-random); see section 4.1.3
uuid[6] = uuid[6]&^0xf0 | 0x40
return fmt.Sprintf("%x-%x-%x-%x-%x", uuid[0:4], uuid[4:6], uuid[6:8], uuid[8:10], uuid[10:]), nil
}