SubtitleTypesetter

A typesetting engine for ASS and SSA subtitles, libass in practice.

The Kotlin dialogue tier in kiteplayer-subtitles reads styles and the common override tags and hands text cues to a platform rasterizer. Full typesetting is a different job: a sign that moves with the camera, a karaoke line filling syllable by syllable, rotated and clipped text. That needs the whole script, every event, and a render per video frame. This interface is that job, expressed in the engine's own vocabulary: events go in, positioned overlay images come out.

Threading

The engine calls every member from one serial lane and never concurrently. An implementation needs no lock of its own. close is also called on that lane, after the last render.

Lifetime of the pixels

The images returned by render are owned by the caller from that moment on. An implementation must not reuse or mutate their bytes afterwards, because a renderer reads them on its own thread for as long as that overlay is on screen.

Functions

Link copied to clipboard
abstract fun addEvent(payload: ByteArray, startMillis: Long, durationMillis: Long)

Adds one container event in the Matroska packet form: ReadOrder,Layer,Style,Name,MarginL, MarginR,MarginV,Effect,Text. Timing is the packet's, in milliseconds on the media timeline. Events are deduplicated by ReadOrder, so re-feeding after a seek is safe.

Link copied to clipboard
abstract fun addFont(name: String, data: ByteArray)

Adds one font, by file name and bytes, for the engine to shape with. Fonts a container attaches and fonts an application configures both arrive here.

Link copied to clipboard
abstract fun clearEvents()

Drops every event of the open track. The header and the fonts stay. Called on a seek.

Link copied to clipboard
abstract override fun close()
Link copied to clipboard
abstract fun openDocument(script: ByteArray)

Starts a fresh track from a whole script, header and events together. This is how an external .ass file is loaded. Any earlier track is discarded; fonts survive.

Link copied to clipboard
abstract fun openTrack(header: ByteArray)

Starts a fresh track from a container's codec header: the [Script Info] and styles sections a Matroska ASS track carries as codec private data. Events arrive through addEvent. Any earlier track is discarded; fonts survive.

Link copied to clipboard
abstract fun render(timeMillis: Long, frame: TypesetFrame): List<OverlayImage>?

Renders the open track at timeMillis for frame.