Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .agents/skills/profile-tv/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ consumed CPU.

## Styled-subtitle (libass) cost

With an ASS/SSA track rendering, the event log carries `assperf:` lines (`window_ms` the span the counts cover, render and whole-job p95/max, bytes
published and uploaded in that window, Normal+Ahead `jobs`, `ahead_hit`, `nwait`, and `worker tid=`) and `FRAMEDROP spans=` gains `assup` (the
With an ASS/SSA track rendering, the event log carries `assperf:` lines, one per worker `w` (the primary and up to two helpers a moving cue starts; `window_ms` the span the counts cover, render and whole-job p95/max, bytes
published and uploaded in that window, Normal+Ahead `jobs`, `ahead_hit`, `shown` (pipeline frames promoted: updates a second), `late`, `stale`, `nwait`, the libass/composite split `lib_p95_us` / `comp_p95_us` (wall) and `lib_cpu_p95_us` / `comp_cpu_p95_us` (the worker thread's CPU time in the same phases: wall far above CPU means it waited for the CPU, not that it computed) with the `images_p95` / `img_kpx_p95` it drew, `scale` (the smallest size a job of the window was drawn at, `1.00` / `0.67` / `0.50`: a heavy moving stretch is drawn smaller, read the figures at their own scale, and each move is one `ass: render scale A -> B` line), and `worker w= tid= nice=`) and `FRAMEDROP spans=` gains `assup` (the
UI-thread GL upload; needs `/tmp/plxnative-framedrop` armed). Read these before attributing a late frame to subtitles; follow the worker
with `tools/tv-sched-trace.sh --tid <tid>`. See `docs/ass-subtitles.md`.

Expand Down
7 changes: 5 additions & 2 deletions ci/build-libass.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,10 @@ def verify_library(path, darwin, readelf=None):
else:
dynamic = subprocess.check_output([readelf, '-d', str(path)], text=True)
needed = re.findall(r'\(NEEDED\).*\[([^\]]+)\]', dynamic)
allowed = {'libc.so.6', 'libm.so.6', 'libgcc_s.so.1', 'libpthread.so.0', 'ld-linux.so.3'}
# librt: src/ass.c times its render phases with clock_gettime, which the build sysroot's glibc
# (2.12, the one this library links against, not the TV's) keeps there. Newer firmware (7.4 and
# later) provides the same clock_gettime@GLIBC_2.4 from libc.so.6.
allowed = {'libc.so.6', 'libm.so.6', 'libgcc_s.so.1', 'libpthread.so.0', 'librt.so.1', 'ld-linux.so.3'}
symbols = subprocess.check_output([readelf, '--dyn-syms', '--wide', str(path)], text=True)
names = []
for line in symbols.splitlines():
Expand Down Expand Up @@ -327,7 +330,7 @@ def autotools_build(name, options):
exports = work / 'exports.map'
exports.write_text('{ global: plx_ass_*; local: *; };\n')
command += ['-shared', '-Wl,-soname,' + name, '-Wl,--no-undefined',
'-Wl,--exclude-libs,ALL', '-Wl,--version-script=' + str(exports)]
'-Wl,--exclude-libs,ALL', '-Wl,--version-script=' + str(exports), '-lrt']
if not host:
# A stable identity for the shipped (stripped) library, so the `.debug` that
# `make symbols-libs` extracts from the unstripped $prefix/lib copy can be paired with it.
Expand Down
18 changes: 15 additions & 3 deletions ci/list-caps.ini
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ reason = Bytes of a redirect body drained; an HTTP transport bound.
class = format
reason = Prefix check of a Content-Range header.

[media-codecs/src/subtitle_extract.rs::collect_manifest]
[media-codecs/src/subtitle_extract.rs::detach_fonts]
class = format
reason = Four-byte font magic check on an attached font.

Expand Down Expand Up @@ -582,9 +582,21 @@ reason = Head/tail byte fingerprint of a side-loaded subtitle.
class = format
reason = MAX_EVENT_BYTES: container, codec or ABR estimator bound of the playback pipeline; not a list the user browses.

[media/src/player/ass.rs::MAX_FONT_BYTES]
[media/src/player/ass/font_names.rs::fold]
class = not-a-list
reason = Clips one font or style NAME to 1024 bytes before it is compared; a name is text, no face or font is left out by it (a longer name only matches more, never less).

[media/src/player/ass/font_names.rs::cff_name]
class = not-a-list
reason = Clips the CFF font NAME read from a face to 1024 bytes before it is compared; text length, no face is left out by it.

[media/src/player/ass/scale.rs::FLIP_WINDOW_MS]
class = not-a-list
reason = How long after a render-scale step up a step down counts as taking it back (a time window of the hysteresis, in playhead milliseconds); no subtitle, cue or frame is left out by it.

[media/src/player/ass.rs::MAX_ASS_RENDERERS]
class = work
reason = Memory budget for embedded fonts (FontBudget); a font past it is skipped and its text falls back to the default face, never a refused track.
reason = Styled-subtitle renderers (a worker and a libass instance each) that may run at once while a moving cue's pipeline wants more frames than one makes; bounds concurrency and memory, and every frame is still rendered, only fewer at a time.

[media/src/player/ass.rs::MAX_PIXELS]
class = format
Expand Down
4 changes: 2 additions & 2 deletions ci/module-layers.ini
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
# draws through (neither may name the other), the hold-band cut (`hold`: the rows a paged store
# keeps, which the store and `ui::cards::HoldBand` both apply), the details-line parts
# (`detail_parts`: the set a profile keeps and the caption policy words), and the test-only lock/net
# helpers every layer's tests use.
# helpers every layer's tests use (`testheap`: the C heap's live bytes, for the tests that count copies).
uses =
members =
eventlog paths process clock task cbuf sha256 sha1 b64 spki dynlib checkpoint storage_worker fontcov surface tile hold detail_parts window
diag::zlib diag::spans diag::heartbeat
devtrig
testlock testnet testscratch testrace
testlock testnet testscratch testrace testheap

[machine]
# EXTRACTED: this layer is the workspace crate `plx_machine` (rust-modules/machine/), the second
Expand Down
93 changes: 87 additions & 6 deletions ci/test_ass_composite.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env python3
"""Exhaustive native arithmetic check against the scalar compositing reference."""
"""Exhaustive native arithmetic check against the scalar compositing reference.

The scalar blend (`ass_blend_pixel`) is checked against the formula on every (coverage, source,
destination) triple. Where the host has NEON (`__ARM_NEON`: the 32-bit ARM TVs and arm64 Macs) the
eight-pixel kernel the row loop uses (`ass_blend8`) is checked the same way, lane by lane with a
different pixel in every lane, so a wrong rounding or a lane that leaks into its neighbour fails; a
host without NEON prints that the vector kernel was not exercised.
"""
from pathlib import Path
import os
import shlex
Expand Down Expand Up @@ -31,14 +38,88 @@
}
}
}
if (a) {
unsigned expected = (s*255 + a/2)/a;
if (expected > 255) expected = 255;
if (ass_straight_channel(s, a, 65536/a) != expected) return 2;
}
}
puts("PASS: 16777216 blend combinations match scalar RGBA");
#ifdef PLX_ASS_NEON
/* The rounding primitive: every numerator a blend can form (at most 255*255) divides as the
* scalar's (n + 127) / 255, eight lanes at a time. */
for (unsigned base = 0; base <= 65025; base += 8) {
uint16_t in[8];
uint8_t out[8];
for (unsigned k = 0; k < 8; ++k) in[k] = base + k <= 65025 ? base + k : 0;
vst1_u8(out, ass_div255_lanes(vld1q_u16(in)));
for (unsigned k = 0; k < 8; ++k)
if (out[k] != (in[k] + 127) / 255) {
fprintf(stderr, "div255 n=%u: %u != %u\n", in[k], out[k], (in[k] + 127) / 255);
return 1;
}
}
/* The kernel at opacity 255, where the coverage is the mask byte itself: every (a, s, d) triple
* reaches every lane, and each lane holds a different one from its neighbours (a and d step by
* lane-dependent amounts, both bijections over a0 and d0), channel by channel as above. */
for (unsigned s = 0; s < 256; ++s) {
const unsigned src[4] = {s, 255 - s, s ^ 85, 255};
const AssSource8 source = ass_source8(src[0] | (src[1] << 8) | (src[2] << 16) |
((uint32_t)src[3] << 24));
for (unsigned a0 = 0; a0 < 256; ++a0) {
for (unsigned d0 = 0; d0 < 256; ++d0) {
uint8_t mask[8], dst[32], expected[32];
for (unsigned k = 0; k < 8; ++k) {
const unsigned a = (a0 + 37 * k) & 255, d = (d0 + 91 * k) & 255;
const unsigned dc[4] = {d, d ^ 170, 255 - d, d};
mask[k] = (uint8_t)a;
for (unsigned c = 0; c < 4; ++c) {
dst[4 * k + c] = (uint8_t)dc[c];
expected[4 * k + c] = (uint8_t)((src[c] * a + dc[c] * (255 - a) + 127) / 255);
}
}
ass_blend8(dst, vld1_u8(mask), vdup_n_u8(255), source);
for (unsigned i = 0; i < 32; ++i)
if (dst[i] != expected[i]) {
fprintf(stderr, "ass_blend8 s=%u a0=%u d0=%u lane %u channel %u: %u != %u\n",
s, a0, d0, i / 4, i % 4, dst[i], expected[i]);
return 1;
}
}
}
}
/* The coverage the kernel computes, (mask * opacity + 127) / 255, is the scalar code's table for
* every opacity and mask byte: here the opacity varies, with a source and destination that
* change with them. */
for (unsigned opacity = 0; opacity < 256; ++opacity) {
for (unsigned m0 = 0; m0 < 256; m0 += 8) {
for (unsigned variant = 0; variant < 16; ++variant) {
const unsigned s = (opacity * 7 + m0 * 3 + variant * 29) & 255;
const unsigned src[4] = {s, 255 - s, s ^ 85, 255};
const AssSource8 source = ass_source8(src[0] | (src[1] << 8) | (src[2] << 16) |
((uint32_t)src[3] << 24));
uint8_t mask[8], dst[32], expected[32];
for (unsigned k = 0; k < 8; ++k) {
const unsigned m = m0 + k, a = (m * opacity + 127) / 255;
const unsigned d = (m * 5 + opacity * 11 + variant * 53 + k) & 255;
const unsigned dc[4] = {d, d ^ 170, 255 - d, 255 - (d ^ 85)};
mask[k] = (uint8_t)m;
for (unsigned c = 0; c < 4; ++c) {
dst[4 * k + c] = (uint8_t)dc[c];
expected[4 * k + c] = (uint8_t)((src[c] * a + dc[c] * (255 - a) + 127) / 255);
}
}
ass_blend8(dst, vld1_u8(mask), vdup_n_u8((uint8_t)opacity), source);
if (memcmp(dst, expected, sizeof dst) != 0) {
fprintf(stderr, "ass_blend8 opacity=%u mask %u..%u variant %u differs from the "
"scalar coverage table\n", opacity, m0, m0 + 7, variant);
return 1;
}
}
}
}
puts("PASS: 16777216 blend combinations and 65280 alpha conversions match scalar RGBA");
puts("PASS: NEON ass_blend8 matches scalar RGBA on 16777216 (coverage, source, destination) "
"triples per lane and on every (mask, opacity) pair");
#else
puts("NOTE: this host has no NEON: the vector kernel (ass_blend8) was NOT exercised, "
"only the scalar blend");
#endif
return 0;
}
'''
Expand Down
Loading
Loading