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 Pion WebRTC transport in transport/pionrtc) embeds them and supplies the media I/O.
Index ¶
- type BaseInput
- func (bi *BaseInput) Cleanup(ctx context.Context) error
- func (bi *BaseInput) Params() Params
- func (bi *BaseInput) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error
- func (bi *BaseInput) PushAudioFrame(ctx context.Context, f *frames.InputAudioRawFrame)
- func (bi *BaseInput) PushTransportMessage(ctx context.Context, raw []byte)
- func (bi *BaseInput) SampleRate() int
- func (bi *BaseInput) StartReading(context.Context) error
- func (bi *BaseInput) StopReading(context.Context) error
- type BaseOutput
- func (bo *BaseOutput) Cleanup(ctx context.Context) error
- func (bo *BaseOutput) Params() Params
- func (bo *BaseOutput) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error
- func (bo *BaseOutput) SampleRate() int
- func (bo *BaseOutput) SendMessage(context.Context, []byte) error
- func (bo *BaseOutput) WriteAudio(context.Context, []byte) error
- type InputDriver
- type OutputDriver
- type Params
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseInput ¶
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.
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) 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(ctx context.Context, f *frames.InputAudioRawFrame)
PushAudioFrame queues a received audio frame to be pushed downstream. The driver calls it for each chunk of audio it reads from the transport.
func (*BaseInput) PushTransportMessage ¶
PushTransportMessage pushes a message received from the client downstream as an InputTransportMessageFrame. A concrete transport calls it when an application message arrives (for example off a data channel).
func (*BaseInput) SampleRate ¶
SampleRate is the input sample rate in Hz, set when the transport starts.
func (*BaseInput) StartReading ¶
StartReading is the default no-op; a concrete transport overrides it.
type BaseOutput ¶
BaseOutput is the tail of a pipeline: it buffers OutputAudioRawFrames, slices them 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.
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) Cleanup ¶
func (bo *BaseOutput) Cleanup(ctx context.Context) error
Cleanup stops the audio goroutine and the processor.
func (*BaseOutput) Params ¶
func (bo *BaseOutput) Params() Params
Params returns the transport parameters.
func (*BaseOutput) ProcessFrame ¶
func (bo *BaseOutput) ProcessFrame(ctx context.Context, f frames.Frame, dir processor.Direction) error
ProcessFrame handles the transport lifecycle and routes audio.
func (*BaseOutput) SampleRate ¶
func (bo *BaseOutput) SampleRate() int
SampleRate is the output sample rate in Hz, set when the transport starts.
func (*BaseOutput) SendMessage ¶
func (bo *BaseOutput) SendMessage(context.Context, []byte) error
SendMessage is the default no-op; a concrete transport overrides it.
func (*BaseOutput) WriteAudio ¶
func (bo *BaseOutput) WriteAudio(context.Context, []byte) error
WriteAudio is the default no-op; a concrete transport overrides it.
type InputDriver ¶
type InputDriver interface {
processor.Processor
// StartReading begins reading media from the transport. It runs under ctx,
// which is canceled when the transport stops.
StartReading(ctx context.Context) error
// StopReading stops reading media from the transport.
StopReading(ctx context.Context) error
}
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.
type OutputDriver ¶
type OutputDriver interface {
processor.Processor
// WriteAudio sends one chunk of interleaved S16LE PCM over the transport.
WriteAudio(ctx context.Context, pcm []byte) error
// SendMessage sends an application message to the client (for example over
// a data channel).
SendMessage(ctx context.Context, data []byte) error
}
OutputDriver is implemented by a concrete output transport so the base can hand it audio chunks and messages to send.
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
// AudioInPassthrough pushes received audio frames downstream.
AudioInPassthrough bool
// 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
// AudioOut10msChunks is how many 10 ms chunks of audio are written at a
// time. With WebRTC Opus this is 2, so audio is written in 20 ms frames.
AudioOut10msChunks int
}
Params configures a transport's audio input and output.
func DefaultParams ¶
func DefaultParams() Params
DefaultParams returns Params with audio input and output enabled and the defaults a WebRTC transport uses: mono, input passthrough on, 20 ms output chunks.
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
}
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package pionrtc implements a WebRTC transport for jargo using Pion.
|
Package pionrtc implements a WebRTC transport for jargo using Pion. |
|
Package wsserver is a WebSocket media transport for telephony.
|
Package wsserver is a WebSocket media transport for telephony. |
|
twilio
Package twilio is the wsserver.Serializer for Twilio Media Streams.
|
Package twilio is the wsserver.Serializer for Twilio Media Streams. |