stream

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 9 Imported by: 0 modules, 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

Overview

Package broadcast streams the player's audio into a Discord voice channel.

Package stream sends an engine's output to a Discord voice socket as Opus, paced by the wall clock: shared by dotamp's broadcast and the house bot.

Index

Constants

This section is empty.

Variables

View Source
var ErrSetup = errors.New("stream setup")

ErrSetup wraps a failure to build the Opus encoder.

View Source
var Silence = []byte{0xF8, 0xFF, 0xFE}

Silence is the Opus packet Discord documents for keeping a stream warm while nothing plays.

Functions

func Drain

func Drain(stop <-chan struct{}, udp UDP)

Drain reads and discards incoming packets until stop closes or Read fails, so the socket never backs up.

func EncodeLoop added in v0.20.0

func EncodeLoop(stop <-chan struct{}, feed *audio.Feed, rate int, emit func([]byte)) error

EncodeLoop encodes the feed to Opus, one 20 ms packet per slot, paced by the wall clock, and hands each packet to emit. When the feed has no audio (paused, between songs) it encodes silence, so a listener's stream never goes idle. It returns when stop closes.

func Run

func Run(stop <-chan struct{}, udp UDP, o Options) error

Run sends the feed as Opus every 20 ms until stop closes (nil) or a write fails (that error).

Types

type OggWriter added in v0.20.0

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

OggWriter frames Opus packets as an Ogg Opus stream (RFC 7845): an OpusHead page, an OpusTags page, then one packet per page. Each writer is a complete stream of its own, so a listener joining late still gets a well-formed file.

func NewOggWriter added in v0.20.0

func NewOggWriter(w io.Writer) *OggWriter

func (*OggWriter) WriteHeaders added in v0.20.0

func (o *OggWriter) WriteHeaders() error

WriteHeaders writes the identification and comment headers.

func (*OggWriter) WritePacket added in v0.20.0

func (o *OggWriter) WritePacket(pkt []byte, samples int) error

WritePacket writes one Opus packet covering samples 48 kHz samples.

type Options

type Options struct {
	Rate   int         // engine sample rate
	Feed   *audio.Feed // engine output before the volume knob
	Logger *slog.Logger
	Label  string // channel name for the stats line
}

type Pacer

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

Pacer hands out 20 ms slots against the wall clock, so a late tick sends what it owes instead of letting the stream slip behind one slot per miss.

func NewPacer

func NewPacer(now time.Time) *Pacer

func (*Pacer) Due

func (p *Pacer) Due(now time.Time) int

Due is how many slots fall due at now: normally 0 or 1, up to burst after a late tick, and one fresh slot after a stall too long to catch up on.

type Pipeline

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

Pipeline turns engine-rate stereo float32 into 20 ms Opus packets.

func NewPipeline

func NewPipeline(inRate int) (*Pipeline, error)

func (*Pipeline) Packets

func (p *Pipeline) Packets() [][]byte

Packets returns every packet ready since the last call.

func (*Pipeline) Push

func (p *Pipeline) Push(stereo []float32)

Push feeds source frames; packets become available as full frames fill.

type Send

type Send int
const (
	SendNothing Send = iota
	SendAudio
	SendSilence
)

type Speaker

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

Speaker decides, tick by tick, whether to send audio, one of Discord's silence frames, or nothing. The speaking flag is set once at join and never dropped: clearing it and raising it again was found to kill the stream on Discord's side (live test, 2026-10-17), while a run of silence frames followed by nothing resumes cleanly.

func (*Speaker) Tick

func (s *Speaker) Tick(havePacket bool) Send

type UDP

type UDP interface {
	Write(p []byte) (int, error)
	Read(p []byte) (int, error)
}

UDP is where packets go; disgo's voice.UDPConn satisfies it.

Jump to

Keyboard shortcuts

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