io

package
v0.2.1-0...-ac2cde4 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2021 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcaster

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

Broadcaster is a generic pull-based broadcaster. Broadcaster is unique in a sense that readers can come and go at anytime, and readers don't need to close or notify broadcaster.

func NewBroadcaster

func NewBroadcaster(source Reader, config *BroadcasterConfig) *Broadcaster

NewBroadcaster creates a new broadcaster. Source is expected to drop frames when any of the readers is slower than the source.

func (*Broadcaster) NewReader

func (broadcaster *Broadcaster) NewReader(copyFn func(interface{}) interface{}) Reader

NewReader creates a new reader. Each reader will retrieve the same data from the source. copyFn is used to copy the data from the source to individual readers. Broadcaster uses a small ring buffer, this means that slow readers might miss some data if they're really late and the data is no longer in the ring buffer.

func (*Broadcaster) ReplaceSource

func (broadcaster *Broadcaster) ReplaceSource(source Reader) error

ReplaceSource replaces the underlying source. This operation is thread safe.

func (*Broadcaster) Source

func (broadcaster *Broadcaster) Source() Reader

ReplaceSource retrieves the underlying source. This operation is thread safe.

type BroadcasterConfig

type BroadcasterConfig struct {
	// BufferSize configures the underlying ring buffer size that's being used
	// to avoid data lost for late readers. The default value is 32.
	BufferSize uint
	// PollDuration configures the sleep duration in waiting for new data to come.
	// The default value is 33 ms.
	PollDuration time.Duration
}

BroadcasterConfig is a config to control broadcaster behaviour

type InsufficientBufferError

type InsufficientBufferError struct {
	RequiredSize int
}

InsufficientBufferError tells the caller that the buffer provided is not sufficient/big enough to hold the whole data/sample.

func (*InsufficientBufferError) Error

func (e *InsufficientBufferError) Error() string

type Reader

type Reader interface {
	// Read reads data from the source. The caller is responsible to release the memory that's associated
	// with data by calling the given release function. When err is not nil, the caller MUST NOT call release
	// as data is going to be nil (no memory was given). Otherwise, the caller SHOULD call release after
	// using the data. The caller is NOT REQUIRED to call release, as this is only a part of memory management
	// optimization. If release is not called, the source is forced to allocate a new memory, which also means
	// there will be new allocations during streaming, and old unused memory will become garbage. As a consequence,
	// these garbage will put a lot of pressure to the garbage collector and makes it to run more often and finish
	// slower as the heap memory usage increases and more garbage to collect.
	Read() (data interface{}, release func(), err error)
}

Reader is a generic data reader. In the future, interface{} should be replaced by a generic type to provide strong type.

type ReaderFunc

type ReaderFunc func() (data interface{}, release func(), err error)

ReaderFunc is a proxy type for Reader

func (ReaderFunc) Read

func (f ReaderFunc) Read() (data interface{}, release func(), err error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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