protocol

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 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 IsMPEGTS

func IsMPEGTS(data []byte) bool

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

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
	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)

Jump to

Keyboard shortcuts

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