sdp

package
v0.0.0-...-b80fe72 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2024 License: ISC Imports: 11 Imported by: 0

Documentation

Overview

Package sdp implements encoding and decoding of Session Description Protocol formatted data as specified in RFC 8866.

Example

A simple Session describing transmission of uncompressed linear PCM audio in RTP starts by setting the mandatory fields Origin and Name. The Media field contains information about the audio such as the sample rate and the number of audio channels. The Session type implements fmt.Stringer; to encode a Session in the SDP text format, use Session.String().

package main

import (
	"fmt"
	"net/netip"

	"github.com/untangledco/streaming/rtp"
	"github.com/untangledco/streaming/sdp"
)

func main() {
	session := sdp.Session{
		Origin: sdp.Origin{
			ID:      3930287268, // example only; use sdp.Now()
			Version: 3930287268, // example only; use sdp.Now()
			Address: netip.MustParseAddr("2001:db8::1"),
		},
		Name: "A call from me to you",
		Media: []sdp.Media{
			{
				Type:      sdp.MediaTypeAudio,
				Port:      6969,
				Transport: sdp.ProtoRTP,
				Format:    []string{rtp.PayloadL16Mono.String()},
				Attributes: []string{
					"rtpmap:" + rtp.PayloadL16Mono.String(),
					"L16/22050",
				},
			},
		},
	}
	fmt.Printf("%s", session)
}
Output:

v=0
o=- 3930287268 3930287268 IN IP6 2001:db8::1
s=A call from me to you
t=0 0
m=audio 6969 RTP/AVP 11
a=rtpmap:11 L16/22050

Index

Examples

Constants

View Source
const (
	BandwidthConferenceTotal = "CT"
	BandwidthAppSpecific     = "AS"
)
View Source
const NoUsername string = "-"

Variables

This section is empty.

Functions

func Now

func Now() int

Now returns the current SDP timestamp; the number of seconds since 1900-01-01T00:00Z.

Types

type Bandwidth

type Bandwidth struct {
	// Type describes the value of Bitrate, usually one of
	// BandwidthConferenceTotal or BandwidthAppSpecific.
	Type string
	// Bitrate is the measure of bits per second.
	Bitrate int
}

func (Bandwidth) String

func (b Bandwidth) String() string

type ConnInfo

type ConnInfo struct {
	Address netip.Addr
	// TTL is the time-to-live of IPv4 multicast packets.
	TTL uint8
	// Count is the number of subsequent IP addresses after
	// Address used in the session.
	Count int
}

ConnInfo represents connection information.

func (*ConnInfo) String

func (c *ConnInfo) String() string

type Media

type Media struct {
	Type      MediaType
	Port      int // IP port
	PortCount int // count of subsequent ports from Port
	Transport TransportProto
	// Format describes the media format. Interpretation of the
	// entries depends on the value of Transport. For example, if
	// Transport is ProtoRTP, Format contains RTP payload type
	// numbers. For more, see the <fmt> description in section 5.14
	// of RFC 8866.
	Format []string

	// Optional fields
	Title      string
	Connection *ConnInfo
	Bandwidth  *Bandwidth
	Attributes []string
}

Media represents a media description.

func (Media) String

func (m Media) String() string

type MediaType

type MediaType uint8
const (
	MediaTypeAudio MediaType = iota
	MediaTypeVideo
	MediaTypeText
	MediaTypeApplication
	MediaTypeMessage
	MediaTypeImage
)

func (MediaType) String

func (t MediaType) String() string

type Origin

type Origin struct {
	// Username is a named identity on the originating host. If unset,
	// the encoded value will be NoUsername.
	Username string

	// ID is a globally unique identifier for the session.
	// The recommended value is a timestamp from Now().
	ID int

	// Version is a version number of the session. It should be
	// incremented each time the session is modified. The recommended
	// value is a timestamp from Now().
	Version int

	// Address is the originating address of the session.
	Address netip.Addr
}

Origin represents the originator of the session as described in RFC 8866 section 5.2.

type Repeat

type Repeat struct {
	Interval time.Duration   // duration between each repetition cycle
	Active   time.Duration   // planned duration of each session
	Offsets  []time.Duration // duration(s) between each session
}

Repeat represents a session's repetition cycle as described in RFC 8866 section 5.10.

func (*Repeat) String

func (rp *Repeat) String() string

type Session

type Session struct {
	Origin Origin
	Name   string

	Info       string
	URI        *url.URL
	Email      *mail.Address
	Phone      string
	Connection *ConnInfo
	Bandwidth  *Bandwidth
	// Time holds the start time and stop time of the Session, at
	// the first and second index respectively.
	Time [2]time.Time
	// Repeat points to a repetition cycle describing for how long
	// and when the session may reoccur.
	Repeat *Repeat
	// Adjustments holds any time adjustments that may occur, for
	// example daylight savings, throughout the period a repetition
	// cycle is active.
	Adjustments []TimeAdjustment
	Attributes  []string
	Media       []Media
}

func ReadSession

func ReadSession(rd io.Reader) (*Session, error)

func (Session) String

func (s Session) String() string

type TimeAdjustment

type TimeAdjustment struct {
	When   time.Time
	Offset time.Duration
}

func (TimeAdjustment) String

func (t TimeAdjustment) String() string

type TransportProto

type TransportProto uint8
const (
	ProtoUDP TransportProto = iota
	ProtoRTP
	ProtoRTPSecure
	ProtoRTPSecureFeedback
)

func (TransportProto) String

func (tp TransportProto) String() string

Jump to

Keyboard shortcuts

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