2024-06-05 20:10:03 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2022-03-10 09:44:48 +00:00
|
|
|
package sdp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Information describes the "i=" field which provides textual information
|
|
|
|
// about the session.
|
|
|
|
type Information string
|
|
|
|
|
|
|
|
func (i Information) String() string {
|
2024-06-05 20:10:03 +00:00
|
|
|
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)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2024-06-05 20:10:03 +00:00
|
|
|
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()
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
2024-06-05 20:10:03 +00:00
|
|
|
|
|
|
|
return
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2024-06-05 20:10:03 +00:00
|
|
|
return stringFromMarshal(c.marshalInto, c.marshalSize)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Address) marshalInto(b []byte) []byte {
|
|
|
|
b = append(b, c.Address...)
|
2022-03-10 09:44:48 +00:00
|
|
|
if c.TTL != nil {
|
2024-06-05 20:10:03 +00:00
|
|
|
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)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
2024-06-05 20:10:03 +00:00
|
|
|
return b
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c Address) marshalSize() (size int) {
|
|
|
|
size = len(c.Address)
|
|
|
|
if c.TTL != nil {
|
|
|
|
size += 1 + lenUint(uint64(*c.TTL))
|
|
|
|
}
|
2022-03-10 09:44:48 +00:00
|
|
|
if c.Range != nil {
|
2024-06-05 20:10:03 +00:00
|
|
|
size += 1 + lenUint(uint64(*c.Range))
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
2024-06-05 20:10:03 +00:00
|
|
|
return
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2024-06-05 20:10:03 +00:00
|
|
|
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) {
|
2022-03-10 09:44:48 +00:00
|
|
|
if b.Experimental {
|
2024-06-05 20:10:03 +00:00
|
|
|
size += 2
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
2024-06-05 20:10:03 +00:00
|
|
|
|
|
|
|
size += len(b.Type) + 1 + lenUint(b.Bandwidth)
|
|
|
|
return
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// EncryptionKey describes the "k=" which conveys encryption key information.
|
|
|
|
type EncryptionKey string
|
|
|
|
|
2024-06-05 20:10:03 +00:00
|
|
|
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)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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 {
|
2024-06-05 20:10:03 +00:00
|
|
|
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)
|
2022-03-10 09:44:48 +00:00
|
|
|
if len(a.Value) > 0 {
|
2024-06-05 20:10:03 +00:00
|
|
|
size += 1 + len(a.Value)
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
2024-06-05 20:10:03 +00:00
|
|
|
|
|
|
|
return size
|
2022-03-10 09:44:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// IsICECandidate returns true if the attribute key equals "candidate".
|
|
|
|
func (a Attribute) IsICECandidate() bool {
|
|
|
|
return a.Key == "candidate"
|
|
|
|
}
|