httpstream

package
v0.0.0-...-5d9d701 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 32 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DASHManager

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

DASHManager accumulates separate video-only and audio-only fMP4 segments from a stream and serves an MPD manifest with two AdaptationSets.

func NewDASHManager

func NewDASHManager(streamKey, basePath string, targetDur float64, maxSegments int) *DASHManager

NewDASHManager creates a new DASH manager for a stream.

func (*DASHManager) GenerateMPD

func (d *DASHManager) GenerateMPD() string

GenerateMPD generates a DASH MPD manifest for the current segment state.

func (*DASHManager) GetAudioInitSegment

func (d *DASHManager) GetAudioInitSegment() ([]byte, bool)

GetAudioInitSegment returns the audio init segment (ftyp+moov).

func (*DASHManager) GetAudioSegment

func (d *DASHManager) GetAudioSegment(seqNum int) ([]byte, bool)

GetAudioSegment returns the audio media segment by sequence number.

func (*DASHManager) GetInitSegment

func (d *DASHManager) GetInitSegment() ([]byte, bool)

GetInitSegment returns the video init segment (ftyp+moov).

func (*DASHManager) GetSegment

func (d *DASHManager) GetSegment(seqNum int) ([]byte, bool)

GetSegment returns the video media segment by sequence number.

func (*DASHManager) InitFromStream

func (d *DASHManager) InitFromStream(stream *core.Stream)

InitFromStream computes the fMP4 init segments from the stream's current startup snapshot. Run uses the same operation after waiting for startup, so a caller cannot publish an init segment built from an incomplete track.

func (*DASHManager) Run

func (d *DASHManager) Run(stream *core.Stream)

Run starts the segment accumulation loop. It reads frames from the stream's RingBuffer, groups them keyframe-to-keyframe, and produces separate video and audio fMP4 segments.

func (*DASHManager) SegmentCount

func (d *DASHManager) SegmentCount() int

SegmentCount returns the number of timeline segments currently available.

func (*DASHManager) SegmentRange

func (d *DASHManager) SegmentRange() (lo, hi int)

SegmentRange returns the SeqNum range [lo, hi] of timeline segments in memory.

func (*DASHManager) Stop

func (d *DASHManager) Stop()

Stop signals the manager to shut down.

type DASHSegment

type DASHSegment struct {
	SeqNum   int     // sequential segment number (0-based)
	Duration float64 // seconds
	Data     []byte
}

DASHSegment holds a single fMP4 media segment (moof+mdat).

type HLSManager

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

HLSManager accumulates TS segments from a stream and serves m3u8 playlists.

func NewHLSManager

func NewHLSManager(streamKey, basePath string, targetDur float64, maxSegments int) *HLSManager

NewHLSManager creates a new HLS manager for a stream.

func (*HLSManager) GenerateM3U8

func (h *HLSManager) GenerateM3U8() string

GenerateM3U8 returns the current live m3u8 playlist.

func (*HLSManager) GetSegment

func (h *HLSManager) GetSegment(seqNum int) ([]byte, bool)

GetSegment returns the segment data for a given sequence number.

func (*HLSManager) Run

func (h *HLSManager) Run(stream *core.Stream)

Run starts the segment accumulation loop. It reads frames from the stream's RingBuffer, muxes them into TS segments split on video keyframes, and maintains a sliding window of recent segments.

func (*HLSManager) SegmentCount

func (h *HLSManager) SegmentCount() int

SegmentCount returns the number of segments currently available.

func (*HLSManager) Stop

func (h *HLSManager) Stop()

Stop signals the manager to shut down.

type HLSSegment

type HLSSegment struct {
	SeqNum        int
	Duration      float64 // seconds
	Data          []byte  // complete TS segment bytes
	Discontinuity bool
}

HLSSegment holds a single TS segment with metadata.

type LLHLSManager

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

LLHLSManager orchestrates LL-HLS segment production and playlist serving.

func NewLLHLSManager

func NewLLHLSManager(streamKey, basePath string, partDuration, segmentDuration float64, segmentCount int, container string) *LLHLSManager

NewLLHLSManager creates a new LL-HLS manager.

func (*LLHLSManager) GeneratePlaylist

func (m *LLHLSManager) GeneratePlaylist(ctx context.Context, targetMSN, targetPart int, skip bool) (string, error)

GeneratePlaylist returns the m3u8 playlist. If targetMSN >= 0, blocks until the requested MSN/part is available (blocking playlist reload).

func (*LLHLSManager) GetFullSegment

func (m *LLHLSManager) GetFullSegment(msn int) ([]byte, bool)

GetFullSegment returns a full segment by MSN (concatenated partial data).

func (*LLHLSManager) GetInitSegment

func (m *LLHLSManager) GetInitSegment() ([]byte, bool)

GetInitSegment returns the fMP4 init segment.

func (*LLHLSManager) GetInitSegmentVersion

func (m *LLHLSManager) GetInitSegmentVersion(version string) ([]byte, bool)

GetInitSegmentVersion returns immutable fMP4 initialization bytes for a retained content-derived version. An empty version selects the current init.

func (*LLHLSManager) GetPartialSegment

func (m *LLHLSManager) GetPartialSegment(msn, partIdx int) ([]byte, bool)

GetPartialSegment returns a partial segment by MSN and part index.

func (*LLHLSManager) Run

func (m *LLHLSManager) Run(stream *core.Stream)

Run starts the segmenter loop. Blocks until stream ends or Stop() is called.

func (*LLHLSManager) SegmentCount

func (m *LLHLSManager) SegmentCount() int

SegmentCount returns the number of completed segments.

func (*LLHLSManager) Stop

func (m *LLHLSManager) Stop()

Stop signals shutdown.

func (*LLHLSManager) WaitForCompletedSegment

func (m *LLHLSManager) WaitForCompletedSegment(ctx context.Context, maxWait time.Duration) bool

WaitForCompletedSegment blocks until the playlist contains one complete segment. The bundled Hls.js treats a part-only initial manifest as an empty level, even though it consumes low-latency parts after startup.

type LLHLSPart

type LLHLSPart struct {
	Index         int     // part index within parent segment
	Duration      float64 // actual duration in seconds
	Independent   bool    // starts with keyframe (IDR)
	Data          []byte  // muxed bytes
	Discontinuity bool
	// contains filtered or unexported fields
}

LLHLSPart represents a partial segment.

type LLHLSPlaylist

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

LLHLSPlaylist generates m3u8 playlists with LL-HLS tags.

func NewLLHLSPlaylist

func NewLLHLSPlaylist(partTarget, segmentTarget float64, basePath, container string) *LLHLSPlaylist

NewLLHLSPlaylist creates a new playlist generator.

func (*LLHLSPlaylist) Generate

func (p *LLHLSPlaylist) Generate(segments []*LLHLSSegment, currentParts []*LLHLSPart, currentMSN int, skip, includeLatestCompletedParts bool) string

Generate produces the m3u8 playlist text.

Parameters:

  • segments: completed segments in the sliding window
  • currentParts: partial segments of the in-progress segment
  • currentMSN: MSN of the in-progress segment
  • skip: if true, emit EXT-X-SKIP for delta updates (client sent _HLS_skip=YES)

type LLHLSSegment

type LLHLSSegment struct {
	MSN           int          // media sequence number
	Duration      float64      // total duration in seconds
	Parts         []*LLHLSPart // partial segments
	Discontinuity bool
	// contains filtered or unexported fields
}

LLHLSSegment represents a completed full segment.

type LLHLSSegmenter

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

LLHLSSegmenter reads AVFrames from a stream and produces LL-HLS segments.

func NewLLHLSSegmenter

func NewLLHLSSegmenter(partDuration, segmentDuration float64, container string, cb LLHLSSegmenterCallbacks) *LLHLSSegmenter

NewLLHLSSegmenter creates a new segmenter.

func (*LLHLSSegmenter) Run

func (s *LLHLSSegmenter) Run(stream *core.Stream, identity ...any)

Run starts the segmenter loop. Blocks until stream ends or Stop() is called.

func (*LLHLSSegmenter) Stop

func (s *LLHLSSegmenter) Stop()

Stop signals the segmenter to shut down.

type LLHLSSegmenterCallbacks

type LLHLSSegmenterCallbacks struct {
	OnInit          func(data []byte)
	OnPart          func(part *LLHLSPart)
	OnSegment       func(seg *LLHLSSegment)
	OnDiscontinuity func()
}

LLHLSSegmenterCallbacks are invoked when segments are produced.

type Module

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

Module implements the HTTP streaming module for FLV, TS, FMP4, HLS, and DASH.

func NewModule

func NewModule() *Module

NewModule creates a new HTTP streaming module.

func (*Module) Addr

func (m *Module) Addr() net.Addr

Addr returns the listener address (useful for tests).

func (*Module) Close

func (m *Module) Close() error

Close shuts down the HTTP server and all managers.

func (*Module) Hooks

func (m *Module) Hooks() []core.HookRegistration

Hooks returns the module's event hooks. We listen for publish stop and stream destroy events to clean up HLS/DASH managers.

func (*Module) Init

func (m *Module) Init(s *core.Server) error

Init initializes the HTTP server.

func (*Module) Name

func (m *Module) Name() string

Name returns the module name.

func (*Module) OnReload

func (m *Module) OnReload(s *core.Server) error

OnReload stops segment managers that captured HLS/DASH/LL-HLS policy so subsequent requests recreate them from the new immutable server snapshot. Listener, TLS, CORS, and module enablement changes remain restart-required.

Jump to

Keyboard shortcuts

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