Documentation ¶
Overview ¶
Package sdp implements Session Description Protocol (SDP)
Index ¶
- Constants
- type Address
- type Attribute
- type Bandwidth
- type Codec
- type ConnectionInformation
- type ConnectionRole
- type Direction
- type EmailAddress
- type EncryptionKey
- type ExtMap
- type Information
- type MediaDescription
- func (d *MediaDescription) Attribute(key string) (string, bool)
- func (d *MediaDescription) WithCandidate(value string) *MediaDescription
- func (d *MediaDescription) WithCodec(payloadType uint8, name string, clockrate uint32, channels uint16, fmtp string) *MediaDescription
- func (d *MediaDescription) WithExtMap(e ExtMap) *MediaDescription
- func (d *MediaDescription) WithFingerprint(algorithm, value string) *MediaDescription
- func (d *MediaDescription) WithICECredentials(username, password string) *MediaDescription
- func (d *MediaDescription) WithMediaSource(ssrc uint32, cname, streamLabel, label string) *MediaDescription
- func (d *MediaDescription) WithPropertyAttribute(key string) *MediaDescription
- func (d *MediaDescription) WithTransportCCExtMap() *MediaDescription
- func (d *MediaDescription) WithValueAttribute(key, value string) *MediaDescription
- type MediaName
- type Origin
- type PhoneNumber
- type RangedPort
- type RepeatTime
- type SessionDescription
- func (s *SessionDescription) Attribute(key string) (string, bool)
- func (s *SessionDescription) GetCodecForPayloadType(payloadType uint8) (Codec, error)
- func (s *SessionDescription) GetPayloadTypeForCodec(wanted Codec) (uint8, error)
- func (s *SessionDescription) Marshal() ([]byte, error)
- func (s *SessionDescription) MarshalSize() (marshalSize int)
- func (s *SessionDescription) Unmarshal(value []byte) error
- func (s *SessionDescription) UnmarshalString(value string) error
- func (s *SessionDescription) WithFingerprint(algorithm, value string) *SessionDescription
- func (s *SessionDescription) WithMedia(md *MediaDescription) *SessionDescription
- func (s *SessionDescription) WithPropertyAttribute(key string) *SessionDescription
- func (s *SessionDescription) WithValueAttribute(key, value string) *SessionDescription
- type SessionName
- type TimeDescription
- type TimeZone
- type Timing
- type Version
Constants ¶
const ( DefExtMapValueABSSendTime = 1 DefExtMapValueTransportCC = 2 DefExtMapValueSDESMid = 3 DefExtMapValueSDESRTPStreamID = 4 ABSSendTimeURI = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time" TransportCCURI = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01" SDESMidURI = "urn:ietf:params:rtp-hdrext:sdes:mid" SDESRTPStreamIDURI = "urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id" AudioLevelURI = "urn:ietf:params:rtp-hdrext:ssrc-audio-level" )
Default ext values
const ( AttrKeyCandidate = "candidate" AttrKeyEndOfCandidates = "end-of-candidates" AttrKeyIdentity = "identity" AttrKeyGroup = "group" AttrKeySSRC = "ssrc" AttrKeySSRCGroup = "ssrc-group" AttrKeyMsid = "msid" AttrKeyMsidSemantic = "msid-semantic" AttrKeyConnectionSetup = "setup" AttrKeyMID = "mid" AttrKeyICELite = "ice-lite" AttrKeyRTCPMux = "rtcp-mux" AttrKeyRTCPRsize = "rtcp-rsize" AttrKeyInactive = "inactive" AttrKeyRecvOnly = "recvonly" AttrKeySendOnly = "sendonly" AttrKeySendRecv = "sendrecv" AttrKeyExtMap = "extmap" AttrKeyExtMapAllowMixed = "extmap-allow-mixed" )
Constants for SDP attributes used in JSEP
const ( SemanticTokenLipSynchronization = "LS" SemanticTokenFlowIdentification = "FID" SemanticTokenForwardErrorCorrection = "FEC" SemanticTokenWebRTCMediaStreams = "WMS" )
Constants for semantic tokens used in JSEP
const (
ExtMapValueTransportCC = 3
)
Constants for extmap key
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attribute ¶
Attribute describes the "a=" field which represents the primary means for extending SDP.
func NewAttribute ¶
NewAttribute constructs a new attribute
func NewPropertyAttribute ¶
NewPropertyAttribute constructs a new attribute
func (Attribute) IsICECandidate ¶
IsICECandidate returns true if the attribute key equals "candidate".
type Bandwidth ¶
Bandwidth describes an optional field which denotes the proposed bandwidth to be used by the session or media.
type Codec ¶
type Codec struct { PayloadType uint8 Name string ClockRate uint32 EncodingParameters string Fmtp string RTCPFeedback []string }
Codec represents a codec
type ConnectionInformation ¶
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 ¶
NewDirection defines a procedure for creating a new direction from a raw 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 (e EncryptionKey) String() string
type ExtMap ¶
ExtMap represents the activation of a single RTP header extension
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, _ []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) WithFingerprint ¶
func (d *MediaDescription) WithFingerprint(algorithm, value string) *MediaDescription
WithFingerprint adds a fingerprint 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.
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.
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 ¶
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 ¶
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, error)
NewJSEPSessionDescription creates a new SessionDescription with some settings that are required by the JSEP spec.
Note: Since v2.4.0, session ID has been fixed to use crypto random according to
JSEP spec, so that NewJSEPSessionDescription now returns error as a second return value.
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) MarshalSize ¶ added in v3.0.7
func (s *SessionDescription) MarshalSize() (marshalSize int)
MarshalSize returns the size of the SessionDescription once marshaled.
func (*SessionDescription) Unmarshal ¶
func (s *SessionDescription) Unmarshal(value []byte) error
Unmarshal converts the value into a []byte and then calls UnmarshalString. Callers should use the more performant UnmarshalString
func (*SessionDescription) UnmarshalString ¶ added in v3.0.8
func (s *SessionDescription) UnmarshalString(value string) error
UnmarshalString 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*)*
possible place and state to exit:
** * * * ** * * * * 99 1 1 1 11 1 1 1 1 3 1 1 26 5 5 4 4
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 ¶
func (s *SessionDescription) WithMedia(md *MediaDescription) *SessionDescription
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 ¶
TimeZone defines the structured object for "z=" line which describes repeated sessions scheduling.