Documentation
¶
Index ¶
- Constants
- Variables
- func Assert(ok bool)
- func Atoi(s string) (i int)
- func Before(s, sep string) string
- func Between(s, sub1, sub2 string) string
- func Caller() string
- func Contains[S ~[]E, E comparable](s S, v E) bool
- func DecodeH264(fmtp string) (profile string, level byte)
- func FFmpegCodecName(name string) string
- func GetKind(name string) string
- func ID(v any) uint32deprecated
- func Index[S ~[]E, E comparable](s S, v E) int
- func MarshalSDP(name string, medias []*Media) ([]byte, error)
- func Max[S ~[]E, E Ordered](x S) E
- func MoveNode(dst, src *Node)
- func NewID() uint32
- func Now90000() uint32
- func RandString(size, base byte) string
- func RegisterCodecHandler(codecName string, factory func(*Codec) CodecHandler)
- func StripUserinfo(s string) string
- type BaseCodecHandler
- func (ch *BaseCodecHandler) ClearCache()
- func (ch *BaseCodecHandler) ProcessPacket(packet *Packet)
- func (ch *BaseCodecHandler) SendCacheTo(s *Sender, playbackFPS int) (nextTimestamp uint32, lastSequence uint16)
- func (ch *BaseCodecHandler) SendQueueTo(s *Sender, playbackFPS int, startTimestamp uint32, lastSequence uint16)
- func (ch *BaseCodecHandler) SetupGOP()
- type Codec
- func (c *Codec) Clone() *Codec
- func (c *Codec) IsAudio() bool
- func (c *Codec) IsRTP() bool
- func (c *Codec) IsVideo() bool
- func (c *Codec) Kind() string
- func (c *Codec) MarshalJSON() ([]byte, error)
- func (c *Codec) Match(remote *Codec) bool
- func (c *Codec) PrintName() string
- func (c *Codec) String() (s string)
- type CodecHandler
- type Connection
- func (c *Connection) Codecs() []*Codecdeprecated
- func (c *Connection) GetMedias() []*Media
- func (c *Connection) GetSource() string
- func (c *Connection) GetTrack(media *Media, codec *Codec) (*Receiver, error)
- func (c *Connection) SetProtocol(s string)
- func (c *Connection) SetRemoteAddr(s string)
- func (c *Connection) SetSource(s string)
- func (c *Connection) SetURL(s string)
- func (c *Connection) Stop() error
- func (c *Connection) WithRequest(r *http.Request)
- type Consumer
- type EventFunc
- type Filter
- type GopCache
- type HandlerFunc
- type Info
- type Listener
- type Media
- func (m *Media) Clone() *Media
- func (m *Media) Equal(media *Media) bool
- func (m *Media) MarshalJSON() ([]byte, error)
- func (m *Media) MatchAll() bool
- func (m *Media) MatchCodec(remote *Codec) *Codec
- func (m *Media) MatchMedia(remote *Media) (codec, remoteCodec *Codec)
- func (m *Media) String() string
- type Mode
- type Node
- type OnceBuffer
- type Ordered
- type Packet
- type Payloader
- type PrebufferCache
- type Producer
- type RTPMixer
- type ReadBuffer
- type Receiver
- type Sender
- func (s *Sender) Bind(parent *Receiver)deprecated
- func (s *Sender) Close()
- func (s *Sender) HandleRTP(parent *Receiver)deprecated
- func (s *Sender) MarshalJSON() ([]byte, error)
- func (s *Sender) Start()
- func (s *Sender) State() string
- func (s *Sender) Wait()
- func (s *Sender) WithParent(parent *Receiver) *Sender
- type StreamPrebuffer
- func (pb *StreamPrebuffer) Add(packet *Packet, trackID byte)
- func (pb *StreamPrebuffer) Clear()
- func (pb *StreamPrebuffer) GetAvailableDuration() int
- func (pb *StreamPrebuffer) GetLatestTimestamp() time.Time
- func (pb *StreamPrebuffer) GetNextPacketAt(currentPos time.Time, maxAllowedTime time.Time) *TimestampedPacket
- func (pb *StreamPrebuffer) GetPacketsFrom(offsetSec int) (startTime time.Time, packets []*TimestampedPacket)
- func (pb *StreamPrebuffer) HasContent() bool
- type TimestampedPacket
- type Waiter
- type Worker
- type WriteBuffer
Constants ¶
const ( DirectionRecvonly = "recvonly" DirectionSendonly = "sendonly" DirectionSendRecv = "sendrecv" )
const ( KindVideo = "video" KindAudio = "audio" )
const ( CodecH264 = "H264" // payloadType: 96 CodecH265 = "H265" CodecVP8 = "VP8" CodecVP9 = "VP9" CodecAV1 = "AV1" CodecJPEG = "JPEG" // payloadType: 26 CodecRAW = "RAW" 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" )
const ( BufferSize = 64 * 1024 // 64K ConnDialTimeout = time.Second * 3 ConnDeadline = time.Second * 5 ProbeTimeout = time.Second * 3 )
const ( BufferDisable = 0 BufferDrainAndClear = -1 )
const (
// MaxPrebufferDuration is the maximum allowed prebuffer duration in seconds
MaxPrebufferDuration = 15
)
const PayloadTypeRAW byte = 255
const ProbeSize = 5 * 1024 * 1024 // 5MB
ProbeSize in my tests MPEG-TS 40Mbit/s 4K-video require more than 1MB for probe
Variables ¶
var ErrCantGetTrack = errors.New("can't get track")
Functions ¶
func Contains ¶ added in v1.9.5
func Contains[S ~[]E, E comparable](s S, v E) bool
Contains reports whether v is present in s.
func DecodeH264 ¶
func FFmpegCodecName ¶ added in v1.9.3
func Index ¶ added in v1.9.5
func Index[S ~[]E, E comparable](s S, v E) int
Index returns the index of the first occurrence of v in s, or -1 if not present.
func Max ¶ added in v1.9.5
func Max[S ~[]E, E Ordered](x S) E
Max returns the maximal value in x. It panics if x is empty. For floating-point E, Max propagates NaNs (any NaN value in x forces the output to be NaN).
func Now90000 ¶
func Now90000() uint32
Now90000 - timestamp for Video (clock rate = 90000 samples per second)
func RandString ¶
RandString base10 - numbers, base16 - hex, base36 - digits+letters base64 - URL safe symbols, base0 - crypto random
func RegisterCodecHandler ¶
func RegisterCodecHandler(codecName string, factory func(*Codec) CodecHandler)
func StripUserinfo ¶ added in v1.9.10
Types ¶
type BaseCodecHandler ¶
type BaseCodecHandler struct {
// contains filtered or unexported fields
}
func (*BaseCodecHandler) ClearCache ¶
func (ch *BaseCodecHandler) ClearCache()
func (*BaseCodecHandler) ProcessPacket ¶
func (ch *BaseCodecHandler) ProcessPacket(packet *Packet)
func (*BaseCodecHandler) SendCacheTo ¶
func (ch *BaseCodecHandler) SendCacheTo(s *Sender, playbackFPS int) (nextTimestamp uint32, lastSequence uint16)
func (*BaseCodecHandler) SendQueueTo ¶
func (ch *BaseCodecHandler) SendQueueTo(s *Sender, playbackFPS int, startTimestamp uint32, lastSequence uint16)
func (*BaseCodecHandler) SetupGOP ¶
func (ch *BaseCodecHandler) SetupGOP()
type Codec ¶
type Codec struct {
Name string // H264, PCMU, PCMA, opus...
ClockRate uint32 // 90000, 8000, 16000...
Channels uint8 // 0, 1, 2
FmtpLine string
PayloadType uint8
}
func ParseCodecString ¶ added in v1.9.10
func UnmarshalCodec ¶
func UnmarshalCodec(md *sdp.MediaDescription, payloadType string) *Codec
func (*Codec) MarshalJSON ¶ added in v1.9.3
MarshalJSON - return FFprobe compatible output
type CodecHandler ¶
type CodecHandler interface {
ProcessPacket(packet *Packet)
SendCacheTo(s *Sender, playbackFPS int) (nextTimestamp uint32, lastSequence uint16)
SendQueueTo(s *Sender, playbackFPS int, startTimestamp uint32, lastSequence uint16)
SetupGOP()
ClearCache()
}
func CreateAudioHandler ¶
func CreateAudioHandler(codec *Codec) CodecHandler
func CreateCodecHandler ¶
func CreateCodecHandler(codec *Codec) CodecHandler
func NewCodecHandler ¶
func NewCodecHandler( codec *Codec, isKeyframeFunc func([]byte) bool, createRTPDepayFunc func(*Codec, HandlerFunc) HandlerFunc, createAVCCRepairFunc func(*Codec, HandlerFunc) HandlerFunc, payloader Payloader, ) CodecHandler
type Connection ¶ added in v1.9.4
type Connection struct {
ID uint32 `json:"id,omitempty"`
FormatName string `json:"format_name,omitempty"` // rtsp, webrtc, mp4, mjpeg, mpjpeg...
Protocol string `json:"protocol,omitempty"` // tcp, udp, http, ws, pipe...
RemoteAddr string `json:"remote_addr,omitempty"` // host:port other info
Source string `json:"source,omitempty"`
URL string `json:"url,omitempty"`
SDP string `json:"sdp,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Medias []*Media `json:"medias,omitempty"`
Recv int `json:"bytes_recv,omitempty"`
Send int `json:"bytes_send,omitempty"`
Receivers []*Receiver `json:"receivers,omitempty"`
Senders []*Sender `json:"senders,omitempty"`
Transport any `json:"-"`
}
Connection just like webrtc.PeerConnection - ID and RemoteAddr used for building Connection(s) graph - FormatName, Protocol, RemoteAddr, Source, URL, SDP, UserAgent used for info about Connection - FormatName and Protocol has FFmpeg compatible names - Transport used for auto closing on Stop
func Create ¶ added in v1.9.4
func Create(w io.Writer) (*Connection, error)
Create like os.Create, init Consumer with existing Transport
func Dial ¶ added in v1.9.4
func Dial(rawURL string) (*Connection, error)
Dial like net.Dial, init Producer via Dialing
func Open ¶ added in v1.9.4
func Open(r io.Reader) (*Connection, error)
Open like os.Open, init Producer from existing Transport
func (*Connection) Codecs
deprecated
added in
v1.9.4
func (c *Connection) Codecs() []*Codec
Deprecated:
func (*Connection) GetMedias ¶ added in v1.9.4
func (c *Connection) GetMedias() []*Media
func (*Connection) GetSource ¶ added in v1.9.7
func (c *Connection) GetSource() string
func (*Connection) GetTrack ¶ added in v1.9.4
func (c *Connection) GetTrack(media *Media, codec *Codec) (*Receiver, error)
func (*Connection) SetProtocol ¶ added in v1.9.4
func (c *Connection) SetProtocol(s string)
func (*Connection) SetRemoteAddr ¶ added in v1.9.4
func (c *Connection) SetRemoteAddr(s string)
func (*Connection) SetSource ¶ added in v1.9.4
func (c *Connection) SetSource(s string)
func (*Connection) SetURL ¶ added in v1.9.4
func (c *Connection) SetURL(s string)
func (*Connection) Stop ¶ added in v1.9.4
func (c *Connection) Stop() error
func (*Connection) WithRequest ¶ added in v1.9.4
func (c *Connection) WithRequest(r *http.Request)
type Filter ¶ added in v1.9.3
type Filter func(handler HandlerFunc) HandlerFunc
Filter - a decorator for any HandlerFunc
type GopCache ¶
type GopCache struct {
// contains filtered or unexported fields
}
func NewGOPCache ¶
func NewGOPCache() *GopCache
func (*GopCache) AddRTPFragment ¶
func (*GopCache) HasContent ¶
type HandlerFunc ¶
type HandlerFunc func(packet *Packet)
HandlerFunc - process input packets (just like http.HandlerFunc)
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener base struct for all classes with support feedback
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
Channel byte // Channel for RTSP
}
Media take best from: - deepch/vdk/format/rtsp/sdp.Media - pion/sdp.MediaDescription
func ParseQuery ¶
func UnmarshalMedia ¶
func UnmarshalMedia(md *sdp.MediaDescription) *Media
func (*Media) MarshalJSON ¶
func (*Media) MatchCodec ¶
func (*Media) MatchMedia ¶
type Node ¶ added in v1.9.3
type Node struct {
Codec *Codec
Input HandlerFunc
Output HandlerFunc
Forward HandlerFunc
// contains filtered or unexported fields
}
Node - Receiver or Sender or Filter (transform)
func (*Node) AppendChild ¶ added in v1.9.3
func (*Node) GetChildren ¶
func (*Node) RemoveChild ¶ added in v1.9.3
func (*Node) WithParent ¶ added in v1.9.3
type OnceBuffer ¶
type OnceBuffer struct {
// contains filtered or unexported fields
}
OnceBuffer will catch only first message
func (*OnceBuffer) Buffer ¶
func (o *OnceBuffer) Buffer() []byte
func (*OnceBuffer) Len ¶
func (o *OnceBuffer) Len() int
type PrebufferCache ¶
type PrebufferCache struct {
// contains filtered or unexported fields
}
func NewPrebufferCache ¶
func NewPrebufferCache(maxDurationSec int, clockRate uint32) *PrebufferCache
func (*PrebufferCache) Add ¶
func (c *PrebufferCache) Add(packet *Packet, isKeyframe bool)
func (*PrebufferCache) Clear ¶
func (c *PrebufferCache) Clear()
func (*PrebufferCache) GetLatestTimestamp ¶
func (c *PrebufferCache) GetLatestTimestamp() uint32
func (*PrebufferCache) GetPacketsFromTimestamp ¶
func (c *PrebufferCache) GetPacketsFromTimestamp(startTS uint32) []*Packet
func (*PrebufferCache) HasContent ¶
func (c *PrebufferCache) HasContent() bool
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 RTPMixer ¶
type RTPMixer struct {
Node
Media *Media
Codec *Codec
Bytes int `json:"bytes,omitempty"`
Packets int `json:"packets,omitempty"`
// contains filtered or unexported fields
}
func (*RTPMixer) MarshalJSON ¶
func (*RTPMixer) RemoveParent ¶
type ReadBuffer ¶
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 ¶
func NewReadBuffer(rd io.Reader) *ReadBuffer
func (*ReadBuffer) Close ¶
func (r *ReadBuffer) Close() error
func (*ReadBuffer) Reset ¶
func (r *ReadBuffer) Reset()
type Receiver ¶
type Receiver struct {
Node
// If set, Bind() will use this Node pointer instead of the embedded Node.
// This avoids Node copying for backchannel mixers where we need to bind to an existing Node.
ParentNode *Node `json:"-"`
// Deprecated: should be removed
Media *Media `json:"-"`
// Deprecated: should be removed
ID byte `json:"-"` // Channel for RTSP, PayloadType for MPEG-TS
Bytes int `json:"bytes,omitempty"`
Packets int `json:"packets,omitempty"`
// PacketHook is called for every packet (for producer-level prebuffer)
PacketHook func(*Packet, byte) // packet, trackID
// contains filtered or unexported fields
}
func NewReceiver ¶
func (*Receiver) MarshalJSON ¶
type Sender ¶
type Sender struct {
Node
InputCache HandlerFunc
// Deprecated:
Media *Media `json:"-"`
// Deprecated:
Handler HandlerFunc `json:"-"`
Bytes int `json:"bytes,omitempty"`
Packets int `json:"packets,omitempty"`
Drops int `json:"drops,omitempty"`
UseGOP bool `json:"-"`
UsePrebuffer bool `json:"-"`
// contains filtered or unexported fields
}
func (*Sender) MarshalJSON ¶
func (*Sender) WithParent ¶ added in v1.9.3
type StreamPrebuffer ¶
type StreamPrebuffer struct {
// contains filtered or unexported fields
}
StreamPrebuffer is a time-based rolling buffer that stores packets as they arrive It maintains original timing and order for all tracks (audio + video)
func NewStreamPrebuffer ¶
func NewStreamPrebuffer(durationSec int) *StreamPrebuffer
NewStreamPrebuffer creates a new stream-level prebuffer
func (*StreamPrebuffer) Add ¶
func (pb *StreamPrebuffer) Add(packet *Packet, trackID byte)
Add adds a packet to the prebuffer with current timestamp
func (*StreamPrebuffer) Clear ¶
func (pb *StreamPrebuffer) Clear()
Clear removes all packets from the buffer
func (*StreamPrebuffer) GetAvailableDuration ¶
func (pb *StreamPrebuffer) GetAvailableDuration() int
GetAvailableDuration returns the actual duration of buffered data in seconds
func (*StreamPrebuffer) GetLatestTimestamp ¶
func (pb *StreamPrebuffer) GetLatestTimestamp() time.Time
GetLatestTimestamp returns the timestamp of the most recent packet
func (*StreamPrebuffer) GetNextPacketAt ¶
func (pb *StreamPrebuffer) GetNextPacketAt(currentPos time.Time, maxAllowedTime time.Time) *TimestampedPacket
GetNextPacketAt returns the next packet at or after the given position that is not beyond maxAllowedTime
func (*StreamPrebuffer) GetPacketsFrom ¶
func (pb *StreamPrebuffer) GetPacketsFrom(offsetSec int) (startTime time.Time, packets []*TimestampedPacket)
GetPacketsFrom returns packets starting from the given offset (in seconds from latest) Returns the starting position and an iterator
func (*StreamPrebuffer) HasContent ¶
func (pb *StreamPrebuffer) HasContent() bool
HasContent returns true if buffer has packets
type TimestampedPacket ¶
type TimestampedPacket struct {
Packet *Packet
ArrivalTime time.Time
TrackID byte // Track identifier (for routing to correct receiver)
}
TimestampedPacket stores a packet with its arrival time
type Waiter ¶
Waiter support: - autotart on first Wait - block new waiters after last Done - safe Done after finish
type Worker ¶
type Worker struct {
// contains filtered or unexported fields
}
type WriteBuffer ¶
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 ¶
func NewWriteBuffer(wr io.Writer) *WriteBuffer
func (*WriteBuffer) Close ¶
func (w *WriteBuffer) Close() error
func (*WriteBuffer) Reset ¶
func (w *WriteBuffer) Reset(wr io.Writer)