# Maintainer: Markus Fritsche <fritsche.markus@gmail.com>
#
# mpv-fourier — mpv with the fourier-umbrella patches. The first patch
# slot exists for the vo_dmabuf_wayland plane-semantics fix per
# marfrit/dmabuf-modifier-triage#1: mpv currently constructs the
# zwp_linux_buffer_params_v1 wl_protocol message with internally
# inconsistent plane semantics on V4L2 stateless decoder dmabufs (per-
# plane fds combined with single-allocation offset for plane 1), causing
# KWin to read the UV chroma plane past-EOF and render solid dark green
# on ohm (RK3566 + hantro G1 + Mali-G52). The patch is not yet written —
# this scaffold prepares the shipping path for when iter1 lands.
#
# Campaign: ~/src/dmabuf-modifier-triage/ (Phase 0 closed 2026-05-08)
# Upstream: https://github.com/mpv-player/mpv
# Build target: fermi LXC actrunner-aarch64-hertz via marfrit-packages
# Gitea Actions; alternative: boltzmann via his subagent + marfrit-publish.

pkgname=mpv-fourier
_upstreampkg=mpv
pkgver=0.41.0
pkgrel=1
pkgdesc='mpv with fourier-umbrella patches (vo_dmabuf_wayland plane-semantics fix slot)'
arch=('aarch64')
url='https://mpv.io/'
license=('GPL-2.0-or-later' 'LGPL-2.1-or-later')
depends=(
    alsa-lib
    desktop-file-utils
    ffmpeg
    glibc
    hicolor-icon-theme
    jack
    lcms2
    libarchive
    libass
    libbluray
    libcdio
    libcdio-paranoia
    libdisplay-info
    libdrm
    libdvdnav
    libdvdread
    libegl
    libgl
    libglvnd
    libjpeg-turbo
    libplacebo
    libpulse
    libsixel
    libva
    libvdpau
    libx11
    libxext
    libxkbcommon
    libxpresent
    libxrandr
    libxss
    libxv
    luajit
    mesa
    mujs
    libpipewire
    rubberband
    sdl2
    openal
    uchardet
    vapoursynth
    vulkan-icd-loader
    wayland
    zlib
)
makedepends=(
    git
    meson
    ninja
    pkgconf
    python-docutils
    wayland-protocols
)
optdepends=(
    'yt-dlp: for video-sharing websites playback'
)
provides=("${_upstreampkg}=${pkgver}" 'libmpv.so')
conflicts=("${_upstreampkg}")
replaces=("${_upstreampkg}")

source=(
    "${_upstreampkg}-${pkgver}.tar.gz::https://github.com/mpv-player/${_upstreampkg}/archive/v${pkgver}/${_upstreampkg}-${pkgver}.tar.gz"
)
sha256sums=(
    'ee21092a5ee427353392360929dc64645c54479aefdb5babc5cfbb5fad626209'
)

prepare() {
    cd "${_upstreampkg}-${pkgver}"

    # Patch slot — iter1 of dmabuf-modifier-triage will produce the actual
    # vo_dmabuf_wayland.c plane-semantics fix and add it as 0001-... here.
    # Once the libva path is also unblocked (by libva-multiplanar iter9)
    # and the WAYLAND_DEBUG verifier confirms whether the bug is purely in
    # mpv's VO or also in libva/ffmpeg producer code, the exact patch
    # shape is determined.
    #
    # When the patch lands, add it to source=() above + sha256sums=() and
    # uncomment the patch -p1 below.
    #
    # patch -p1 < "${srcdir}/0001-vo_dmabuf_wayland-plane-semantics.patch"
    :
}

build() {
    cd "${_upstreampkg}-${pkgver}"
    arch-meson build \
        --buildtype=release \
        -Dlibmpv=true \
        -Dmanpage-build=enabled \
        -Dcdda=enabled \
        -Ddvbin=enabled \
        -Ddvdnav=enabled \
        -Dlibarchive=enabled \
        -Dopenal=enabled \
        -Dsdl2-audio=enabled \
        -Dsdl2-video=enabled \
        -Dsdl2-gamepad=enabled
    meson compile -C build
}

package() {
    cd "${_upstreampkg}-${pkgver}"
    meson install -C build --destdir "${pkgdir}"

    install -Dm644 LICENSE.GPL  "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.GPL"
    install -Dm644 LICENSE.LGPL "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.LGPL"
}
