frameloop

package
v0.0.0-...-bdda42b Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPanic = &PanicErr{}

ErrPanic is used to check for a PanicErr with errors.Is, and should not be used for anything else.

Functions

This section is empty.

Types

type Frame

type Frame = image.NRGBA

type FrameLoop

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

func New

func New(
	ctx context.Context, target io.Writer, frameRate int,
	frames <-chan *Frame, sent chan *Frame,
) *FrameLoop

New creates a new frame loop.

The frames channel is used to get the frames to be written to the target writer. The given frameRate will be maintained by writing the last received frame again if a new frame was not received in time.

If the sent channel is not nil, then every written frame will be sent to it right after it was written. If the same frame was written again due to not receiving a new one, then that frame will be sent again. However, a full sent channel will lose frames (non-blocking sends).

Every received frame will be written at least once before a new frame is accepted, unless the frame loop ends first.

The loop will start when the first frame is received, and will end after ctx is done, or Stop() is called, or a write error occurs.

func (*FrameLoop) Done

func (fl *FrameLoop) Done() <-chan struct{}

Done returns a channel that will be closed when the frame loop has ended and will not write any more frames.

func (*FrameLoop) Err

func (fl *FrameLoop) Err() error

Err will return any error that occurred in the frame loop. It will be valid once the frame loop has ended, and the Stop channel is closed.

func (*FrameLoop) Stop

func (fl *FrameLoop) Stop()

Stop will cause the frame loop to end, and not write out any more frames.

Calling Stop may cause a received frame to not be written out, if the time to write it out has not yet arrived. However, a frame that is already being written will be completed before the loop is ended, to avoid writing partial frames.

func (*FrameLoop) StopWait

func (fl *FrameLoop) StopWait() error

StopWait will cause the frame loop to end, wait for it to do so, and return any error that occurred in the frame loop. See also Stop().

func (*FrameLoop) WaitFrame

func (fl *FrameLoop) WaitFrame() *Frame

WaitFrame waits for a frame to be returned by the frame loop, and returns that frame. This returns nil if the frame loop exits before another frame is returned, or if the returned frame was nil.

type PanicErr

type PanicErr struct {
	// Where is where the panic occurred, and is used in the message.
	Where string

	// Value is the recovered value from the panic.
	Value interface{}
}

PanicErr is used when a panic is turned into an error.

If the panic value is an error, this error unwraps into that error.

func (PanicErr) As

func (e PanicErr) As(target interface{}) bool

As converts between PanicErr and *PanicErr, for use with errors.As.

func (PanicErr) Error

func (e PanicErr) Error() string

Error implements the error interface.

func (PanicErr) Is

func (e PanicErr) Is(target error) bool

Is checks if the target is ErrPanic, to allow use with errors.Is

func (PanicErr) Unwrap

func (e PanicErr) Unwrap() error

Unwrap returns the panic value if it was an error, or nil otherwise.

Jump to

Keyboard shortcuts

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