# ARM build from the upstream release source bundle. The vendor CEF bundle
# is x86-only, so this build omits browser sources/docks. AJA is unavailable
# in Arch Linux ARM. Other plugins use upstream architecture detection.

pkgname=obs-studio
pkgver=32.2.2
pkgrel=1
pkgdesc="Free and open source software for video recording and live streaming (without the x86-only CEF browser source)"
arch=('aarch64')
url="https://obsproject.com"
license=('GPL-2.0-or-later')
depends=(
  'alsa-lib'
  'curl'
  'ffmpeg>=8'
  'fontconfig'
  'freetype2'
  'gcc-libs'
  'glib2'
  'glibc'
  'jack'
  'jansson'
  'libdatachannel>=0.24.3' # WebRTC/WHIP output
  'libfdk-aac'
  'libgl'
  'libjuice'
  'libpipewire'
  'libpulse'
  'librist' # MPEGTS output
  'libva'
  'libx11'
  'libxcb'
  'libxcomposite'
  'libxkbcommon'
  'luajit' # Lua scripting
  'mbedtls3>=3.6.1'
  'pciutils'
  'python>=3.14' # Python scripting
  'qrcodegencpp-cmake' # obs-websocket connect QR code
  'qt6-base>=6.8'
  'qt6-svg'
  'qt6-wayland'
  'rnnoise'
  'sndio'
  'speexdsp'
  'srt' # MPEGTS output
  'systemd-libs'
  'util-linux-libs'
  'v4l-utils'
  'wayland'
  'x264'
  'zlib'
)
makedepends=(
  'asio' # header-only, obs-websocket
  'cmake'
  'extra-cmake-modules'
  'nlohmann-json' # header-only, obs-websocket and plugin manager
  'simde' # header-only, SIMD portability layer libobs uses on ARM
  'swig' # scripting bindings
  'uthash' # header-only, libobs
  'vlc' # VLC source plugin builds against libvlc headers, dlopens at runtime
  'websocketpp' # header-only, obs-websocket
)
optdepends=(
  'vlc: VLC media source'
  'v4l2loopback-dkms: V4L2 virtual camera output'
)
source=("https://github.com/obsproject/obs-studio/releases/download/$pkgver/OBS-Studio-$pkgver-Sources.tar.gz")
sha512sums=('6346b5bff255c9178ef57296489af11bc6949076b4084d3dff8d3da923c8b0d2ab64edb312629c54b8d4be1510bb4166b92838a8c6c2db55a7ee9e08108166de')

build() {
  local cmake_options=(
    -S "obs-studio-$pkgver-sources"
    -B build
    -DCMAKE_BUILD_TYPE=Release
    -DCMAKE_INSTALL_PREFIX=/usr
    -DCMAKE_INSTALL_LIBDIR=lib
    -DENABLE_BROWSER=OFF # no linux-aarch64 CEF exists
    -DENABLE_AJA=OFF # libajantv2 is not in ALARM
    -DENABLE_LIBFDK=ON
    -DENABLE_JACK=ON
    -DENABLE_SNDIO=ON
    -DENABLE_VLC=ON
    -DENABLE_WAYLAND=ON

    # The tarball has no .git for the version machinery to read.
    -DOBS_VERSION_OVERRIDE="$pkgver"
    -DOBS_COMPILE_DEPRECATION_AS_WARNING=ON

    # Use Arch's side-by-side MbedTLS 3 CMake configuration.
    -DMbedTLS_DIR=/usr/lib/mbedtls3/cmake/MbedTLS

    -Wno-dev
  )
  cmake "${cmake_options[@]}"
  cmake --build build
}

package() {
  DESTDIR="$pkgdir" cmake --install build
}
