forked from pion/webrtc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
marshal.go
118 lines (98 loc) · 2.95 KB
/
marshal.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
117
118
package sdp
import (
"strings"
)
// Marshal takes a SDP struct to text
// https://tools.ietf.org/html/rfc4566#section-5
// Session description
// v= (protocol version)
// o= (originator and session identifier)
// s= (session name)
// i=* (session information)
// u=* (URI of description)
// e=* (email address)
// p=* (phone number)
// c=* (connection information -- not required if included in
// all media)
// b=* (zero or more bandwidth information lines)
// One or more time descriptions ("t=" and "r=" lines; see below)
// z=* (time zone adjustments)
// k=* (encryption key)
// a=* (zero or more session attribute lines)
// Zero or more media descriptions
//
// Time description
// t= (time the session is active)
// r=* (zero or more repeat times)
//
// Media description, if present
// m= (media name and transport address)
// i=* (media title)
// c=* (connection information -- optional if included at
// session level)
// b=* (zero or more bandwidth information lines)
// k=* (encryption key)
// a=* (zero or more media attribute lines)
func (s *SessionDescription) Marshal() (raw string) {
raw += keyValueBuild("v=", s.Version.String())
raw += keyValueBuild("o=", s.Origin.String())
raw += keyValueBuild("s=", s.SessionName.String())
if s.SessionInformation != nil {
raw += keyValueBuild("i=", s.SessionInformation.String())
}
if s.URI != nil {
uri := s.URI.String()
raw += keyValueBuild("u=", &uri)
}
if s.EmailAddress != nil {
raw += keyValueBuild("e=", s.EmailAddress.String())
}
if s.PhoneNumber != nil {
raw += keyValueBuild("p=", s.PhoneNumber.String())
}
if s.ConnectionInformation != nil {
raw += keyValueBuild("c=", s.ConnectionInformation.String())
}
for _, b := range s.Bandwidth {
raw += keyValueBuild("b=", b.String())
}
for _, td := range s.TimeDescriptions {
raw += keyValueBuild("t=", td.Timing.String())
for _, r := range td.RepeatTimes {
raw += keyValueBuild("r=", r.String())
}
}
rawTimeZones := make([]string, 0)
for _, z := range s.TimeZones {
rawTimeZones = append(rawTimeZones, z.String())
}
if len(rawTimeZones) > 0 {
timeZones := strings.Join(rawTimeZones, " ")
raw += keyValueBuild("z=", &timeZones)
}
if s.EncryptionKey != nil {
raw += keyValueBuild("k=", s.EncryptionKey.String())
}
for _, a := range s.Attributes {
raw += keyValueBuild("a=", a.String())
}
for _, md := range s.MediaDescriptions {
raw += keyValueBuild("m=", md.MediaName.String())
if md.MediaTitle != nil {
raw += keyValueBuild("i=", md.MediaTitle.String())
}
if md.ConnectionInformation != nil {
raw += keyValueBuild("c=", md.ConnectionInformation.String())
}
for _, b := range md.Bandwidth {
raw += keyValueBuild("b=", b.String())
}
if md.EncryptionKey != nil {
raw += keyValueBuild("k=", md.EncryptionKey.String())
}
for _, a := range md.Attributes {
raw += keyValueBuild("a=", a.String())
}
}
return raw
}