recorder

package
v0.0.0-...-94d7571 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidMarkerName = errors.New("invalid marker name")

ErrInvalidMarkerName is returned by Mark when the marker name is empty or too long. Callers can use errors.Is to surface a 400.

View Source
var ErrInvalidParams = errors.New("invalid recording parameters")

ErrInvalidParams indicates the requested recording parameters are invalid for this server (e.g. audio requested without a configured source/socket). Callers can use errors.Is to surface a client-facing error instead of a 500.

View Source
var ErrNotRecording = errors.New("no active recording")

ErrNotRecording is returned by Mark when no recording is actively running. Callers can use errors.Is to surface a 409.

View Source
var ErrRecordingFinalizing = errors.New("recording is being finalized")

ErrRecordingFinalizing is returned when attempting to access a recording that is currently being finalized (remuxed to add duration metadata).

Functions

This section is empty.

Types

type FFmpegManager

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

func NewFFmpegManager

func NewFFmpegManager() *FFmpegManager

func (*FFmpegManager) DeregisterRecorder

func (fm *FFmpegManager) DeregisterRecorder(ctx context.Context, recorder Recorder) error

func (*FFmpegManager) GetRecorder

func (fm *FFmpegManager) GetRecorder(id string) (Recorder, bool)

func (*FFmpegManager) ListActiveRecorders

func (fm *FFmpegManager) ListActiveRecorders(ctx context.Context) []Recorder

func (*FFmpegManager) RegisterRecorder

func (fm *FFmpegManager) RegisterRecorder(ctx context.Context, recorder Recorder) error

func (*FFmpegManager) StopAll

func (fm *FFmpegManager) StopAll(ctx context.Context) error

type FFmpegRecorder

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

FFmpegRecorder encapsulates an FFmpeg recording session with platform-specific screen capture. It manages the lifecycle of a single FFmpeg process and provides thread-safe operations.

func (*FFmpegRecorder) Delete

func (fr *FFmpegRecorder) Delete(ctx context.Context) error

Delete removes the recording file from disk. Returns ErrRecordingFinalizing if the recording is currently being finalized.

func (*FFmpegRecorder) ForceStop

func (fr *FFmpegRecorder) ForceStop(ctx context.Context) error

ForceStop immediately terminates the recording process.

func (*FFmpegRecorder) ID

func (fr *FFmpegRecorder) ID() string

ID returns the unique identifier for this recorder.

func (*FFmpegRecorder) IsDeleted

func (fr *FFmpegRecorder) IsDeleted(ctx context.Context) bool

func (*FFmpegRecorder) IsRecording

func (fr *FFmpegRecorder) IsRecording(ctx context.Context) bool

IsRecording returns true if a recording is currently in progress.

func (*FFmpegRecorder) Mark

func (fr *FFmpegRecorder) Mark(name string) (string, int64, error)

Mark records a named marker at the current time. It returns the stored (trimmed) marker name and the offset from the recording start in milliseconds. The offset is provisional: it is measured against the capture anchor at mark time, while the authoritative value is the chapter start computed at finalize.

Returns ErrNotRecording if the recording isn't actively running and ErrInvalidMarkerName if the name is empty or exceeds maxMarkerNameLen.

func (*FFmpegRecorder) Metadata

func (fr *FFmpegRecorder) Metadata() *RecordingMetadata

Metadata is an incomplete snapshot of the recording metadata.

func (*FFmpegRecorder) Params

Params returns a deep copy of the merged recording parameters.

func (*FFmpegRecorder) Recording

Recording returns the recording file as an io.ReadCloser. Returns ErrRecordingFinalizing if the recording is currently being finalized.

func (*FFmpegRecorder) Start

func (fr *FFmpegRecorder) Start(ctx context.Context) error

Start begins the recording process by launching ffmpeg with the configured parameters.

func (*FFmpegRecorder) Stop

func (fr *FFmpegRecorder) Stop(ctx context.Context) error

Stop gracefully stops the recording using a multi-phase shutdown process.

func (*FFmpegRecorder) WaitForFinalization

func (fr *FFmpegRecorder) WaitForFinalization(ctx context.Context) error

WaitForFinalization blocks until finalization completes and returns the result. If finalization hasn't started, it will be triggered. If already complete, returns the cached result immediately. This is useful for callers like the download handler that need to wait for finalization before accessing the recording.

type FFmpegRecorderFactory

type FFmpegRecorderFactory func(id string, overrides FFmpegRecordingParams) (Recorder, error)

func NewFFmpegRecorderFactory

func NewFFmpegRecorderFactory(pathToFFmpeg string, config FFmpegRecordingParams, ctrl scaletozero.Controller) FFmpegRecorderFactory

NewFFmpegRecorderFactory returns a factory that creates new recorders. The provided pathToFFmpeg is used as the binary to execute; if empty it defaults to "ffmpeg" which is expected to be discoverable on the host's PATH.

type FFmpegRecordingParams

type FFmpegRecordingParams struct {
	FrameRate   *int
	DisplayNum  *int
	MaxSizeInMB *int
	// MaxDurationInSeconds optionally limits the total recording time. If nil there is no duration limit.
	MaxDurationInSeconds *int
	OutputDir            *string
	RecordAudio          *bool
	AudioSource          *string
	PulseServer          *string
}

func (FFmpegRecordingParams) Validate

func (p FFmpegRecordingParams) Validate() error

type Marker

type Marker struct {
	Name string
	At   time.Time
}

Marker records a named point in time during a recording. At finalize the markers are written into the output MP4 as chapters so they can be scrubbed to in any tool that reads MP4 chapter metadata.

type RecordManager

type RecordManager interface {
	// GetRecorder retrieves a recorder by its ID.
	// Returns the recorder and true if found, nil and false otherwise.
	GetRecorder(id string) (Recorder, bool)

	// ListActiveRecorders returns a list of IDs for all registered recorders
	ListActiveRecorders(ctx context.Context) []Recorder

	// DeregisterRecorder removes a recorder from the manager.
	DeregisterRecorder(ctx context.Context, recorder Recorder) error

	// RegisterRecorder registers a recorder with the given ID.
	// Returns an error if a recorder with the same ID already exists.
	RegisterRecorder(ctx context.Context, recorder Recorder) error

	// StopAll stops all active recorders.
	StopAll(ctx context.Context) error
}

RecordManager defines the interface for managing multiple recorder instances. Implementations should be thread-safe for concurrent access.

type Recorder

type Recorder interface {
	ID() string
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
	ForceStop(ctx context.Context) error
	// Mark records a named marker at the current time. It returns the stored
	// (trimmed) marker name and the provisional offset from the recording start
	// in milliseconds.
	Mark(name string) (string, int64, error)
	IsRecording(ctx context.Context) bool
	Metadata() *RecordingMetadata
	Recording(ctx context.Context) (io.ReadCloser, *RecordingMetadata, error)
	Delete(ctx context.Context) error
	IsDeleted(ctx context.Context) bool
}

Recorder defines the interface for recording functionality.

type RecordingMetadata

type RecordingMetadata struct {
	Size      int64
	StartTime time.Time
	EndTime   time.Time
}

Jump to

Keyboard shortcuts

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