forked from gortc/sdp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.go
71 lines (68 loc) · 1.63 KB
/
encoder.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
package sdp
func (s Session) appendAttributes(attrs Attributes) Session {
for _, v := range attrs {
if v.Value == blank {
s = s.AddFlag(v.Key)
} else {
s = s.AddAttribute(v.Key, v.Value)
}
}
return s
}
// Append encodes message to Session and returns result.
//
// See RFC 4566 Section 5.
func (m *Message) Append(s Session) Session {
s = s.AddVersion(m.Version)
s = s.AddOrigin(m.Origin)
s = s.AddSessionName(m.Name)
if len(m.Info) > 0 {
s = s.AddSessionInfo(m.Info)
}
if len(m.URI) > 0 {
s = s.AddURI(m.URI)
}
if len(m.Email) > 0 {
s = s.AddEmail(m.Email)
}
if len(m.Phone) > 0 {
s = s.AddPhone(m.Phone)
}
if !m.Connection.Blank() {
s = s.AddConnectionData(m.Connection)
}
for t, v := range m.Bandwidths {
s = s.AddBandwidth(t, v)
}
// One or more time descriptions ("t=" and "r=" lines)
for _, t := range m.Timing {
s = s.AddTiming(t.Start, t.End)
if len(t.Offsets) > 0 {
s = s.AddRepeatTimesCompact(t.Repeat, t.Active, t.Offsets...)
}
}
if len(m.TZAdjustments) > 0 {
s = s.AddTimeZones(m.TZAdjustments...)
}
if !m.Encryption.Blank() {
s = s.AddEncryption(m.Encryption)
}
s = s.appendAttributes(m.Attributes)
for i := range m.Medias {
s = s.AddMediaDescription(m.Medias[i].Description)
if len(m.Medias[i].Title) > 0 {
s = s.AddSessionInfo(m.Medias[i].Title)
}
if !m.Medias[i].Connection.Blank() {
s = s.AddConnectionData(m.Medias[i].Connection)
}
for t, v := range m.Medias[i].Bandwidths {
s = s.AddBandwidth(t, v)
}
if !m.Medias[i].Encryption.Blank() {
s = s.AddEncryption(m.Medias[i].Encryption)
}
s = s.appendAttributes(m.Medias[i].Attributes)
}
return s
}