Building Kodi: Enabling Automatic Frame Rate Control

This guide assumes that you have installed the packages from the first post, https://forum.odroid.com/viewtopic.php?f=98&t=32173#p233475, and are using the exact same OS image, as this is not tested on any other image. We are again modifying the kernel, and I am in no way responsible for any damage on your hardware. This guide is for tinkering and HIFI/Video hobby enthusiasts that know what they are doing.

Figure 1 – Kodi automatic frame rate adjustment https://www.youtube.com/watch?v=mJ0z7qAw2Jo

Modifying the Kernel

Back in spring of 2018, the great @memeka and myself were about to discover the great unknown. I was studying the DRM mixer source code in the kernel and saw that one plane with NV21 and NV12 color capabilities were disabled, known as the OVERLAY plane. The picture as you see on your TV is made of different layers in DRM that are placed on top of each other, the highest Z position is the top most layer. That OVERLAY plane is normally provided to display videos coming from the hardware decoder of the board which exactly outputs in that NV21/NV12 format but it was disabled! This needed to run DRMPRIME with a zero copy!?

So to sum everything up, the images coming from the hardware decoder have to be scaled down and/or color converted, and the scaler hardware component on the board was not implemented in this kernel version, so it couldn’t be used. However, since Kodi makes use of different layers in DRM and needs at least two layers, the concept of the GBM backend was designed. We were thinking about what could be done, and memeka came up with the genius idea to use the cursor plane as the OVERLAY plane and this is what we did first in this howto: patch the kernel in order to swap the disabled OVERLAY plane with the CURSOR plane. Kodi will then be able to switch video resolution and GUI resolution independently!

So, we are not getting DRMPRIME with this, but Kodi with GBM windowing system with great video performance without any tearing, and, as far as I know, automatic frame rate control.

Changing Kodi

Team Kodi has closed the doors to everything other than the Mesa GBM GPU drivers. I hope we will see Mali for Mesa soon to be released, so we have to change that and the use of DRM inside Kodi which means that this will be the second part of this guide: patching Kodi.

Patching the Kernel

Get the source code if you don’t have it already:

$ git clone https://github.com/hardkernel/linux.git
$ cd linux
$ wget -O drm_plane_fix.patch https://pastebin.com/raw/MiTbZsPs
$ patch -p1 < drm_plane_fix.patch

$ make odroidxu4_defconfig
$ make -j7
$ sudo cp arch/arm/boot/zImage /media/boot/.
$ sudo cp arch/arm/boot/dts/exynos5422-odroidxu4.dtb /media/boot/.
$ sudo make modules_install

Patch Kodi

Use the following commands to patch Kodi:

$ git clone https://github.com/xbmc/xbmc.git
$ cd xbmc
$ wget -O kodi.patch https://pastebin.com/raw/mzAiCU2Q
$ patch -p1 < kodi.patch
Patching internal FFmpeg to prevent a memory leak (separate because maybe not needed in the future)
$ wget -O FFmpeg_fix.patch https://pastebin.com/raw/rRbXTfra
$ patch -p1 < FFmpeg_fix.patch Next, you’ll need to get a ton of pre-requirements: $ sudo apt-get install antlr autoconf automake autopoint autotools-dev ca-certificates-java curl debhelper default-jre default-jre-headless default-libmysqlclient-dev dh-autoreconf dh-python dh-strip-nondeterminism doxygen fontforge-common fontforge-nox fonts-droid-fallback gawk gettext gettext-base gir1.2-harfbuzz-0.0 gir1.2-ibus-1.0 gperf groovy icu-devtools intltool-debian ivy java-common junit4 libantlr-java libao-common libao-dev libao4 libapache-pom-java libarchive-zip-perl libasan3 libasm-java libass-dev libass9 libasyncns0 libavahi-client-dev libavahi-common-dev libbluetooth-dev libbluray-dev libbluray2 libboost-atomic1.65-dev libboost-atomic1.65.1 libboost-chrono1.65-dev libboost-chrono1.65.1 libboost-date-time1.65-dev libboost-date-time1.65.1 libboost-dev libboost-filesystem1.65.1 libboost-serialization1.65-dev libboost-serialization1.65.1 libboost-system1.65-dev libboost-system1.65.1 libboost-thread-dev libboost-thread1.65-dev libboost-thread1.65.1 libboost1.65-dev libbs2b0 libbsf-java libbz2-dev libcap-dev libcapnp-0.6.1 libcdio-dev libcdio17 libcec-dev libcec4 libchromaprint1 libclang1-6.0 libcommons-cli-java libcommons-lang-java libcommons-logging-java libcommons-parent-java libcrossguid-dev libcrossguid0 libcurl4-gnutls-dev libcwiid-dev libcwiid1 libdbus-1-dev libevent-2.1-6 libexpat1-dev libfftw3-double3 libfile-stripnondeterminism-perl libflac8 libflite1 libfluidsynth1 libfontconfig1-dev libfontforge2 libfribidi-dev libfstrcmp-dev libfstrcmp0 libgcrypt20-dev libgdraw5 libgif-dev libgif7 libglib2.0-bin libglib2.0-dev libglib2.0-dev-bin libglvnd-core-dev libglvnd-dev libgme0 libgmp-dev libgmpxx4ldbl libgnutls-dane0 libgnutls-openssl27 libgnutls28-dev libgnutlsxx28 libgpg-error-dev libgraphite2-dev libgsm1 libgtest-dev libhamcrest-java libharfbuzz-dev libharfbuzz-gobject0 libharfbuzz-icu0 libhawtjni-runtime-java libibus-1.0-5 libibus-1.0-dev libicu-dev libicu-le-hb-dev libicu-le-hb0 libiculx60 libidn2-0-dev libidn2-dev libiso9660-10 libiso9660-dev libjack-jackd2-0 libjansi-java libjansi-native-java libjline2-java libjpeg-dev libjpeg-turbo8-dev libjpeg8-dev liblcms2-dev libldb1 libllvm6.0 libltdl-dev liblzo2-dev libmad0 libmicrohttpd-dev libmicrohttpd12 libmirclient-dev libmirclient9 libmircommon-dev libmircommon7 libmircookie-dev libmircookie2 libmircore-dev libmircore1 libmirprotobuf3 libmodplug-dev libmodplug1 libmp3lame0 libmpg123-0 libmysofa0 libmysqlclient-dev libmysqlclient20 libnfs-dev libnfs11 libnorm1 libnspr4 libnss3 libogg0 libomxil-bellagio-dev libomxil-bellagio0 libopengl0 libopenjp2-7 libopenmpt0 libopus0 libp11-kit-dev libp8-platform-dev libp8-platform2 libpangoxft-1.0-0 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5 libpgm-5.2-0 libplist-dev libplist3 libpostproc-dev libpostproc54 libprotobuf-dev libprotobuf-lite10 libprotobuf10 libpython-dev libpython2.7 libpython2.7-dev libqdox-java librsvg2-bin librubberband2 libsensors4 libservlet3.1-java libshairport-dev libshairport2 libshine3 libsmbclient libsmbclient-dev libsnappy1v5 libsndfile1 libsndio-dev libsndio6.1 libsodium23 libsoxr0 libspeex1 libspiro0 libsqlite3-dev libssh-gcrypt-4 libssh-gcrypt-dev libtag1-dev libtag1v5 libtag1v5-vanilla libtalloc2 libtasn1-6-dev libtdb1 libtevent0 libtheora0 libtimedate-perl libtinyxml-dev libtinyxml2.6.2v5 libtool libtwolame0 libunbound2 libuninameslist1 libvdpau1 libvorbis0a libvorbisenc2 libvorbisfile3 libvpx5 libwavpack1 libwbclient0 libwebpdemux2 libwebpmux3 libx264-152 libx265-146 libxapian30 libxml2-dev libxmu-dev libxmu-headers libxmu6 libxpp3-java libxvidcore4 libyajl-dev libyajl2 libzmq5 libzvbi-common libzvbi0 mysql-common nettle-dev openjdk-11-jre openjdk-11-jre-headless po-debconf python-dev python-pil python-talloc python2.7-dev python3-distutils python3-lib2to3 samba-libs swig swig3.0 unzip uuid-dev yasm zip ccache libinput-dev libpulse-dev pulseaudio
Generate the Makefile and export some extra compiler switches:
$ export CPPFLAGS="-mfloat-abi=hard -marm -mtune=cortex-a15.cortex-a7 -mcpu=cortex-a15 -mfpu=neon-vfpv4 -ftree-vectorize -mvectorize-with-neon-quad -ffast-math" $ export CXXFLAGS=$CPPFLAGS $ export CXX_FLAGS=$CXXFLAGS $ mkdir kodi $ cd kodi $ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DCORE_PLATFORM_NAME=gbm -DGBM_RENDER_SYSTEM=gles \ -DENABLE_ALSA=ON -DENABLE_AIRTUNES=ON -DENABLE_UPNP=ON \ -DENABLE_INTERNAL_FMT=ON -DENABLE_INTERNAL_RapidJSON=ON \ -DENABLE_OPENGLES=ON -DENABLE_OPENGL=OFF -DENABLE_X=OFF \ -DVERBOSE=OFF -DENABLE_SMBCLIENT=OFF -DENABLE_CEC=ON -DENABLE_NEON=ON \ -DWITH_CPU=armv7-a -DENABLE_AVAHI=ON \ -DENABLE_PULSEAUDIO=ON -DENABLE_CCACHE=ON \ -DENABLE_APP_AUTONAME=OFF -DENABLE_DVDCSS=OFF -DENABLE_INTERNAL_CROSSGUID=OFF -DENABLE_OPTICAL=OFF \ -DENABLE_EVENTCLIENTS=ON \ -DENABLE_VAAPI=OFF -DENABLE_VDPAU=OFF -DENABLE_INTERNAL_FLATBUFFERS=ON ../. $ make -j7 $ sudo make install
Run Kodi, then go to Settings -> Player and adjust setting level on the lower left side, there is Basic, Standard, Advanced and Expert chose either Advanced or Expert. Go to Settings -> Player -> Videos and enable adjust display refresh rate to On start/stop. Go to Settings -> System -> Display -> Whitelist and add all resolutions you want to be able to switch automatically.

Fix CEC

With Kernel 4.10+, a new Linux CEC Framework was introduced, so you need a special libcec library. Here is how to build it from source:

Pulse eight platform support library:

$ sudo apt-get install cmake build-essential
$ git clone https://github.com/Pulse-Eight/platform.git
$ mkdir platform/build
$ cd platform/build
$ cmake ..
$ make -j7
$ sudo make install
Pulse eight libcec library with new Linux framework support patch. Note, you should uninstall any old libcec files before testing:
$ sudo apt-get install cmake libudev-dev python-dev swig
$ git clone https://github.com/Pulse-Eight/libcec.git
$ cd libcec
$ wget -O libcec.patch $ https://github.com/Kwiboo/libcec/commit/48255b7d4e1cba1050b8abfbd03be37c0737e832.patch
$ git apply libcec.patch
$ mkdir build
$ cd build
$ cmake -DHAVE_LINUX_API=1 ..
$ make -j7
$ sudo make install
$ sudo ldconfig
For more information, please see the ODROID forum thread at https://forum.odroid.com/viewtopic.php?f=98&t=32173#p235249.

Be the first to comment

Leave a Reply