-
Notifications
You must be signed in to change notification settings - Fork 1
/
rtp.go
58 lines (43 loc) · 933 Bytes
/
rtp.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
package main
import (
"github.com/pion/webrtc/v3"
"log"
"net"
)
// Wanted to use channels, but they're too slow and cause packet loss??
var track *webrtc.TrackLocalStaticRTP
func InitWebRTCTrack(mime string, sid string) {
switch mime {
case "video/VP8":
break
case "video/H264":
break
default:
log.Panicln("Unsupported codec selected!")
}
ltrack, err := webrtc.NewTrackLocalStaticRTP(webrtc.RTPCodecCapability{MimeType: mime}, "video", sid)
if err != nil {
log.Panicln(err)
}
track = ltrack
}
func RunUDPRTPServer(ip string, port int) {
ln, err := net.ListenUDP("udp", &net.UDPAddr{
IP: net.ParseIP(ip),
Port: port,
})
if err != nil {
log.Panicln(err)
}
defer ln.Close()
log.Printf("Listening for RTP packets on udp://%s:%d", ip, port)
buf := make([]byte, 1600)
for {
n, _, err := ln.ReadFrom(buf)
if err != nil {
log.Println(err)
continue
}
track.Write(buf[:n])
}
}