Video on Linux went through a Flutter texture: 8-bit sRGB, which cannot carry HDR at all, and which forced a whole-window Flutter recomposite for every video frame. This moves it onto a wl_subsurface stacked below the Flutter surface, with mpv rendering into an EGL window surface on it through the libmpv render API. The subsurface is desynchronized, so video and UI now present independently. With the plane in place HDR follows: the surface is described to the compositor through wp_color_manager_v1 as the source's own curve and gamut - PQ or HLG, BT.2020 - carrying whatever HDR10 static metadata the stream actually declares. The description and the buffer it describes land on the same commit, staged and validated before mpv is switched, so a PQ frame is never presented labelled sRGB. A five-second watchdog bounds the one wait a compositor could otherwise leave hanging. A session that cannot host the plane - X11, or a compositor without wl_subcompositor - fails initialize with VIDEO_PLANE_UNSUPPORTED naming the reason: the texture path is gone, and refusing by name beats degrading to something the user cannot see. An SDR output, a missing capability or an 8-bit config keep the plane and simply leave it undescribed. The output's colour state is trusted only when it has been earned. Every landed property step records itself as it lands; a reset or sequence that cannot finish downgrades its result to unknown and marks the applied-output cache untrusted until a clean apply earns it back. A plane whose output state cannot be named is quarantined - hidden, its description withdrawn - and the quarantine is recorded state: an unrelated visibility change cannot put a mislabelled plane back on screen, and only a commit that resolves to a nameable outcome lifts it. A rect collapsing to zero detaches the buffer exactly as hiding does, a refused setVideoRect drops the Dart-side sent-rect cache so the next layout pass retries for free, and a refused tone-mapping pick tells the user instead of dying in a log. NVIDIA's Wayland EGL (through at least 610.xx) offers no 10-bit unorm window configs, so the plane takes half-float as the tier between 10-bit unorm and 8-bit, declares the whole surface opaque so the compositor never reads the alpha those configs carry, and states GL_RGBA16F rather than a 10-bit lie. Whether the output is in HDR is read from luminance headroom above its own reference white rather than from the preferred transfer function, which current KWin no longer answers PQ for; the margin is half a stop, because KWin reports an undimmed maximum over a software-dimmed SDR white. Validated on an RTX 4090 (driver 610.57.04) under KWin 6.7.4 with locked-exposure photographs. Who tone-maps is a user choice. The default is the compositor: photographed on a 400-nit HDR output against a PQ chart it keeps 400 -> 1000 nits monotonic and separated where the player leg flattens them, because the player path drives mpv's legacy vo_gpu, whose own standalone output scores the same. The gap is the renderer, not the wiring. The decision itself - what the source carries, what the output supports, what to tell mpv and what to tell the compositor - lives in hdr_metadata.h, free of Wayland and GTK so its luminance validation can be tested without a display server. Sending an incoherent luminance set is a protocol error that disconnects the client, so the rules are worth a unit test. The deb, rpm and pacman packages now declare wayland-client, wayland-egl and EGL: the plane links them directly and bundle-libs.sh deliberately never bundles them, since they are coupled to the running compositor and GPU driver. lib/dev/harness_main.dart is a second entrypoint for measuring this on hardware - it drives one clip with scripted mpv properties and reports the colour state mpv actually settled on. Nothing imports it, so it is tree-shaken out of the app. Verified on a Steam Deck against an external 400-nit HDR display: the compositor reports PQ / BT.2020, the connector carries HDR_OUTPUT_METADATA, and against mpv vo=gpu-next on the same frame the shipped build sits 4.90 counts away overall - closer to the reference HDR player than to its own SDR fallback.
265 lines
7.4 KiB
Bash
Executable File
265 lines
7.4 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)"
|
|
NATIVE_INPUTS_MANIFEST="${NATIVE_INPUTS_MANIFEST:-$SCRIPT_DIR/native-inputs.json}"
|
|
|
|
manifest_value() {
|
|
python3 - "$NATIVE_INPUTS_MANIFEST" "$1" "$2" <<'PY'
|
|
import json
|
|
import sys
|
|
|
|
with open(sys.argv[1], encoding="utf-8") as source:
|
|
manifest = json.load(source)
|
|
value = manifest["inputs"][sys.argv[2]][sys.argv[3]]
|
|
if not isinstance(value, str) or not value:
|
|
raise SystemExit(f"invalid manifest value: {sys.argv[2]}.{sys.argv[3]}")
|
|
print(value)
|
|
PY
|
|
}
|
|
|
|
FFMPEG_VERSION="$(manifest_value ffmpeg version)"
|
|
FFMPEG_URL="$(manifest_value ffmpeg url)"
|
|
FFMPEG_SHA256="$(manifest_value ffmpeg sha256)"
|
|
SHADERC_VERSION="$(manifest_value shaderc version)"
|
|
SHADERC_URL="$(manifest_value shaderc url)"
|
|
SHADERC_REF="$(manifest_value shaderc ref)"
|
|
SHADERC_COMMIT="$(manifest_value shaderc commit)"
|
|
LIBPLACEBO_VERSION="$(manifest_value libplacebo version)"
|
|
LIBPLACEBO_URL="$(manifest_value libplacebo url)"
|
|
LIBPLACEBO_REF="$(manifest_value libplacebo ref)"
|
|
LIBPLACEBO_COMMIT="$(manifest_value libplacebo commit)"
|
|
MPV_VERSION="$(manifest_value mpv version)"
|
|
MPV_URL="$(manifest_value mpv url)"
|
|
MPV_SHA256="$(manifest_value mpv sha256)"
|
|
|
|
sha256_file() {
|
|
if command -v sha256sum >/dev/null 2>&1; then
|
|
sha256sum "$1" | cut -d ' ' -f 1
|
|
else
|
|
shasum -a 256 "$1" | cut -d ' ' -f 1
|
|
fi
|
|
}
|
|
|
|
download_verified() {
|
|
local url="$1"
|
|
local expected_sha256="$2"
|
|
local destination="$3"
|
|
local temporary
|
|
local actual_sha256
|
|
|
|
if [[ ! "$expected_sha256" =~ ^[0-9a-f]{64}$ ]]; then
|
|
echo "Invalid SHA-256 pin for $url" >&2
|
|
return 1
|
|
fi
|
|
|
|
mkdir -p "$(dirname "$destination")"
|
|
temporary="$(mktemp "${destination}.tmp.XXXXXX")"
|
|
if ! curl \
|
|
--fail \
|
|
--location \
|
|
--silent \
|
|
--show-error \
|
|
--proto '=https,file' \
|
|
--tlsv1.2 \
|
|
--output "$temporary" \
|
|
"$url"; then
|
|
rm -f "$temporary"
|
|
return 1
|
|
fi
|
|
|
|
actual_sha256="$(sha256_file "$temporary")"
|
|
if [ "$actual_sha256" != "$expected_sha256" ]; then
|
|
echo "SHA-256 mismatch for $url" >&2
|
|
echo "Expected: $expected_sha256" >&2
|
|
echo "Actual: $actual_sha256" >&2
|
|
rm -f "$temporary" "$destination"
|
|
return 1
|
|
fi
|
|
|
|
mv "$temporary" "$destination"
|
|
}
|
|
|
|
checkout_verified_ref() {
|
|
local url="$1"
|
|
local ref="$2"
|
|
local expected_commit="$3"
|
|
local destination="$4"
|
|
local actual_commit
|
|
|
|
if [[ ! "$expected_commit" =~ ^[0-9a-f]{40}$ ]]; then
|
|
echo "Invalid Git commit pin for $url at $ref" >&2
|
|
return 1
|
|
fi
|
|
|
|
rm -rf "$destination"
|
|
if ! git clone --quiet --depth 1 --branch "$ref" --no-checkout \
|
|
"$url" "$destination"; then
|
|
rm -rf "$destination"
|
|
return 1
|
|
fi
|
|
|
|
actual_commit="$(git -C "$destination" rev-parse 'HEAD^{commit}')"
|
|
if [ "$actual_commit" != "$expected_commit" ]; then
|
|
echo "Git ref mismatch for $url at $ref" >&2
|
|
echo "Expected: $expected_commit" >&2
|
|
echo "Actual: $actual_commit" >&2
|
|
rm -rf "$destination"
|
|
return 1
|
|
fi
|
|
|
|
git -C "$destination" checkout --quiet --detach "$expected_commit"
|
|
}
|
|
|
|
cleanup_srcdir=""
|
|
|
|
cleanup() {
|
|
if [ -n "$cleanup_srcdir" ]; then
|
|
rm -rf -- "$cleanup_srcdir"
|
|
fi
|
|
}
|
|
|
|
main() {
|
|
local prefix="${PREFIX:-$(pwd)/libmpv-prefix}"
|
|
local jobs="${JOBS:-$(nproc)}"
|
|
local srcdir
|
|
|
|
mkdir -p "$prefix"
|
|
prefix="$(realpath "$prefix")"
|
|
export PKG_CONFIG_PATH="$prefix/lib/pkgconfig:$prefix/lib/$(uname -m)-linux-gnu/pkgconfig:${PKG_CONFIG_PATH:-}"
|
|
|
|
srcdir="$(mktemp -d)"
|
|
cleanup_srcdir="$srcdir"
|
|
trap cleanup EXIT
|
|
cd "$srcdir"
|
|
|
|
echo "==> Sources in $srcdir"
|
|
echo "==> Install prefix: $prefix"
|
|
echo ""
|
|
|
|
# ─── Step 1: ffmpeg (static libraries) ─────────────────────────────────────
|
|
echo "==> Building ffmpeg $FFMPEG_VERSION (static, decoder-only)..."
|
|
download_verified "$FFMPEG_URL" "$FFMPEG_SHA256" "$srcdir/ffmpeg.tar.xz"
|
|
tar -xJf "$srcdir/ffmpeg.tar.xz"
|
|
cd "ffmpeg-${FFMPEG_VERSION}"
|
|
|
|
./configure \
|
|
--prefix="$prefix" \
|
|
--enable-gpl \
|
|
--enable-version3 \
|
|
--enable-static \
|
|
--disable-shared \
|
|
--enable-pic \
|
|
--disable-programs \
|
|
--disable-doc \
|
|
--disable-encoders \
|
|
--disable-muxers \
|
|
--enable-muxer=spdif \
|
|
--disable-devices \
|
|
--disable-bsfs \
|
|
--enable-bsf=aac_adtstoasc,av1_metadata,extract_extradata,h264_metadata,h264_mp4toannexb,hevc_metadata,hevc_mp4toannexb,vp9_metadata \
|
|
--disable-filters \
|
|
--enable-filter=aformat,aresample,format,null,scale \
|
|
--enable-gnutls \
|
|
--enable-vaapi \
|
|
--disable-vdpau \
|
|
--disable-debug \
|
|
--disable-stripping
|
|
|
|
make -j"$jobs"
|
|
make install
|
|
cd "$srcdir"
|
|
echo ""
|
|
echo "==> ffmpeg done."
|
|
echo ""
|
|
|
|
# ─── Step 2: shaderc (static library) ───────────────────────────────────────
|
|
echo "==> Building shaderc $SHADERC_VERSION (static)..."
|
|
checkout_verified_ref \
|
|
"$SHADERC_URL" "$SHADERC_REF" "$SHADERC_COMMIT" \
|
|
"$srcdir/shaderc-v${SHADERC_VERSION}"
|
|
cd "shaderc-v${SHADERC_VERSION}"
|
|
./utils/git-sync-deps
|
|
|
|
cmake -S . -B build \
|
|
-DCMAKE_BUILD_TYPE=Release \
|
|
-DCMAKE_INSTALL_PREFIX="$prefix" \
|
|
-DSHADERC_SKIP_TESTS=ON \
|
|
-DSHADERC_SKIP_EXAMPLES=ON \
|
|
-DSHADERC_SKIP_COPYRIGHT_CHECK=ON \
|
|
-DBUILD_SHARED_LIBS=OFF \
|
|
-DCMAKE_POSITION_INDEPENDENT_CODE=ON
|
|
|
|
cmake --build build -j"$jobs"
|
|
cmake --install build
|
|
cd "$srcdir"
|
|
echo ""
|
|
echo "==> shaderc done."
|
|
echo ""
|
|
|
|
# ─── Step 3: libplacebo (static library) ───────────────────────────────────
|
|
echo "==> Building libplacebo $LIBPLACEBO_VERSION (static)..."
|
|
checkout_verified_ref \
|
|
"$LIBPLACEBO_URL" "$LIBPLACEBO_REF" "$LIBPLACEBO_COMMIT" \
|
|
"$srcdir/libplacebo-v${LIBPLACEBO_VERSION}"
|
|
cd "libplacebo-v${LIBPLACEBO_VERSION}"
|
|
git submodule update --init --recursive
|
|
|
|
meson setup build \
|
|
--prefix="$prefix" \
|
|
--default-library=static \
|
|
-Dvulkan=disabled \
|
|
-Dd3d11=disabled \
|
|
-Ddemos=false \
|
|
-Dtests=false
|
|
|
|
ninja -C build -j"$jobs"
|
|
ninja -C build install
|
|
cd "$srcdir"
|
|
echo ""
|
|
echo "==> libplacebo done."
|
|
echo ""
|
|
|
|
# ─── Step 4: mpv (shared libmpv) ───────────────────────────────────────────
|
|
echo "==> Building mpv $MPV_VERSION (shared libmpv only)..."
|
|
download_verified "$MPV_URL" "$MPV_SHA256" "$srcdir/mpv.tar.gz"
|
|
tar -xzf "$srcdir/mpv.tar.gz"
|
|
cd "mpv-${MPV_VERSION}"
|
|
|
|
# The runner's only video path is a Wayland subsurface, and it hands mpv
|
|
# MPV_RENDER_PARAM_WL_DISPLAY so VAAPI can find the device instead of falling
|
|
# back to software decoding. A libmpv built without Wayland cannot use that.
|
|
# VDPAU goes with X11 - it has no Wayland backend at all.
|
|
meson setup build \
|
|
--prefix="$prefix" \
|
|
-Dlibmpv=true \
|
|
-Dcplayer=false \
|
|
-Dbuild-date=false \
|
|
-Dlua=enabled \
|
|
-Djavascript=enabled \
|
|
-Dcplugins=disabled \
|
|
-Dmanpage-build=disabled \
|
|
-Djack=disabled \
|
|
-Dvulkan=disabled \
|
|
-Dd3d11=disabled \
|
|
-Dgl=enabled \
|
|
-Dvaapi=enabled \
|
|
-Dalsa=enabled \
|
|
-Dpulse=enabled \
|
|
-Dpipewire=enabled \
|
|
-Dvdpau=disabled \
|
|
-Dwayland=enabled \
|
|
-Dx11=disabled
|
|
|
|
ninja -C build -j"$jobs"
|
|
ninja -C build install
|
|
echo ""
|
|
echo "==> mpv done."
|
|
echo ""
|
|
echo "==> libmpv build complete. Output in $prefix"
|
|
}
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
main "$@"
|
|
fi
|