# Maintainer: Krassy Boykinov <kboykinov@teamcentrixx.com>
pkgname=gst-plugins-rs
pkgver=0.13.6
pkgrel=0
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 --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 --print-errorlogs -C output
}

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

tools() {
	amove usr/bin
}

sha512sums="
3f5981d4c1d68a25ab0fdef8593eee295041567cbb5efa3a8d13752cc46a609861b6a85a9d3d245a30397600f2a49428a64b12acaaa4684397ebdb4244d7cbf7  gst-plugins-rs-0.13.6.tar.gz
a19f8cededda5f08e0fafe0074bd04700d31566bc002c60a4807a709b7d97fe3c331437054e668d9e30c4afb97fa6bb87a74ee37ee0e77ae09ccb55dbf4efad2  0001-use-cargo-auditable.patch
004862f52560082ceedd81d530643f191c2497f9fe0f3cc878a96414836cca759e542727f9cf3b67c6edae51f605bd31cfc15675da4668ef7efd112c0cfbe147  0002-dylib.patch
"
