transport

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: BSD-2-Clause Imports: 19 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

Overview

Package transport defines the boundary between a pipeline and the outside world. A Transport exposes an input processor that turns received media into frames and an output processor that turns frames into sent media.

This package holds the transport-agnostic base processors; a concrete transport (for example the WebRTC transport in transport/rtc) embeds them and supplies the media I/O.

Index

Constants

View Source
const (
	// EventClientConnected fires when a client connects, with the client as
	// its argument. What a client is depends on the transport.
	EventClientConnected = "on_client_connected"
	// EventClientDisconnected fires when a client disconnects, with the client
	// as its argument.
	EventClientDisconnected = "on_client_disconnected"
	// EventAppMessage fires for an application message from a client, with the
	// message and its sender as arguments.
	EventAppMessage = "on_app_message"
)

The events a transport raises about its clients.

View Source
const (
	DefaultVideoOutWidth       = 1024
	DefaultVideoOutHeight      = 768
	DefaultVideoOutFramerate   = 30
	DefaultVideoOutColorFormat = "RGB"
)

The video output shape when the parameters name none.

View Source
const (
	// CameraVideoSource is the user's camera.
	CameraVideoSource = "camera"
	// ScreenVideoSource is the user's screen share.
	ScreenVideoSource = "screenVideo"
)

The video sources a user can send.

View Source
const DefaultAudioOutWriteTimeout = 10 * time.Second

DefaultAudioOutWriteTimeout bounds a single write to the transport before the peer is taken to be gone.

View Source
const DefaultVideoInFramerate = 30

DefaultVideoInFramerate is the rate a video source is captured at when its parameters name none.

View Source
const EveryFrame = -1

EveryFrame is the framerate that passes on every frame a video source sends.

View Source
const JitterTolerance = 50 * time.Millisecond

JitterTolerance is how early a frame may arrive and still count as due, at most half an interval. It covers jitter in the incoming stream, which is about the same at any framerate.

Variables

This section is empty.

Functions

func CaptureFramerate added in v0.7.0

func CaptureFramerate(framerate int, onRequestOnly bool) int

CaptureFramerate is the sampler framerate for a CaptureParticipantVideo call's arguments. A sampler passes on only the frames that answer image requests at a framerate of 0, which is how onRequestOnly is applied.

Types

type BaseInput

type BaseInput struct {
	*processor.Base
	// contains filtered or unexported fields
}

BaseInput is the head of a pipeline: it turns received audio into InputAudioRawFrames and pushes them downstream. A concrete transport embeds it and implements InputDriver to supply the media reading; the driver calls PushAudioFrame for each chunk of audio it receives.

The audio received is queued, and a task of the session (the audio task) takes it from there, runs it through the input filter and pushes it on.

func NewBaseInput

func NewBaseInput(name string, params Params, self InputDriver) *BaseInput

NewBaseInput builds a BaseInput. self is the embedding transport, used to dispatch StartReading/StopReading and to process frames.

func (*BaseInput) AnswerImageRequests added in v0.7.0

func (bi *BaseInput) AnswerImageRequests(
	ctx context.Context, requests []*frames.UserImageRequestFrame, reason string,
)

AnswerImageRequests completes image requests that no frame will answer, with an error result naming why. The tool call that made each request would otherwise never finish.

func (*BaseInput) Capabilities added in v0.3.0

func (bi *BaseInput) Capabilities() capabilities.BotCapabilities

Capabilities is the media this transport receives from the user: audio and video as the parameters enable them, and screen shares.

Whether screen shares are received is unknown when video input is enabled with no VideoInSources, since the application then decides which sources to capture, and when the transport does not capture screen shares through VideoInSources.

func (*BaseInput) Cleanup

func (bi *BaseInput) Cleanup(ctx context.Context) error

Cleanup stops the audio task, the input filter and the processor.

The teardown runs on the session's loop, as one step among its tasks: the pipeline cleans up from a goroutine of its own, and the frame that ended the session may still be stopping the same task.

func (*BaseInput) EnableAudioInStreamOnStart added in v0.1.0

func (bi *BaseInput) EnableAudioInStreamOnStart(enabled bool)

EnableAudioInStreamOnStart sets whether the transport streams audio as soon as it starts. A transport that reads Params.AudioInStreamsOnStart when it starts can be told otherwise through this, up until then.

func (*BaseInput) Params

func (bi *BaseInput) Params() Params

Params returns the transport parameters.

func (*BaseInput) ProcessFrame

func (bi *BaseInput) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame handles the transport lifecycle and forwards frames.

func (*BaseInput) PushAudioFrame

func (bi *BaseInput) PushAudioFrame(_ context.Context, f frames.InputAudioFrame)

PushAudioFrame queues a received audio frame to be pushed downstream by the audio task. The driver calls it for each chunk of audio it reads from the transport. It never blocks, so it can be called from anywhere, a goroutine reading the transport included.

func (*BaseInput) PushBotConnected added in v0.1.0

func (bi *BaseInput) PushBotConnected(ctx context.Context)

PushBotConnected reports that the bot itself has joined the session. Only a transport where the bot joins something has this to report: a room on a media server, where the bot is a participant like any other. On a transport a client dials into directly there is nothing to join, and nothing is reported.

func (*BaseInput) PushClientConnected added in v0.1.0

func (bi *BaseInput) PushClientConnected(ctx context.Context)

PushClientConnected reports that a remote participant has connected. A concrete transport calls it where its own connection tells it one arrived; on a transport a client dials into, that has already happened by the time the pipeline runs, so it is reported as the transport starts reading.

It goes downstream from the head of the pipeline, in order with the StartFrame that opened the run, which is what lets an observer time how long the call took to become answerable.

func (*BaseInput) PushParticipantMessage added in v0.3.0

func (bi *BaseInput) PushParticipantMessage(ctx context.Context, raw []byte, participantID string)

PushParticipantMessage is PushTransportMessage for a transport that knows who sent the message. The frame carries participantID as its ParticipantID, so whatever handles the message can tell whose it was.

func (*BaseInput) PushTransportMessage

func (bi *BaseInput) PushTransportMessage(ctx context.Context, raw []byte)

PushTransportMessage emits a message received from the client as an InputTransportMessageFrame. A concrete transport calls it when an application message arrives (for example off a data channel).

It is broadcast rather than pushed one way, so whatever handles client messages hears them wherever it sits: a processor placed ahead of the input transport reads them traveling upstream, one placed behind it reads them traveling downstream. Only the copy going its way reaches it, so it handles the message once.

func (*BaseInput) PushVideoFrame added in v0.7.0

func (bi *BaseInput) PushVideoFrame(ctx context.Context, f frames.InputImageFrame)

PushVideoFrame pushes an image read from the user's video downstream, when video input is enabled and the transport is not paused.

func (*BaseInput) SampleRate

func (bi *BaseInput) SampleRate() int

SampleRate is the input sample rate in Hz, set when the transport starts.

func (*BaseInput) Setup added in v0.1.0

func (bi *BaseInput) Setup(ctx context.Context, s processor.Setup) error

Setup resolves the rate the transport reads at. A rate configured on the transport wins; otherwise it takes the pipeline's input rate, which it knows from the moment it is set up rather than when the StartFrame arrives.

func (*BaseInput) StartAudioStreaming added in v0.1.0

func (bi *BaseInput) StartAudioStreaming(context.Context) error

StartAudioStreaming is the default no-op; a concrete transport overrides it to begin streaming audio from its source.

func (*BaseInput) StartReading

func (bi *BaseInput) StartReading(context.Context) error

StartReading is the default no-op; a concrete transport overrides it.

func (*BaseInput) StopReading

func (bi *BaseInput) StopReading(context.Context) error

StopReading is the default no-op; a concrete transport overrides it.

func (*BaseInput) SupportsVideoInSource added in v0.7.0

func (bi *BaseInput) SupportsVideoInSource(string) bool

SupportsVideoInSource reports whether this transport captures a video source listed in Params.VideoInSources as its user connects. A transport that does overrides it; a listed source it reports false for is ignored, with a warning. The default captures none.

It is called while the transport is being built, so an override must answer from the source alone.

type BaseOutput

type BaseOutput struct {
	*processor.Base
	// contains filtered or unexported fields
}

BaseOutput is the tail of a pipeline: it routes each outgoing frame to the sender for the destination the frame names, and each sender buffers audio, slices it into fixed-size chunks, and hands each chunk to the concrete transport to send. Chunking into small, uniform pieces keeps output latency low and makes interruptions responsive. A concrete transport embeds it and implements OutputDriver to send the audio.

The per-destination state lives on mediaSender rather than here, so a transport that carries several outgoing streams (several tracks, say) keeps one buffer, one mixer and one speaking state per stream instead of sharing one set between them.

func NewBaseOutput

func NewBaseOutput(name string, params Params, self OutputDriver) *BaseOutput

NewBaseOutput builds a BaseOutput. self is the embedding transport, used to dispatch WriteAudio and to process frames.

func (*BaseOutput) Capabilities added in v0.3.0

func (bo *BaseOutput) Capabilities() capabilities.BotCapabilities

Capabilities is the media this transport sends to the user: audio and video as the parameters enable them.

func (*BaseOutput) ChunkSize added in v0.1.0

func (bo *BaseOutput) ChunkSize() int

ChunkSize is the size in bytes of the audio chunks the output writes, set when the transport starts.

func (*BaseOutput) Cleanup

func (bo *BaseOutput) Cleanup(ctx context.Context) error

Cleanup stops the senders, the output filter and the processor.

The senders are torn down on the session's loop, as one step among its tasks: the pipeline cleans up from a goroutine of its own, and the frame that ended the session may still be stopping the same tasks.

func (*BaseOutput) Params

func (bo *BaseOutput) Params() Params

Params returns the transport parameters.

func (*BaseOutput) PlaysOutput added in v0.2.0

func (bo *BaseOutput) PlaysOutput()

PlaysOutput marks this processor as a transport's output end.

A frame pushed from here has been through the playback clock, so it carries the timing of what the caller actually hears; the same frame on its way in has not. Something reporting what the bot is saying keys on that difference, and the marker is how it recognizes the output end without depending on which transport it is.

func (*BaseOutput) ProcessFrame

func (bo *BaseOutput) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error

ProcessFrame handles the transport lifecycle and routes frames to the sender for the destination they name.

func (*BaseOutput) RegisterAudioDestination added in v0.1.0

func (bo *BaseOutput) RegisterAudioDestination(context.Context, string) error

RegisterAudioDestination is the default no-op; a concrete transport overrides it to open the outgoing stream a destination names.

func (*BaseOutput) RegisterVideoDestination added in v0.7.0

func (bo *BaseOutput) RegisterVideoDestination(context.Context, string) error

RegisterVideoDestination is the default no-op; a concrete transport overrides it to open the outgoing video stream a destination names.

func (*BaseOutput) SampleRate

func (bo *BaseOutput) SampleRate() int

SampleRate is the output sample rate in Hz, set when the transport starts.

func (*BaseOutput) SendMessage

SendMessage is the default no-op; a concrete transport overrides it.

func (*BaseOutput) Setup added in v0.1.0

func (bo *BaseOutput) Setup(ctx context.Context, s processor.Setup) error

Setup resolves the rate the transport writes at. A rate configured on the transport wins; otherwise it takes the pipeline's output rate, which it knows from the moment it is set up rather than when the StartFrame arrives.

func (*BaseOutput) StartWriting added in v0.1.0

func (bo *BaseOutput) StartWriting(context.Context) error

StartWriting is the default no-op; a concrete transport overrides it to open its outgoing media path.

func (*BaseOutput) SupportsNativeDTMF added in v0.1.0

func (bo *BaseOutput) SupportsNativeDTMF() bool

SupportsNativeDTMF reports whether the transport signals a keypress itself. The default is false, so the keys are sounded as audio instead. A transport whose protocol carries keypresses overrides this and WriteDTMFNative, which keeps the keys out of the audio a recording would capture.

func (*BaseOutput) WriteAudio

WriteAudio is the default no-op; a concrete transport overrides it. A base with no transport under it sends nothing, so it reports the audio as unsent.

func (*BaseOutput) WriteDTMF added in v0.1.0

func (bo *BaseOutput) WriteDTMF(ctx context.Context, f frames.DTMFOutput) error

WriteDTMF sends the keys the frame carries, natively when the transport can and as audio when it cannot.

func (*BaseOutput) WriteDTMFNative added in v0.1.0

func (bo *BaseOutput) WriteDTMFNative(context.Context, frames.DTMFOutput) error

WriteDTMFNative signals the keys over the transport's own protocol. A transport that answers true to SupportsNativeDTMF overrides this; the default says it did not, which is what makes claiming support without implementing it an error rather than silence.

func (*BaseOutput) WriteTransportFrame added in v0.1.0

func (bo *BaseOutput) WriteTransportFrame(context.Context, frames.Frame) error

WriteTransportFrame is the default no-op; a concrete transport overrides it.

func (*BaseOutput) WriteVideoFrame added in v0.7.0

func (bo *BaseOutput) WriteVideoFrame(context.Context, *frames.OutputImageRawFrame) (bool, error)

WriteVideoFrame is the default no-op; a concrete transport that sends video overrides it. A base with no transport under it sends nothing, so it reports the image as unsent.

type BaseTransport added in v0.7.0

type BaseTransport struct {
	// Name labels the transport in the warnings the defaults log.
	Name string
}

BaseTransport is the part of a Transport every transport shares. A concrete transport embeds it and overrides what it supports: one with client events overrides GetClientID, and one that receives user video overrides CaptureParticipantVideo.

func (BaseTransport) CaptureParticipantVideo added in v0.7.0

func (b BaseTransport) CaptureParticipantVideo(context.Context, string, int, string, bool) error

CaptureParticipantVideo is the default for a transport that receives no user video: it logs a warning and captures nothing.

func (BaseTransport) GetClientID added in v0.7.0

func (b BaseTransport) GetClientID(any) string

GetClientID is the default for a transport with no client ids: it logs a warning and returns "".

type InputDriver

type InputDriver interface {
	processor.Processor
	// StartReading begins reading media from the transport.
	StartReading(ctx context.Context) error
	// StopReading stops reading media from the transport.
	StopReading(ctx context.Context) error
	// StartAudioStreaming begins streaming audio from the transport's source,
	// for a transport that does not start streaming as soon as it connects. It
	// is driven by an InputTransportStartAudioStreamingFrame; the default does
	// nothing.
	//
	// A transport with a source it can hold back reads Params.AudioInStreamOnStart
	// when it starts, leaves the source closed when it is off, and opens it here.
	StartAudioStreaming(ctx context.Context) error
	// SupportsVideoInSource reports whether the transport captures a video
	// source listed in Params.VideoInSources as its user connects. A listed
	// source it reports false for is ignored, with a warning. The default
	// captures none.
	SupportsVideoInSource(videoSource string) bool
}

InputDriver is implemented by a concrete input transport so the base can start and stop the transport-specific media reading. A driver produces audio by calling BaseInput.PushAudioFrame.

The base calls its methods from a task of the session's loop (see package tasks). A driver reads the transport from tasks of its own, made with CreateTask, each blocking read wrapped in tasks.Await, so that whatever it pushes into the pipeline is pushed from the session's loop. Only PushAudioFrame may be called from anywhere: it queues and never blocks.

type OutputDriver

type OutputDriver interface {
	processor.Processor
	// WriteAudio sends one chunk of audio over the transport. The frame carries
	// the interleaved S16LE PCM in AudioData, and the outgoing stream it belongs
	// to in TransportDestination, so a transport serving several streams can
	// send it on the right one.
	//
	// It must return once ctx is done, however far it had got. Stopping the
	// output cancels ctx and then waits for the audio task to finish, and the
	// task is inside this call whenever it is sending, so a write that blocks
	// past cancellation holds the pipeline open for good. A transport that
	// paces its sends, or waits for room downstream, waits on ctx.Done()
	// alongside whatever else it waits for.
	//
	// It reports whether the transport took the chunk. A transport with nowhere
	// to put it returns false and no error: its track is not live yet, or its
	// stream has closed. Nothing failed, but the audio will not be heard, so the
	// base does not forward the frame downstream as though it had been. An error
	// is a genuine failure, which the base logs; audio that errored counts as
	// not taken either way.
	//
	// Taken is not the same as written. A transport whose wire format buffers
	// audio across chunks has taken one that produced no payload of its own: the
	// audio reaches the client inside a later message, so the chunk is still
	// paced and still travels downstream.
	WriteAudio(ctx context.Context, f frames.OutputAudioFrame) (sent bool, err error)
	// SendMessage sends the frame's application message to the client (for
	// example over a data channel). The transport encodes the payload, because
	// only it knows what its wire carries: one whose format is supplied as a
	// serializer hands the frame over and lets the serializer decide, and one
	// that speaks JSON to its client encodes it here.
	SendMessage(ctx context.Context, f frames.OutputTransportMessage) error
	// SupportsNativeDTMF reports whether the transport signals a keypress over
	// its own protocol. A transport that does overrides this and
	// WriteDTMFNative; one that does not has its keys sounded as audio, which
	// is the only way a keypress travels a call that carries nothing but audio.
	SupportsNativeDTMF() bool
	// WriteDTMFNative signals the frame's keys over the transport's protocol.
	// It is called only when SupportsNativeDTMF reports true.
	WriteDTMFNative(ctx context.Context, f frames.DTMFOutput) error
	// WriteTransportFrame handles a queued frame that carries no audio, once the
	// audio ahead of it has been sent. A transport overrides it to act on frame
	// types it carries itself; the default does nothing.
	WriteTransportFrame(ctx context.Context, f frames.Frame) error
	// StartWriting opens the transport's outgoing media path, so that nothing is
	// sent before it can carry audio. The base calls it while starting, and only
	// once it returns does it start the senders and report the transport ready.
	// A transport with nothing to open leaves the default, which does nothing.
	StartWriting(ctx context.Context) error
	// RegisterAudioDestination opens the outgoing stream a destination names,
	// for a transport that serves more than one. It is called for each entry in
	// Params.AudioOutDestinations when the transport starts, and a destination
	// that fails to open is skipped rather than being sent to. The default does
	// nothing.
	RegisterAudioDestination(ctx context.Context, destination string) error
	// RegisterVideoDestination opens the outgoing video stream a destination
	// names, for a transport that serves more than one. It is called for each
	// entry in Params.VideoOutDestinations when the transport starts. The
	// default does nothing.
	RegisterVideoDestination(ctx context.Context, destination string) error
	// WriteVideoFrame sends one image as a frame of the outgoing video, sized to
	// the video output size. The frame names the stream it belongs to in
	// TransportDestination. It reports whether the transport took the image; a
	// transport that sends no video leaves the default, which takes none.
	//
	// Like WriteAudio, it must return once ctx is done.
	WriteVideoFrame(ctx context.Context, f *frames.OutputImageRawFrame) (sent bool, err error)
}

OutputDriver is implemented by a concrete output transport so the base can hand it audio chunks and messages to send.

The base calls every method from a task of the session's loop (see package tasks): the audio task, the video task, or the output's frame handling. A method that waits for anything (the network, a pacing clock, room downstream) waits through package tasks, with tasks.Await around the blocking call or tasks.Sleep for a pause, so the rest of the session runs meanwhile. The work around the wait (encoding the audio, say) stays on the loop, which is what keeps two writes from encoding at the same time.

type Params

type Params struct {
	// AudioInEnabled enables receiving audio.
	AudioInEnabled bool
	// AudioInSampleRate is the input sample rate in Hz; 0 uses the StartFrame's.
	AudioInSampleRate int
	// AudioInChannels is the number of input channels.
	AudioInChannels int
	// AudioInStreamOnStart starts streaming audio as soon as the transport
	// starts; nil enables it. Set it false to hold the audio back until
	// something asks for it with an InputTransportStartAudioStreamingFrame,
	// which is how a client that has not said it is ready yet is kept off the
	// pipeline.
	AudioInStreamOnStart *bool
	// AudioInPassthrough pushes received audio frames downstream; nil defaults
	// to true. Set it false for a transport whose audio is consumed inside the
	// input transport alone.
	AudioInPassthrough *bool
	// AudioInFilter, when set, transforms received audio (for example noise
	// reduction) before it is pushed downstream to VAD, STT and turn detection.
	AudioInFilter audio.Filter

	// AudioOutEnabled enables sending audio.
	AudioOutEnabled bool
	// AudioOutSampleRate is the output sample rate in Hz; 0 uses the StartFrame's.
	AudioOutSampleRate int
	// AudioOutChannels is the number of output channels.
	AudioOutChannels int
	// AudioOutBitrate is the output bitrate in bits per second; 0 uses the
	// codec default.
	AudioOutBitrate int
	// AudioOutAutoSilence fills the outgoing stream with silence while nothing
	// is queued for it, rather than letting it go quiet; nil enables it. A
	// transport whose stream has to keep flowing leaves it on; one that would
	// rather wait for audio turns it off.
	AudioOutAutoSilence *bool
	// AudioOut10msChunks is how many 10 ms chunks of audio are written at a
	// time; 0 writes four, so audio is handed to the transport 40 ms at a time.
	// A transport that frames the audio itself (Opus at 20 ms, say) re-splits
	// what it is given, so this sizes the buffering rather than the framing.
	AudioOut10msChunks int
	// AudioOutFilter, when set, transforms the audio the pipeline sends to the
	// default destination, before the mixer and the write. Audio the transport
	// generates itself (mixer audio, end silence, DTMF tones) is not filtered.
	// A FilterControlFrame reaches it in step with the audio queued around it.
	AudioOutFilter audio.Filter
	// AudioOutVolume is the volume of the output audio, as a multiplier on its
	// samples, applied after the filter and before the mixer; nil plays it at
	// 1.0. A VolumeFrame changes it while the transport runs, and a
	// VolumeGainFrame adjusts it for some audio.
	AudioOutVolume *float64
	// AudioOutMixer, when set, mixes auxiliary audio (for example background
	// music) into the outgoing audio before it is sent. It serves the default
	// destination only; use AudioOutMixers to mix into a named one.
	AudioOutMixer audio.Mixer
	// AudioOutMixers maps a destination name to the mixer serving it, for a
	// transport that sends several outgoing streams and wants different
	// auxiliary audio (or none) on each. It takes precedence over AudioOutMixer.
	AudioOutMixers map[string]audio.Mixer
	// AudioOutWriteTimeout bounds a single write to the transport before the peer
	// is taken to be gone. A peer that stops reading blocks the write on buffers
	// that never drain, which no transport can report as an error, so how long
	// the write takes is the only signal there is. Zero uses
	// DefaultAudioOutWriteTimeout.
	AudioOutWriteTimeout time.Duration
	// AudioOutEndSilenceSecs is how many seconds of silence are sent after the
	// last of the audio when the pipeline ends, so the closing words are not
	// clipped by whatever closes on top of them. Nil defaults to 2 seconds, and
	// 0 sends none.
	AudioOutEndSilenceSecs *int
	// AudioOutDestinations names the additional outgoing audio streams the
	// transport serves, beyond the default unnamed one. A frame is routed to the
	// destination it carries, so each stream keeps its own buffer, mixer and
	// speaking state. Leave it empty for a transport with a single stream.
	AudioOutDestinations []string

	// VideoInEnabled enables receiving video.
	VideoInEnabled bool
	// VideoInSources are the video sources to capture from each user as they
	// connect, keyed by source ("camera", "screenVideo", or a source of the
	// transport's own). A source not listed is captured only when the
	// application asks for it, with the transport's CaptureParticipantVideo.
	// It requires VideoInEnabled. A transport that does not capture a listed
	// source logs a warning and ignores it, so check the logs if video does not
	// arrive as configured.
	VideoInSources map[string]VideoInSourceParams

	// VideoOutEnabled enables sending video.
	VideoOutEnabled bool
	// VideoOutIsLive sends each image as a frame of live video, paced at
	// VideoOutFramerate, rather than repeating the last image (or cycling the
	// last sprite) until another arrives.
	VideoOutIsLive bool
	// VideoOutWidth and VideoOutHeight are the size of the video sent, in
	// pixels; 0 uses 1024 by 768. An image of another size is resized to it.
	VideoOutWidth  int
	VideoOutHeight int
	// VideoOutFramerate is the rate video is sent at, in frames per second; 0
	// uses 30.
	VideoOutFramerate int
	// VideoOutColorFormat is the pixel format of the video sent; "" uses "RGB".
	VideoOutColorFormat string
	// VideoOutCodec is the codec the transport prefers for the video it sends,
	// such as "VP8" or "H264", or "" for the transport's own choice.
	VideoOutCodec string
	// VideoOutDestinations names the additional outgoing video streams the
	// transport serves, beyond the default unnamed one. A destination named in
	// both this and AudioOutDestinations is served by one sender carrying both.
	VideoOutDestinations []string
}

Params configures a transport's audio input and output.

func DefaultParams

func DefaultParams() Params

DefaultParams returns Params with audio input and output enabled and mono audio each way.

It asks for 20 ms output chunks rather than leaving the parameter at its own default of 40 ms: it is the shape a WebRTC transport writes in, so the audio is handed over already framed and the transport does not re-split it.

func (Params) AudioInPassesThrough added in v1.0.0

func (p Params) AudioInPassesThrough() bool

AudioInPassesThrough reports whether received audio is pushed downstream, which it is unless the parameter says otherwise.

func (Params) AudioInStreamsOnStart added in v0.1.0

func (p Params) AudioInStreamsOnStart() bool

AudioInStreamsOnStart reports whether received audio reaches the pipeline as soon as the transport starts, which it does unless the parameter says otherwise.

func (Params) AudioOutEndSilence added in v1.0.0

func (p Params) AudioOutEndSilence() int

AudioOutEndSilence is how many seconds of silence are sent after the last of the audio when the pipeline ends: the configured value, or 2 when unset.

func (Params) AudioOutFillsSilence added in v0.1.0

func (p Params) AudioOutFillsSilence() bool

AudioOutFillsSilence reports whether the outgoing stream is kept flowing with silence while nothing is queued for it, which it is unless the parameter says otherwise.

func (Params) AudioOutStartVolume added in v0.4.0

func (p Params) AudioOutStartVolume() float64

AudioOutStartVolume is the volume the output audio starts at: the configured one, or 1.0.

func (Params) AudioOutWrite added in v0.1.0

func (p Params) AudioOutWrite() time.Duration

AudioOutWrite is how long one write to the transport may take before the peer is written off, which is the configured value or the default.

func (Params) Validate added in v0.7.0

func (p Params) Validate() error

Validate checks the parameters: no negative sizes or rates, video sources only with video input enabled, and no framerate on a source captured only on request.

The checks are written out rather than read from struct tags: the parameters hold the application's own filters and mixers, which a tag-driven validator would walk into while they are in use.

func (Params) VideoOutFormat added in v0.7.0

func (p Params) VideoOutFormat() string

VideoOutFormat is the pixel format of the video sent: the configured one, or "RGB".

func (Params) VideoOutRate added in v0.7.0

func (p Params) VideoOutRate() int

VideoOutRate is the rate video is sent at: the configured one, or 30 frames per second.

func (Params) VideoOutSize added in v0.7.0

func (p Params) VideoOutSize() (width, height int)

VideoOutSize is the size of the video sent: the configured one, or 1024 by 768.

type Transport

type Transport interface {

	// Input returns the processor that emits frames from received media.
	Input() processor.Processor
	// Output returns the processor that sends frames as media.
	Output() processor.Processor
	// Events returns the registry of the events the transport raises, such as
	// EventClientConnected and EventClientDisconnected.
	Events() *event.Registry
	// GetClientID returns the id of a client, as passed to
	// EventClientConnected. It is the participant id CaptureParticipantVideo
	// and image requests take. A transport with client events implements it;
	// BaseTransport logs a warning and returns "".
	GetClientID(client any) string
	// CaptureParticipantVideo captures a participant's video source, passing on
	// framerate frames per second, or every frame for EveryFrame. With
	// onRequestOnly it passes on only the frames that answer image requests,
	// and framerate does not apply.
	//
	// It captures a source on demand, where Params.VideoInSources captures the
	// listed sources as each user connects, and it takes precedence over that
	// for the source. A transport that receives user video implements it;
	// BaseTransport logs a warning.
	CaptureParticipantVideo(
		ctx context.Context, participantID string, framerate int, videoSource string, onRequestOnly bool,
	) error
	// contains filtered or unexported methods
}

Transport is a source and sink of media for a pipeline. Input and Output return the processors that sit at the head and tail of the pipeline.

type VideoInSampler added in v0.7.0

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

VideoInSampler decides which frames of one incoming video source a transport passes on.

A user's camera or screen share sends frames at its own rate, often 15 to 30 per second, while a bot usually wants fewer: a vision bot may want one a second, or only a frame when it asks for one. An input transport keeps one sampler per video source and calls Sample for every frame that arrives; the sampler says whether to pass that frame on or drop it.

The framerate decides which frames are passed on:

  • EveryFrame: every frame.
  • 0: only frames that answer an image request.
  • N > 0: N frames per second, on the schedule described below.

Whatever the framerate, an image request queued with AddRequest is answered by the next frame that arrives, which is passed on with the request.

For N > 0, frames are due on a fixed schedule, one interval (1/N seconds) apart:

  • On schedule. A frame is due once its scheduled time comes, or up to a tolerance before it, since frames never arrive exactly on time. The next frame is scheduled one interval after this frame's scheduled time, not its arrival time, so the rate does not drift. A frame arriving late moves the schedule to its arrival, so a stream slower than the framerate passes every frame rather than falling further and further behind.
  • Fresh start. The first frame, a frame that answers a request, and the first frame after a stall (more than an interval past its scheduled time) start a new schedule from their arrival. After a stall this passes on one frame instead of a burst catching up on the missed ones.

The tolerance is the smaller of JitterTolerance and half an interval. At low framerates the next frame after any frame is therefore close to a full interval later; at framerates near the stream's own rate it covers the stream's jitter, so every frame passes.

A sampler is not safe for concurrent use; VideoInSamplers is.

func NewVideoInSampler added in v0.7.0

func NewVideoInSampler(framerate int) *VideoInSampler

NewVideoInSampler builds a sampler passing on framerate frames per second. 0 passes on frames only to answer requests, and EveryFrame passes on every frame.

func (*VideoInSampler) AddRequest added in v0.7.0

func (s *VideoInSampler) AddRequest(request *frames.UserImageRequestFrame)

AddRequest queues an image request for the next frame to answer.

func (*VideoInSampler) Framerate added in v0.7.0

func (s *VideoInSampler) Framerate() int

Framerate is the frames per second the sampler passes on.

func (*VideoInSampler) Sample added in v0.7.0

Sample decides whether to pass on the frame that just arrived. It reports whether to pass the frame on, and the image request the frame answers, or nil.

func (*VideoInSampler) SetFramerate added in v0.7.0

func (s *VideoInSampler) SetFramerate(framerate int)

SetFramerate changes the frames per second the sampler passes on.

func (*VideoInSampler) TakeRequests added in v0.7.0

func (s *VideoInSampler) TakeRequests() []*frames.UserImageRequestFrame

TakeRequests removes and returns the image requests waiting for a frame, oldest first.

type VideoInSamplers added in v0.7.0

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

VideoInSamplers are an input transport's video samplers, by participant and video source. They are safe for concurrent use.

func NewVideoInSamplers added in v0.7.0

func NewVideoInSamplers() *VideoInSamplers

NewVideoInSamplers builds a set with no sources being sampled.

func (*VideoInSamplers) AddRequest added in v0.7.0

func (v *VideoInSamplers) AddRequest(
	participantID, videoSource string, request *frames.UserImageRequestFrame,
) bool

AddRequest queues an image request for the next frame of a source to answer. It reports whether the request was queued: false when the source is not being sampled, so nothing would answer it.

func (*VideoInSamplers) Capture added in v0.7.0

func (v *VideoInSamplers) Capture(participantID, videoSource string, framerate int)

Capture starts sampling a source, or changes its framerate. Changing the framerate keeps the source's sampler, so image requests already waiting on it are still answered.

func (*VideoInSamplers) Clear added in v0.7.0

Clear stops sampling every video source, and returns the image requests that were waiting on any of them.

func (*VideoInSamplers) IsCapturing added in v0.7.0

func (v *VideoInSamplers) IsCapturing(participantID, videoSource string) bool

IsCapturing reports whether Capture was called for a source.

func (*VideoInSamplers) RemoveParticipant added in v0.7.0

func (v *VideoInSamplers) RemoveParticipant(participantID string) []*frames.UserImageRequestFrame

RemoveParticipant stops sampling every video source of a participant, one who left say, and returns the image requests that were waiting on their video.

func (*VideoInSamplers) Sample added in v0.7.0

func (v *VideoInSamplers) Sample(participantID, videoSource string) (bool, *frames.UserImageRequestFrame)

Sample decides whether to pass on the frame that just arrived from a source, as VideoInSampler.Sample does. A frame from a source that is not being sampled is never due.

func (*VideoInSamplers) TakeRequests added in v0.7.0

func (v *VideoInSamplers) TakeRequests(participantID, videoSource string) []*frames.UserImageRequestFrame

TakeRequests removes and returns the image requests waiting for a frame from a participant's source, keeping the samplers. An empty videoSource takes the requests waiting on every source of the participant.

type VideoInSourceParams added in v0.7.0

type VideoInSourceParams struct {
	// Framerate is how many frames per second to pass on from the source; 0
	// passes on 30. It does not apply with OnRequestOnly.
	Framerate int
	// OnRequestOnly passes on frames only to answer a UserImageRequestFrame,
	// rather than continuously at Framerate.
	OnRequestOnly bool
}

VideoInSourceParams says how a transport captures one video source from the user.

func (VideoInSourceParams) Rate added in v0.7.0

func (p VideoInSourceParams) Rate() int

Rate is how many frames per second to pass on from the source: the configured rate, or DefaultVideoInFramerate.

Directories

Path Synopsis
Package livekit implements a jargo transport that joins a LiveKit room as a participant.
Package livekit implements a jargo transport that joins a LiveKit room as a participant.
Package localaudio is a transport that captures from the local microphone and plays back through the local speaker, for running a bot on the same machine with no browser or telephony leg.
Package localaudio is a transport that captures from the local microphone and plays back through the local speaker, for running a bot on the same machine with no browser or telephony leg.
Package rtc implements a WebRTC transport for jargo.
Package rtc implements a WebRTC transport for jargo.
Package whatsapp answers inbound WhatsApp Business calls and bridges their audio into a jargo pipeline.
Package whatsapp answers inbound WhatsApp Business calls and bridges their audio into a jargo pipeline.
Package wsclient is a WebSocket client transport: it dials a WebSocket server and bridges the socket to a jargo pipeline, so a pipeline can talk to a remote peer in both directions.
Package wsclient is a WebSocket client transport: it dials a WebSocket server and bridges the socket to a jargo pipeline, so a pipeline can talk to a remote peer in both directions.
rtviclient
Package rtviclient is the frame serializer for a jargo pipeline acting as an RTVI client.
Package rtviclient is the frame serializer for a jargo pipeline acting as an RTVI client.
Package wsserver is a WebSocket media transport for telephony.
Package wsserver is a WebSocket media transport for telephony.
evalws
Package evalws is the bot's end of an eval: the eval serializer, the connection's flags, and the eval transport over a WebSocket the bot accepted.
Package evalws is the bot's end of an eval: the eval serializer, the connection's flags, and the eval transport over a WebSocket the bot accepted.
exotel
Package exotel is the wsserver.Serializer for Exotel Media Streaming (the Voicebot applet).
Package exotel is the wsserver.Serializer for Exotel Media Streaming (the Voicebot applet).
plivo
Package plivo is the wsserver.Serializer for Plivo Audio Streaming.
Package plivo is the wsserver.Serializer for Plivo Audio Streaming.
protobuf
Package protobuf is the wsserver.Serializer a WebSocket client speaks: frames encoded as protobuf and sent in binary WebSocket messages.
Package protobuf is the wsserver.Serializer a WebSocket client speaks: frames encoded as protobuf and sent in binary WebSocket messages.
protobuf/internal/framepb
Package framepb holds the generated types for the protobuf frame format a WebSocket client speaks.
Package framepb holds the generated types for the protobuf frame format a WebSocket client speaks.
rtviws
Package rtviws is the wsserver.Serializer that carries the RTVI protocol over a plain WebSocket, so an RTVI client can drive a jargo bot without WebRTC.
Package rtviws is the wsserver.Serializer that carries the RTVI protocol over a plain WebSocket, so an RTVI client can drive a jargo bot without WebRTC.
telnyx
Package telnyx is the wsserver.Serializer for Telnyx Media Streaming.
Package telnyx is the wsserver.Serializer for Telnyx Media Streaming.
twilio
Package twilio is the wsserver.Serializer for Twilio Media Streams.
Package twilio is the wsserver.Serializer for Twilio Media Streams.

Jump to

Keyboard shortcuts

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