sdp

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2023 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sdp implements RFC 4566 SDP: Session Description Protocol.

Index

Constants

This section is empty.

Variables

View Source
var ErrFailedToDecodeIP = errors.New("invalid IP")

ErrFailedToDecodeIP means that decoder failed to parse IP.

Functions

func NTPToTime

func NTPToTime(v uint64) time.Time

NTPToTime converts NTP timestamp to time.Time with special case for Zero time, that is interpreted as 0 timestamp.

func TimeToNTP

func TimeToNTP(t time.Time) uint64

TimeToNTP converts time.Time to NTP timestamp with special case for Zero time, that is interpreted as 0 timestamp.

Types

type Attribute

type Attribute struct {
	Key   string
	Value string
}

Attribute represents key:value pair.

type Attributes

type Attributes []Attribute

Attributes is list of k:v.

func (Attributes) Flag

func (a Attributes) Flag(flag string) bool

Flag returns true if set.

func (Attributes) Value

func (a Attributes) Value(attribute string) string

Value returns value of first attribute.

func (Attributes) Values

func (a Attributes) Values(attribute string) []string

Values returns list of values associated to attribute.

type BandwidthType

type BandwidthType string

BandwidthType is <bwtype> sub-field of Bandwidth field.

const (
	BandwidthConferenceTotal     BandwidthType = "CT"
	BandwidthApplicationSpecific BandwidthType = "AS"
	// defined in RFC 3890
	BandwidthApplicationSpecificTransportIndependent BandwidthType = "TIAS"
)

Possible values for <bwtype> defined in section 5.8.

type Bandwidths

type Bandwidths map[BandwidthType]int

Bandwidths is map of BandwidthsType and int (bytes per second).

type ConnectionData

type ConnectionData struct {
	NetworkType string // <nettype>
	AddressType string // <addrtype>
	IP          net.IP // <base multicast address>
	TTL         byte   // <ttl>
	Addresses   byte   // <number of addresses>
}

ConnectionData is representation for Connection Data field. Only IP field is required. NetworkType and AddressType have sensible defaults.

func (ConnectionData) Blank

func (c ConnectionData) Blank() bool

Blank determines if ConnectionData is blank value.

func (ConnectionData) ConnectionAddress

func (c ConnectionData) ConnectionAddress() string

ConnectionAddress formats <connection-address> sub-field.

func (ConnectionData) Equal

func (c ConnectionData) Equal(b ConnectionData) bool

Equal returns c == b.

func (ConnectionData) String

func (c ConnectionData) String() string

type DecodeError

type DecodeError struct {
	Reason string
	Place  string
}

DecodeError wraps Reason of error and occurrence Place.

func (DecodeError) Error

func (e DecodeError) Error() string

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

Decoder decodes session.

func NewDecoder

func NewDecoder(s Session) Decoder

NewDecoder returns Decoder for Session.

func (*Decoder) Decode

func (d *Decoder) Decode(m *Message) error

Decode message from session.

type Encryption

type Encryption struct {
	Method string
	Key    string
}

Encryption wraps encryption Key and Method.

func (Encryption) Blank

func (e Encryption) Blank() bool

Blank determines whether Encryption is blank value.

func (Encryption) Equal

func (e Encryption) Equal(b Encryption) bool

Equal returns e == b.

type Line

type Line struct {
	Type  Type
	Value []byte
}

Line of SDP session.

Form

<type>=<value>

Where <type> MUST be exactly one case-significant character and <value> is structured text whose format depends on <type>.

func (Line) AppendTo

func (l Line) AppendTo(b []byte) []byte

AppendTo appends Line encoded value to b.

func (*Line) Decode

func (l *Line) Decode(b []byte) error

Decode parses b into l and returns error if any.

Decode does not reuse b, so it is safe to corrupt it.

func (Line) Equal

func (l Line) Equal(b Line) bool

Equal returns true if l == b.

func (Line) String

func (l Line) String() string

type Media

type Media struct {
	Title       string
	Description MediaDescription
	Connection  ConnectionData
	Attributes  Attributes
	Encryption  Encryption
	Bandwidths  Bandwidths
}

Media is media description and attributes.

func (*Media) AddAttribute

func (m *Media) AddAttribute(k string, values ...string)

AddAttribute appends new k-v pair to attribute list.

func (*Media) AddFlag

func (m *Media) AddFlag(f string)

AddFlag appends new flag to attribute list.

func (*Media) Attribute

func (m *Media) Attribute(k string) string

Attribute returns string v.

func (*Media) Flag

func (m *Media) Flag(f string) bool

Flag returns true if set.

func (*Media) PayloadFormat

func (m *Media) PayloadFormat(payloadType string) string

PayloadFormat returns payload format from a=rtpmap. See RFC 4566 Section 6.

type MediaDescription

type MediaDescription struct {
	Type        string
	Port        int
	PortsNumber int
	Protocol    string
	Formats     []string
}

MediaDescription represents Media Description field value.

func (MediaDescription) Equal

Equal returns true if b equals to m.

type Medias

type Medias []Media

Medias is list of Media.

type Message

type Message struct {
	Version       int
	Origin        Origin
	Name          string
	Info          string
	Email         string
	Phone         string
	URI           string
	Connection    ConnectionData
	Attributes    Attributes
	Medias        Medias
	Encryption    Encryption
	Bandwidths    map[BandwidthType]int
	BandwidthType BandwidthType
	Timing        []Timing
	TZAdjustments []TimeZone
}

Message is top level abstraction.

func Decode

func Decode(b []byte) (*Message, error)

Decode decodes b as SDP message, returning error if any.

func (*Message) AddAttribute

func (m *Message) AddAttribute(k, v string)

AddAttribute appends new k-v pair to attribute list.

func (*Message) AddFlag

func (m *Message) AddFlag(f string)

AddFlag appends new flag to attribute list.

func (*Message) Append

func (m *Message) Append(s Session) Session

Append encodes message to Session and returns result.

See RFC 4566 Section 5.

func (*Message) Attribute

func (m *Message) Attribute(attribute string) string

Attribute returns string v.

func (*Message) End

func (m *Message) End() time.Time

End returns end of session.

func (*Message) Flag

func (m *Message) Flag(flag string) bool

Flag returns true if set.

func (*Message) Start

func (m *Message) Start() time.Time

Start returns start of session.

type Origin

type Origin struct {
	Username       string // <username>
	SessionID      int64  // <sess-id>
	SessionVersion int64  // <sess-version>
	NetworkType    string // <nettype>
	AddressType    string // <addrtype>
	Address        string // <unicast-address>
}

Origin is field defined in RFC4566 5.2. See https://tools.ietf.org/html/rfc4566#section-5.2.

func (*Origin) Equal

func (o *Origin) Equal(b Origin) bool

Equal returns b == o.

type RtpMap

type RtpMap struct {
	Type   int
	Format string
	Rate   int
}

func NewRtpMap

func NewRtpMap(typ int, format string, rate int) *RtpMap

func ParseRtpMap

func ParseRtpMap(s string) (*RtpMap, error)

func (*RtpMap) String

func (m *RtpMap) String() string

type Session

type Session []Line

Session is set of Lines.

func DecodeSession

func DecodeSession(b []byte, s Session) (Session, error)

DecodeSession decodes Session from b, returning error if any. Blank lines and leading/trialing whitespace are ignored.

If s is passed, it will be reused with its lines. It is safe to mutate b.

func (Session) AddAttribute

func (s Session) AddAttribute(attribute string, values ...string) Session

AddAttribute appends Attribute field to Session in a=<attribute>:<value>" form. If len(values) > 1, then "<value>" is "<val1> <val2> ... <valn>", and if len(values) == 0, then AddFlag method is used in "a=<flag>" form.

func (Session) AddBandwidth

func (s Session) AddBandwidth(t BandwidthType, bandwidth int) Session

AddBandwidth appends Bandwidth field to Session.

func (Session) AddConnectionData

func (s Session) AddConnectionData(data ConnectionData) Session

AddConnectionData appends Connection Data field to Session using ConnectionData struct with sensible defaults.

func (Session) AddConnectionDataIP

func (s Session) AddConnectionDataIP(ip net.IP) Session

AddConnectionDataIP appends Connection Data field using only ip address.

func (Session) AddEmail

func (s Session) AddEmail(email string) Session

AddEmail appends Email Address field to Session.

func (Session) AddEncryption

func (s Session) AddEncryption(e Encryption) Session

AddEncryption appends Encryption and is shorthand for AddEncryptionKey.

func (Session) AddEncryptionKey

func (s Session) AddEncryptionKey(method, key string) Session

AddEncryptionKey appends Encryption Key field with method and key in "k=<method>:<encryption key>" format to Session.

func (Session) AddEncryptionMethod

func (s Session) AddEncryptionMethod(method string) Session

AddEncryptionMethod appends Encryption Key field with only method in "k=<method>" format to Session.

func (Session) AddFlag

func (s Session) AddFlag(attribute string) Session

AddFlag appends Attribute field to Session in "a=<flag>" form.

func (Session) AddLine

func (s Session) AddLine(t Type, v string) Session

AddLine appends t=v to Session.

func (Session) AddMediaDescription

func (s Session) AddMediaDescription(m MediaDescription) Session

AddMediaDescription appends Media Description field to Session.

func (Session) AddOrigin

func (s Session) AddOrigin(o Origin) Session

AddOrigin appends Origin field to Session.

func (Session) AddPhone

func (s Session) AddPhone(phone string) Session

AddPhone appends Phone Address field to Session.

func (Session) AddRaw

func (s Session) AddRaw(k rune, v string) Session

AddRaw appends k=v to Session.

func (Session) AddRepeatTimes

func (s Session) AddRepeatTimes(interval, duration time.Duration,
	offsets ...time.Duration) Session

AddRepeatTimes appends Repeat Times field to Session.

func (Session) AddRepeatTimesCompact

func (s Session) AddRepeatTimesCompact(interval, duration time.Duration,
	offsets ...time.Duration) Session

AddRepeatTimesCompact appends Repeat Times field to Session using "compact" syntax.

func (Session) AddSessionInfo

func (s Session) AddSessionInfo(info string) Session

AddSessionInfo appends Session Information field to Session.

func (Session) AddSessionName

func (s Session) AddSessionName(name string) Session

AddSessionName appends Session Name field to Session.

func (Session) AddTimeZones

func (s Session) AddTimeZones(zones ...TimeZone) Session

AddTimeZones append TimeZones field to Session.

func (Session) AddTiming

func (s Session) AddTiming(start, end time.Time) Session

AddTiming appends Timing field to Session. Both start and end can be zero.

func (Session) AddTimingNTP

func (s Session) AddTimingNTP(start, end uint64) Session

AddTimingNTP appends Timing field to Session with NTP timestamps as input. It is just wrapper for AddTiming and NTPToTime.

func (Session) AddURI

func (s Session) AddURI(uri string) Session

AddURI appends Uniform Resource Identifier field to Session.

func (Session) AddVersion

func (s Session) AddVersion(version int) Session

AddVersion appends Version field to Session.

func (Session) AppendTo

func (s Session) AppendTo(b []byte) []byte

AppendTo appends all session lines to b and returns b.

func (Session) Equal

func (s Session) Equal(b Session) bool

Equal returns true if b == s.

type TimeZone

type TimeZone struct {
	Start  time.Time
	Offset time.Duration
}

TimeZone is representation of <adjustment time> <offset> pair.

type Timing

type Timing struct {
	Start   time.Time
	End     time.Time
	Repeat  time.Duration
	Active  time.Duration
	Offsets []time.Duration
}

Timing wraps "repeat times" and "timing" information.

type Type

type Type rune

Type of SDP Line is exactly one case-significant character.

const (
	TypeProtocolVersion    Type = 'v'
	TypeOrigin             Type = 'o'
	TypeSessionName        Type = 's'
	TypeSessionInformation Type = 'i'
	TypeURI                Type = 'u'
	TypeEmail              Type = 'e'
	TypePhone              Type = 'p'
	TypeConnectionData     Type = 'c'
	TypeBandwidth          Type = 'b'
	TypeTiming             Type = 't'
	TypeRepeatTimes        Type = 'r'
	TypeTimeZones          Type = 'z'
	TypeEncryptionKey      Type = 'k'
	TypeAttribute          Type = 'a'
	TypeMediaDescription   Type = 'm'
)

Attribute types as described in RFC 4566.

func (Type) String

func (t Type) String() string

Directories

Path Synopsis
Package errors provides simple error handling primitives.
Package errors provides simple error handling primitives.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL