Thanks @Jonas Lang
What steps did you take to build TVH. Where did you get the instructions from.
Lots of information coming up....
I am building the latest tvheadend (4.3-2049~g1a437c88e) on a Pi 4 running Ubuntu Server 22.04.1 (64-bit)
My procedure is adapted from this post by Russell Tobin
https://tvheadend.org/d/4492-manual-building-deb-packages-on-clean-ubuntu-or-other-debian-distros?r=44265#message-44265.
I also took advice from your own post
https://tvheadend.org/d/8133-tvheadend-build-and-install-on-ubuntu-22-04-64-bit-x86_64-platform-for-beginners?r=47999
My main aim was to build a version of TVHeadend modelled on the same options/features that Michael Marleys builds have in his PPA https://launchpad.net/~mamarley/+archive/ubuntu/tvheadend-git.
Install rpi-userland on a Pi 4 running Ubuntu 22.04.1 64-bit
The Pi 4 running 64-bit OS does not support the rpi-userland support binaries and libraries to support things like transcoding so I cross compile the rpi-userland sources for 32-bit on my 64-system using this script
https://gist.github.com/satmandu/c462ab301cbe09bd6e7cf4db7f626727.
I'm not sure how necessary this step is, for instance you still don't get MMAL support.
In total I needed all these packages to install rpi-userland
sudo apt install make cmake clang libgcc1-armhf-cross libc6-armhf-cross libstdc++6-armhf-cross
Update the Pi config file
I then update the /boot/firmware/config.txt on the Pi 4 to this...
[all]
kernel=vmlinuz
cmdline=cmdline.txt
initramfs initrd.img followkernel
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# gpu_mem=128
gpu_mem=320
[pi4]
max_framebuffers=2
arm_boost=1
# Added when building TVH on Pi 4 running Ubuntu Pi 22.04
# dtoverlay=vc4-fkms-v3d,cma-128
dtoverlay=vc4-kms-v3d-pi4
[all]
# Enable the audio output, I2C and SPI interfaces on the GPIO header. As these
# parameters related to the base device-tree they must appear *before* any
# other dtoverlay= specification
dtparam=audio=on
dtparam=i2c_arm=on
dtparam=spi=on
# Comment out the following line if the edges of the desktop appear outside
# the edges of your display
disable_overscan=1
# If you have issues with audio, you may try uncommenting the following line
# which forces the HDMI output into HDMI mode instead of DVI (which doesn't
# support audio output)
#hdmi_drive=2
# Enable the serial pins
enable_uart=1
# Autoload overlays for any recognized cameras or displays that are attached
# to the CSI/DSI ports. Please note this is for libcamera support, *not* for
# the legacy camera stack
camera_auto_detect=1
display_auto_detect=1
# Config settings specific to arm64
arm_64bit=1
dtoverlay=dwc2
[cm4]
# Enable the USB2 outputs on the IO board (assuming your CM4 is plugged into
# such a board)
dtoverlay=dwc2,dr_mode=host
[all]
TO BUILD TVHEADEND
I first install these packages... I gathered together this list by pain-stakingly building and rebuilding many many times...
sudo apt install build-essential cmake pkg-config git bzip2 wget gettext debhelper python3 python3-dev python3-pip python3-rpi.gpio python2-minimal dvb-apps libraspberrypi-dev libraspberrypi-bin libraspberrypi0 libhdhomerun-dev libvpx-dev libx264-dev libx265-dev libopus-dev libssl-dev libavahi-client-dev libavcodec-dev libavcodec-extra libavfilter-dev libavfilter-extra libavformat-dev libavutil-dev libfdk-aac-dev libswscale-dev libdvbcsa-dev libswresample-dev libiconv-hook-dev libkqueue-dev liburiparser-dev libcurl4-gnutls-dev libpcre2-dev libpcre3-dev libva-dev libva-drm2 libva-x11-2 libsystemd-dev libomxil-bellagio-dev libprotobuf-dev libtcmalloc-minimal4 libgoogle-perftools-dev zlib1g-dev
This is my build script adapted from the Russel Tobin instructions and using the same build options as Michael Marley as specified in this build log output from his PPA https://launchpadlibrarian.net/627632817/buildlog_ubuntu-jammy-arm64.tvheadend_4.3.0~pre+202210071820-0~built202210071932~git81838dbb6~ubuntu22.04.1_BUILDING.txt.gz
#!/bin/bash
#
# Name: buildTVH.sh
#
# Description: Build script for tvheadend on Ubuntu 20.04.1 64bit on Raspberry 4
# Based on buildTVH.sh in /usr/local/src/ of "original" Ubuntu Pi 4
export LD_LIBRARY_PATH=/opt/vc/lib
BASE=$(dirname "$0")
SANITIZER=leak # or address
export CFLAGS="-fsanitize=$SANITIZER"
export LDFLAGS="-fsanitize=$SANITIZER"
(
if [ -d "$BASE/tvheadend" ]; then
cd "$BASE/tvheadend"
make distclean
git pull
else
# Ensure you have all needed TVH build packages as per MMarley
# Install rpi-userland libraries / binaries
# https://gist.github.com/satmandu/c462ab301cbe09bd6e7cf4db7f626727
cd "$BASE"
git clone -v https://github.com/tvheadend/tvheadend.git tvheadend # --depth=5 (need version tag workaround else 0.0.0 version)
#git clone -b -v release/4.2 https://github.com/tvheadend/tvheadend.git
cd "$BASE/tvheadend"
fi
# If cross compiling on another system you would specify a target as a parameter to Autobuild.sh below,
# e.g: ./Autobuild.sh -j$(nproc) -t focal-arm64
echo "AUTOBUILD_CONFIGURE_EXTRA=\"\${AUTOBUILD_CONFIGURE_EXTRA:-} --arch=armhf\"" > Autobuild/focal-armhf.sh
echo "DEBDIST=focal" >> Autobuild/focal-armhf.sh
echo "source Autobuild/debian.sh" >> Autobuild/focal-armhf.sh
echo "AUTOBUILD_CONFIGURE_EXTRA=\"\${AUTOBUILD_CONFIGURE_EXTRA:-} --arch=arm64\"" > Autobuild/focal-arm64.sh
echo "DEBDIST=focal" >> Autobuild/focal-arm64.sh
echo "source Autobuild/debian.sh" >> Autobuild/focal-arm64.sh
#================================================================================================================
# These are the build options that Michael Marley uses as specified in his TVH build output:
# https://launchpadlibrarian.net/627632817/ .. continued in next line->
# buildlog_ubuntu-jammy-arm64.tvheadend_4.3.0~pre+202210071820-0~built202210071932~git81838dbb6~ubuntu22.04.1_BUILDING.txt.gz
#
time (
AUTOBUILD_CONFIGURE_EXTRA="--enable-hdhomerun_client --disable-hdhomerun_static --disable-dvbscan --enable-libav \
--disable-ffmpeg_static --enable-libx264 --disable-libx264_static --enable-libx265 --disable-libx265_static \
--enable-libvpx --disable-libvpx_static --enable-libtheora --disable-libtheora_static --enable-libvorbis \
--disable-libvorbis_static --enable-libfdkaac --disable-libfdkaac_static --enable-libopus --disable-libopus_static \
--enable-vaapi --enable-nvenc --enable-omx --enable-dvbcsa --enable-dvben50221 --enable-libsystemd_daemon \
--enable-pcre2 --enable-pngquant --enable-ddci --python=/usr/bin/python3" \
./Autobuild.sh -j$(nproc)
)
) 2>&1 | tee "$BASE/build.log"
This builds a tvheadend.deb file successfully which I then try to install as mentioned i my first post above giving me the errors.
I am confused about many things. For instance I managed to build and install tvheadend (4.3-2038~g5f9404117) a few weeks ago just fine on the same Pi 4 running Ubuntu 22.04. Of course I was using a few different build options then and with likely a different version of the tvheadend source code from the git. So many things may have changed compared to now. I wonder if a library has changed version or the kernel maybe is now different on my Pi...
Back then I used these build options used by Stefan S in tvheadend thread
https://tvheadend.org/d/4492-manual-building-deb-packages-on-clean-ubuntu-or-other-debian-distros?r=48075#message-48075
time (
AUTOBUILD_CONFIGURE_EXTRA="--disable-ffmpeg_static --disable-libfdkaac_static --disable-libtheora_static --disable-libopus_static \
--disable-libvorbis_static --disable-libvpx_static --disable-libx264_static --disable-libx265_static --enable-libfdkaac \
--enable-libopus --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --disable-avahi \
--disable-dbus_1 --disable-bintray_cache --disable-execinfo --disable-hdhomerun_static --enable-hdhomerun_client \
--enable-libav --enable-pngquant --enable-trace --enable-vaapi --enable-dvbscan --enable-dvbcsa \
--enable-dvben50221 --disable-android --enable-libtheora --enable-pie --enable-nvenc --disable-ccache \
--enable-gperftools --enable-gtimer_check --enable-slow_memoryinfo --enable-cclang_threadsan --enable-ccdebug \
--enable-ddci --enable-omx --enable-libsystemd_daemon --enable-pcre2 --python=/usr/bin/python3" \
./Autobuild.sh -j$(nproc)
)
) 2>&1 | tee "$BASE/build.log"
For that version to build, install and run I would have need a slightly different set of packages, I do not remember what the differences were.
The systemd situation
I've seen your other post where you took advice about making a systemd service file to auto start tvheadend. However the build steps I follow here create a systemd unit file and when I managed to get this to work before tvheadend just auto-started. Even now it makes this systemd unit file for me...
/lib/systemd/system/tvheadend.service
[Unit]
Description=Tvheadend - a TV streaming server and DVR
# Add existing services you want started before Tvheadend, e.g, mount
# units..
# After=auditd.service syslog.target network.target local-fs.target mnt-recordings.mount
# See "man systemd.mount" or view https://www.freedesktop.org/software/systemd/man/systemd.mount.html
After=auditd.service syslog.target network.target local-fs.target
[Service]
EnvironmentFile=/etc/default/tvheadend
#ExecStart=/usr/bin/tvheadend -f -p /run/tvheadend.pid $OPTIONS
ExecStart=/usr/bin/tvheadend -f -p /run/tvheadend.pid -u hts -g video
PIDFile=/run/tvheadend.pid
Type=forking
Restart=on-failure
RestartSec=54s
# To enable watchdog functionality, uncomment these, remove Type=forking
# and compile with --enable-libsystemd_daemon
#Type=notify
#WatchdogSec=1m
#TimeoutStartSec=5m
#TimeoutStopSec=20
[Install]
WantedBy=multi-user.target
Trying to run TVHeadend manually
If I try to start the binary manually I get this error:
ubuntu@ubuntu:/etc/systemd$ /usr/bin/tvheadend -f -p /run/tvheadend.pid -u hts -g video
LeakSanitizer:DEADLYSIGNAL
==1142==ERROR: LeakSanitizer: SEGV on unknown address 0xfffffffffffff020 (pc 0xffff904fcc0c bp 0xffffc51c3540 sp 0xffffc51c3530 T0)
==1142==The signal is caused by a READ memory access.
#0 0xffff904fcc0c in __lsan::GetMallocUsableSize(void const*) ../../../../src/libsanitizer/lsan/lsan_allocator.cpp:148
#1 0xffff840556a8 (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x356a8)
#2 0xffff84041028 (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x21028)
#3 0xffff84048eb8 (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x28eb8)
#4 0xffff84049c78 (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x29c78)
#5 0xffff8404b484 (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x2b484)
#6 0xffff84030c50 in _nss_systemd_getgrent_r (/lib/aarch64-linux-gnu/libnss_systemd.so.2+0x10c50)
#7 0xffff8df9f45c (/lib/aarch64-linux-gnu/libc.so.6+0x10f45c)
#8 0xffff8df44260 in getgrent_r (/lib/aarch64-linux-gnu/libc.so.6+0xb4260)
#9 0xffff8df9efb0 (/lib/aarch64-linux-gnu/libc.so.6+0x10efb0)
#10 0xffff8df439a0 in getgrent (/lib/aarch64-linux-gnu/libc.so.6+0xb39a0)
#11 0xaaaadacc51a8 (/usr/bin/tvheadend+0x1551a8)
#12 0xffff8deb73f8 (/lib/aarch64-linux-gnu/libc.so.6+0x273f8)
#13 0xffff8deb74c8 in __libc_start_main (/lib/aarch64-linux-gnu/libc.so.6+0x274c8)
#14 0xaaaadacc88ac (/usr/bin/tvheadend+0x1588ac)
LeakSanitizer can not provide additional info.
SUMMARY: LeakSanitizer: SEGV ../../../../src/libsanitizer/lsan/lsan_allocator.cpp:148 in __lsan::GetMallocUsableSize(void const*)
==1142==ABORTING
ubuntu@ubuntu:/etc/systemd$
A memory leak? I tried googling for hints about that. There was a tvheadend branch that was dealing with a memory leak but I don't think that is the issue here since I am getting the same error when I build and try to install an older version of tvheadend 4.3-2037~gd9b76b57e which is from the time it DID build, install and run just fine for me a few weeks ago.
Ultimately I would like to understand how to import the tvheadend source code into an IDE, learn how to make changes to the source code locally and make pull requests so that's why all these steps are important for me to understand.
Any help much appreciated.
Flex