-
Notifications
You must be signed in to change notification settings - Fork 0
/
usingPionSDP.go
116 lines (106 loc) · 2.34 KB
/
usingPionSDP.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package main
import (
"net"
"github.com/openaudiocollective/sap"
"github.com/pion/sdp"
)
func main() {
// Resolve the address
raddr, err := net.ResolveUDPAddr("udp", "224.0.0.255:9875")
if err != nil {
panic(err)
}
// Establish the UDP connection
conn, err := net.DialUDP("udp", nil, raddr)
if err != nil {
panic(err)
}
/*
v=0
o=- 1423986 1423994 IN IP4 169.254.98.63
s=AOIP44-serial-1614 : 2
c=IN IP4 239.65.45.154/32
t=0 0
a=keywds:Dante
m=audio 5004 RTP/AVP 97
i=2 channels: TxChan 0, TxChan 1
a=recvonly
a=rtpmap:96 L24/48000/2
a=ptime:1
a=ts-refclk:ptp=IEEE1588-2008:00-00-00-FF-FE-00-00-00:0
a=mediaclk:direct=142410716
*/
inf := sdp.Information("2 channels: TxChan 0, TxChan 1")
rng := 32
sess := sdp.SessionDescription{
Version: 0,
Origin: sdp.Origin{
Username: "-",
SessionID: 1423986,
SessionVersion: 1423994,
NetworkType: "IN",
AddressType: "IP4",
UnicastAddress: "169.254.98.63",
},
SessionName: "AOIP44-serial-1614 : 2",
SessionInformation: &inf,
ConnectionInformation: &sdp.ConnectionInformation{
NetworkType: "IN",
AddressType: "IP4",
Address: &sdp.Address{
IP: net.ParseIP("239.65.45.154"),
Range: &rng,
},
},
TimeDescriptions: []sdp.TimeDescription{
sdp.TimeDescription{
Timing: sdp.Timing{StartTime: 0, StopTime: 0},
},
},
Attributes: []sdp.Attribute{
sdp.Attribute{
Key: "keywds",
Value: "Dante",
},
},
MediaDescriptions: []*sdp.MediaDescription{
&sdp.MediaDescription{
MediaName: sdp.MediaName{Media: "audio", Port: sdp.RangedPort{Value: 5004}, Protos: []string{"RTP/AVP"}, Formats: []string{"97"}},
Attributes: []sdp.Attribute{
sdp.Attribute{
Key: "recvonly",
},
sdp.Attribute{
Key: "rtpmap",
Value: "96 L24/48000/2",
},
sdp.Attribute{
Key: "ptime",
Value: "1",
},
sdp.Attribute{
Key: "ts-refclk",
Value: "ptp=IEEE1588-2008:00-00-00-FF-FE-00-00-00:0",
},
sdp.Attribute{
Key: "mediaclk",
Value: "direct=142410716`",
},
},
},
},
}
payload := []byte(sess.Marshal())
pckt, err := sap.NewPacket(payload, *raddr)
if err != nil {
panic(err)
}
mrshl, err := pckt.Marshal()
if err != nil {
panic(err)
}
_, err = conn.Write(mrshl)
if err != nil {
panic(err)
}
}