push

package
v0.0.42 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrStreamAlreadyActive = errors.New("ingestor: stream already has an active pusher")

ErrStreamAlreadyActive is returned by Registry.Acquire when another pusher is already connected to the requested stream slot.

Functions

This section is empty.

Types

type ConnectFunc

type ConnectFunc func(ctx context.Context, streamID, bufferWriteID domain.StreamCode, input domain.Input) error

ConnectFunc is invoked when an encoder starts publishing a registered stream. The implementation should call ingestor.Service.startPullWorker for the given input (which points to this server's play endpoint).

type PlayFunc

type PlayFunc func(ctx context.Context, key string, info PlayInfo, writeFrame func(cid gocodec.CodecID, data []byte, pts, dts uint32) error) error

PlayFunc is invoked when an external play client connects for a key that has no active ingest relay. It should stream frames to the client via writeFrame until ctx is cancelled or an error occurs. Return a non-nil error only when the stream is not available (causes the client to receive NOTFOUND).

info carries per-connection metadata captured at OnPlay handshake time. Callers that don't care can ignore it; current consumer is the play-sessions tracker.

type PlayInfo added in v0.0.42

type PlayInfo struct {
	// RemoteAddr is the peer's "ip:port" string from the underlying TCP conn.
	RemoteAddr string
	// FlashVer is the client-supplied "flashVer" from the RTMP connect command.
	// Loosely equivalent to a User-Agent — populated by VLC, ffplay, OBS etc.
	FlashVer string
}

PlayInfo describes the remote peer of an external RTMP play client.

type RTMPServer

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

RTMPServer accepts RTMP push connections from encoders, validates them against the push Registry, and relays each live stream to an internal RTMP play subscriber (joy4 RTMPReader) via a loopback connection. External play clients (VLC, ffplay) are served via an optional PlayFunc.

func NewRTMPServer

func NewRTMPServer(addr string, registry Registry, onConnect ConnectFunc) (*RTMPServer, error)

NewRTMPServer creates an RTMPServer. addr is the TCP bind address (e.g. ":1935").

func (*RTMPServer) Run

func (s *RTMPServer) Run(ctx context.Context) error

Run binds the TCP listener and accepts RTMP connections until ctx is cancelled.

func (*RTMPServer) SetPlayFunc

func (s *RTMPServer) SetPlayFunc(fn PlayFunc)

SetPlayFunc registers a handler for external RTMP play clients. Must be called before Run. Safe to call concurrently.

type Registry

type Registry interface {
	// Lookup checks whether key is registered and returns its targets.
	// It does NOT change the active-pusher state; use it for pre-flight
	// checks (e.g. SRT HandleConnect) where you can't yet commit.
	Lookup(key string) (bufferWriteID domain.StreamCode, streamID domain.StreamCode, buf *buffer.Service, err error)

	// Acquire atomically checks that key is registered and that no other
	// pusher is currently active, then marks the slot as occupied.
	// Returns ErrStreamAlreadyActive if another pusher holds the slot.
	Acquire(key string) (bufferWriteID domain.StreamCode, streamID domain.StreamCode, buf *buffer.Service, err error)

	// Release clears the active-pusher mark so the next encoder can Acquire.
	// It is safe to call Release even if Acquire was never called for key.
	Release(key string)
}

Registry maps a stream key (the stream code) to the stream's buffer hub slot. Push servers (RTMP, SRT) use this to route incoming encoder connections.

A stream is eligible to receive a push connection only if it has been registered via ingestor.Service.Start with a publish:// input URL. Only one active pusher per stream is allowed at a time; subsequent connection attempts are rejected until the current pusher disconnects.

Jump to

Keyboard shortcuts

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