# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=gst-plugins-rs
pkgver=0.13.3
pkgrel=1
pkgdesc="Gstreamer rust plugins"
url="https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs"
arch="all"
license="MIT AND Apache-2.0 AND MPL-2.0 AND LGPL-2.1-or-later"
makedepends="
	cargo-auditable
	cargo-c
	dav1d-dev
	gst-plugins-bad-dev
	gst-plugins-base-dev
	gtk4.0-dev
	libsodium-dev
	meson
	nasm
	openssl-dev
	"
subpackages="$pkgname-dev"
_plugins="cdg
	claxon
	dav1d
	fallbackswitch
	ffv1
	fmp4
	gif
	gopbuffer
	gtk4
	hlssink3
	hsv
	json
	lewton
	livesync
	mp4
	mpegtslive
	ndi
	originalbuffer
	quinn
	raptorq
	rav1e
	regex
	reqwest
	rsaudiofx
	rsclosedcaption
	rsfile
	rsflv
	rsinter
	rsonvif
	rspng
	rsrtp
	rsrtsp
	rstracers
	rsvideofx
	rswebp
	sodium
	spotify
	textahead
	textwrap
	threadshare
	togglerecord
	uriplaylistbin
	webrtchttp
	"
source="https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/archive/$pkgver/gst-plugins-rs-$pkgver.tar.gz
	0001-use-cargo-auditable.patch
	0002-dylib.patch
	"
options="net !check" # they don't run

export SODIUM_USE_PKG_CONFIG=1

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

case "$CARCH" in
	# Some plugins run out of memory compiling, disable them
	armhf|armv7|x86)
		_opts="-Daws=disabled -Dwebrtc=disabled"
		;;
	*)
		_plugins="$_plugins aws rswebrtc"
		# tools is currently only used when webrtc is enabled
		subpackages="$subpackages $pkgname-tools"
		;;
esac

_sub_plugin() {
	local n=${subpkgname##"$pkgname"-}
	pkgdesc="Gstreamer rust plugin for $n"
	amove usr/lib/gstreamer-1.0/libgst"$n".so
}

for _plugin in $_plugins; do
	subpackages="$subpackages $pkgname-$_plugin:_sub_plugin"
done

build() {
	export CARGO_PROFILE_RELEASE_OPT_LEVEL=3
	abuild-meson \
		--buildtype=release \
		$_opts \
		. output
	meson compile -C output
}

check() {
	meson test --no-rebuild --print-errorlogs -C output
}

package() {
	DESTDIR="$pkgdir" meson install --no-rebuild -C output
}

tools() {
	amove usr/bin
}

sha512sums="
02c0bbacc1ebd0d6f4de00ffb18578068da3776ddf5c39d096bb0b9bb392c376d08e22d3028a04029132cd5bc74e3ac9b567a87f9937b64ca3529196bf7a3764  gst-plugins-rs-0.13.3.tar.gz
5831b9e1f1f5a6c29d302256e76802053dd93bf316be818c4a4b33c8a2ea70827e5905627a41ed9cd0d582dc90f22c834ebae776f4cb481911014fbbe429917d  0001-use-cargo-auditable.patch
004862f52560082ceedd81d530643f191c2497f9fe0f3cc878a96414836cca759e542727f9cf3b67c6edae51f605bd31cfc15675da4668ef7efd112c0cfbe147  0002-dylib.patch
"
