v0.0.0-...-18f3c65 Latest Latest

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

Go to latest
Published: Sep 13, 2020 License: Apache-2.0 Imports: 9 Imported by: 0




View Source
const (
	HeaderSize           = 12
	EventHeaderSize      = 4
	Version         byte = 2


View Source
var (
	ErrBadVersion                  = errors.New("bad rtp version header")
	ErrExtendedHeadersNotSupported = errors.New("rtp extended headers not supported")


func CharToDtmf

func CharToDtmf(ch byte) (event uint8, err error)

Turns ascii character into corresponding telephone event.

func DtmfToChar

func DtmfToChar(event uint8) (byte, error)

Turns telephone event into ASCII character.

func Listen

func Listen(host string) (sock net.PacketConn, err error)


type EventHeader

type EventHeader struct {
	// The event field is a number between 0 and 255 identifying a specific
	// telephony event. An IANA registry of event codes for this field has been
	// established (see IANA Considerations, Section 7). The initial content of
	// this registry consists of the events defined in Section 3.
	Event uint8

	// If set to a value of one, the "end" bit indicates that this packet
	// contains the end of the event. For long-lasting events that have to be
	// split into segments (see below, Section, only the final packet
	// for the final segment will have the E bit set.
	E bool

	// This field is reserved for future use. The sender MUST set it to zero, and
	// the receiver MUST ignore it.
	R bool

	// For DTMF digits and other events representable as tones, this field
	// describes the power level of the tone, expressed in dBm0 after dropping
	// the sign. Power levels range from 0 to -63 dBm0. Thus, larger values
	// denote lower volume. This value is defined only for events for which the
	// documentation indicates that volume is applicable. For other events, the
	// sender MUST set volume to zero and the receiver MUST ignore the value.
	Volume uint8

	// The duration field indicates the duration of the event or segment being
	// reported, in timestamp units, expressed as an unsigned integer in network
	// byte order. For a non-zero value, the event or segment began at the
	// instant identified by the RTP timestamp and has so far lasted as long as
	// indicated by this parameter. The event may or may not have ended. If the
	// event duration exceeds the maximum representable by the duration field,
	// the event is split into several contiguous segments as described below
	// (Section
	// The special duration value of zero is reserved to indicate that the event
	// lasts "forever", i.e., is a state and is considered to be effective until
	// updated. A sender MUST NOT transmit a zero duration for events other than
	// those defined as states. The receiver SHOULD ignore an event report with
	// zero duration if the event is not a state.
	// Events defined as states MAY contain a non-zero duration, indicating that
	// the sender intends to refresh the state before the time duration has
	// elapsed ("soft state").
	// For a sampling rate of 8000 Hz, the duration field is sufficient to
	// express event durations of up to approximately 8 seconds.
	Duration uint16

EventHeader stores things like DTMF and is encoded after Header.

func (*EventHeader) Read

func (h *EventHeader) Read(b []byte)

Reads header bits from buffer.

func (*EventHeader) Write

func (h *EventHeader) Write(b []byte)

Writes header bits to buffer.

type Frame

type Frame [160]int16
type Header struct {
	Pad  bool   // Padding flag is used for secure RTP.
	Mark bool   // Marker flag is used for RFC2833.
	PT   uint8  // Payload type you got from SDP.
	Seq  uint16 // Sequence id useful for reordering packets.
	TS   uint32 // Timestamp measured in samples.
	Ssrc uint32 // Random ID used to identify an RTP session.

Header is encoded at the beginning of a UDP audio packet.

func (*Header) Read

func (h *Header) Read(b []byte) error

Read extracts an RTP header from a byte slice.

func (*Header) Write

func (h *Header) Write(b []byte) []byte

Write appends an RTP header to a byte slice.

type Session

type Session struct {

	// Channel to which received RTP frames and errors are published.
	C <-chan *Frame
	R chan<- *Frame
	E <-chan error

	// Underlying UDP socket.
	Sock *net.UDPConn

	// Address of remote endpoint. This might change mid-session. If it's nil,
	// then egress packets are dropped.
	Peer *net.UDPAddr

	// Header is the current header that gets mutated with each transmit.
	Header Header
	// contains filtered or unexported fields

Session allows sending and receiving slinear frames for a single SIP media session. These frames are encoded as µLaw and transmitted over UDP. No support for RTCP is provided.

func NewSession

func NewSession(host string) (rs *Session, err error)

Creates a new RTP µLaw 20ptime session listening on host with a random port selected from the range [16384,32768].

func (*Session) Close

func (rs *Session) Close()

func (*Session) CloseAfterError

func (rs *Session) CloseAfterError()

func (*Session) Send

func (rs *Session) Send(frame *Frame) (err error)

func (*Session) SendDTMF

func (rs *Session) SendDTMF(digit byte) error

func (*Session) SendRaw

func (rs *Session) SendRaw(pt uint8, data []byte, samps uint32) (err error)

Jump to

Keyboard shortcuts

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