COMMENT-main=		low-level multimedia framework - client & server
COMMENT-libs=		low-level multimedia framework - libraries
COMMENT-gst=		GStreamer elements for PipeWire

PW_PROJECT=		pipewire
PW_VERSION=		1.6.11
PKGNAME-libs=		lib${PW_PROJECT}-${PW_VERSION}
PKGNAME-gst=		gst-plugin-pipewire-${PW_VERSION}

REVISION-main=		14
REVISION-libs=		1
REVISION-gst=		0

SHARED_LIBS += pipewire-0.3              1.0 # 0.1610.0

MULTI_PACKAGES=		-main -libs -gst

WANTLIB-main += ${COMPILER_LIBCXX} X11 Xfixes c camera camera-base
WANTLIB-main += canberra curses dbus-1 ebur128 epoll-shim fftw3f gio-2.0
WANTLIB-main += glib-2.0 gobject-2.0 m opus pipewire-0.3 readline sndfile
WANTLIB-main += sndio

WANTLIB-libs += intl pthread

WANTLIB-gst += glib-2.0 gobject-2.0 gstallocators-1.0 gstaudio-1.0
WANTLIB-gst += gstbase-1.0 gstreamer-1.0 gstvideo-1.0 m pipewire-0.3

# needs -std=c++17 (during configure)
COMPILER=		base-clang ports-gcc
COMPILER_LANGS=		c c++

MODULES=		devel/dconf \
			devel/meson \
			lang/python

MODPY_RUNDEP=		No

BUILD_DEPENDS=		devel/doxygen \
			devel/gettext,-tools \
			devel/libstdthreads \
			textproc/py-docutils

LIB_DEPENDS-main=	${BASE_PKGPATH},-libs \
			audio/libcanberra \
			audio/libebur128 \
			audio/libsndfile \
			devel/epoll-shim \
			math/fftw3,-main,float \
			multimedia/libcamera \
			x11/dbus

LIB_DEPENDS-libs=	devel/gettext,-runtime

LIB_DEPENDS-gst=	${BASE_PKGPATH},-libs \
			multimedia/gstreamer1/plugins-base

RUN_DEPENDS-gst=	# empty

# needs a pipewire-session-manager
RUN_DEPENDS-main +=	${MODDCONF_RUN_DEPENDS} \
			multimedia/pipewire/wireplumber

RUN_DEPENDS-libs=	# empty

# libintl
CONFIGURE_ENV +=	CPPFLAGS="-I${LOCALBASE}/include -I${LOCALBASE}/include/libepoll-shim" \
			LDFLAGS="-L${LOCALBASE}/lib"

CONFIGURE_ARGS=		-Dman=enabled \
			-Dsession-managers=[] \
			-Dlibsystemd=disabled \
			-Dsystemd-user-service=disabled \
			-Dlogind=disabled \
			-Dudev=disabled \
			-Dlegacy-rtkit=false \
			-Dalsa=disabled \
			-Dflatpak=disabled \
			-Dselinux=disabled \
			-Dsnap=disabled

# until supported and/or proven useful
CONFIGURE_ARGS +=	-Dpipewire-alsa=disabled \
			-Dbluez5=disabled \
			-Droc=disabled \
			-Decho-cancel-webrtc=disabled \
			-Dlv2=disabled \
			-Davb=disabled \
			-Dlibffado=disabled \
			-Dlibmysofa=disabled \
			-Donnxruntime=disabled

# XXX to be revisited; AirPlay output and machine-to-machine streaming
CONFIGURE_ARGS +=	-Dlibpulse=disabled
CONFIGURE_ARGS +=	-Draop=disabled
CONFIGURE_ARGS +=	-Davahi=disabled

# PAM limits.d file
CONFIGURE_ARGS +=	-Drlimits-install=false

# only useful for examples which we don't install
CONFIGURE_ARGS +=	-Dsdl2=disabled

# only useful for bluez5 which we disable above
CONFIGURE_ARGS +=	-Dlibusb=disabled

# needs udev
CONFIGURE_ARGS +=	-Dv4l2=disabled

# XXX needs O_TMPFILE
CONFIGURE_ARGS +=	-Dpipewire-v4l2=disabled

# plugin that talks to an external JACK server (not useful)
CONFIGURE_ARGS +=	-Djack=disabled

# XXX to be revisited; useful to replace audio/jack
# replaces libjack, so that PipeWire acts as the JACK server
CONFIGURE_ARGS +=	-Dpipewire-jack=disabled

# sndio SPA plugin; XXX to be sent upstream
CONFIGURE_ARGS +=	-Dsndio=enabled
post-extract:
	mkdir -p ${WRKSRC}/spa/plugins/sndio
	cp ${FILESDIR}/sndio/*.{c,h} ${FILESDIR}/sndio/meson.build \
		${WRKSRC}/spa/plugins/sndio

post-install:
# load the sndio spa plugin and create the sndio device
	${INSTALL_DATA_DIR} ${PREFIX}/share/pipewire/pipewire.conf.d
	${INSTALL_DATA} ${FILESDIR}/10-sndio.conf \
		${PREFIX}/share/pipewire/pipewire.conf.d/

# start the PulseAudio server (pipewire-pulse) from pipewire;
# upstream relies on systemd user socket activation for this
	${SUBST_CMD} -m 0644 -c ${FILESDIR}/20-pulse.conf.in \
		${PREFIX}/share/pipewire/pipewire.conf.d/20-pulse.conf

# systemd socket activation is not supported on OpenBSD
	${INSTALL_DATA_DIR} ${PREFIX}/share/examples/pipewire/xdg/autostart
	${INSTALL_DATA} ${FILESDIR}/pipewire.desktop \
		${PREFIX}/share/examples/pipewire/xdg/autostart

# RTKit and rtprio(2)-style scheduling are not available on OpenBSD
.for _confd in client jack pipewire-pulse pipewire
	${INSTALL_DATA_DIR} ${PREFIX}/share/pipewire/${_confd}.conf.d/
	${INSTALL_DATA} ${FILESDIR}/10-no-rtkit.conf \
		${PREFIX}/share/pipewire/${_confd}.conf.d/
.endfor

.include <bsd.port.mk>
