core

package
v1.8.3 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2023 License: MIT Imports: 16 Imported by: 3

README

PCM

RTSP

  • PayloadType=10 - L16/44100/2 - Linear PCM 16-bit big endian
  • PayloadType=11 - L16/44100/1 - Linear PCM 16-bit big endian

https://en.wikipedia.org/wiki/RTP_payload_formats

Apple QuickTime

  • raw - 16-bit data is stored in little endian format
  • twos - 16-bit data is stored in big endian format
  • sowt - 16-bit data is stored in little endian format
  • in24 - denotes 24-bit, big endian
  • in32 - denotes 32-bit, big endian
  • fl32 - denotes 32-bit floating point PCM
  • fl64 - denotes 64-bit floating point PCM
  • alaw - denotes A-law logarithmic PCM
  • ulaw - denotes mu-law logarithmic PCM

https://wiki.multimedia.cx/index.php/PCM

FFmpeg RTSP

pcm_s16be, 44100 Hz, stereo => 10
pcm_s16be, 48000 Hz, stereo => 96 L16/48000/2
pcm_s16be, 44100 Hz, mono   => 11

pcm_s16le, 48000 Hz, stereo => 96 (b=AS:1536)
pcm_s16le, 44100 Hz, stereo => 96 (b=AS:1411)
pcm_s16le, 16000 Hz, stereo => 96 (b=AS:512)
pcm_s16le, 8000 Hz, stereo  => 96 (b=AS:256)

pcm_s16le, 48000 Hz, mono   => 96 (b=AS:768)
pcm_s16le, 44100 Hz, mono   => 96 (b=AS:705)
pcm_s16le, 16000 Hz, mono   => 96 (b=AS:256)
pcm_s16le, 8000 Hz, mono    => 96 (b=AS:128)

Documentation

Index

Constants

View Source
const (
	DirectionRecvonly = "recvonly"
	DirectionSendonly = "sendonly"
	DirectionSendRecv = "sendrecv"
)
View Source
const (
	KindVideo = "video"
	KindAudio = "audio"
)
View Source
const (
	CodecH264 = "H264" // payloadType: 96
	CodecH265 = "H265"
	CodecVP8  = "VP8"
	CodecVP9  = "VP9"
	CodecAV1  = "AV1"
	CodecJPEG = "JPEG" // payloadType: 26

	CodecPCMU = "PCMU" // payloadType: 0
	CodecPCMA = "PCMA" // payloadType: 8
	CodecAAC  = "MPEG4-GENERIC"
	CodecOpus = "OPUS" // payloadType: 111
	CodecG722 = "G722"
	CodecMP3  = "MPA" // payload: 14, aka MPEG-1 Layer III
	CodecPCM  = "L16" // Linear PCM (big endian)

	CodecPCML = "PCML" // Linear PCM (little endian)

	CodecELD  = "ELD" // AAC-ELD
	CodecFLAC = "FLAC"

	CodecAll = "ALL"
	CodecAny = "ANY"
)
View Source
const (
	UnsupportedCodec    = "unsupported codec"
	WrongMediaDirection = "wrong media direction"
)
View Source
const (
	BufferSize      = 64 * 1024 // 64K
	ConnDialTimeout = time.Second * 3
	ConnDeadline    = time.Second * 5
	ProbeTimeout    = time.Second * 3
)
View Source
const (
	BufferDisable       = 0
	BufferDrainAndClear = -1
)
View Source
const PayloadTypeRAW byte = 255
View Source
const ProbeSize = 5 * 1024 * 1024 // 5MB

ProbeSize in my tests MPEG-TS 40Mbit/s 4K-video require more than 1MB for probe

Variables

View Source
var ErrCantGetTrack = errors.New("can't get track")

Functions

func Any added in v1.5.0

func Any(errs ...error) error

func Assert

func Assert(ok bool)

func Atoi added in v1.5.0

func Atoi(s string) (i int)

func Between

func Between(s, sub1, sub2 string) string

func Caller

func Caller() string

func DecodeH264

func DecodeH264(fmtp string) string

func GetKind

func GetKind(name string) string

func MarshalSDP

func MarshalSDP(name string, medias []*Media) ([]byte, error)

func Now90000 added in v1.5.0

func Now90000() uint32

Now90000 - timestamp for Video (clock rate = 90000 samples per second)

func RandString

func RandString(size, base byte) string

RandString base10 - numbers, base16 - hex, base36 - digits+letters base64 - URL safe symbols, base0 - crypto random

Types

type Codec

type Codec struct {
	Name        string // H264, PCMU, PCMA, opus...
	ClockRate   uint32 // 90000, 8000, 16000...
	Channels    uint16 // 0, 1, 2
	FmtpLine    string
	PayloadType uint8
}

func UnmarshalCodec

func UnmarshalCodec(md *sdp.MediaDescription, payloadType string) *Codec

func (*Codec) Clone

func (c *Codec) Clone() *Codec

func (*Codec) IsAudio added in v1.7.0

func (c *Codec) IsAudio() bool

func (*Codec) IsRTP

func (c *Codec) IsRTP() bool

func (*Codec) IsVideo added in v1.7.0

func (c *Codec) IsVideo() bool

func (*Codec) Kind added in v1.7.0

func (c *Codec) Kind() string

func (*Codec) Match

func (c *Codec) Match(remote *Codec) bool

func (*Codec) PrintName added in v1.7.0

func (c *Codec) PrintName() string

func (*Codec) String

func (c *Codec) String() string

func (*Codec) Text

func (c *Codec) Text() string

type Consumer

type Consumer interface {
	// GetMedias - return Media(s) with local Media.Direction:
	// - sendonly for Consumer Video/Audio
	// - recvonly for Consumer backchannel
	GetMedias() []*Media

	AddTrack(media *Media, codec *Codec, track *Receiver) error

	// Deprecated: rename to Close()
	Stop() error
}

type EventFunc

type EventFunc func(msg any)

type HandlerFunc

type HandlerFunc func(packet *rtp.Packet)

HandlerFunc like http.HandlerFunc

type Info

type Info struct {
	Type       string      `json:"type,omitempty"`
	URL        string      `json:"url,omitempty"`
	RemoteAddr string      `json:"remote_addr,omitempty"`
	UserAgent  string      `json:"user_agent,omitempty"`
	SDP        string      `json:"sdp,omitempty"`
	Medias     []*Media    `json:"medias,omitempty"`
	Receivers  []*Receiver `json:"receivers,omitempty"`
	Senders    []*Sender   `json:"senders,omitempty"`
	Recv       int         `json:"recv,omitempty"`
	Send       int         `json:"send,omitempty"`
}

type Listener

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

Listener base struct for all classes with support feedback

func (*Listener) Fire

func (l *Listener) Fire(msg any)

func (*Listener) Listen

func (l *Listener) Listen(f EventFunc)

type Media

type Media struct {
	Kind      string   `json:"kind,omitempty"`      // video or audio
	Direction string   `json:"direction,omitempty"` // sendonly, recvonly
	Codecs    []*Codec `json:"codecs,omitempty"`

	ID string `json:"id,omitempty"` // MID for WebRTC, Control for RTSP
}

Media take best from: - deepch/vdk/format/rtsp/sdp.Media - pion/sdp.MediaDescription

func ParseQuery

func ParseQuery(query map[string][]string) (medias []*Media)

func UnmarshalMedia

func UnmarshalMedia(md *sdp.MediaDescription) *Media

func (*Media) Clone

func (m *Media) Clone() *Media

func (*Media) Equal added in v1.3.2

func (m *Media) Equal(media *Media) bool

func (*Media) MarshalJSON

func (m *Media) MarshalJSON() ([]byte, error)

func (*Media) MatchAll

func (m *Media) MatchAll() bool

func (*Media) MatchCodec

func (m *Media) MatchCodec(remote *Codec) *Codec

func (*Media) MatchMedia

func (m *Media) MatchMedia(remote *Media) (codec, remoteCodec *Codec)

func (*Media) String

func (m *Media) String() string

type Mode

type Mode byte
const (
	ModeActiveProducer Mode = iota + 1 // typical source (client)
	ModePassiveConsumer
	ModePassiveProducer
	ModeActiveConsumer
)

func (Mode) String

func (m Mode) String() string

type OnceBuffer added in v1.7.0

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

OnceBuffer will catch only first message

func (*OnceBuffer) Buffer added in v1.7.0

func (o *OnceBuffer) Buffer() []byte

func (*OnceBuffer) Len added in v1.7.0

func (o *OnceBuffer) Len() int

func (*OnceBuffer) Write added in v1.7.0

func (o *OnceBuffer) Write(p []byte) (n int, err error)

func (*OnceBuffer) WriteTo added in v1.7.0

func (o *OnceBuffer) WriteTo(w io.Writer) (n int64, err error)

type Packet added in v1.7.0

type Packet struct {
	PayloadType uint8
	Sequence    uint16
	Timestamp   uint32 // PTS if DTS == 0 else DTS
	Composition uint32 // CTS = PTS-DTS (for support B-frames)
	Payload     []byte
}

type Producer

type Producer interface {
	// GetMedias - return Media(s) with local Media.Direction:
	// - recvonly for Producer Video/Audio
	// - sendonly for Producer backchannel
	GetMedias() []*Media

	// GetTrack - return Receiver, that can only produce rtp.Packet(s)
	GetTrack(media *Media, codec *Codec) (*Receiver, error)

	// Deprecated: rename to Run()
	Start() error

	// Deprecated: rename to Close()
	Stop() error
}

type ReadBuffer added in v1.7.0

type ReadBuffer struct {
	io.Reader

	BufferSize int
	// contains filtered or unexported fields
}

ReadBuffer support buffering and Seek over buffer positive BufferSize will enable buffering mode Seek to negative offset will clear buffer Seek with a positive BufferSize will continue buffering after the last read from the buffer Seek with a negative BufferSize will clear buffer after the last read from the buffer Read more than BufferSize will raise error

func NewReadBuffer added in v1.7.0

func NewReadBuffer(rd io.Reader) *ReadBuffer

func (*ReadBuffer) Close added in v1.7.0

func (r *ReadBuffer) Close() error

func (*ReadBuffer) Peek added in v1.7.0

func (r *ReadBuffer) Peek(n int) ([]byte, error)

func (*ReadBuffer) Read added in v1.7.0

func (r *ReadBuffer) Read(p []byte) (n int, err error)

func (*ReadBuffer) Reset added in v1.7.0

func (r *ReadBuffer) Reset()

func (*ReadBuffer) Seek added in v1.7.0

func (r *ReadBuffer) Seek(offset int64, whence int) (int64, error)

type Receiver

type Receiver struct {
	Codec *Codec
	Media *Media

	ID byte // Channel for RTSP, PayloadType for MPEG-TS
	// contains filtered or unexported fields
}

func NewReceiver

func NewReceiver(media *Media, codec *Codec) *Receiver

func VA added in v1.7.0

func VA(receivers []*Receiver) (video, audio *Receiver)

VA - helper, for extract video and audio receivers from list

func (*Receiver) Close

func (t *Receiver) Close()

func (*Receiver) MarshalJSON

func (t *Receiver) MarshalJSON() ([]byte, error)

func (*Receiver) Replace

func (t *Receiver) Replace(target *Receiver)

func (*Receiver) Senders

func (t *Receiver) Senders() (senders []*Sender)

func (*Receiver) String

func (t *Receiver) String() string

func (*Receiver) WriteRTP

func (t *Receiver) WriteRTP(packet *rtp.Packet)

WriteRTP - fast and non blocking write to all readers buffers

type Sender

type Sender struct {
	Codec *Codec
	Media *Media

	Handler HandlerFunc
	// contains filtered or unexported fields
}

func NewSender

func NewSender(media *Media, codec *Codec) *Sender

func (*Sender) Close

func (s *Sender) Close()

func (*Sender) HandleRTP

func (s *Sender) HandleRTP(track *Receiver)

func (*Sender) MarshalJSON

func (s *Sender) MarshalJSON() ([]byte, error)

func (*Sender) String

func (s *Sender) String() string

type SuperConsumer added in v1.7.0

type SuperConsumer struct {
	Type       string    `json:"type,omitempty"`
	URL        string    `json:"url,omitempty"`
	RemoteAddr string    `json:"remote_addr,omitempty"`
	UserAgent  string    `json:"user_agent,omitempty"`
	SDP        string    `json:"sdp,omitempty"`
	Medias     []*Media  `json:"medias,omitempty"`
	Senders    []*Sender `json:"senders,omitempty"`
	Send       int       `json:"send,omitempty"`
}

func (*SuperConsumer) AddTrack added in v1.7.0

func (s *SuperConsumer) AddTrack(media *Media, codec *Codec, track *Receiver) error

func (*SuperConsumer) Close added in v1.7.0

func (s *SuperConsumer) Close() error

func (*SuperConsumer) Codecs added in v1.7.0

func (s *SuperConsumer) Codecs() []*Codec

func (*SuperConsumer) GetMedias added in v1.7.0

func (s *SuperConsumer) GetMedias() []*Media

type SuperProducer added in v1.7.0

type SuperProducer struct {
	Type      string      `json:"type,omitempty"`
	URL       string      `json:"url,omitempty"`
	SDP       string      `json:"sdp,omitempty"`
	Medias    []*Media    `json:"medias,omitempty"`
	Receivers []*Receiver `json:"receivers,omitempty"`
	Recv      int         `json:"recv,omitempty"`
}

func (*SuperProducer) Close added in v1.7.0

func (s *SuperProducer) Close() error

func (*SuperProducer) GetMedias added in v1.7.0

func (s *SuperProducer) GetMedias() []*Media

func (*SuperProducer) GetTrack added in v1.7.0

func (s *SuperProducer) GetTrack(media *Media, codec *Codec) (*Receiver, error)

type Waiter

type Waiter struct {
	sync.WaitGroup
	// contains filtered or unexported fields
}

Waiter support: - autotart on first Wait - block new waiters after last Done - safe Done after finish

func (*Waiter) Add

func (w *Waiter) Add(delta int)

func (*Waiter) Done

func (w *Waiter) Done(err error)

func (*Waiter) Wait

func (w *Waiter) Wait() error

func (*Waiter) WaitChan

func (w *Waiter) WaitChan() <-chan error

type Worker

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

func NewWorker

func NewWorker(d time.Duration, f func() time.Duration) *Worker

NewWorker run f after d

func (*Worker) Do

func (w *Worker) Do()

Do - instant timer run

func (*Worker) Stop

func (w *Worker) Stop()

type WriteBuffer added in v1.7.0

type WriteBuffer struct {
	io.Writer
	// contains filtered or unexported fields
}

WriteBuffer by defaul Write(s) to bytes.Buffer. But after WriteTo to new io.Writer - calls Reset. Reset will flush current buffer data to new writer and starts to Write to new io.Writer WriteTo will be locked until Write fails or Close will be called.

func NewWriteBuffer added in v1.7.0

func NewWriteBuffer(wr io.Writer) *WriteBuffer

func (*WriteBuffer) Close added in v1.7.0

func (w *WriteBuffer) Close() error

func (*WriteBuffer) Reset added in v1.7.0

func (w *WriteBuffer) Reset(wr io.Writer)

func (*WriteBuffer) Write added in v1.7.0

func (w *WriteBuffer) Write(p []byte) (n int, err error)

func (*WriteBuffer) WriteTo added in v1.7.0

func (w *WriteBuffer) WriteTo(wr io.Writer) (n int64, err error)

Jump to

Keyboard shortcuts

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