worker

package
v3.0.5 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2023 License: Apache-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetFrameSizeFor

func GetFrameSizeFor(hz int, frame int) int

GetFrameSizeFor calculates audio frame size, i.e. 48k*frame/1000*2

func New

func New(conf worker.Config, log *logger.Logger, done chan struct{}) (services service.Group)

func ResampleStretchNew

func ResampleStretchNew(pcm []int16, size int) []int16

ResampleStretchNew does a simple stretching of audio samples. something like: [1,2,3,4,5,6] -> [1,2,x,x,3,4,x,x,5,6,x,x] -> [1,2,1,2,3,4,3,4,5,6,5,6]

Types

type Buffer

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

Buffer is a simple non-thread safe ring buffer for audio samples. It should be used for 16bit PCM (LE interleaved) data.

func NewBuffer

func NewBuffer(numSamples int) Buffer

func (*Buffer) Write

func (b *Buffer) Write(s Samples, onFull OnFull) (r int)

Write fills the buffer with data calling a callback function when the internal buffer fills out.

Consider two cases:

1. Underflow, when the length of written data is less than the buffer's available space. 2. Overflow, when the length exceeds the current available buffer space. In the both cases we overwrite any previous values in the buffer and move the internal write pointer on the length of written data. In the first case we won't call the callback, but it will be called every time when the internal buffer overflows until all samples are read.

type CloudSaveRoom

type CloudSaveRoom struct {
	GamingRoom
	// contains filtered or unexported fields
}

func WithCloudStorage

func WithCloudStorage(room GamingRoom, storage CloudStorage) *CloudSaveRoom

func (*CloudSaveRoom) Download

func (c *CloudSaveRoom) Download() error

func (*CloudSaveRoom) HasSave

func (c *CloudSaveRoom) HasSave() bool

func (*CloudSaveRoom) SaveGame

func (c *CloudSaveRoom) SaveGame() error

type CloudStorage

type CloudStorage interface {
	Save(name string, localPath string) (err error)
	Load(name string) (data []byte, err error)
}

func GetCloudStorage

func GetCloudStorage(provider, key string) (CloudStorage, error)

type Connection added in v3.0.5

type Connection interface {
	Disconnect()
	Id() com.Uid
	ProcessPackets(func(api.In[com.Uid]) error) chan struct{}

	Send(api.PT, any) ([]byte, error)
	Notify(api.PT, any)
	Route(api.In[com.Uid], *api.Out)
}

type GamingRoom

type GamingRoom interface {
	GetId() string
	Close()
	CleanupUser(*Session)
	HasSave() bool
	StartEmulator()
	SaveGame() error
	LoadGame() error
	ToggleMultitap()
	HasUser(*Session) bool
	AddUser(*Session)
	PollUserInput(*Session)
	EnableAutosave(periodS int)
	GetEmulator() emulator.Emulator
	GetLog() *logger.Logger
}

type OnFull

type OnFull func(s Samples)

Buffer is a simple non-thread safe ring buffer for audio samples. It should be used for 16bit PCM (LE interleaved) data.

type OracleDataStorageClient

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

func NewOracleDataStorageClient

func NewOracleDataStorageClient(accessURL string) (*OracleDataStorageClient, error)

NewOracleDataStorageClient returns either a new Oracle Data Storage client or some error in case of failure. Oracle infrastructure access is based on pre-authenticated requests, see: https://docs.oracle.com/en-us/iaas/Content/Object/Tasks/usingpreauthenticatedrequests.htm

It follows broken Google Cloud Storage client design.

func (*OracleDataStorageClient) Load

func (s *OracleDataStorageClient) Load(name string) (data []byte, err error)

func (*OracleDataStorageClient) Save

func (s *OracleDataStorageClient) Save(name string, localPath string) (err error)

type RecordingRoom

type RecordingRoom struct {
	GamingRoom
	// contains filtered or unexported fields
}

func WithRecording

func WithRecording(room GamingRoom, rec bool, recUser string, game string, conf worker.Config) *RecordingRoom

func (*RecordingRoom) Close

func (r *RecordingRoom) Close()

func (*RecordingRoom) IsRecording

func (r *RecordingRoom) IsRecording() bool

func (*RecordingRoom) ToggleRecording

func (r *RecordingRoom) ToggleRecording(active bool, user string)

type Room

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

func NewRoom

func NewRoom(id string, game games.GameMetadata, onClose func(*Room), conf worker.Config, log *logger.Logger) *Room

func (*Room) AddUser

func (r *Room) AddUser(user *Session)

func (*Room) CleanupUser

func (r *Room) CleanupUser(user *Session)

func (*Room) Close

func (r *Room) Close()

func (*Room) EnableAutosave

func (r *Room) EnableAutosave(periodSec int)

func (*Room) GetEmulator

func (r *Room) GetEmulator() emulator.Emulator

func (*Room) GetId

func (r *Room) GetId() string

func (*Room) GetLog

func (r *Room) GetLog() *logger.Logger

func (*Room) HasSave

func (r *Room) HasSave() bool

func (*Room) HasUser

func (r *Room) HasUser(u *Session) bool

func (*Room) IsEmpty

func (r *Room) IsEmpty() bool

func (*Room) LoadGame

func (r *Room) LoadGame() error

func (*Room) PollUserInput

func (r *Room) PollUserInput(session *Session)

func (*Room) SaveGame

func (r *Room) SaveGame() error

func (*Room) StartEmulator

func (r *Room) StartEmulator()

func (*Room) ToggleMultitap

func (r *Room) ToggleMultitap()

type Router

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

Router tracks and routes freshly connected users to a game room. Basically, it holds user connection data until some user makes (connects to) a new room (game), then it manages all the cross-references between room and users. Rooms and users has 1-to-n relationship.

func NewRouter

func NewRouter() Router

func (*Router) AddUser

func (r *Router) AddUser(user *Session)

func (*Router) Close

func (r *Router) Close()

func (*Router) GetRoom

func (r *Router) GetRoom(id string) GamingRoom

func (*Router) GetUser

func (r *Router) GetUser(uid com.Uid) *Session

func (*Router) RemoveDisconnect added in v3.0.5

func (r *Router) RemoveDisconnect(user *Session)

func (*Router) SetRoom

func (r *Router) SetRoom(room GamingRoom)

type Samples

type Samples []int16

Buffer is a simple non-thread safe ring buffer for audio samples. It should be used for 16bit PCM (LE interleaved) data.

type Session

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

Session represents WebRTC connection of the user.

func NewSession

func NewSession(rtc *webrtc.Peer, id com.Uid) *Session

func (*Session) Disconnect added in v3.0.5

func (s *Session) Disconnect()

func (*Session) GetPeerConn

func (s *Session) GetPeerConn() *webrtc.Peer

func (*Session) GetPlayerIndex

func (s *Session) GetPlayerIndex() int

func (*Session) GetSetRoom

func (s *Session) GetSetRoom(v GamingRoom) GamingRoom

func (*Session) Id

func (s *Session) Id() com.Uid

func (*Session) IsConnected

func (s *Session) IsConnected() bool

func (*Session) SendAudio

func (s *Session) SendAudio(sample *media.Sample) error

func (*Session) SendVideo

func (s *Session) SendVideo(sample *media.Sample) error

func (*Session) SetPlayerIndex

func (s *Session) SetPlayerIndex(index int)

func (*Session) SetRoom

func (s *Session) SetRoom(room GamingRoom)

type Worker

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

func (*Worker) Run

func (w *Worker) Run()

func (*Worker) Stop

func (w *Worker) Stop() error

Directories

Path Synopsis
zip
image
Package image contains functions for rotations of points in a 2-dimensional space.
Package image contains functions for rotations of points in a 2-dimensional space.
h264
Package h264 implements cgo bindings for [x264](https://www.videolan.org/developers/x264.html) library.
Package h264 implements cgo bindings for [x264](https://www.videolan.org/developers/x264.html) library.
vpx
yuv

Jump to

Keyboard shortcuts

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