recorder

package
v0.3.19 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 34 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package recorder is the screen recorder service: the lifecycle state machine (idle, starting, recording, stopping), the elapsed timer, options from the modules.recorder config, and the engine. The engine asks the share picker for an output, has the compositor copy its frames into a buffer on the GPU behind it, encodes them to H.264 on that GPU's video encoder with an optional webcam overlay, mixes the microphone and the desktop's audio into Opus, and muxes both into MP4 or Matroska.

Index

Constants

View Source
const (
	ServiceName = "dev.stubbe.lys.Recorder1"
	ServicePath = "/dev/stubbe/lys/Recorder"
)

D-Bus identity (the Rust RecorderService's registration).

Variables

View Source
var ErrNoVideoEncoder = gpu.ErrNoVideoEncoder

ErrNoVideoEncoder is a GPU that cannot encode H.264: the recorder has no other encoder.

View Source
var ErrPickerCancelled = errors.New("recorder: nothing was picked to record")

ErrPickerCancelled is a start the user dismissed at the picker.

View Source
var ErrReplayOff = errors.New("recorder: the instant replay is not armed")

ErrReplayOff is a save with no instant replay armed.

Functions

func FormatElapsed

func FormatElapsed(totalSecs uint32) string

FormatElapsed is format_elapsed: H:MM:SS above the hour, M:SS within.

func OutputPath

func OutputPath(configuredDir string, format config.RecorderFormat, now time.Time) string

OutputPath is output_path: lys-shell-<local timestamp>.<format> in the configured directory, else the videos directory; a format's name is its extension.

func ReplayPath added in v0.3.15

func ReplayPath(configuredDir string, format config.RecorderFormat, now time.Time) string

ReplayPath is where a replay saved at now goes: lys-shell-replay-<local timestamp to the millisecond>.<format>, beside the recordings, so two saves in one second never replace each other.

func VideosDir

func VideosDir() string

VideosDir is videos_dir: $XDG_VIDEOS_DIR, else $HOME/Videos.

func WebcamMargin

func WebcamMargin(w, h int32) int32

WebcamMargin is the uniform inset, a percentage of the shorter side. The dropdown's position preview uses it too.

Types

type Change

type Change struct {
	Status      Status
	Active      bool
	Paused      bool
	Preparing   bool
	ElapsedSecs uint32
	OutputPath  string
	// Error is why the last recording failed to start or ended on its
	// own, "" once a new one starts.
	Error string
	// Replay is the instant replay's state, ReplayBytes the memory its
	// ring holds while armed.
	Replay      ReplayStatus
	ReplayBytes uint64
}

Change is the state the bar module, the dropdown, and the daemon read.

type Daemon

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

Daemon is the dev.stubbe.lys.Recorder1 object (wayle-shell-core/src/services/recorder/dbus.rs).

func NewDaemon

func NewDaemon(state *State) *Daemon

NewDaemon wraps the state for export.

func (*Daemon) Export

func (d *Daemon) Export(conn *dbus.Conn) (func(), error)

Export serves the interface under its well-known name; the returned release drops the name.

func (*Daemon) Pause

func (d *Daemon) Pause() *dbus.Error

Pause pauses the recording.

func (*Daemon) ReplaySave added in v0.3.15

func (d *Daemon) ReplaySave() (string, *dbus.Error)

ReplaySave writes the replay's last seconds to a file and returns it.

func (*Daemon) ReplayStart added in v0.3.15

func (d *Daemon) ReplayStart() *dbus.Error

ReplayStart arms the instant replay.

func (*Daemon) ReplayStop added in v0.3.15

func (d *Daemon) ReplayStop() *dbus.Error

ReplayStop disarms the instant replay.

func (*Daemon) Resume

func (d *Daemon) Resume() *dbus.Error

Resume resumes a paused recording.

func (*Daemon) Start

func (d *Daemon) Start() *dbus.Error

Start begins a recording.

func (*Daemon) Stop

func (d *Daemon) Stop() *dbus.Error

Stop finalizes the recording.

func (*Daemon) Toggle

func (d *Daemon) Toggle() *dbus.Error

Toggle starts or stops.

type Engine

type Engine interface {
	// OpenSession negotiates the source, showing the picker when no
	// choice is remembered; ctx cancels it.
	OpenSession(ctx context.Context, showCursor bool) (Session, error)
	// OpenOutput opens the output named output, or the focused one for
	// config.ReplayOutputFocused, without asking.
	OpenOutput(output string, showCursor bool) (Session, error)
}

Engine opens capture sessions.

type GPUEngine added in v0.2.0

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

GPUEngine is the production Engine: the share picker for an output or a region of one, screencopy into a buffer on the GPU behind it, the GPU's H.264 encoder, and the audio service for the microphone and the desktop.

func NewGPUEngine added in v0.2.0

func NewGPUEngine(picker Picker, audio *pulse.Service, logical LogicalSize, focused func() (string, bool), stateDir string) *GPUEngine

NewGPUEngine records through picker, with audio from audio (nil when there is no audio server, which fails a recording that asks for sound), regions measured by logical, the focused output named by focused, remembering the pick in stateDir ("" remembers nothing).

func (*GPUEngine) OpenOutput added in v0.3.15

func (e *GPUEngine) OpenOutput(output string, showCursor bool) (Session, error)

OpenOutput implements Engine: output, or the focused one, opened for capture on its GPU with no picker.

func (*GPUEngine) OpenSession added in v0.2.0

func (e *GPUEngine) OpenSession(ctx context.Context, showCursor bool) (Session, error)

OpenSession implements Engine: the remembered output or region, else the one the user picks, opened for capture on its GPU.

type Hooks

type Hooks struct {
	Toast  func(label, icon string, durationMS uint32)
	Notify func(appName, summary, body, icon string)
}

Hooks are the user-facing reports: an OSD toast and a desktop notification. Nil hooks are skipped.

type LogicalSize added in v0.2.0

type LogicalSize func(output string) (image.Point, bool)

LogicalSize is an output's size in the compositor's logical space, false when the output is not known: what a region is measured in.

type Options

type Options struct {
	OutputPath string
	Format     config.RecorderFormat
	Framerate  uint32
	ShowCursor bool
	// Microphone captures MicrophoneDevice ("" the default source);
	// SystemAudio the default sink's monitor.
	Microphone       bool
	MicrophoneDevice string
	SystemAudio      bool
	// Webcam is the overlay, nil for none.
	Webcam *Webcam
}

Options is one recording's settings.

func BuildOptions

func BuildOptions(cfg config.RecorderConfig, now time.Time) Options

BuildOptions is build_options: the recording's options from the config, the output named for now.

type Picker added in v0.2.0

type Picker interface {
	Pick(ctx context.Context, caller portaldialogs.Caller, r sharepicker.Request) (string, error)
	Dismiss(ctx context.Context, handle string) error
}

Picker shows the share picker: sharepicker.Client.

type Recording

type Recording interface {
	// SetPaused pauses or resumes the capture: paused time is cut from
	// the file.
	SetPaused(paused bool)
	// Stop drains the encoders and finalizes the file, blocking until
	// it is written; the error says what of it could not be.
	Stop() error
}

Recording is one running capture.

type Replay added in v0.3.15

type Replay interface {
	// Save writes what the ring holds to path as format without
	// stopping the capture.
	Save(path string, format config.RecorderFormat) error
	// Bytes is the memory the ring holds.
	Bytes() uint64
	// Stop ends the capture and frees the ring.
	Stop() error
}

Replay is one armed instant replay.

type ReplayStatus added in v0.3.15

type ReplayStatus int

ReplayStatus is the instant replay's lifecycle.

const (
	ReplayOff ReplayStatus = iota
	ReplayStarting
	ReplayArmed
)

Replay statuses.

func (ReplayStatus) String added in v0.3.15

func (s ReplayStatus) String() string

String names the status.

type Session

type Session interface {
	// Start records the source with opts; term reports an unexpected
	// end (a source disconnect, a full disk), never a requested Stop.
	Start(opts Options, term func(reason string)) (Recording, error)
	// StartReplay records the source with opts into a ring holding the
	// last span; onKey runs after each keyframe enters it.
	StartReplay(opts Options, span time.Duration, term func(reason string), onKey func()) (Replay, error)
	Close()
}

Session is a negotiated capture source, held across the start delay and closed when the recording ends.

type State

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

State is the recorder service. Safe for concurrent use.

func NewState

func NewState(engine Engine, cfg func() config.RecorderConfig, hooks Hooks) *State

NewState builds the service over an engine, reading options from cfg at each start.

func (*State) Changes

func (s *State) Changes() (<-chan Change, func())

Changes delivers a snapshot on every change and elapsed second to every subscriber; stop ends the feed.

func (*State) ConfigureReplay added in v0.3.15

func (s *State) ConfigureReplay(enable bool)

ConfigureReplay applies modules.recorder.replay.enable: switching it on arms the replay, off disarms it. An unchanged value leaves a replay started or stopped from the CLI as it is.

func (*State) SaveReplay added in v0.3.15

func (s *State) SaveReplay() (string, error)

SaveReplay writes the replay's last seconds to a new file in the output directory, without stopping it, and returns the file.

func (*State) SetPaused

func (s *State) SetPaused(paused bool)

SetPaused pauses or resumes an active recording.

func (*State) Snapshot

func (s *State) Snapshot() Change

Snapshot reads the current state.

func (*State) Start

func (s *State) Start()

Start begins a recording with the current config. The Idle→Starting claim is synchronous, so a second call while one is in flight is a no-op; the rest (picker, delay, recording) runs off the caller.

func (*State) StartReplay added in v0.3.15

func (s *State) StartReplay()

StartReplay arms the instant replay on the configured output. The Off→Starting claim is synchronous; opening the output and starting the capture run off the caller.

func (*State) Stop

func (s *State) Stop()

Stop stops the recording, or cancels one still starting. Only the first call from Starting or Recording does work. From Recording the UI flips to stopped at once, the blocking finalize runs off the caller, and the status settles to Idle after it.

func (*State) StopReplay added in v0.3.15

func (s *State) StopReplay()

StopReplay disarms the instant replay, freeing its ring; one still starting is torn down as it comes up.

func (*State) Toggle

func (s *State) Toggle()

Toggle keys off the lifecycle, not active: during the start delay a toggle cancels the pending start (state.rs's toggle).

type Status

type Status int

Status is the lifecycle gate (state.rs's Status), updated synchronously so rapid clicks never double-start.

const (
	StatusIdle Status = iota
	StatusStarting
	StatusRecording
	StatusStopping
)

Statuses.

func (Status) String

func (s Status) String() string

String names the status.

type Webcam

type Webcam struct {
	// Device is the V4L2 node; "" auto-selects the first camera.
	Device string
	// X and Y place the frame in the free space, 0-100.
	X, Y uint32
	// Size is the frame width as a percentage of the recording, 1-100.
	Size uint32
}

Webcam is the picture-in-picture overlay.

Directories

Path Synopsis
Package recordertest is the scripted recorder.Engine every recorder test drives: sessions and recordings that record their calls, an optional gate that holds OpenSession (the output picker), and a hook that ends a recording as a failed capture would.
Package recordertest is the scripted recorder.Engine every recorder test drives: sessions and recordings that record their calls, an optional gate that holds OpenSession (the output picker), and a hook that ends a recording as a failed capture would.

Jump to

Keyboard shortcuts

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