Skip to content

Commit

Permalink
Bluez APTX support in pipewire (#50)
Browse files Browse the repository at this point in the history
* add pipewire aptx

---------

Co-authored-by: Guillaume <gplourde@proton.me>
  • Loading branch information
Perpixel and Guillaume authored Oct 27, 2024
1 parent ac8e916 commit aa9dc28
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 161 deletions.
15 changes: 7 additions & 8 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ ARG BASE_IMAGE="${BASE_IMAGE}"
ARG FEDORA_VERSION="${FEDORA_VERSION}"
ARG NVIDIA_VERSION="${NVIDIA_VERSION}"

# Build NVIDIA drivers
# Build NVIDIA drivers and other source packages
#
# This will build the rpm from rpmfusion source and then make
# them available to the final image in this container.i

FROM ${BASE_IMAGE}:${FEDORA_VERSION} as nvidia-builder
FROM ${BASE_IMAGE}:${FEDORA_VERSION} as builder
ARG NVIDIA_VERSION="${NVIDIA_VERSION}"
ARG BUILDROOT=/build
COPY build_files/ "${BUILDROOT}"
RUN rpm-ostree cliwrap install-to-root / \
&& "${BUILDROOT}"/scripts/nvidia-modules-build.sh
&& "${BUILDROOT}"/scripts/build-nvidia-modules.sh \
&& "${BUILDROOT}"/scripts/build-pipewire-aptx.sh

# Build final image
#
Expand All @@ -23,10 +22,10 @@ ARG BUILDROOT=/build

# Copy build scripts
COPY build_files/ "${BUILDROOT}"
# Copy built modules from nvidia-builder step
COPY --from=nvidia-builder /tmp/nvidia/modules "${BUILDROOT}"/nvidia-modules
# Copy built modules from builder step
COPY --from=builder /tmp/built/. /
# Copy configuration files to root
COPY system_files /
COPY ./system_files/. /
# Copy cosign public key
COPY cosign.pub /usr/etc/pki/containers/perpixel.pub
# Run installer and commit image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set -oeux pipefail

ARCH="$(rpm -E '%_arch')"
KERNEL_VERSION=$(rpm -q --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}' kernel)
BUILT_DIR=/tmp/built

# Import external functions
source "$(dirname "$0")"/functions.sh
Expand All @@ -13,21 +14,24 @@ disable-repo /etc/yum.repos.d/fedora-cisco-openh264.repo
disable-repo /etc/yum.repos.d/fedora-updates-testing.repo
disable-repo /etc/yum.repos.d/fedora-updates-archive.repo

mkdir -p /tmp/nvidia
pushd /tmp/nvidia

# Install build requirements
# Getting kernel source from Koji in order to avoid build failure when silverblue image kernel is outdated
dnf install koji g++ kmod patch -y
koji download-build --arch="${ARCH}" kernel-"${KERNEL_VERSION}"
dnf install -y kernel-devel-*.rpm
rm -rf kernel*.rpm
rm -rf /tmp/nvidia/*.rpm

# Making sure ld is available on fedora 40
ln -s /usr/bin/ld.bfd /etc/alternatives/ld && ln -s /etc/alternatives/ld /usr/bin/ld

# Clone open NVIDIA kernel modules from Github
git clone --depth 1 --branch "${NVIDIA_VERSION}" https://github.com/NVIDIA/open-gpu-kernel-modules /build/nvidia
git clone --depth 1 --branch "${NVIDIA_VERSION}" https://github.com/NVIDIA/open-gpu-kernel-modules /tmp/nvidia/src

# Build kernel modules
cd /build/nvidia
pushd /tmp/nvidia/src
ln -s kernel-open kernel

# Kernel patchs
Expand All @@ -37,6 +41,9 @@ ln -s kernel-open kernel
make modules -j"$(nproc)" KERNEL_UNAME="${KERNEL_VERSION}" SYSSRC="/usr/src/kernels/${KERNEL_VERSION}" IGNORE_CC_MISMATCH=1 IGNORE_XEN_PRESENCE=1 IGNORE_PREEMPT_RT_PRESENCE=1

# Copy modules
mkdir -p /tmp/nvidia/modules
cp /build/nvidia/kernel-open/nvidia*.ko /tmp/nvidia/modules
rm -rf /build/nvidia

mkdir -p "${BUILT_DIR}"/usr/lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video
install -D -m 0755 ./kernel/nvidia*.ko ${BUILT_DIR}/usr/lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video/
popd
popd
rm -rf /tmp/nvidia
39 changes: 39 additions & 0 deletions build_files/scripts/build-pipewire-aptx.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
set -oex pipefail

SPA_VERSION=0.2
PIPEWIRE_VERSION=$(rpm -q --queryformat '%{VERSION}' pipewire)
BUILT_DIR=/tmp/built

mkdir /tmp/pipewire
pushd /tmp/pipewire

# install build deps
dnf install -y meson gcc cmake glib2-devel dbus-devel sbc-devel bluez-libs-devel

# install libfreeaptx
git clone https://github.com/iamthehorker/libfreeaptx /tmp/pipewire/libfreeaptx
pushd /tmp/pipewire/libfreeaptx
make install PREFIX=/tmp/built/usr
popd

# export LIBRARY_PATH=/tmp/built/usr/lib64:${LIBRARY_PATH}
# export LD_LIBRARY_PATH=/tmp/built/usr/lib64:${LD_LIBRARY_PATH}
# export C_INCLUDE_PATH=/tmp/built/usr/include:${C_INCLUDE_PATH}
export PKG_CONFIG_PATH=/tmp/built/usr/lib/pkgconfig:${PKG_CONFIG_PATH}

# build bluez5-codec-aptx
rm -rf /tmp/pipewire/src
# get source
git clone --depth 1 --branch "${PIPEWIRE_VERSION}" https://gitlab.freedesktop.org/pipewire/pipewire.git /tmp/pipewire/src
pushd /tmp/pipewire/src

meson setup build
meson configure build -D bluez5-codec-aptx=enabled --auto-features=disabled \
-D examples=disabled -D bluez5=enabled -D bluez5-codec-aptx=enabled \
-D session-managers=[]
meson compile -C build spa-codec-bluez5-aptx
mkdir -p "${BUILT_DIR}"/usr/lib64/spa-"${SPA_VERSION}"/bluez5
install -pm 0755 ./build/spa/plugins/bluez5/libspa-codec-bluez5-aptx.so \
"${BUILT_DIR}"/usr/lib64/spa-"${SPA_VERSION}"/bluez5/
popd
69 changes: 0 additions & 69 deletions build_files/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,11 @@

set -oex pipefail

source "${BUILDROOT}"/scripts/functions.sh

# variables
#
KERNEL_VERSION=$(rpm -q --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}' kernel)
ARCH=$(rpm -E '%_arch')

# define nvidia driver install process
#
install_nvidia_drivers() {

mkdir -p /tmp/nvidia-install
pushd /tmp/nvidia-install

# download
curl -O https://download.nvidia.com/XFree86/Linux-"${ARCH}"/"${NVIDIA_VERSION}"/NVIDIA-Linux-"${ARCH}"-"${NVIDIA_VERSION}".run
# extract
sh ./NVIDIA-Linux-"${ARCH}"-"${NVIDIA_VERSION}".run --extract-only --target nvidiapkg
# install driver files
pushd ./nvidiapkg
./nvidia-installer -s \
--no-kernel-modules \
--x-library-path=/usr/lib64 \
--no-x-check \
--no-check-for-alternate-installs \
--skip-module-load \
--skip-depmod \
--no-rebuild-initramfs \
--glvnd-egl-config-path=/usr/lib64 \
--no-questions \
--no-systemd \
--no-kernel-module-source \
--no-dkms \
--log-file-name=/tmp/nvidia-installer.log

cat /tmp/nvidia-installer.log

nvidia-xconfig --allow-empty-initial-configuration --no-sli --base-mosaic

mkdir -p /usr/lib/systemd/system-{sleep,preset}

# Systemd units and script for suspending/resuming
printf '%s\n' 'enable nvidia-hibernate.service' \
'enable nvidia-resume.service' \
'enable nvidia-suspend.service' \
'enable nvidia-powerd.service' >/usr/lib/systemd/system-preset/70-nvidia.preset
chmod 0644 /usr/lib/systemd/system-preset/70-nvidia.preset

install -p -m 0644 systemd/system/nvidia-{hibernate,powerd,resume,suspend}.service /usr/lib/systemd/system/

# Install dbus config
# install -m 0755 -d %{buildroot}%{_dbus_systemd_dir}
install -p -m 0644 nvidia-dbus.conf /usr/share/dbus-1/system.d/
# Ignore powerd binary exiting if hardware is not present
# We should check for information in the DMI table
sed -i -e 's/ExecStart=/ExecStart=-/g' /usr/lib/systemd/system/nvidia-powerd.service
install -p -m 0755 systemd/system-sleep/nvidia /usr/lib/systemd/system-sleep
install -p -m 0755 systemd/nvidia-sleep.sh /usr/bin/
popd

# install open kernel modules
pushd /tmp/nvidia-modules
mkdir -p /lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video
install -D -m 0755 nvidia*.ko /lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video/
depmod "${KERNEL_VERSION}"
popd
}

install_nvidia_container_toolkit() {
curl -s -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo | tee /etc/yum.repos.d/nvidia-container-toolkit.repo
dnf install nvidia-container-toolkit -y
Expand Down Expand Up @@ -97,13 +34,7 @@ install_packages() {

install_packages
source "$(dirname "$0")"/nvidia-installer.sh
# install nvidia kernel modules
pushd "${BUILDROOT}"/nvidia-modules
mkdir -p /lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video
install -D -m 0755 nvidia*.ko /lib/modules/"${KERNEL_VERSION}"/kernel/drivers/video/
depmod "${KERNEL_VERSION}"
popd
#install_nvidia_drivers
install_nvidia_container_toolkit
build_initramfs
cleanup
38 changes: 1 addition & 37 deletions build_files/scripts/nvidia-installer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _datadir=/usr/share
_target_cpu=x86_64
_bindir=/usr/bin
_sysconfdir=/etc
_modprobedir=/lib/modprobe.d
_modprobedir=/usr/lib/modprobe.d
_unitdir=/usr/lib/systemd/system
_systemd_util_dir=/usr/lib/systemd
_udevrulesdir=/usr/lib/udev/rules.d
Expand Down Expand Up @@ -44,32 +44,6 @@ cat /tmp/nvidia-installer.log
install -p -m 0644 -D 10_nvidia.json ${_datadir}/glvnd/egl_vendor.d/10_nvidia.json
install -p -m 0644 -D *_nvidia_*.json ${_datadir}/glvnd/egl_vendor.d/

# X stuff
mkdir -p ${_sysconfdir}/X11/xorg.conf.d
printf '%s\n' \
'Section "OutputClass"' \
' Identifier "nvidia"' \
' MatchDriver "nvidia-drm"' \
' Driver "nvidia"' \
' Option "AllowEmptyInitialConfiguration"' \
' Option "SLI" "Auto"' \
' Option "BaseMosaic" "on"' \
'EndSection' \
>${_sysconfdir}/X11/xorg.conf.d/10-nvidia.conf

# TODO: this doesn't seems to work?
printf '%s\n' \
'enable nvidia-hibernate.service' \
'enable nvidia-resume.service' \
'enable nvidia-suspend.service' \
'# enable nvidia-powerd.service' \
>${_systemd_util_dir}/system-preset/70-nvidia-driver.preset
chmod 0644 ${_systemd_util_dir}/system-preset/70-nvidia-driver.preset

printf 'enable nvidia-persistenced.service\n' \
>${_systemd_util_dir}/system-preset/70-nvidia-driver-cuda.preset
chmod 0644 ${_systemd_util_dir}/system-preset/70-nvidia-driver-cuda.preset

mkdir -p ${_unitdir}/
install -p -m 0644 systemd/system/*.service ${_unitdir}/
install -p -m 0755 -D systemd/system-sleep/nvidia ${_systemd_util_dir}/system-sleep/nvidia
Expand All @@ -79,16 +53,6 @@ systemctl enable nvidia-hibernate nvidia-resume nvidia-suspend
nvidia-xconfig --allow-empty-initial-configuration --no-sli --base-mosaic
ldconfig

# printf '%s\n' \
# '# Enable runtime PM for NVIDIA VGA/3D controller devices on driver bind' \
# 'ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="auto"' \
# 'ACTION=="bind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="auto"' \
# '# Disable runtime PM for NVIDIA VGA/3D controller devices on driver unbind' \
# 'ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030000", TEST=="power/control", ATTR{power/control}="on"' \
# 'ACTION=="unbind", SUBSYSTEM=="pci", ATTR{vendor}=="0x10de", ATTR{class}=="0x030200", TEST=="power/control", ATTR{power/control}="on"' \
# >${_udevrulesdir}/80-nvidia-pm.rules
# chmod 0644 ${_udevrulesdir}/80-nvidia-pm.rules

# nvidia-persistenced

tar -xf nvidia-persistenced-init.tar.bz2
Expand Down
33 changes: 7 additions & 26 deletions build_files/scripts/packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,13 @@ INCLUDED_PACKAGES=(
distrobox
clang
cmake
egl-x11
egl-gbm
egl-utils
egl-wayland
gettext
libglvnd-egl
libwayland-egl
hwinfo
libtool
lld
fd-find
ffmpeg
ffmpeg-libs
fswatch
fzf
gcc
gcc-c++
git
gnome-session-xsession
htop
Expand All @@ -44,7 +35,6 @@ INCLUDED_PACKAGES=(
nvidia-vaapi-driver
nvtop
opencl-filesystem
pipewire-codec-aptx
plymouth-theme-spinfinity
ripgrep
rclone
Expand All @@ -60,15 +50,6 @@ INCLUDED_PACKAGES=(
)

EXCLUDED_PACKAGES=(
libavdevice-free
libavcodec-free
libavfilter-free
libavformat-free
libavutil-free
libpostproc-free
libswresample-free
libswscale-free
ffmpeg-free
mesa-va-drivers
firefox-langpacks
firefox
Expand All @@ -89,14 +70,14 @@ if [[ ${#EXCLUDED_PACKAGES[@]} -gt 0 ]]; then
fi

# Download and install rpm fusion package
wget -P /tmp/rpms \
https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-"${FEDORA_VERSION}".noarch.rpm \
https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-"${FEDORA_VERSION}".noarch.rpm
# wget -P /tmp/rpms \
# https://mirrors.rpmfusion.org/free/fedora/rpmfusion-free-release-"${FEDORA_VERSION}".noarch.rpm \
# https://mirrors.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-"${FEDORA_VERSION}".noarch.rpm

# Install RPMFusion
dnf install /tmp/rpms/rpmfusion*.rpm -y
disable-repo /etc/yum.repos.d/rpmfusion-nonfree-updates-testing.repo
disable-repo /etc/yum.repos.d/rpmfusion-free-updates-testing.repo
# dnf install /tmp/rpms/rpmfusion*.rpm -y
# disable-repo /etc/yum.repos.d/rpmfusion-nonfree-updates-testing.repo
# disable-repo /etc/yum.repos.d/rpmfusion-free-updates-testing.repo

# Just install INCLUDED if EXCLUDED is empty
if [[ ${#INCLUDED_PACKAGES[@]} -gt 0 && "${#EXCLUDED_PACKAGES[@]}" -eq 0 ]]; then
Expand Down
8 changes: 8 additions & 0 deletions system_files/etc/X11/xorg.conf.d/10-nvidia.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Section "OutputClass"
Identifier "nvidia"
MatchDriver "nvidia-drm"
Driver "nvidia"
Option "AllowEmptyInitialConfiguration"
Option "SLI" "Auto"
Option "BaseMosaic" "on"
EndSection
2 changes: 2 additions & 0 deletions system_files/etc/environment
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
GBM_BACKEND=nvidia-drm
__GLX_VENDOR_LIBRARY_NAME=nvidia
__GL_SHADER_DISK_CACHE_SKIP_CLEANUP=1
MOZ_DISABLE_RDD_SANDBOX=1
LIBVA_DRIVER_NAME=nvidia
12 changes: 1 addition & 11 deletions system_files/etc/modprobe.d/nvidia.conf
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
# prevent nouveau module from loading
blacklist nouveau

# force modeset and fbdev
options nvidia_drm modeset=1
options nvidia_drm fbdev=1
options nvidia NVreg_EnableGpuFirmware=1

# save and restore memory allocations
options nvidia NVreg_PreserveVideoMemoryAllocations=1
options nvidia NVreg_TemporaryFilePath=/var/tmp
options nvidia-drm modeset=1 fbdev=1
1 change: 1 addition & 0 deletions system_files/usr/lib/dracut/dracut.conf.d/10-nvidia.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
force_drivers+=" nvidia nvidia_modeset nvidia_uvm nvidia_drm "
install_optional_items+=" /etc/modprobe.d/nvidia.conf "
install_optional_items+=" /usr/lib/modprobe.d/nvidia.conf "
24 changes: 24 additions & 0 deletions system_files/usr/lib/modprobe.d/nvidia.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Nouveau must be blacklisted here as well beside from the initrd to avoid a
# delayed loading (for example on Optimus laptops where the Nvidia card is not
# driving the main display).

blacklist nouveau

# Make a soft dependency for nvidia-uvm as adding the module loading to
# /usr/lib/modules-load.d/nvidia-uvm.conf for systemd consumption, makes the
# configuration file to be added to the initrd but not the module, throwing an
# error on plymouth about not being able to find the module.
# Ref: /usr/lib/dracut/modules.d/00systemd/module-setup.sh

# Even adding the module is not the correct thing, as we don't want it to be
# included in the initrd, so use this configuration file to specify the
# dependency.

softdep nvidia post: nvidia-uvm

# Enable complete power management. From:
# file:///usr/share/doc/nvidia-driver/html/powermanagement.html

options nvidia NVreg_DynamicPowerManagement=0x02
options nvidia NVreg_EnableS0ixPowerManagement=1
options nvidia NVreg_PreserveVideoMemoryAllocations=1
Loading

0 comments on commit aa9dc28

Please sign in to comment.