-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
77 lines (67 loc) · 1.29 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
77
package rtp
import (
"fmt"
. "github.com/Monibuca/engine"
. "github.com/mask-pp/plugin-rtp/transport"
"golang.org/x/sync/errgroup"
"log"
)
var (
config = struct {
ListenPorts string
AutoPull bool
Timeout int
Reconnect bool
}{"6000:6000", false, 0, false}
)
func init() {
InstallPlugin(&PluginConfig{
Name: "RTP",
Type: PLUGIN_PUBLISHER | PLUGIN_HOOK,
Config: &config,
Run: runPlugin,
HotConfig: map[string]func(interface{}){
"AutoPull": func(value interface{}) {
config.AutoPull = value.(bool)
},
},
})
}
func runPlugin() {
start, end, err := SplitPorts(config.ListenPorts)
if err != nil {
log.Fatal(err)
}
var e errgroup.Group
for ; start <= end; start++ {
start := start
e.Go(func() error {
if IsPortInUse(start) {
return fmt.Errorf("RTSP port[%d] In Use", start)
}
return ListenRtp(uint16(start))
})
}
if err = e.Wait(); err != nil {
log.Fatal(err)
}
}
// 启动一套rtp数据接收生产线
func ListenRtp(port uint16) error {
var (
e errgroup.Group
rtp = &Session{
ITransport: NewTCPServer(port, true),
RTP: RTP{},
PSCache: make(map[uint32]*PSInfo),
}
)
defer rtp.Close()
e.Go(func() error {
return rtp.Start()
})
e.Go(func() error {
return rtp.PacketHandler()
})
return e.Wait()
}