-
Notifications
You must be signed in to change notification settings - Fork 61
/
Copy pathcommon_description.go
190 lines (151 loc) · 3.87 KB
/
common_description.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sdp
import (
"strconv"
)
// Information describes the "i=" field which provides textual information
// about the session.
type Information string
func (i Information) String() string {
return stringFromMarshal(i.marshalInto, i.marshalSize)
}
func (i Information) marshalInto(b []byte) []byte {
return append(b, i...)
}
func (i Information) marshalSize() (size int) {
return len(i)
}
// ConnectionInformation defines the representation for the "c=" field
// containing connection data.
type ConnectionInformation struct {
NetworkType string
AddressType string
Address *Address
}
func (c ConnectionInformation) String() string {
return stringFromMarshal(c.marshalInto, c.marshalSize)
}
func (c ConnectionInformation) marshalInto(b []byte) []byte {
b = append(append(b, c.NetworkType...), ' ')
b = append(b, c.AddressType...)
if c.Address != nil {
b = append(b, ' ')
b = c.Address.marshalInto(b)
}
return b
}
func (c ConnectionInformation) marshalSize() (size int) {
size = len(c.NetworkType)
size += 1 + len(c.AddressType)
if c.Address != nil {
size += 1 + c.Address.marshalSize()
}
return
}
// Address desribes a structured address token from within the "c=" field.
type Address struct {
Address string
TTL *int
Range *int
}
func (c *Address) String() string {
return stringFromMarshal(c.marshalInto, c.marshalSize)
}
func (c *Address) marshalInto(b []byte) []byte {
b = append(b, c.Address...)
if c.TTL != nil {
b = append(b, '/')
b = strconv.AppendInt(b, int64(*c.TTL), 10)
}
if c.Range != nil {
b = append(b, '/')
b = strconv.AppendInt(b, int64(*c.Range), 10)
}
return b
}
func (c Address) marshalSize() (size int) {
size = len(c.Address)
if c.TTL != nil {
size += 1 + lenUint(uint64(*c.TTL)) //nolint:gosec // G115
}
if c.Range != nil {
size += 1 + lenUint(uint64(*c.Range)) //nolint:gosec // G115
}
return
}
// Bandwidth describes an optional field which denotes the proposed bandwidth
// to be used by the session or media.
type Bandwidth struct {
Experimental bool
Type string
Bandwidth uint64
}
func (b Bandwidth) String() string {
return stringFromMarshal(b.marshalInto, b.marshalSize)
}
func (b Bandwidth) marshalInto(d []byte) []byte {
if b.Experimental {
d = append(d, "X-"...)
}
d = append(append(d, b.Type...), ':')
return strconv.AppendUint(d, b.Bandwidth, 10)
}
func (b Bandwidth) marshalSize() (size int) {
if b.Experimental {
size += 2
}
size += len(b.Type) + 1 + lenUint(b.Bandwidth)
return
}
// EncryptionKey describes the "k=" which conveys encryption key information.
type EncryptionKey string
func (e EncryptionKey) String() string {
return stringFromMarshal(e.marshalInto, e.marshalSize)
}
func (e EncryptionKey) marshalInto(b []byte) []byte {
return append(b, e...)
}
func (e EncryptionKey) marshalSize() (size int) {
return len(e)
}
// Attribute describes the "a=" field which represents the primary means for
// extending SDP.
type Attribute struct {
Key string
Value string
}
// NewPropertyAttribute constructs a new attribute.
func NewPropertyAttribute(key string) Attribute {
return Attribute{
Key: key,
}
}
// NewAttribute constructs a new attribute.
func NewAttribute(key, value string) Attribute {
return Attribute{
Key: key,
Value: value,
}
}
func (a Attribute) String() string {
return stringFromMarshal(a.marshalInto, a.marshalSize)
}
func (a Attribute) marshalInto(b []byte) []byte {
b = append(b, a.Key...)
if len(a.Value) > 0 {
b = append(append(b, ':'), a.Value...)
}
return b
}
func (a Attribute) marshalSize() (size int) {
size = len(a.Key)
if len(a.Value) > 0 {
size += 1 + len(a.Value)
}
return size
}
// IsICECandidate returns true if the attribute key equals "candidate".
func (a Attribute) IsICECandidate() bool {
return a.Key == "candidate"
}