protocol

package
v0.0.39 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package protocol provides URL-based protocol detection and media stream utilities.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyTarget added in v0.0.20

func CopyTarget(rawURL string) (string, error)

CopyTarget parses a `copy://<upstream_stream_code>` URL and returns the upstream code. v1 grammar is strict: scheme must be exactly `copy`, host must be a non-empty stream code, no path / query / fragment / userinfo are allowed (those positions are reserved for future qualifiers like `copy://X/raw` or `copy://X/track_2` and rejecting them now keeps the surface clean for that extension).

Returns an error message that names the offending part so the API layer can surface it directly to the user without further interpretation.

func IsCopyURLError added in v0.0.20

func IsCopyURLError(err error) bool

IsCopyURLError reports whether err originated from CopyTarget.

func IsMPEGTS

func IsMPEGTS(data []byte) bool

IsMPEGTS returns true when data begins with the MPEG-TS sync byte 0x47.

func IsMixerURLError added in v0.0.22

func IsMixerURLError(err error) bool

IsMixerURLError reports whether err originated from MixerTargets.

func IsPushListen

func IsPushListen(rawURL string) bool

IsPushListen returns true when the URL signals that the server should accept incoming encoder connections (push mode) for a stream.

Two forms are recognised:

  1. publish:// — the preferred, protocol-agnostic form. Encoders may push via RTMP or SRT; the stream code is the only routing key needed.

  2. Legacy wildcard-host form — rtmp://0.0.0.0:port/... or srt://0.0.0.0:port/... Still recognised for backward compatibility.

Examples:

publish://          → true  (preferred)
rtmp://0.0.0.0:1935 → true  (legacy)
srt://0.0.0.0:9999  → true  (legacy)
rtmp://server.com   → false (remote pull source)

func SplitTSPackets

func SplitTSPackets(data []byte) [][]byte

SplitTSPackets splits a raw byte slice into 188-byte MPEG-TS packets. Incomplete trailing bytes are discarded.

Types

type Kind

type Kind string

Kind classifies a stream URL into a transport category used internally by the ingestor to choose the right reader implementation.

const (
	KindUDP     Kind = "udp"     // raw MPEG-TS over UDP (unicast or multicast)
	KindHLS     Kind = "hls"     // HLS playlist pull over HTTP/HTTPS
	KindFile    Kind = "file"    // local filesystem path
	KindRTMP    Kind = "rtmp"    // RTMP / RTMPS (pull or push-listen)
	KindRTSP    Kind = "rtsp"    // RTSP pull
	KindSRT     Kind = "srt"     // SRT (pull caller or push listener)
	KindPublish Kind = "publish" // accept any push protocol; stream code is the routing key
	KindCopy    Kind = "copy"    // re-stream another in-process stream's published output
	KindMixer   Kind = "mixer"   // combine video from one in-process stream with audio from another
	KindUnknown Kind = "unknown"
)

Kind constants classify ingest URLs; see Detect.

func Detect

func Detect(rawURL string) Kind

Detect returns the protocol Kind for the given URL. All classification is done purely from the scheme and URL structure — the caller never needs to specify the protocol manually.

rtmp://...                → KindRTMP
rtmps://...               → KindRTMP
srt://...                 → KindSRT
udp://...                 → KindUDP
rtsp:// or rtsps://...    → KindRTSP
http(s)://...*.m3u8       → KindHLS
file:// or /absolute/path → KindFile
publish://                → KindPublish (push-listen, any protocol)
copy://<stream_code>      → KindCopy   (re-stream another in-process stream)
mixer://<video>,<audio>   → KindMixer  (replace audio of one stream with another)

type MixerSpec added in v0.0.22

type MixerSpec struct {
	Video                string
	Audio                string
	AudioFailureContinue bool
}

MixerSpec is the parsed result of a `mixer://` URL.

Video / Audio          — upstream stream codes (host part, comma-separated)
AudioFailureContinue   — when true, the mixer keeps forwarding video-only
                         after the audio upstream goes away. When false
                         (default) audio failure aborts the whole stream
                         (video failure ALWAYS aborts).

func MixerTargets added in v0.0.22

func MixerTargets(rawURL string) (MixerSpec, error)

MixerTargets parses a `mixer://<video_code>,<audio_code>[?audio_failure=continue]` URL. v1 grammar:

  • scheme exactly "mixer"
  • host is `<video>,<audio>` — both codes non-empty, no `:` (no port)
  • no path / fragment / userinfo
  • only one query parameter accepted: `audio_failure=continue` (default omitted)

Returns an error message naming the offending part so the API layer can surface it directly to the user.

Jump to

Keyboard shortcuts

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