Documentation
¶
Overview ¶
Package ffmpeg finds the ffmpeg program that screen sharing runs, and on Windows and macOS installs a verified build of it when there is none.
Which ffmpeg is used (Find): the one $REMOHOP_FFMPEG names, else one on PATH (the system's), else RemoHop's own copy. RemoHop's copy is only ever downloaded when someone asks for it (`remohop ffmpeg install`, the button in the desktop app and the quick support window, or turning unattended access on in the desktop app on Windows, for the service: target.go), never by itself. Once there, a copy from an earlier pin is replaced with this version's build (Installer.Upgrade, Plan.Refresh). The download is one of the builds pinned in builds.go: a fixed, versioned file whose SHA-256 is in this source. It is fetched over HTTPS (through the proxy that HTTPS_PROXY names, if any), checked against the pin before anything in it is read, and only the ffmpeg program is taken out of it, into this user's RemoHop directory. REMOHOP_FFMPEG_DOWNLOAD=off (or the setting ffmpeg-download off) switches downloads off.
The builds are GPL builds. Screen sharing prefers hardware encoders, which LGPL builds have too, but falls back to libx264 where there is no working one (a virtual machine, a server without a GPU): it is much faster than the encoders an LGPL build has (OpenH264, software AV1). RemoHop runs ffmpeg as a separate program and does not ship it: the user's computer downloads it from its publisher.
Linux is left to its distribution's ffmpeg.
Index ¶
- Constants
- Variables
- func AsService(path func() string)
- func Dir() (string, error)
- func DownloadDisabled() (bool, string)
- func DownloadDisabledFor(t Target) (bool, string)
- func Install(ctx context.Context, o Options) (string, error)
- func InstallHint() string
- func IsService() bool
- func Remove() (bool, error)
- func ServiceHint() string
- func TrustedForSystem(string) bool
- func Version(ctx context.Context, ffmpeg string) string
- type Build
- type Found
- type Installer
- type Kind
- type Manifest
- type Options
- type PinnedInfo
- type Plan
- type Progress
- type ServiceStatus
- type Status
- type Target
- type UIState
Constants ¶
const ( // PathEnv names the ffmpeg program to use, whatever else there is. PathEnv = "REMOHOP_FFMPEG" // DownloadEnv set to off switches downloads off (for managed // computers); it wins over the setting. DownloadEnv = "REMOHOP_FFMPEG_DOWNLOAD" // SettingDownload is the same as a setting (`remohop config`). SettingDownload = "ffmpeg-download" )
Environment variables and the setting.
Variables ¶
var ErrBusy = errors.New("ffmpeg is already being installed")
ErrBusy: an install is already under way.
var ErrNotFound = errors.New("ffmpeg not found")
ErrNotFound: there is no ffmpeg.
var ErrUnsupported = errors.New("RemoHop has no ffmpeg build to download for " + runtime.GOOS + "/" + runtime.GOARCH +
"; install ffmpeg with the system's package manager")
ErrUnsupported: there is no pinned build for this system.
Service, when set, finds the RemoHop service that shares this computer's screen with a directory of its own: on Windows, the service installed with --unattended (internal/service sets it). ok is false when there is none.
Functions ¶
func AsService ¶
func AsService(path func() string)
AsService tells the package that this process is the Windows service, which has a copy of ffmpeg of its own (target.go) and cannot use a user's. path reads the PATH it would start with now (the machine's, and its own Environment value): Find looks there too.
func Dir ¶
Dir is where RemoHop's copy lives: "ffmpeg" in RemoHop's directory ($REMOHOP_CONFIG_DIR, as the Windows service and tests have it), except on Windows where it goes to the local (not roaming) application data directory, %LocalAppData%\remohop\ffmpeg: a 100 MB program has no place in a roaming profile.
func DownloadDisabled ¶
DownloadDisabled reports whether downloads are switched off, and by what (the environment variable or the setting).
func DownloadDisabledFor ¶
DownloadDisabledFor reports whether downloads for t are switched off, and by what. Any switch counts: this process's (DownloadDisabled: its environment, this user's setting) and t's (its environment and its own setting, which for the Windows service are the machine's).
func Install ¶
Install downloads this system's pinned build, checks it, and puts its ffmpeg program in Dir. It returns the program's path. An unverified download is deleted and never opened as an archive, let alone run.
func InstallHint ¶
func InstallHint() string
InstallHint is the sentence that offers `remohop ffmpeg install`, or "" where it cannot be used (no pinned build, downloads switched off).
func IsService ¶
func IsService() bool
IsService reports whether this process is the Windows service (AsService).
func ServiceHint ¶
func ServiceHint() string
ServiceHint is what to do when the Windows service has no ffmpeg: it cannot use one installed for a user (winget's default, the desktop app's button), only its own copy, the machine's PATH or REMOHOP_FFMPEG in its own environment.
func TrustedForSystem ¶
TrustedForSystem: only the Windows service runs ffmpeg as LocalSystem in a user's session (trust_windows.go).
Types ¶
type Build ¶
type Build struct {
// Version is ffmpeg's version, as people read it.
Version string
// Source names who builds it, for people (the status and the UI).
Source string
// License is the build's licence: all of these are GPL builds, as
// they include libx264 (see the package comment).
License string
// URLs are mirrors of the same file, tried in order; each must be
// HTTPS.
URLs []string
// SHA256 is the archive's hash, in hex.
SHA256 string
// Size is the archive's size in bytes.
Size int64
// Member is the path of the program in the archive (a zip file).
Member string
// MemberSize is the program's size in bytes once extracted.
MemberSize int64
}
Build is one ffmpeg build RemoHop may download: an archive at a fixed, versioned address whose SHA-256 is pinned here. The archive is checked against the pin before anything in it is read, and only the ffmpeg program is taken from it.
type Found ¶
Found is the ffmpeg in use.
func Find ¶
Find is the ffmpeg screen sharing uses: $REMOHOP_FFMPEG (as it is, as before), else one on PATH, else RemoHop's copy. In the Windows service (AsService), PATH is also the machine's PATH as it is now: Windows gives services the environment it had when it started, so an ffmpeg installed for all users since then would otherwise be missed until a restart of the computer.
func FindFor ¶
FindFor is Find as t sees it: its REMOHOP_FFMPEG, else ffmpeg on its PATH, else its copy. An error other than ErrNotFound means its copy could not be looked at (its directory is the administrators' only).
func InstallFor ¶
InstallFor installs RemoHop's copy for t, in its directory, exactly as Install does for this user: the same pinned build, the same checks. Call PrepareFor first. Downloads switched off for t (DownloadDisabledFor) are refused. It returns the ffmpeg t uses afterwards.
type Installer ¶
type Installer struct {
// OnChange, if set, is called when State changes.
OnChange func()
// For tests: what finds ffmpeg, installs it, the pinned build, and
// what describes RemoHop's copy (InstalledManifest).
Find func() (Found, error)
Install func(ctx context.Context, progress Progress) (string, error)
Pinned func() (Build, bool)
Manifest func() (Manifest, bool)
// contains filtered or unexported fields
}
Installer runs the one-click install for a UI: one at a time, in the background, with its progress in State. The zero value works.
func (*Installer) Refresh ¶
func (in *Installer) Refresh()
Refresh forgets the last answer, so that the next State looks for ffmpeg again.
func (*Installer) Start ¶
Start begins an install in the background; State follows it. ctx ends it (the app quitting).
func (*Installer) Upgrade ¶
Upgrade replaces RemoHop's copy of ffmpeg, quietly in the background, when screen sharing uses it and it is not the build this program pins: RemoHop downloaded it from an earlier pin (its manifest says so), and it would otherwise stay as it is, as Install keeps a copy whose hash is the pin's. An ffmpeg the user put there (REMOHOP_FFMPEG, PATH) or a copy without a manifest is left alone, and so is everything while downloads are switched off. The old program stays in use until the new one is verified and in place (Install). The desktop app and the quick support window call it when they start; it runs once per Installer (an attempt that failed is made again when the app next starts). done, if set, hears how it went. It reports whether it started, with the manifest of the copy it replaces.
type Manifest ¶
type Manifest struct {
Version string `json:"version"`
Source string `json:"source"`
URL string `json:"url"`
SHA256 string `json:"sha256"` // the archive's
Installed time.Time `json:"installed"`
}
Manifest describes RemoHop's copy (ffmpeg.json next to it).
func InstalledManifest ¶
InstalledManifest describes RemoHop's copy, if there is one.
func ManifestFor ¶
ManifestFor describes t's copy, if it has one.
type Options ¶
type Options struct {
// Progress, if set, hears how far the install is.
Progress Progress
// Force installs again when the same build is already installed.
Force bool
// Client downloads; nil means a client that goes through the proxy
// the environment names (HTTPS_PROXY).
Client *http.Client
// Dir, if set, is where to install instead of Dir(): another RemoHop
// instance's directory (InstallFor). Whoever sets it makes sure that
// only the accounts that instance trusts can change what is there.
Dir string
// contains filtered or unexported fields
}
Options adjust Install; the zero value installs this system's pinned build.
type PinnedInfo ¶
type PinnedInfo struct {
Version string `json:"version"`
Source string `json:"source"`
License string `json:"license"`
URLs []string `json:"urls"`
SHA256 string `json:"sha256"`
SizeMB int `json:"size_mb"`
}
PinnedInfo is a Build for the status.
type Plan ¶
type Plan struct {
// Found is the ffmpeg it uses, if any.
Found *Found `json:"found,omitempty"`
// Install: it has none, and RemoHop can install its copy for it.
Install bool `json:"install,omitempty"`
// Refresh: it uses RemoHop's copy, which RemoHop downloaded from an
// earlier pin (its manifest's hash is not this program's pin), and
// RemoHop can replace it with the pinned build. Found is the old one
// until then.
Refresh bool `json:"refresh,omitempty"`
// Why it has none and RemoHop cannot install one (no build for this
// system, downloads switched off).
Why string `json:"why,omitempty"`
}
Plan is what RemoHop would do about another instance's ffmpeg.
func PlanFor ¶
PlanFor decides whether to install RemoHop's copy for t: only when t finds no ffmpeg at all, RemoHop has a build for this system, and no switch turned downloads off (DownloadDisabledFor). It also decides whether to replace the copy t uses (Refresh): only when RemoHop installed it (it has a manifest) from another pin, under the same conditions. An ffmpeg t finds otherwise is left alone.
type Progress ¶
Progress reports an install's stage ("downloading", "verifying", "installing") and, while downloading, the bytes done of total.
type ServiceStatus ¶
type ServiceStatus struct {
Name string `json:"name"`
// Dir is where its copy is (or would be).
Dir string `json:"dir"`
Found *Found `json:"found,omitempty"`
// Installed describes its copy, if it has one.
Installed *Manifest `json:"installed,omitempty"`
// Error: its directory could not be read (it is the administrators'
// only).
Error string `json:"error,omitempty"`
}
ServiceStatus is the service's side of the status.
type Status ¶
type Status struct {
Found *Found `json:"found,omitempty"`
Version string `json:"version,omitempty"`
// Installed describes RemoHop's copy, whether in use or not.
Installed *Manifest `json:"installed,omitempty"`
// Pinned is the build `install` downloads here, if any.
Pinned *PinnedInfo `json:"pinned,omitempty"`
// DownloadOff names what switched downloads off.
DownloadOff string `json:"download_off,omitempty"`
// Service is the ffmpeg of the Windows service with unattended
// access, if there is one.
Service *ServiceStatus `json:"service,omitempty"`
}
Status is what `remohop ffmpeg status --json` prints.
type Target ¶
type Target struct {
// Name says which, for people ("the RemoHop service").
Name string
// ConfigDir is its RemoHop directory. Its copy of ffmpeg is in the
// "ffmpeg" directory there (CopyDir), as Dir is for that instance.
ConfigDir string
// Getenv reads its environment: PathEnv, PATH and DownloadEnv. Nil
// means an empty one.
Getenv func(string) string
// Secure, if set, is called with CopyDir before anything in it is
// looked at, and again after this process installed into it
// (installed). It creates the directory if need be, moves aside one
// that cannot be trusted, and leaves it and everything in it
// changeable only by the accounts the instance trusts. note says what
// it moved aside, if anything.
Secure func(dir string, installed bool) (note string, err error)
}
Target is a RemoHop instance other than this process that runs ffmpeg.
type UIState ¶
type UIState struct {
// Missing: no ffmpeg was found, so screen sharing cannot work.
Missing bool `json:"missing"`
// CanInstall: RemoHop can download a verified build here (a pinned
// build for this system, downloads not switched off).
CanInstall bool `json:"can_install"`
// Disabled names what switched downloads off, if anything did.
Disabled string `json:"disabled,omitempty"`
// SizeMB is the download's size.
SizeMB int `json:"size_mb,omitempty"`
Version string `json:"version,omitempty"`
Source string `json:"source,omitempty"`
// Stage is the install under way: downloading (Percent), verifying,
// installing.
Stage string `json:"stage,omitempty"`
Percent int `json:"percent"`
// Error is the last install's failure.
Error string `json:"error,omitempty"`
}
UIState is ffmpeg as the desktop app and the quick support window show it: whether screen sharing lacks it, and the one-click install.