sdp

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 10, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContentType = "application/sdp"
	MaxLength   = 1450
)

Variables

View Source
var (
	ULAWCodec = Codec{PT: 0, Name: "PCMU", Rate: 8000}
	DTMFCodec = Codec{PT: 101, Name: "telephone-event", Rate: 8000, Fmtp: "0-16"}
	Opus      = Codec{PT: 111, Name: "opus", Rate: 48000, Param: "2"}

	StandardCodecs = map[uint8]Codec{
		0:  ULAWCodec,
		3:  {PT: 3, Name: "GSM", Rate: 8000},
		4:  {PT: 4, Name: "G723", Rate: 8000},
		5:  {PT: 5, Name: "DVI4", Rate: 8000},
		6:  {PT: 6, Name: "DVI4", Rate: 16000},
		7:  {PT: 7, Name: "LPC", Rate: 8000},
		8:  {PT: 8, Name: "PCMA", Rate: 8000},
		9:  {PT: 9, Name: "G722", Rate: 8000},
		10: {PT: 10, Name: "L16", Rate: 44100, Param: "2"},
		11: {PT: 11, Name: "L16", Rate: 44100},
		12: {PT: 12, Name: "QCELP", Rate: 8000},
		13: {PT: 13, Name: "CN", Rate: 8000},
		14: {PT: 14, Name: "MPA", Rate: 90000},
		15: {PT: 15, Name: "G728", Rate: 8000},
		16: {PT: 16, Name: "DVI4", Rate: 11025},
		17: {PT: 17, Name: "DVI4", Rate: 22050},
		18: {PT: 18, Name: "G729", Rate: 8000},
		25: {PT: 25, Name: "CelB", Rate: 90000},
		26: {PT: 26, Name: "JPEG", Rate: 90000},
		28: {PT: 28, Name: "nv", Rate: 90000},
		31: {PT: 31, Name: "H261", Rate: 90000},
		32: {PT: 32, Name: "MPV", Rate: 90000},
		33: {PT: 33, Name: "MP2T", Rate: 90000},
		34: {PT: 34, Name: "H263", Rate: 90000},
	}
)
View Source
var (
	ErrInvalidSDP    = errors.New("invalid sdp")
	WarnMalformedSDP = errors.New("parsing issues in sdp")
)

Functions

This section is empty.

Types

type Codec

type Codec struct {
	PT    uint8  // 7-bit payload type we need to put in our RTP packets
	Name  string // e.g. PCMU, G729, telephone-event, etc.
	Rate  int    // frequency in hertz.  usually 8000
	Param string // sometimes used to specify number of channels
	Fmtp  string // some extra info; i.e. dtmf might set as "0-16"
	// contains filtered or unexported fields
}

Codec describes one of the codec lines in an SDP. This data will be magically filled in if the rtpmap wasn't provided (assuming it's a well known codec having a payload type less than 96.)

func NewCodec added in v0.2.0

func NewCodec(pt uint8) (*Codec, error)

func (*Codec) Append

func (codec *Codec) Append(b *bytes.Buffer)

func (*Codec) IsValid added in v0.2.0

func (codec *Codec) IsValid() bool

If this codec is dynamic, it must have an rtpmap line present. If it is static, an rtpmap line is not required

type Media

type Media struct {
	Type      MediaType         // audio, video, text, application, message, etc.
	Proto     TransportProtocol // RTP, SRTP, UDP, UDPTL, TCP, TLS, etc.
	Port      uint16            // Port number (0 - 2^16-1)
	NumPorts  int               // If multiple ports are being used
	Addr      string            // The address from the media-specific `c=` line, if present
	Direction MediaDirection    // sendrecv, sendonly, recvonly, inactive
	Codecs    []*Codec          // Collection of codecs of a specific type.
	Ptime     int               // Transmit frame every N milliseconds (default 20)
	Maxptime  int               // Maximum number of milliseconds per packet (default 20)
	Attrs     [][2]string       // Attributes for this media description
	Other     [][2]string       // Unrecognized properties for this media description
}

Media is a high level representation of the c=/m=/a= lines for describing a specific type of media. Only "audio" and "video" are supported at this time.

func NewMediaFromLine added in v0.2.0

func NewMediaFromLine(line string, strict bool) (*Media, error)

Parse an `m=` line (e.g. "audio 30126 RTP/AVP 0 96") and return a corresponding Media object

func (*Media) Append

func (media *Media) Append(b *bytes.Buffer)

type MediaDirection added in v0.2.0

type MediaDirection string
const (
	SendRecv MediaDirection = "sendrecv"
	SendOnly MediaDirection = "sendonly"
	RecvOnly MediaDirection = "recvonly"
	Inactive MediaDirection = "inactive"
)

type MediaType added in v0.2.0

type MediaType string

Known media types from RFC8866 sections 5.14 and 8.2.2, and other places

const (
	MediaTypeAudio       MediaType = "audio"
	MediaTypeVideo       MediaType = "video"
	MediaTypeText        MediaType = "text"
	MediaTypeApplication MediaType = "application"
	MediaTypeMessage     MediaType = "message"
	MediaTypeImage       MediaType = "image" // RFC6466
)

func IsKnownMediaType added in v0.2.0

func IsKnownMediaType(name string) (MediaType, bool)

type Origin

type Origin struct {
	User    string // First value in o= line
	ID      string // Second value in o= line
	Version string // Third value in o= line
	Addr    string // Tracks IP of original user-agent
}

Origin represents the session origin (o=) line of an SDP. Who knows what this is supposed to do.

func (*Origin) Append

func (origin *Origin) Append(b *bytes.Buffer)

type SDP

type SDP struct {
	Origin    *Origin        // This must always be present
	Addr      string         // Connect to this IP; never blank (from c=)
	Media     []*Media       // Media descriptions, e.g. audio, video
	Session   string         // s= Session Name (default "-")
	Time      string         // t= Active Time (default "0 0")
	Direction MediaDirection // If 'a=sendonly', 'a=recvonly', or 'a=inactive' was specified in SDP
	Attrs     [][2]string    // a= lines we don't recognize
	Other     [][2]string    // Other description
}

SDP represents a Session Description Protocol SIP payload.

func New

func New(addr *net.UDPAddr, codecs ...*Codec) *SDP

Easy way to create a basic, everyday SDP for VoIP.

func Parse

func Parse(s string, strict bool) (*SDP, error)

parses sdp message text into a happy data structure

func (*SDP) Append

func (sdp *SDP) Append(b *bytes.Buffer)

func (*SDP) ContentType

func (sdp *SDP) ContentType() string

func (*SDP) Data

func (sdp *SDP) Data() []byte

func (*SDP) String

func (sdp *SDP) String() string

type TransportProtocol added in v0.2.0

type TransportProtocol string
const (
	ProtoRTPAVP   TransportProtocol = "RTP/AVP"
	ProtoRTPAVPF  TransportProtocol = "RTP/AVPF"
	ProtoRTPSAVP  TransportProtocol = "RTP/SAVP"
	ProtoRTPSAVPF TransportProtocol = "RTP/SAVPF"
	ProtocolTCPIP TransportProtocol = "TCP/IP"
	ProtocolUDP   TransportProtocol = "udp"
)

func IsKnownTransportProtocol added in v0.2.0

func IsKnownTransportProtocol(name string) (TransportProtocol, bool)

Jump to

Keyboard shortcuts

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