dca

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: Apache-2.0, BSD-3-Clause Imports: 13 Imported by: 0

README

This is a stripped down, modified version of https://github.com/jonas747/dca

Until https://github.com/jonas747/dca/pull/15 gets merged, this will suffice.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadFrame = errors.New("bad frame")
)
View Source
var (
	ErrVoiceConnClosed = errors.New("voice connection closed")
)
View Source
var StdEncodeOptions = &EncodeOptions{
	Volume:           256,
	FrameRate:        48000,
	FrameDuration:    20,
	Bitrate:          64,
	CompressionLevel: 10,
	PacketLoss:       1,
	BufferedFrames:   100,
	VariableBitrate:  true,
}

StdEncodeOptions is the standard options for encoding

Functions

This section is empty.

Types

type EncodeOptions

type EncodeOptions struct {
	Volume           int  // change audio volume (256=normal)
	FrameRate        int  // audio sampling rate (ex 48000)
	FrameDuration    int  // audio frame duration can be 20, 40, or 60 (ms)
	Bitrate          int  // audio encoding bitrate in kb/s can be 8 - 128
	PacketLoss       int  // expected packet loss percentage
	CompressionLevel int  // Compression level, higher is better quality but slower encoding (0 - 10)
	BufferedFrames   int  // How big the frame buffer should be
	VariableBitrate  bool // Whether vbr is used or not (variable bitrate)
	Threads          int  // Number of threads to use, 0 for auto
}

EncodeOptions is a set of options for encoding dca

type EncodeSession

type EncodeSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func EncodeFile

func EncodeFile(path string, options *EncodeOptions) (session *EncodeSession, err error)

EncodeFile encodes the file/url/other in path

func (*EncodeSession) Cleanup

func (e *EncodeSession) Cleanup()

Cleanup cleans up the encoding session, throwing away all unread frames and stopping ffmpeg ensuring that no ffmpeg processes starts piling up on your system You should always call this after it's done

func (*EncodeSession) FrameDuration

func (e *EncodeSession) FrameDuration() time.Duration

FrameDuration implements OpusReader, retruning the duratio of each frame

func (*EncodeSession) OpusFrame

func (e *EncodeSession) OpusFrame() (frame []byte, err error)

OpusFrame implements OpusReader, returning the next opus frame

func (*EncodeSession) Read

func (e *EncodeSession) Read(p []byte) (n int, err error)

Read implements io.Reader, n == len(p) if err == nil, otherwise n contains the number bytes read before an error occured

func (*EncodeSession) ReadFrame

func (e *EncodeSession) ReadFrame() (frame []byte, err error)

ReadFrame blocks until a frame is read or there are no more frames Note: If rawoutput is not set, the first frame will be a metadata frame

func (*EncodeSession) Running

func (e *EncodeSession) Running() (running bool)

Running returns true if running

func (*EncodeSession) Stop

func (e *EncodeSession) Stop() error

Stop stops the encoding session

func (*EncodeSession) Truncate

func (e *EncodeSession) Truncate()

Truncate is deprecated, use Cleanup instead this will be removed in a future version

type Frame

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

type OpusReader

type OpusReader interface {
	OpusFrame() (frame []byte, err error)
	FrameDuration() time.Duration
}

type StreamingSession

type StreamingSession struct {
	sync.Mutex
	// contains filtered or unexported fields
}

StreamingSession provides an easy way to directly transmit opus audio to discord from an encode session.

func NewStream

func NewStream(source OpusReader, vc *discordgo.VoiceConnection, done chan error) *StreamingSession

Creates a new stream from an Opusreader. source : The source of the opus frames to be sent, either from an encoder or decoder. vc : The voice connecion to stream to. done : If not nil, an error will be sent on it when completed.

func (*StreamingSession) Finished

func (s *StreamingSession) Finished() (bool, error)

Finished returns whether the stream finished or not, and any error that caused it to stop

func (*StreamingSession) Paused

func (s *StreamingSession) Paused() bool

Paused returns whether the stream is paused or not

func (*StreamingSession) PlaybackPosition

func (s *StreamingSession) PlaybackPosition() time.Duration

PlaybackPosition returns the the duration of content we have transmitted so far

func (*StreamingSession) SetPaused

func (s *StreamingSession) SetPaused(paused bool)

SetPaused provides pause/unpause functionality

Jump to

Keyboard shortcuts

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