forked from webver/RstpToWs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.go
55 lines (52 loc) · 1.16 KB
/
stream.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
package main
import (
"log"
"time"
"github.com/webver/vdk/format/rtsp"
)
func serveStreams() {
for k, v := range Config.Streams {
go func(name, url string) {
stopHlsCast := make(chan bool, 1)
for {
log.Println(name, "connect", url)
rtsp.DebugRtsp = true
rtsp.DebugRtp = false
session, err := rtsp.Dial(url)
if err != nil {
log.Println(name, err)
time.Sleep(5 * time.Second)
continue
}
session.RtpKeepAliveTimeout = time.Duration(10 * time.Second)
if err != nil {
log.Println(name, err)
time.Sleep(5 * time.Second)
continue
}
codec, err := session.Streams()
if err != nil {
log.Println(name, err)
time.Sleep(5 * time.Second)
continue
}
Config.codecAdd(name, codec)
Config.updateStatus(name, true)
Config.startHlsCast(name, stopHlsCast)
for {
pkt, err := session.ReadPacket()
if err != nil {
log.Println(name, err)
break
}
Config.cast(name, pkt)
}
session.Close()
stopHlsCast <- true
Config.updateStatus(name, false)
log.Println(name, "reconnect wait 5s")
time.Sleep(5 * time.Second)
}
}(k, v.URL)
}
}