%bcond_with systemd
%bcond_with rtkit
%bcond_with man

%global apiversion   0.3
%global spaversion   0.2

#global snap       20141103
#global gitrel     327
#global gitcommit  aec811798cd883a454b9b5cd82c77831906bbd2d
#global shortcommit %(c=%{gitcommit}; echo ${c:0:5})

# https://bugzilla.redhat.com/983606
%global _hardened_build 1

# where/how to apply multilib hacks
%global multilib_archs x86_64 %{ix86} ppc64 ppc s390x s390 sparc64 sparcv9 ppc64le

Name:           pipewire
Summary:        Media Sharing Server
Version:        0.3.24
Release:        1%{?snap:.%{snap}git%{shortcommit}}%{?_dist_release}%{?with_systemd:.systemd}
Group:          multimedia
Vendor:         Project Vine
Distribution:   Vine Linux

License:        LGPLv2+
URL:            https://pipewire.org/
%if 0%{?gitrel}
# git clone git://anongit.freedesktop.org/gstreamer/pipewire
# cd pipewire; git reset --hard %{gitcommit}; ./autogen.sh; make; make distcheck
Source0:        pipewire-%{version}-%{gitrel}-g%{shortcommit}.tar.gz
%else
Source0:        https://github.com/PipeWire/pipewire/archive/%{version}.tar.gz
%endif

## upstream patches

## upstreamable patches

## fedora patches
Patch0:         0001-conf-start-media-session-through-pipewire.patch

BuildRequires:  meson >= 0.35.0
BuildRequires:  gcc
BuildRequires:  pkgconfig
BuildRequires:  pkgconfig(dbus-1)
BuildRequires:  pkgconfig(glib-2.0) >= 2.32
BuildRequires:  pkgconfig(gio-unix-2.0) >= 2.32
BuildRequires:  pkgconfig(gstreamer-1.0) >= 1.10.0
BuildRequires:  pkgconfig(gstreamer-base-1.0) >= 1.10.0
BuildRequires:  pkgconfig(gstreamer-plugins-base-1.0) >= 1.10.0
BuildRequires:  pkgconfig(gstreamer-net-1.0) >= 1.10.0
BuildRequires:  pkgconfig(gstreamer-allocators-1.0) >= 1.10.0
BuildRequires:  pkgconfig(vulkan)
BuildRequires:  pkgconfig(bluez)
%if %{with systemd}
BuildRequires:  systemd-devel >= 184
%else
BuildRequires:  pkgconfig(libudev)
%endif
BuildRequires:  alsa-lib-devel
BuildRequires:  libv4l-devel
BuildRequires:  doxygen
%if %{with man}
BuildRequires:  xmltoman
%endif
BuildRequires:  graphviz
BuildRequires:  sbc-devel
BuildRequires:  libsndfile-devel

Requires(pre):  shadow-utils
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
%if %{with systemd}
Requires:       systemd >= 184
%endif
%if %{with rtkit}
Requires:       rtkit
%endif

# https://bugzilla.redhat.com/983606
%global _hardened_build 1

%if %{with systemd}
## enable systemd activation
%global systemd 1
%endif

%description
PipeWire is a multimedia server for Linux and other Unix like operating
systems.


%package libs
Summary:        Libraries for PipeWire clients
Group:          system
License:        LGPLv2+
Recommends:     %{name}%{?_isa} = %{version}-%{release}

%description libs
This package contains the runtime libraries for any application that wishes
to interface with a PipeWire media server.


%package gstreamer
Summary:        GStreamer elements for PipeWire
Group:          multimedia
License:        MIT
Recommends:     %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description gstreamer
This package contains GStreamer elements to interface with a
PipeWire media server.


%package devel
Summary:        Headers and libraries for PipeWire client development
Group:          programming
License:        LGPLv2+
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description devel
Headers and libraries for developing applications that can communicate with
a PipeWire media server.


%package doc
Summary:        PipeWire media server documentation
Group:          documentation
License:        LGPLv2+

%description doc
This package contains documentation for the PipeWire media server.


%package utils
Summary:        PipeWire media server utilities
Group:          multimedia
License:        LGPLv2+
Requires:       %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}

%description utils
This package contains command line utilities for the PipeWire media server.


%package alsa
Summary:        PipeWire media server ALSA support
Group:          multimedia
License:        MIT
Recommends:     %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
%if 0
# Ensure this is provided by default to route all audio
Supplements:    %{name} = %{version}-%{release}
# Replace PulseAudio and JACK ALSA plugins with PipeWire
## N.B.: If alsa-plugins gets updated in F33, this will need to be bumped
Obsoletes:      alsa-plugins-jack < 1.2.2-5
Obsoletes:      alsa-plugins-pulseaudio < 1.2.2-5
%endif

%description alsa
This package contains an ALSA plugin for the PipeWire media server.


%package jack-audio-connection-kit
Summary:        PipeWire JACK implementation
Group:          multimedia
License:        MIT
Recommends:     %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libjack%{?_isa} = %{version}-%{release}
BuildRequires:  jack-audio-connection-kit-devel >= 1.9.10
Conflicts:      jack-audio-connection-kit
Conflicts:      jack-audio-connection-kit-dbus
# Fixed jack subpackages
Conflicts:      %{name}-libjack < 0.3.13-6
Conflicts:      %{name}-jack-audio-connection-kit < 0.3.13-6
# Replaces libjack subpackage
Obsoletes:      %{name}-libjack < 0.3.19-2
Provides:       %{name}-libjack = %{version}-%{release}
Provides:       %{name}-libjack%{?_isa} = %{version}-%{release}
%if 0
# Ensure this is provided by default to route all audio
Supplements:    %{name} = %{version}-%{release}
# Replace JACK with PipeWire-JACK
## N.B.: If jack gets updated in F33, this will need to be bumped
Obsoletes:      jack-audio-connection-kit < 1.9.16-2
%endif

%description jack-audio-connection-kit
This package provides a JACK implementation based on PipeWire


%package plugin-jack
Summary:        PipeWire media server JACK support
Group:          multimedia
License:        MIT
BuildRequires:  jack-audio-connection-kit-devel
Recommends:     %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
Requires:       jack-audio-connection-kit

%description plugin-jack
This package contains the PipeWire spa plugin to connect to a JACK server.


%package pulseaudio
Summary:        PipeWire PulseAudio implementation
Group:          multimedia
License:        MIT
Recommends:     %{name}%{?_isa} = %{version}-%{release}
Requires:       %{name}-libs%{?_isa} = %{version}-%{release}
BuildRequires:  pulseaudio-libs
Conflicts:      pulseaudio
# Fixed pulseaudio subpackages
Conflicts:      %{name}-libpulse < 0.3.13-6
Conflicts:      %{name}-pulseaudio < 0.3.13-6
%if 0
# Ensure this is provided by default to route all audio
Supplements:    %{name} = %{version}-%{release}
# Replace PulseAudio with PipeWire-PulseAudio
## N.B.: If pulseaudio gets updated in F33, this will need to be bumped
Obsoletes:      pulseaudio < 14.2-3
Obsoletes:      pulseaudio-esound-compat < 14.2-3
Obsoletes:      pulseaudio-module-bluetooth < 14.2-3
Obsoletes:      pulseaudio-module-gconf < 14.2-3
Obsoletes:      pulseaudio-module-gsettings < 14.2-3
Obsoletes:      pulseaudio-module-jack < 14.2-3
Obsoletes:      pulseaudio-module-lirc < 14.2-3
Obsoletes:      pulseaudio-module-x11 < 14.2-3
Obsoletes:      pulseaudio-module-zeroconf < 14.2-3
Obsoletes:      pulseaudio-qpaeq < 14.2-3
%endif

# Virtual Provides to support swapping between PipeWire-PA and PA
Provides:       pulseaudio-daemon
Conflicts:      pulseaudio-daemon
Provides:       pulseaudio-module-bluetooth
Provides:       pulseaudio-module-jack

%description pulseaudio
This package provides a PulseAudio implementation based on PipeWire


%debug_package


%prep
%setup -q -T -b0 -n %{name}-%{version}%{?gitrel:-%{gitrel}-g%{shortcommit}}
%autopatch -p1


%build
%meson \
	-D docs=enabled \
%if %{with man}
	-D man=enabled \
%else
	-D man=disabled \
%endif
	-D gstreamer=enabled \
	-D jack=enabled \
	-D pipewire-jack=enabled \
	-D pipewire-pulseaudio=enabled \
	-D vulkan=enabled \
	-D gstreamer-device-provider=disabled \
	-D sdl2=disabled \
	-D libcamera=disabled \
	-D audiotestsrc=disabled \
	-D videotestsrc=disabled \
	-D volume=disabled \
	-D bluez5-codec-aptx=disabled \
	-D bluez5-codec-ldac=disabled \
	-D bluez5-codec-aac=disabled \
%if %{with systemd}
	-D systemd=enabled
%else
	-D systemd=disabled
%endif
%meson_build


%install
%meson_install

mkdir -p %{buildroot}%{_sysconfdir}/ld.so.conf.d/
echo %{_libdir}/pipewire-%{apiversion}/jack/ > %{buildroot}%{_sysconfdir}/ld.so.conf.d/pipewire-jack-%{_arch}.conf

mkdir -p %{buildroot}%{_sysconfdir}/alsa/conf.d/
cp %{buildroot}%{_datadir}/alsa/alsa.conf.d/50-pipewire.conf \
        %{buildroot}%{_sysconfdir}/alsa/conf.d/50-pipewire.conf
cp %{buildroot}%{_datadir}/alsa/alsa.conf.d/99-pipewire-default.conf \
        %{buildroot}%{_sysconfdir}/alsa/conf.d/99-pipewire-default.conf
touch %{buildroot}%{_sysconfdir}/pipewire/media-session.d/with-alsa

%if %{with systemd}
# We don't start the media session with systemd yet
rm %{buildroot}%{_userunitdir}/pipewire-media-session.*
%endif

%find_lang %{name}


%check
%meson_test


%pre
getent group pipewire >/dev/null || groupadd -r pipewire
getent passwd pipewire >/dev/null || \
    useradd -r -g pipewire -d %{_localstatedir}/run/pipewire -s /sbin/nologin -c "PipeWire System Daemon" pipewire
exit 0

%if %{with systemd}
%post
%systemd_user_post pipewire.service
%systemd_user_post pipewire.socket

%post pulseaudio
%systemd_user_post pipewire-pulse.service
%systemd_user_post pipewire-pulse.socket
%endif


%files
%license COPYING LICENSE
%doc README.md
%if %{with systemd}
%{_userunitdir}/pipewire.*
%endif
%{_bindir}/pipewire
%{_bindir}/pipewire-media-session
%dir %{_sysconfdir}/pipewire/
%config(noreplace) %{_sysconfdir}/pipewire/client.conf
%config(noreplace) %{_sysconfdir}/pipewire/client-rt.conf
%config(noreplace) %{_sysconfdir}/pipewire/jack.conf
%config(noreplace) %{_sysconfdir}/pipewire/pipewire.conf
%config(noreplace) %{_sysconfdir}/pipewire/pipewire-pulse.conf
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/alsa-monitor.conf
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/bluez-monitor.conf
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/media-session.conf
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/v4l2-monitor.conf
%if %{with man}
%{_mandir}/man5/pipewire.conf.5*
%endif

%files libs -f %{name}.lang
%license COPYING LICENSE
%doc README.md
%{_libdir}/libpipewire-%{apiversion}.so.*
%{_libdir}/pipewire-%{apiversion}/
%{_libdir}/spa-%{spaversion}/
%{_libdir}/gstreamer-1.0/libgstpipewire.*
%{_libdir}/alsa-lib/libasound_module_*_pipewire.so
/lib/udev/rules.d/90-pipewire-alsa.rules
%{_datadir}/alsa/alsa.conf.d/50-pipewire.conf
%{_datadir}/alsa/alsa.conf.d/99-pipewire-default.conf
%dir %{_datadir}/alsa-card-profile
%dir %{_datadir}/alsa-card-profile/mixer
%dir %{_datadir}/alsa-card-profile/mixer/paths
%dir %{_datadir}/alsa-card-profile/mixer/profile-sets
%{_datadir}/alsa-card-profile/mixer/paths/*
%{_datadir}/alsa-card-profile/mixer/profile-sets/*
%config(noreplace) %{_sysconfdir}/alsa/conf.d/50-pipewire.conf
%config(noreplace) %{_sysconfdir}/alsa/conf.d/99-pipewire-default.conf

%files gstreamer
%{_libdir}/gstreamer-1.0/libgstpipewire.*

%files devel
%{_libdir}/libpipewire-%{apiversion}.so
%{_includedir}/pipewire-%{apiversion}/
%{_includedir}/spa-%{spaversion}/
%{_libdir}/pkgconfig/libpipewire-%{apiversion}.pc
%{_libdir}/pkgconfig/libspa-%{spaversion}.pc

%files doc
%{_datadir}/doc/pipewire/html

%files utils
%{_bindir}/pw-*
%{_bindir}/spa-*

%files alsa
%{_libdir}/alsa-lib/libasound_module_pcm_pipewire.so
%{_libdir}/alsa-lib/libasound_module_ctl_pipewire.so
%{_datadir}/alsa/alsa.conf.d/50-pipewire.conf
%{_datadir}/alsa/alsa.conf.d/99-pipewire-default.conf
%config(noreplace) %{_sysconfdir}/alsa/conf.d/50-pipewire.conf
%config(noreplace) %{_sysconfdir}/alsa/conf.d/99-pipewire-default.conf
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/with-alsa

%files jack-audio-connection-kit
%{_bindir}/pw-jack
%if %{with man}
%{_mandir}/man1/pw-jack.1*
%endif
%{_libdir}/pipewire-%{apiversion}/jack/libjack.so*
%{_libdir}/pipewire-%{apiversion}/jack/libjacknet.so*
%{_libdir}/pipewire-%{apiversion}/jack/libjackserver.so*
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/with-jack
%{_sysconfdir}/ld.so.conf.d/pipewire-jack-%{_arch}.conf

%files plugin-jack
%{_libdir}/spa-%{spaversion}/jack/

%files pulseaudio
%{_bindir}/pipewire-pulse
%if %{with systemd}
%{_userunitdir}/pipewire-pulse.*
%endif
%config(noreplace) %{_sysconfdir}/pipewire/media-session.d/with-pulseaudio


%changelog
* Fri Mar 26 2021 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.3.24-1
- new upstream release.
- dropped Patch0.
- imported Patch0 from rawhide.
- dropped ldconfig scriptlets.
- enabled gstreamer, pulseaudio and jack.

* Mon Aug 03 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.3.8-1
- new upstream release.
- dropped Patch1 and 2: fixed in upstream.
- imported Patch0 from rawhide.

* Wed Jul 29 2020 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.2.7-1
- new upstream release.

* Mon Sep 23 2019 Tomohiro "Tomo-p" KATO <tomop@teamgedoh.net> - 0.2.6-6
- initial build for Vine Linux.

* Mon Sep 16 2019 Kalev Lember <klember@redhat.com> - 0.2.6-5
- Don't require the daemon package for -devel subpackage
- Move pipewire.conf man page to the daemon package

* Fri Jul 26 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.6-4
- Rebuilt for https://fedoraproject.org/wiki/Fedora_31_Mass_Rebuild

* Wed Jun 19 2019 Wim Taymans <wtaymans@redhat.com> - 0.2.6-3
- Add patch to reuse fd in pipewiresrc
- Add patch for device provider
- Add patch to disable extra security checks until portal is fixed.

* Tue Jun 04 2019 Kalev Lember <klember@redhat.com> - 0.2.6-2
- Split libpipewire and the gstreamer plugin out to -libs subpackage

* Wed May 22 2019 Wim Taymans <wtaymans@redhat.com> - 0.2.6-1
- Update to 0.2.6
- Add patch for alsa-lib 1.1.9 include path

* Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.2.5-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild

* Fri Jan 04 2019 Wim Taymans <wtaymans@redhat.com> - 0.2.5-2
- Add patch to avoid invalid conversion error with C++ compilers

* Thu Nov 22 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.5-1
- Update to 0.2.5

* Thu Nov 22 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.4-1
- Update to 0.2.4

* Thu Oct 18 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.3-2
- Add systemd socket activation

* Thu Aug 30 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.3-1
- Update to 0.2.3

* Tue Jul 31 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.2-1
- Update to 0.2.2

* Fri Jul 20 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.1-1
- Update to 0.2.1

* Tue Jul 17 2018 Wim Taymans <wtaymans@redhat.com> - 0.2.0-1
- Update to 0.2.0

* Fri Jul 13 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.9-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild

* Tue Feb 27 2018 Wim Taymans <wtaymans@redhat.com> - 0.1.9-1
- Update to 0.1.9

* Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.1.8-3
- Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild

* Sat Feb 03 2018 Igor Gnatenko <ignatenkobrain@fedoraproject.org> - 0.1.8-2
- Switch to %%ldconfig_scriptlets

* Tue Jan 23 2018 Wim Taymans <wtaymans@redhat.com> - 0.1.8-1
- Update to 0.1.8

* Fri Nov 24 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.7-1
- Update to 0.1.7
- Add to build when memfd_create is already defined

* Fri Nov 03 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.6-1
- Update to 0.1.6

* Tue Sep 19 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.5-2
- Add patch to avoid segfault when probing

* Tue Sep 19 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.5-1
- Update to 0.1.5

* Thu Sep 14 2017 Kalev Lember <klember@redhat.com> - 0.1.4-3
- Rebuilt for GNOME 3.26.0 megaupdate

* Fri Sep 08 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.4-2
- Install SPA hooks

* Wed Aug 23 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.4-1
- Update to 0.1.4

* Wed Aug 09 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.3-1
- Update to 0.1.3

* Tue Jul 04 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.2-1
- Update to 0.1.2
- Added more build requirements
- Make separate doc package

* Mon Jun 26 2017 Wim Taymans <wtaymans@redhat.com> - 0.1.1-1
- Update to 0.1.1
- Add dbus-1 to BuildRequires
- change libs-devel to -devel

* Wed Sep 9 2015 Wim Taymans <wtaymans@redhat.com> - 0.1.0-2
- Fix BuildRequires to use pkgconfig, add all dependencies found in configure.ac
- Add user and groups  if needed
- Add license to %%licence

* Tue Sep 1 2015 Wim Taymans <wtaymans@redhat.com> - 0.1.0-1
- First version
