Documentation
¶
Overview ¶
Package syncsched aligns subtitles to their videos inside the server: search's Align, and the sync jobs a person starts with their previews. One slot runs one alignment at a time; ffmpeg still parses each video in its own process.
Index ¶
- Constants
- Variables
- type Aligned
- type Aligner
- func (a *Aligner) Align(ctx context.Context, inst statedb.InstanceID, payload []byte, tag language.Tag, ...) (Aligned, error)
- func (a *Aligner) Collectors() []measure.Metric
- func (a *Aligner) Preview(ctx context.Context, inst statedb.InstanceID, from time.Duration) (stream io.ReadCloser, contentType string, found bool, err error)
- func (a *Aligner) Proposal(owner int64, id status.JobID) (Proposal, bool)
- func (a *Aligner) Propose(ctx context.Context, req ProposeRequest) (status.Job, error)
- func (a *Aligner) Resync(ctx context.Context, req ResyncRequest) (status.Job, error)
- func (a *Aligner) Run(ctx context.Context) error
- type Deps
- type Proposal
- type ProposeRequest
- type ResyncRequest
- type Target
Constants ¶
const ( MaxQueuedPerOwner = 8 MaxQueued = 64 MaxProposalsPerOwner = 16 MaxProposals = 256 ProposalTTL = 15 * time.Minute MaxPreviews = 2 MaxBatch = 500 )
The bounds on what the jobs and previews hold.
Variables ¶
var ( // ErrSyncFailed wraps a tool, extraction or panic failure; Align still // returns a usable Identity and Unverified result beside it. ErrSyncFailed = errors.New("syncsched: sync failed") // ErrDifferentCut is Align's answer for a candidate made for another cut // of the video: it carries no result, and a proposal or batch file // ending on it applies nothing. ErrDifferentCut = subsync.ErrDifferentCut // ErrSyncCapacity is MaxQueuedPerOwner queued or running jobs for the // owner or MaxQueued overall, or MaxProposalsPerOwner unexpired // proposals for the owner or MaxProposals overall. ErrSyncCapacity = errors.New("syncsched: sync capacity") // ErrBatchTooLarge is a Resync over more than MaxBatch files. ErrBatchTooLarge = errors.New("syncsched: batch too large") // ErrPreviewCapacity is MaxPreviews previews streaming. ErrPreviewCapacity = errors.New("syncsched: preview capacity") // ErrPreviewRange is a preview start outside 0 to 24 h. ErrPreviewRange = errors.New("syncsched: preview start out of range") )
var Causes = append([]string{ causeDifferentCut, causeFFmpegUnavailable, causeNoReference, causeNoAudio, causeUnverified, causeWriteFailed, causeSyncFailed, }, codesOf(mediawrite.Codes)...)
Causes is every cause a sync job ends with, in its wire spelling: its own, then the codes of mediawrite.Codes, which a file's read, video open or write passes on.
var Codes = slices.Concat([]struct { Err error Code string }{ {ErrSyncCapacity, "sync_capacity"}, {ErrBatchTooLarge, "body_invalid"}, {ErrPreviewCapacity, "preview_capacity"}, {ErrPreviewRange, "preview_range"}, }, status.StartCodes, mediawrite.Codes)
Codes is every sentinel the api-called exports return (Propose, Proposal, Resync, Preview), status.StartCodes' and mediawrite's passed on, with the code api answers for it. ErrSyncFailed and ErrDifferentCut are absent: only Align returns them, only search calls Align, and jobs report causes instead.
Functions ¶
This section is empty.
Types ¶
type Aligned ¶
Aligned is Align's result: the parsed candidate, the timing to deliver it at and the pass's outcome.
type Aligner ¶
type Aligner struct {
// contains filtered or unexported fields
}
Aligner runs every alignment through its one slot. Construct it with New.
func (*Aligner) Align ¶
func (a *Aligner) Align(ctx context.Context, inst statedb.InstanceID, payload []byte, tag language.Tag, d timing.Decision) (Aligned, error)
Align is search's call; it writes nothing and waits for the slot in the automatic class. A payload no parser reads is timing.ErrFormatUnsupported, and Skip is Identity and Trusted at once. Otherwise the reference runs up to subsync.MaxModel, then, under ReferenceThenAudio, audio when the reference neither verified nor refused, after a reference failure too unless ffmpeg is missing or the video cannot be opened. Another cut returns ErrDifferentCut alone, a failure with no verified result Identity and Unverified beside ErrSyncFailed, and an ended context its error.
func (*Aligner) Collectors ¶
Collectors are the sync series, for app to register through obs.
func (*Aligner) Preview ¶
func (a *Aligner) Preview(ctx context.Context, inst statedb.InstanceID, from time.Duration) (stream io.ReadCloser, contentType string, found bool, err error)
Preview streams inst's video from from as ffmpeg.Runner.Preview cuts it, with its content type; false when the store holds no inst. from outside 0 to 24 h is ErrPreviewRange, and MaxPreviews streams already open ErrPreviewCapacity. Closing the stream ends ffmpeg and frees its place; the matching subtitle track is timing.RenderVTT's with the same from.
func (*Aligner) Proposal ¶
Proposal is owner's result of Propose job id for ProposalTTL after the job ended; false for another owner's job, one still running, one that holds none, or one expired.
func (*Aligner) Propose ¶
Propose starts a Sync job aligning req.File by req.Method once Current confirms req.Expect and the bounds admit it, so a stale file, a full bound (ErrSyncCapacity) or a status refusal answers before any job is visible. A keyed resend, or an unexpired proposal of the same owner, file, expectation and method, returns that job. The job settles with the file's forced flag; a Rigid file aligns up to Linear, and an audio request on it ends with cause different_cut before it runs. A job that settles a fit holds its Proposal; one ending on any other cause holds none.
func (*Aligner) Resync ¶
Resync starts one Sync job over 1 to MaxBatch files (more is ErrBatchTooLarge), or returns a keyed resend's job. Each file is read with Current at its turn, aligned in the batch class as Propose's job aligns it, and applied with Retime only when Verified; a file that changed, is refused or does not verify is skipped, and the job's cause is the first skip's. It ends Succeeded when every file applied, Partial when some did, else Failed; a stop takes effect between files and inside one.
type Deps ¶
type Deps struct {
Writer *mediawrite.Writer
Prober *embedded.Prober
Status *status.Store
Policy func() language.Policy
Logger *slog.Logger
}
Deps is what New needs; every field but Logger is required. Policy reads the language policy in force, which picks the reference track.
type Proposal ¶
type Proposal struct {
Timing timing.Timing
Ended time.Time
Job status.JobID
File mediawrite.FileRef
Outcome timing.Outcome
Expect mediawrite.Expectation
}
Proposal is a Propose job's result: the fit's Timing, below the gate included, against the file's baseline, and its settled Outcome. api applies it with Writer.Retime and that Outcome unchanged, so a below-gate proposal stays Unverified.
type ProposeRequest ¶
type ProposeRequest struct {
Key *status.JobKey
File mediawrite.FileRef
Expect mediawrite.Expectation
Owner int64
Method timing.Method
}
ProposeRequest asks for one file's alignment by Method, MethodReference or Audio, for the owner status.Job.Owner names.
type ResyncRequest ¶
ResyncRequest asks for its Files' alignment by Method, MethodReference or Audio, for the owner status.Job.Owner names.
type Target ¶
type Target struct {
File mediawrite.FileRef
Expect mediawrite.Expectation
}
Target is one file of a Resync, as its caller listed it.