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
- Variables
- func FormatElapsed(totalSecs uint32) string
- func OutputPath(configuredDir string, format config.RecorderFormat, now time.Time) string
- func ReplayPath(configuredDir string, format config.RecorderFormat, now time.Time) string
- func VideosDir() string
- func WebcamMargin(w, h int32) int32
- type Change
- type Daemon
- func (d *Daemon) Export(conn *dbus.Conn) (func(), error)
- func (d *Daemon) Pause() *dbus.Error
- func (d *Daemon) ReplaySave() (string, *dbus.Error)
- func (d *Daemon) ReplayStart() *dbus.Error
- func (d *Daemon) ReplayStop() *dbus.Error
- func (d *Daemon) Resume() *dbus.Error
- func (d *Daemon) Start() *dbus.Error
- func (d *Daemon) Stop() *dbus.Error
- func (d *Daemon) Toggle() *dbus.Error
- type Engine
- type GPUEngine
- type Hooks
- type LogicalSize
- type Options
- type Picker
- type Recording
- type Replay
- type ReplayStatus
- type Session
- type State
- func (s *State) Changes() (<-chan Change, func())
- func (s *State) ConfigureReplay(enable bool)
- func (s *State) SaveReplay() (string, error)
- func (s *State) SetPaused(paused bool)
- func (s *State) Snapshot() Change
- func (s *State) Start()
- func (s *State) StartReplay()
- func (s *State) Stop()
- func (s *State) StopReplay()
- func (s *State) Toggle()
- type Status
- type Webcam
Constants ¶
const ( ServiceName = "dev.stubbe.lys.Recorder1" ServicePath = "/dev/stubbe/lys/Recorder" )
D-Bus identity.
Variables ¶
var ErrNoVideoEncoder = gpu.ErrNoVideoEncoder
ErrNoVideoEncoder is a GPU that cannot encode H.264: the recorder has no other encoder.
var ErrPickerCancelled = errors.New("recorder: nothing was picked to record")
ErrPickerCancelled is a start the user dismissed at the picker.
var ErrReplayOff = errors.New("recorder: the instant replay is not armed")
ErrReplayOff is a save with no instant replay armed.
var ErrReplaySaving = errors.New("recorder: an instant replay save is already writing")
ErrReplaySaving is a save while another is still writing.
Functions ¶
func FormatElapsed ¶
FormatElapsed renders H:MM:SS above the hour, M:SS within.
func OutputPath ¶
OutputPath is lys-shell-<local timestamp>.<format> in the configured directory, else the videos directory; a format's name is its extension.
func ReplayPath ¶
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 ¶
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, ReplaySaving whether a save is writing.
Replay ReplayStatus
ReplayBytes uint64
ReplaySaving bool
}
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.
func (*Daemon) Export ¶
Export serves the interface under its well-known name; the returned release drops the name.
func (*Daemon) ReplaySave ¶
ReplaySave writes the replay's last seconds to a file and returns it.
func (*Daemon) ReplayStart ¶
ReplayStart arms the instant replay.
func (*Daemon) ReplayStop ¶
ReplayStop disarms the instant replay.
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 ¶
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 ¶
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 ¶
OpenOutput implements Engine: output, or the focused one, opened for capture on its GPU with no picker.
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 ¶
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 the recording's options from the config, the output named for now.
type Picker ¶
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 ¶
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 ¶
type ReplayStatus int
ReplayStatus is the instant replay's lifecycle.
const ( ReplayOff ReplayStatus = iota ReplayStarting ReplayArmed )
Replay statuses.
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() error
}
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, now func() time.Time) *State
NewState builds the service over an engine, reading options from cfg at each start and naming the files it saves by the wall time now reads.
func (*State) Changes ¶
Changes delivers a snapshot on every change and elapsed second to every subscriber; stop ends the feed.
func (*State) ConfigureReplay ¶
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 ¶
SaveReplay writes the replay's last seconds to a new file in the output directory, without stopping it, and returns the file. One save writes at a time: another while it does fails with ErrReplaySaving.
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 ¶
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 ¶
func (s *State) StopReplay()
StopReplay disarms the instant replay, freeing its ring once a save still writing it returns; one still starting is torn down as it comes up.
Source Files
¶
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. |