Documentation
¶
Index ¶
- Constants
- func CloseWasmContext(ctx context.Context) error
- func GetWasmContext(ctx context.Context) (*wasmContext, error)
- func Version() string
- type Application
- type Bandwidth
- type Decoder
- func (dec *Decoder) Decode(data []byte, pcm []int16) (int, error)
- func (dec *Decoder) DecodeFEC(data []byte, pcm []int16) (int, error)
- func (dec *Decoder) DecodeFECFloat32(data []byte, pcm []float32) (int, error)
- func (dec *Decoder) DecodeFloat32(data []byte, pcm []float32) (int, error)
- func (dec *Decoder) DecodePLC(pcm []int16) (int, error)
- func (dec *Decoder) DecodePLCFloat32(pcm []float32) (int, error)
- func (dec *Decoder) Init(sampleRate int, channels int) error
- func (dec *Decoder) LastPacketDuration() (int, error)
- type Encoder
- func (enc *Encoder) Bitrate() (int, error)
- func (enc *Encoder) Complexity() (int, error)
- func (enc *Encoder) DTX() (bool, error)
- func (enc *Encoder) Encode(pcm []int16, data []byte) (int, error)
- func (enc *Encoder) EncodeFloat32(pcm []float32, data []byte) (int, error)
- func (enc *Encoder) InBandFEC() (bool, error)
- func (enc *Encoder) InDTX() (bool, error)
- func (enc *Encoder) MaxBandwidth() (Bandwidth, error)
- func (enc *Encoder) PacketLossPerc() (int, error)
- func (enc *Encoder) Reset() error
- func (enc *Encoder) SampleRate() (int, error)
- func (enc *Encoder) SetBitrate(bitrate int) error
- func (enc *Encoder) SetBitrateToAuto() error
- func (enc *Encoder) SetBitrateToMax() error
- func (enc *Encoder) SetComplexity(complexity int) error
- func (enc *Encoder) SetDTX(dtx bool) error
- func (enc *Encoder) SetInBandFEC(fec bool) error
- func (enc *Encoder) SetMaxBandwidth(maxBw Bandwidth) error
- func (enc *Encoder) SetPacketLossPerc(lossPerc int) error
- func (enc *Encoder) SetVBR(vbr bool) error
- func (enc *Encoder) SetVBRConstraint(constraint bool) error
- func (enc *Encoder) VBR() (bool, error)
- func (enc *Encoder) VBRConstraint() (bool, error)
- type Error
- type WasmFunctions
Constants ¶
const ( ErrOK = Error(0) // OPUS_OK ErrBadArg = Error(-1) // OPUS_BAD_ARG ErrBufferTooSmall = Error(-2) // OPUS_BUFFER_TOO_SMALL ErrInternalError = Error(-3) // OPUS_INTERNAL_ERROR ErrInvalidPacket = Error(-4) // OPUS_INVALID_PACKET ErrUnimplemented = Error(-5) // OPUS_UNIMPLEMENTED ErrInvalidState = Error(-6) // OPUS_INVALID_STATE ErrAllocFail = Error(-7) // OPUS_ALLOC_FAIL )
Libopus errors using integer values corresponding to OPUS_*.
const ( // AppVoIP is for voice over IP. AppVoIP = Application(2048) // OPUS_APPLICATION_VOIP // AppAudio is for general audio. AppAudio = Application(2049) // OPUS_APPLICATION_AUDIO // AppLowdelay is for low latency. AppRestrictedLowdelay = Application(2051) // OPUS_APPLICATION_RESTRICTED_LOWDELAY )
Variables ¶
This section is empty.
Functions ¶
func CloseWasmContext ¶
CloseWasmContext closes the global Wasm runtime. This should typically be called when the application exits.
func GetWasmContext ¶
GetWasmContext returns the initialized global Wasm context. It will trigger initialization if not already done.
Types ¶
type Application ¶
type Application int
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder contains the state of an Opus decoder using WebAssembly.
func NewDecoder ¶
NewDecoder allocates a new Opus decoder and initializes it. wasmBinary is the []byte content of the opus.wasm file.
func (*Decoder) Decode ¶
Decode encoded Opus data into the supplied int16 PCM buffer. Returns the number of decoded samples per channel.
func (*Decoder) DecodeFEC ¶
DecodeFEC decodes a packet with FEC. pcm must be the size of the lost packet. Returns samples decoded per channel.
func (*Decoder) DecodeFECFloat32 ¶
DecodeFECFloat32 decodes a packet with FEC. pcm must be the size of the lost packet. Returns samples decoded per channel.
func (*Decoder) DecodeFloat32 ¶
DecodeFloat32 encoded Opus data into the supplied float32 PCM buffer. Returns the number of decoded samples per channel.
func (*Decoder) DecodePLC ¶
DecodePLC recovers a lost packet using PLC. pcm must be the size of the lost packet. Returns samples decoded per channel.
func (*Decoder) DecodePLCFloat32 ¶
DecodePLCFloat32 recovers a lost packet using PLC. pcm must be the size of the lost packet. Returns samples decoded per channel.
func (*Decoder) LastPacketDuration ¶
LastPacketDuration gets the duration (in samples per channel) of the last successfully decoded/concealed packet.
type Encoder ¶
type Encoder struct {
// contains filtered or unexported fields
}
Encoder contains the state of an Opus encoder using WebAssembly.
func NewEncoder ¶
func NewEncoder(sampleRate int, channels int, application Application) (*Encoder, error)
NewEncoder allocates a new Opus encoder and initializes it. wasmBinary is the []byte content of the opus.wasm file.
func (*Encoder) Complexity ¶
Complexity returns the computational complexity used by the encoder.
func (*Encoder) DTX ¶
DTX reports whether this encoder is configured to use discontinuous transmission (DTX).
func (*Encoder) EncodeFloat32 ¶
EncodeFloat32 raw PCM data (float32) and store the result.
func (*Encoder) InBandFEC ¶
InBandFEC gets the encoder's configured inband forward error correction (FEC).
func (*Encoder) InDTX ¶
InDTX returns whether the last encoded frame was either a comfort noise update or not encoded due to DTX.
func (*Encoder) MaxBandwidth ¶
MaxBandwidth gets the encoder's configured maximum allowed bandpass.
func (*Encoder) PacketLossPerc ¶
PacketLossPerc gets the encoder's configured packet loss percentage.
func (*Encoder) Reset ¶
Reset resets the codec state to be equivalent to a freshly initialized state.
func (*Encoder) SampleRate ¶
SampleRate returns the encoder sample rate in Hz.
func (*Encoder) SetBitrate ¶
SetBitrate sets the bitrate of the Encoder.
func (*Encoder) SetBitrateToAuto ¶
SetBitrateToAuto allows the encoder to automatically set the bitrate.
func (*Encoder) SetBitrateToMax ¶
SetBitrateToMax causes the encoder to use as much rate as it can.
func (*Encoder) SetComplexity ¶
SetComplexity sets the encoder's computational complexity.
func (*Encoder) SetInBandFEC ¶
SetInBandFEC configures the encoder's use of inband forward error correction (FEC).
func (*Encoder) SetMaxBandwidth ¶
SetMaxBandwidth configures the maximum bandpass that the encoder will select automatically.
func (*Encoder) SetPacketLossPerc ¶
SetPacketLossPerc configures the encoder's expected packet loss percentage.
func (*Encoder) SetVBRConstraint ¶
SetVBRConstraint configures the encoder's use of constrained VBR.
func (*Encoder) VBRConstraint ¶
VBRConstraint reports whether this encoder is configured to use constrained VBR.
type WasmFunctions ¶
type WasmFunctions struct { // Common Malloc api.Function Free api.Function // Encoder functions OpusEncoderGetSize api.Function OpusEncoderInit api.Function OpusEncode api.Function OpusEncodeFloat api.Function BridgeEncoderSetDtx api.Function BridgeEncoderGetDtx api.Function BridgeEncoderGetInDtx api.Function BridgeEncoderGetSampleRate api.Function BridgeEncoderSetBitrate api.Function BridgeEncoderGetBitrate api.Function BridgeEncoderSetComplexity api.Function BridgeEncoderGetComplexity api.Function BridgeEncoderSetMaxBandwidth api.Function BridgeEncoderGetMaxBandwidth api.Function BridgeEncoderSetInbandFec api.Function BridgeEncoderGetInbandFec api.Function BridgeEncoderSetPacketLossPerc api.Function BridgeEncoderGetPacketLossPerc api.Function BridgeEncoderSetVbr api.Function BridgeEncoderGetVbr api.Function BridgeEncoderSetVbrConstraint api.Function BridgeEncoderGetVbrConstraint api.Function BridgeEncoderResetState api.Function // Decoder functions OpusDecoderGetSize api.Function OpusDecoderInit api.Function OpusDecode api.Function OpusDecodeFloat api.Function BridgeDecoderGetLastPacketDuration api.Function // Constant getter functions GetOpusOkAddress api.Function GetOpusBadArgAddress api.Function GetOpusBufferTooSmallAddress api.Function GetOpusInternalErrorAddress api.Function GetOpusInvalidPacketAddress api.Function GetOpusUnimplementedAddress api.Function GetOpusInvalidStateAddress api.Function GetOpusAllocFailAddress api.Function GetOpusBandwidthNarrowbandAddress api.Function GetOpusBandwidthMediumbandAddress api.Function GetOpusBandwidthWidebandAddress api.Function GetOpusBandwidthSuperWidebandAddress api.Function GetOpusBandwidthFullbandAddress api.Function GetOpusAutoAddress api.Function GetOpusBitrateMaxAddress api.Function }
WasmFunctions holds cached an api.Function instances from the Wasm module.