README


Pion SDP

A Go implementation of the SDP

Pion SDP Sourcegraph Widget Slack Widget
Build Status GoDoc Coverage Status Go Report Card


See DESIGN.md for an overview of features and future goals.

Roadmap

The library is used as a part of our WebRTC implementation. Please refer to that roadmap to track our major milestones.

Community

Pion has an active community on the Golang Slack. Sign up and join the #pion channel for discussions and support. You can also use Pion mailing list.

We are always looking to support your projects. Please reach out if you have something to build!

If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible:

License

MIT License - see LICENSE for full text

Documentation

Overview

Package sdp implements Session Description Protocol (SDP)

Index

Constants

View Source
const (
	AttrKeyIdentity        = "identity"
	AttrKeyGroup           = "group"
	AttrKeySSRC            = "ssrc"
	AttrKeySSRCGroup       = "ssrc-group"
	AttrKeyMsidSemantic    = "msid-semantic"
	AttrKeyConnectionSetup = "setup"
	AttrKeyMID             = "mid"
	AttrKeyICELite         = "ice-lite"
	AttrKeyRTCPMux         = "rtcp-mux"
	AttrKeyRTCPRsize       = "rtcp-rsize"
)

Constants for SDP attributes used in JSEP

View Source
const (
	SemanticTokenLipSynchronization     = "LS"
	SemanticTokenFlowIdentification     = "FID"
	SemanticTokenForwardErrorCorrection = "FEC"
	SemanticTokenWebRTCMediaStreams     = "WMS"
)

Constants for semantic tokens used in JSEP

View Source
const (
	ExtMapValueTransportCC = 3
)

Constants for extmap key

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Address string
	TTL     *int
	Range   *int
}

Address desribes a structured address token from within the "c=" field.

func (*Address) String

func (c *Address) String() string

type Attribute

type Attribute struct {
	Key   string
	Value string
}

Attribute describes the "a=" field which represents the primary means for extending SDP.

func NewAttribute

func NewAttribute(key, value string) Attribute

NewAttribute constructs a new attribute

func NewPropertyAttribute

func NewPropertyAttribute(key string) Attribute

NewPropertyAttribute constructs a new attribute

func (*Attribute) IsICECandidate

func (a *Attribute) IsICECandidate() bool

IsICECandidate returns true if the attribute key equals "candidate".

func (*Attribute) String

func (a *Attribute) String() *string

func (*Attribute) ToICECandidate

func (a *Attribute) ToICECandidate() (ICECandidate, error)

ToICECandidate parses the attribute as an ICE Candidate.

type Bandwidth

type Bandwidth struct {
	Experimental bool
	Type         string
	Bandwidth    uint64
}

Bandwidth describes an optional field which denotes the proposed bandwidth to be used by the session or media.

func (*Bandwidth) String

func (b *Bandwidth) String() *string

type Codec

type Codec struct {
	PayloadType        uint8
	Name               string
	ClockRate          uint32
	EncodingParameters string
	Fmtp               string
	RTCPFeedback       []string
}

Codec represents a codec

func (Codec) String

func (c Codec) String() string

type ConnectionInformation

type ConnectionInformation struct {
	NetworkType string
	AddressType string
	Address     *Address
}

ConnectionInformation defines the representation for the "c=" field containing connection data.

func (*ConnectionInformation) String

func (c *ConnectionInformation) String() *string

type ConnectionRole

type ConnectionRole int

ConnectionRole indicates which of the end points should initiate the connection establishment

const (
	// ConnectionRoleActive indicates the endpoint will initiate an outgoing connection.
	ConnectionRoleActive ConnectionRole = iota + 1

	// ConnectionRolePassive indicates the endpoint will accept an incoming connection.
	ConnectionRolePassive

	// ConnectionRoleActpass indicates the endpoint is willing to accept an incoming connection or to initiate an outgoing connection.
	ConnectionRoleActpass

	// ConnectionRoleHoldconn indicates the endpoint does not want the connection to be established for the time being.
	ConnectionRoleHoldconn
)

func (ConnectionRole) String

func (t ConnectionRole) String() string

type Direction

type Direction int

Direction is a marker for transmission directon of an endpoint

const (
	//DirectionSendRecv is for bidirectional communication
	DirectionSendRecv Direction = iota + 1
	//DirectionSendOnly is for outgoing communication
	DirectionSendOnly
	//DirectionRecvOnly is for incoming communication
	DirectionRecvOnly
	//DirectionInactive is for no communication
	DirectionInactive
)

func NewDirection

func NewDirection(raw string) (Direction, error)

NewDirection defines a procedure for creating a new direction from a raw string.

func (Direction) String

func (t Direction) String() string

type EmailAddress

type EmailAddress string

EmailAddress describes a structured representations for the "e=" line which specifies email contact information for the person responsible for the conference.

func (*EmailAddress) String

func (e *EmailAddress) String() *string

type EncryptionKey

type EncryptionKey string

EncryptionKey describes the "k=" which conveys encryption key information.

func (*EncryptionKey) String

func (s *EncryptionKey) String() *string

type ExtMap

type ExtMap struct {
	Value     int
	Direction Direction
	URI       *url.URL
	ExtAttr   *string
}

ExtMap represents the activation of a single RTP header extension

func (*ExtMap) Clone

func (e *ExtMap) Clone() Attribute

Clone converts this object to an Attribute

func (*ExtMap) Marshal

func (e *ExtMap) Marshal() string

Marshal creates a string from an ExtMap

func (*ExtMap) Name

func (e *ExtMap) Name() string

Name returns the constant name of this object

func (*ExtMap) Unmarshal

func (e *ExtMap) Unmarshal(raw string) error

Unmarshal creates an Extmap from a string

type ICECandidate

type ICECandidate struct {
	Foundation          string
	Component           uint16
	Priority            uint32
	Address             string
	Protocol            string
	Port                uint16
	Typ                 string
	RelatedAddress      string
	RelatedPort         uint16
	ExtensionAttributes []ICECandidateAttribute
}

ICECandidate is used to (un)marshal ICE candidates.

func (ICECandidate) Marshal

func (c ICECandidate) Marshal() string

Marshal returns the string representation of the ICECandidate

func (*ICECandidate) Unmarshal

func (c *ICECandidate) Unmarshal(raw string) error

Unmarshal popuulates the ICECandidate from its string representation

type ICECandidateAttribute

type ICECandidateAttribute struct {
	Key   string
	Value string
}

ICECandidateAttribute represents an ICE candidate extension attribute

type Information

type Information string

Information describes the "i=" field which provides textual information about the session.

func (*Information) String

func (i *Information) String() *string

type MediaDescription

type MediaDescription struct {
	// m=<media> <port>/<number of ports> <proto> <fmt> ...
	// https://tools.ietf.org/html/rfc4566#section-5.14
	MediaName MediaName

	// i=<session description>
	// https://tools.ietf.org/html/rfc4566#section-5.4
	MediaTitle *Information

	// c=<nettype> <addrtype> <connection-address>
	// https://tools.ietf.org/html/rfc4566#section-5.7
	ConnectionInformation *ConnectionInformation

	// b=<bwtype>:<bandwidth>
	// https://tools.ietf.org/html/rfc4566#section-5.8
	Bandwidth []Bandwidth

	// k=<method>
	// k=<method>:<encryption key>
	// https://tools.ietf.org/html/rfc4566#section-5.12
	EncryptionKey *EncryptionKey

	// a=<attribute>
	// a=<attribute>:<value>
	// https://tools.ietf.org/html/rfc4566#section-5.13
	Attributes []Attribute
}

MediaDescription represents a media type. https://tools.ietf.org/html/rfc4566#section-5.14

func NewJSEPMediaDescription

func NewJSEPMediaDescription(codecType string, codecPrefs []string) *MediaDescription

NewJSEPMediaDescription creates a new MediaName with some settings that are required by the JSEP spec.

func (*MediaDescription) Attribute

func (d *MediaDescription) Attribute(key string) (string, bool)

Attribute returns the value of an attribute and if it exists

func (*MediaDescription) WithCandidate

func (d *MediaDescription) WithCandidate(value string) *MediaDescription

WithCandidate adds an ICE candidate to the media description Deprecated: use WithICECandidate instead

func (*MediaDescription) WithCodec

func (d *MediaDescription) WithCodec(payloadType uint8, name string, clockrate uint32, channels uint16, fmtp string) *MediaDescription

WithCodec adds codec information to the media description

func (*MediaDescription) WithExtMap

func (d *MediaDescription) WithExtMap(e ExtMap) *MediaDescription

WithExtMap adds an extmap to the media description

func (*MediaDescription) WithICECandidate

func (d *MediaDescription) WithICECandidate(c ICECandidate) *MediaDescription

WithICECandidate adds an ICE candidate to the media description

func (*MediaDescription) WithICECredentials

func (d *MediaDescription) WithICECredentials(username, password string) *MediaDescription

WithICECredentials adds ICE credentials to the media description

func (*MediaDescription) WithMediaSource

func (d *MediaDescription) WithMediaSource(ssrc uint32, cname, streamLabel, label string) *MediaDescription

WithMediaSource adds media source information to the media description

func (*MediaDescription) WithPropertyAttribute

func (d *MediaDescription) WithPropertyAttribute(key string) *MediaDescription

WithPropertyAttribute adds a property attribute 'a=key' to the media description

func (*MediaDescription) WithTransportCCExtMap

func (d *MediaDescription) WithTransportCCExtMap() *MediaDescription

WithTransportCCExtMap adds an extmap to the media description

func (*MediaDescription) WithValueAttribute

func (d *MediaDescription) WithValueAttribute(key, value string) *MediaDescription

WithValueAttribute adds a value attribute 'a=key:value' to the media description

type MediaName

type MediaName struct {
	Media   string
	Port    RangedPort
	Protos  []string
	Formats []string
}

MediaName describes the "m=" field storage structure.

func (*MediaName) String

func (m *MediaName) String() *string

type Origin

type Origin struct {
	Username       string
	SessionID      uint64
	SessionVersion uint64
	NetworkType    string
	AddressType    string
	UnicastAddress string
}

Origin defines the structure for the "o=" field which provides the originator of the session plus a session identifier and version number.

func (*Origin) String

func (o *Origin) String() *string

type PhoneNumber

type PhoneNumber string

PhoneNumber describes a structured representations for the "p=" line specify phone contact information for the person responsible for the conference.

func (*PhoneNumber) String

func (p *PhoneNumber) String() *string

type RangedPort

type RangedPort struct {
	Value int
	Range *int
}

RangedPort supports special format for the media field "m=" port value. If it may be necessary to specify multiple transport ports, the protocol allows to write it as: <port>/<number of ports> where number of ports is a an offsetting range.

func (*RangedPort) String

func (p *RangedPort) String() string

type RepeatTime

type RepeatTime struct {
	Interval int64
	Duration int64
	Offsets  []int64
}

RepeatTime describes the "r=" fields of the session description which represents the intervals and durations for repeated scheduled sessions.

func (*RepeatTime) String

func (r *RepeatTime) String() *string

type SessionDescription

type SessionDescription struct {
	// v=0
	// https://tools.ietf.org/html/rfc4566#section-5.1
	Version Version

	// o=<username> <sess-id> <sess-version> <nettype> <addrtype> <unicast-address>
	// https://tools.ietf.org/html/rfc4566#section-5.2
	Origin Origin

	// s=<session name>
	// https://tools.ietf.org/html/rfc4566#section-5.3
	SessionName SessionName

	// i=<session description>
	// https://tools.ietf.org/html/rfc4566#section-5.4
	SessionInformation *Information

	// u=<uri>
	// https://tools.ietf.org/html/rfc4566#section-5.5
	URI *url.URL

	// e=<email-address>
	// https://tools.ietf.org/html/rfc4566#section-5.6
	EmailAddress *EmailAddress

	// p=<phone-number>
	// https://tools.ietf.org/html/rfc4566#section-5.6
	PhoneNumber *PhoneNumber

	// c=<nettype> <addrtype> <connection-address>
	// https://tools.ietf.org/html/rfc4566#section-5.7
	ConnectionInformation *ConnectionInformation

	// b=<bwtype>:<bandwidth>
	// https://tools.ietf.org/html/rfc4566#section-5.8
	Bandwidth []Bandwidth

	// https://tools.ietf.org/html/rfc4566#section-5.9
	// https://tools.ietf.org/html/rfc4566#section-5.10
	TimeDescriptions []TimeDescription

	// z=<adjustment time> <offset> <adjustment time> <offset> ...
	// https://tools.ietf.org/html/rfc4566#section-5.11
	TimeZones []TimeZone

	// k=<method>
	// k=<method>:<encryption key>
	// https://tools.ietf.org/html/rfc4566#section-5.12
	EncryptionKey *EncryptionKey

	// a=<attribute>
	// a=<attribute>:<value>
	// https://tools.ietf.org/html/rfc4566#section-5.13
	Attributes []Attribute

	// https://tools.ietf.org/html/rfc4566#section-5.14
	MediaDescriptions []*MediaDescription
}

SessionDescription is a a well-defined format for conveying sufficient information to discover and participate in a multimedia session.

func NewJSEPSessionDescription

func NewJSEPSessionDescription(identity bool) *SessionDescription

NewJSEPSessionDescription creates a new SessionDescription with some settings that are required by the JSEP spec.

func (*SessionDescription) Attribute

func (s *SessionDescription) Attribute(key string) (string, bool)

Attribute returns the value of an attribute and if it exists

func (*SessionDescription) GetCodecForPayloadType

func (s *SessionDescription) GetCodecForPayloadType(payloadType uint8) (Codec, error)

GetCodecForPayloadType scans the SessionDescription for the given payload type and returns the codec

func (*SessionDescription) GetPayloadTypeForCodec

func (s *SessionDescription) GetPayloadTypeForCodec(wanted Codec) (uint8, error)

GetPayloadTypeForCodec scans the SessionDescription for a codec that matches the provided codec as closely as possible and returns its payload type

func (*SessionDescription) Marshal

func (s *SessionDescription) Marshal() ([]byte, error)

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 (*SessionDescription) Unmarshal

func (s *SessionDescription) Unmarshal(value []byte) error

Unmarshal is the primary function that deserializes the session description message and stores it inside of a structured SessionDescription object.

The States Transition Table describes the computation flow between functions (namely s1, s2, s3, ...) for a parsing procedure that complies with the specifications laid out by the rfc4566#section-5 as well as by JavaScript Session Establishment Protocol draft. Links:

https://tools.ietf.org/html/rfc4566#section-5
https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24

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)

In order to generate the following state table and draw subsequent deterministic finite-state automota ("DFA") the following regex was used to derive the DFA:

vosi?u?e?p?c?b*(tr*)+z?k?a*(mi?c?b*k?a*)*

Please pay close attention to the `k`, and `a` parsing states. In the table below in order to distinguish between the states belonging to the media description as opposed to the session description, the states are marked with an asterisk ("a*", "k*"). +--------+----+-------+----+-----+----+-----+---+----+----+---+---+-----+---+---+----+---+----+ | STATES | a* | a*,k* | a | a,k | b | b,c | e | i | m | o | p | r,t | s | t | u | v | z | +--------+----+-------+----+-----+----+-----+---+----+----+---+---+-----+---+---+----+---+----+ | s1 | | | | | | | | | | | | | | | | 2 | | | s2 | | | | | | | | | | 3 | | | | | | | | | s3 | | | | | | | | | | | | | 4 | | | | | | s4 | | | | | | 5 | 6 | 7 | | | 8 | | | 9 | 10 | | | | s5 | | | | | 5 | | | | | | | | | 9 | | | | | s6 | | | | | | 5 | | | | | 8 | | | 9 | | | | | s7 | | | | | | 5 | 6 | | | | 8 | | | 9 | 10 | | | | s8 | | | | | | 5 | | | | | | | | 9 | | | | | s9 | | | | 11 | | | | | 12 | | | 9 | | | | | 13 | | s10 | | | | | | 5 | 6 | | | | 8 | | | 9 | | | | | s11 | | | 11 | | | | | | 12 | | | | | | | | | | s12 | | 14 | | | | 15 | | 16 | 12 | | | | | | | | | | s13 | | | | 11 | | | | | 12 | | | | | | | | | | s14 | 14 | | | | | | | | 12 | | | | | | | | | | s15 | | 14 | | | 15 | | | | 12 | | | | | | | | | | s16 | | 14 | | | | 15 | | | 12 | | | | | | | | | +--------+----+-------+----+-----+----+-----+---+----+----+---+---+-----+---+---+----+---+----+

func (*SessionDescription) WithFingerprint

func (s *SessionDescription) WithFingerprint(algorithm, value string) *SessionDescription

WithFingerprint adds a fingerprint to the session description

func (*SessionDescription) WithMedia

WithMedia adds a media description to the session description

func (*SessionDescription) WithPropertyAttribute

func (s *SessionDescription) WithPropertyAttribute(key string) *SessionDescription

WithPropertyAttribute adds a property attribute 'a=key' to the session description

func (*SessionDescription) WithValueAttribute

func (s *SessionDescription) WithValueAttribute(key, value string) *SessionDescription

WithValueAttribute adds a value attribute 'a=key:value' to the session description

type SessionName

type SessionName string

SessionName describes a structured representations for the "s=" field and is the textual session name.

func (*SessionName) String

func (s *SessionName) String() *string

type TimeDescription

type TimeDescription struct {
	// t=<start-time> <stop-time>
	// https://tools.ietf.org/html/rfc4566#section-5.9
	Timing Timing

	// r=<repeat interval> <active duration> <offsets from start-time>
	// https://tools.ietf.org/html/rfc4566#section-5.10
	RepeatTimes []RepeatTime
}

TimeDescription describes "t=", "r=" fields of the session description which are used to specify the start and stop times for a session as well as repeat intervals and durations for the scheduled session.

type TimeZone

type TimeZone struct {
	AdjustmentTime uint64
	Offset         int64
}

TimeZone defines the structured object for "z=" line which describes repeated sessions scheduling.

func (*TimeZone) String

func (z *TimeZone) String() string

type Timing

type Timing struct {
	StartTime uint64
	StopTime  uint64
}

Timing defines the "t=" field's structured representation for the start and stop times.

func (*Timing) String

func (t *Timing) String() *string

type Version

type Version int

Version describes the value provided by the "v=" field which gives the version of the Session Description Protocol.

func (*Version) String

func (v *Version) String() *string