pbWriter

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Options)

Option is the type for a function option

func Channels

func Channels(chs int) Option

Channels is a functional option to set the amount of channels to be used with the audio device. Typically this is either Mono (1) or Stereo (2). Make sure that your audio device supports the specified amount of channels.

func Encoder

func Encoder(enc audiocodec.Encoder) Option

Encoder is a functional option to set a specific decoder. By default, the opus decoder is used.

func FramesPerBuffer

func FramesPerBuffer(s int) Option

FramesPerBuffer is a functional option which sets the amount of sample frames our audio device will request / provide when executing the callback. Example: A buffer with 960 frames at 48000kHz / stereo contains 1920 samples and results in 20ms Audio.

func Samplerate

func Samplerate(s float64) Option

Samplerate is a functional option to set the sampling rate of the audio device. Make sure your audio device supports the specified sampling rate.

func ToWireCb

func ToWireCb(cb func([]byte)) Option

ToWireCb is a functional option to set the callback which will be executed when data has been serialized and is ready to be send to the network.

func UserID

func UserID(s string) Option

UserID is a functional option to set the UserID. All serialized protobufs contain the UserID to mark their origin.

type Options

type Options struct {
	DeviceName      string
	Encoder         audiocodec.Encoder
	Channels        int
	Samplerate      float64
	FramesPerBuffer int
	UserID          string
	ToWireCb        func([]byte)
}

Options is the data structure holding the optional values. The values are typically set by calling the functional options.

type PbWriter

type PbWriter struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PbWriter implements the audio.Sink interface. It is used to encode audio.Msg with a selected audiocodec into Protocol buffers. This Sink is typically used when audio frames have to be send to the network.

func NewPbWriter

func NewPbWriter(opts ...Option) (*PbWriter, error)

NewPbWriter is the constructor for a ProtoBufWriter. The ToWireCb callback will be executed when an audio.Msg has been encoded into a protobuf byte slice and ready to be send to the network. Additional functional options can be passed in (e.g. the audio codec to be used).

func (*PbWriter) Close

func (pbw *PbWriter) Close() error

Close is not implemented

func (*PbWriter) Flush

func (pbw *PbWriter) Flush()

Flush clears all internal buffers

func (*PbWriter) SetToWireCb

func (pbw *PbWriter) SetToWireCb(cb func([]byte))

SetToWireCb allows to set a callback which will be called whenever the data has been serialized and is ready to be send on the wire.

func (*PbWriter) SetVolume

func (pbw *PbWriter) SetVolume(v float32)

SetVolume sets the volume for this sink

func (*PbWriter) Start

func (pbw *PbWriter) Start() error

Start starts this audio sink.

func (*PbWriter) Stop

func (pbw *PbWriter) Stop() error

Stop disables this audio sink.

func (*PbWriter) Volume

func (pbw *PbWriter) Volume() float32

Volume returns the volume for this sink

func (*PbWriter) Write

func (pbw *PbWriter) Write(audioMsg audio.Msg) error

Write is called to encode audio.Msg with a specified audio codec into protobufs. The Token is not used. On success the protobuf ([]byte) will be returned in a callback.

Jump to

Keyboard shortcuts

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