CedarX/XBMC

XBMC is a popular media center software with 10-foot interface designed for large-screen televisions, and it enables media players and set-top boxes based on Allwinner SoCs with CedarX to play and view high-definition videos, music, and other digital media files from local and network storage media, as well as stream podcasts, videocasts, and such of the internet.

This article contain instructions on compiling and developing XBMC on and for Allwinner A10 SoC, these instructions are specifically only meant for developers and advanced or expert Linux users that can actively assist with the porting.

=Overview= XBMC has already have an initial port for the A10 SoC with CedarX hardware accelerated video decoding, this experimental third-party port and the code patches has not yet made it upstream into mainline XBMC.

Pre-built application binaries of this port are not available so therefore you will need to compile XBMC yourself, at least until if and when the code makes it into the mainline XBMC upstream at http://xbmc.org

Team-XBMC, the official development team of XBMC, does currently not recommend that any end-user buy Allwinner based hardware for the specific purpose of only running XBMC since they do not have the resources to support this platform as of yet.

More information about XBMC can be found on wikipedia http://en.wikipedia.org/wiki/XBMC and the XBMC wiki http://wiki.xbmc.org or http://forum.xbmc.org

= Native Compile of XBMC = This is a little how-to of steps to compile XBMC native on the Mele A1000 or A2000 from Gimli's's GitHub (http://github.com/huceke/xbmc) or Empat0's GitHub http://github.com/empatzero/xbmca10*

The development work on the coding side on this port to Allwinner's A10 SoC with CedarX hardware accelerated video decoding was all done by Gimli (a.k.a. huceke) and Empat0 (a.k.a. empat zero).


 * The used repository in the example below is however from a fork at http://github.com/rellla/xbmca10 which contains a few adaptions.

The result should be a debian/unstable(armhf) system with XBMC using CedarX.

Create SD-Card
Create a bootable SD-Card follwing FirstSteps and Debian. Be sure to use a kernel with mali-drivers-version r3p0 (sunxi-3.0 should be good).

Boot into Debian
Boot the new debian sid from the sdcard directly from the mele and bring the system up to date: root@mele:~/# apt-get update root@mele:~/# apt-get upgrade root@mele:~/# apt-get install git Create your workspace directory: root@mele:~/# mkdir melehacking root@mele:~/# cd melehacking

Install dependencies and do some modifications
root@mele:~/melehacking# git clone git://github.com/rellla/xbmca10.git root@mele:~/melehacking# git checkout stage/Frodo root@mele:~/melehacking# apt-get build-dep xbmc

this should install the following packages: autoconf automake autopoint autotools-dev binutils bsdmainutils build-essential bzip2 cmake cmake-data comerr-dev cpp cpp-4.4 cpp-4.6 curl debhelper dpkg-dev emacsen-common fontconfig-config g++ g++-4.4 g++-4.6 gawk gcc gcc-4.4 gcc-4.4-base gcc-4.6 gcc-4.6-base gettext gettext-base gperf groff-base html2text intltool-debian krb5-multidev libao-common libao-dev libao4 libarchive12 libasound2 libasound2-dev libasprintf0c2 libass-dev libass4 libasyncns0 libavahi-client-dev libavahi-client3 libavahi-common-data libavahi-common-dev libavahi-common3 libavcodec-dev libavcodec53 libavfilter-dev libavfilter2 libavformat-dev libavformat53 libavutil-dev libavutil51 libbluetooth-dev libbluetooth3 libbluray-dev libbluray1 libboost-date-time1.49-dev libboost-date-time1.49.0 libboost-dev libboost-serialization1.49-dev libboost-serialization1.49.0 libboost-thread-dev libboost-thread1.49-dev libboost-thread1.49.0 libboost1.49-dev libbz2-dev libc-dev-bin libc6-dev libcaca-dev libcaca0 libcdio-dev libcdio13 libcec-dev libcec1 libcroco3 libcurl3 libcurl4-gnutls-dev libcwiid-dev libcwiid1 libdbus-1-3 libdbus-1-dev libdirac-encoder0 libdirectfb-1.2-9 libdirectfb-dev libdirectfb-extra libdpkg-perl libdrm-dev libdrm-nouveau1a libdrm-omap1 libdrm-radeon1 libdrm2 libegl1-mesa libegl1-mesa-dev libegl1-mesa-drivers libelf1 libenca-dev libenca0 libexpat1-dev libflac-dev libflac8 libfontconfig1 libfontconfig1-dev libfreetype6 libfreetype6-dev libfribidi-dev libfribidi0 libgbm1 libgcrypt11-dev libgettextpo0 libgl1-mesa-dev libgl1-mesa-glx libglapi-mesa libgles2-mesa libgles2-mesa-dev libglew-dev libglew1.7 libglib2.0-bin libglib2.0-dev libglu1-mesa libglu1-mesa-dev libgmp10 libgnutls-dev libgnutls-openssl27 libgnutlsxx27 libgomp1 libgpg-error-dev libgsm1 libgssrpc4 libhal-dev libhal-storage-dev libhal-storage1 libhal1 libice-dev libice6 libicu48 libidn11-dev libiso9660-8 libiso9660-dev libjasper-dev libjasper1 libjbig-dev libjbig0 libjpeg8 libjpeg8-dev libjson0 libkadm5clnt-mit8 libkadm5srv-mit8 libkdb5-6 libkms1 libkrb5-dev liblcms1 libldap2-dev libltdl-dev libltdl7 liblzo2-2 liblzo2-dev libmad0 libmad0-dev libmicrohttpd-dev libmicrohttpd10 libmikmod2 libmikmod2-dev libmodplug-dev libmodplug1 libmp3lame-dev libmp3lame0 libmpc2 libmpeg2-4 libmpeg2-4-dev libmpfr4 libmysqlclient-dev libmysqlclient18 libnettle4 libnfs-dev libnfs1 libogg-dev libogg0 libomxil-bellagio-dev libomxil-bellagio0 libopencv-core2.3 libopencv-imgproc2.3 libopenjpeg2 libopenvg1-mesa liborc-0.4-0 libp11-kit-dev libpcre3-dev libpcrecpp0 libpipeline1 libplist-dev libplist1 libpng12-0 libpng12-dev libpopt0 libpostproc-dev libpostproc52 libpthread-stubs0 libpthread-stubs0-dev libpulse-dev libpulse-mainloop-glib0 libpulse0 libpython2.7 librtmp-dev libsamplerate0 libsamplerate0-dev libschroedinger-1.0-0 libsdl-image1.2 libsdl-image1.2-dev libsdl-mixer1.2 libsdl-mixer1.2-dev libsdl1.2-dev libsdl1.2debian libshairport-dev libshairport1 libsigsegv2 libslang2-dev libsm-dev libsm6 libsmbclient libsmbclient-dev libsndfile1 libspeex1 libsqlite3-0 libsqlite3-dev libssh2-1-dev libssl-dev libstdc++6-4.4-dev libstdc++6-4.6-dev libswscale-dev libswscale2 libtalloc2 libtasn1-3-dev libtdb1 libtheora0 libtiff4 libtiff4-dev libtiffxx0c2 libtimedate-perl libtinyxml-dev libtinyxml2.6.2 libtool libts-0.0-0 libts-dev libudev-dev libunistring0 libva-dev libva-egl1 libva-glx1 libva-tpi1 libva-x11-1 libva1 libvdpau-dev libvdpau1 libvorbis-dev libvorbis0a libvorbisenc2 libvorbisfile3 libvpx1 libwayland0 libwbclient0 libwebp-dev libwebp2 libx11-dev libx11-xcb-dev libx11-xcb1 libx264-123 libxau-dev libxcb-dri2-0 libxcb-glx0 libxcb-glx0-dev libxcb-render0 libxcb-shape0 libxcb-xfixes0 libxcb1-dev libxdamage-dev libxdamage1 libxdmcp-dev libxext-dev libxfixes-dev libxfixes3 libxi6 libxml2-dev libxmlrpc-core-c3 libxmu-dev libxmu-headers libxmu6 libxrandr-dev libxrandr2 libxrender-dev libxrender1 libxt-dev libxt6 libxtst6 libxvidcore4 libxxf86vm-dev libxxf86vm1 libyajl-dev libyajl2 linux-libc-dev m4 make man-db mesa-common-dev mysql-common patch pkg-config po-debconf python python-dev python-imaging python-minimal python-support python2.7 python2.7-dev python2.7-minimal tsconf ttf-dejavu-core ucf x11-common x11proto-core-dev x11proto-damage-dev x11proto-dri2-dev x11proto-fixes-dev x11proto-gl-dev x11proto-input-dev x11proto-kb-dev x11proto-randr-dev x11proto-render-dev x11proto-xext-dev x11proto-xf86vidmode-dev xorg-sgml-doctools xtrans-dev yasm zip zlib1g-dev

need to install 3 more dependencies: root@mele:~/melehacking# apt-get install swig default-jre cmake libgtk2.0-bin libssh-4 libssh-dev

and remove all EGL/GLES-stuff to avoid conflicts root@mele:~/melehacking# apt-get remove libegl1-mesa libegl1-mesa-dev libegl1-mesa-drivers libgles2-mesa libgles2-mesa-dev

and create an swap-file, because otherwise the compiler runs out of memory during compiling and aborts root@mele:~/melehacking# dd if=/dev/zero of=/swap bs=1M count=384 root@mele:~/melehacking# mkswap -c /swap root@mele:~/melehacking# swapon /swap

Start copying cedarx, gles libs etc.
The following external libs/ repos are used/ downloaded:
 * taglib: https://github.com/downloads/taglib/taglib/taglib-1.8.tar.gz
 * cedarx: https://github.com/linux-sunxi/cedarx-libs/tree/master/libcedarv/linux-armhf
 * libmad: ftp://ftp.mars.org/pub/mpeg/libmad-0.15.1b.tar.gz
 * mali: https://github.com/linux-sunxi/sunxi-mali-proprietary/tree/master/r3p0/armhf
 * mali-dev: https://github.com/linux-sunxi/sunxi-mali/tree/master/include

root@mele:~/melehacking# cd xbmca10/tools/a10/depends root@mele:~/melehacking/xbmca10/tools/a10/depends# make

Compile xbmc and install it
root@mele:/allwinner/xbmc-pvr-bin/lib/xbmc# echo -e "\nA10HWR=1" >> /etc/environment root@mele:~/melehacking/xbmca10/tools/a10/depends# make -C xbmc root@mele:~/melehacking/xbmca10/tools/a10/depends# cd ../../../ root@mele:~/melehacking/xbmca10# make install

Create Debian package
root@mele:~/melehacking/xbmca10/tools/a10/depends# cd package root@mele:~/melehacking/xbmca10/tools/a10/depends/package# make I did not try to do a "dpkg -i", but i think, in my case (debian/unstable) DEBIAN/control has to be reworked to make it install without any dependency problems.

Start xbmc
After a reboot you modprobe the needed modules: root@mele:~/# modprobe disp root@mele:~/# modprobe lcd root@mele:~/# modprobe hdmi root@mele:~/# modprobe mali root@mele:~/# export A10HWR=1 (if A10HWR isn't set already) root@mele:~/# cd /allwinner/xbmc-pvr-bin/lib/xbmc root@mele:/allwinner/xbmc-pvr-bin/lib/xbmc# ./xbmc.bin

Some hints:

 * If you get a compiler error when processing h264.o or building xbmc.bin, then check, if swap is enabled. The compiler ran out of memory!
 * If deb-building fails, check, if your tmp-directory has enough free space and is no tmpfs, because of the lack of memory an mele.
 * To use the bash-script bin/xbmc to start xbmc, you have to comment out the exec of FEH.py, because of a failing test of glxinfo -> no display found.

Cross Compile of XBMC
This was tested with the github.com/empatzero/xbmca10 and built in Linux Mint. You will need several packages on the build system and a copy of the root file system of the target to build against. This assumes you are running off an SD card with the root file system in /dev/sdb2

Prepare Root File System
git clone git://github.com/empatzero/xbmca10.git sudo dd if=/dev/sdb2 of=rootfs_xbmc.img sudo mount -o loop rootfs_xbmc.img /mnt/rootfs-a10 sudo ln -s /mnt/rootfs-a10/lib/arm-linux-gnueabihf /lib/arm-linux-gnueabihf sudo ln -s /mnt/rootfs-a10/usr/lib/arm-linux-gnueabihf /usr/lib/arm-linux-gnueabihf sudo ln -s /mnt/rootfs-a10/usr/include/arm-linux-gnueabihf /usr/include/arm-linux-gnueabihf
 * 1) Checkout xbmc
 * 1) Follow all steps for a native build EXCEPT the git clone should be done on the build system.  Stop at swap file creation.
 * 2) Sync and move SD card to build system
 * 3) Create an image of the file system
 * 1) Mount the image
 * 1) Create symlinks to the mounted libraries

Update XBMC build config
Update this section at line 48 of tools/a10/depends/depends.mk with your values #where is your arm rootfs SDKSTAGE=/mnt/rootfs-a10 #where is your xbmc install root XBMCPREFIX=/allwinner/xbmc-pvr-bin$(HF) #where is your toolchain TOOLCHAIN=/usr/arm-linux-gnueabi$(HF)

Setup Cross Compiler
apt-get install cmake shtool swig autoconf autotools-dev automake libtool default-jre gawk gperf zip g++-4.6-arm-linux-gnueabihf autopoint (maybe not complete listing)
 * 1) Install packages (build system) g++-arm-linux-gnueabihf or  g++-4.6-arm-linux-gnueabihf should work
 * 1) You may gave to set all symlinks to version files (gcc -> gcc-4.6 etc...)

Build
root@mint:~/melehacking/xbmca10/tools/a10/depends# make root@mint:~/melehacking/xbmca10/tools/a10/depends# make -C xbmc root@mint:~/melehacking/xbmca10/tools/a10/depends# cd ../../../ root@mint:~/melehacking/xbmca10# make root@mint:~/melehacking/xbmca10/tools/a10/depends# cd ../../../ root@mint:~/melehacking/xbmca10# make install root@mint:~/melehacking/xbmca10/cp -r /allwinner/xbmc-pvr-binhf /dev/sdb2/allwinner/xbmc-pvr-binhf
 * 1) At this point the settings are basically the same for the native build
 * 1) Do not run this again, if your compilation fails, after correcting run make from the xbmc root like this...
 * 1) And finally to install
 * 1) You should copy from your install location on your build system to an identical location on the target system (may not vital that they have the same path) like so...

Start xbmc
Run as for a native build. After a reboot you modprobe the needed modules: root@mele:~/# modprobe disp root@mele:~/# modprobe lcd root@mele:~/# modprobe hdmi root@mele:~/# modprobe mali root@mele:~/# export A10HWR=1 (if A10HWR isn't set already) root@mele:~/# cd /allwinner/xbmc-pvr-bin/lib/xbmc root@mele:/allwinner/xbmc-pvr-bin/lib/xbmc# ./xbmc.bin

Troubleshooting
ln -s usr/include/dbus1.0/dbus usr/include/dbus
 * 1) Depending on your setup you may have to change some things to build
 * 2) If mysql_config is not found, even though it is clearly there you can set disable-mysql in Makefile under xbmca10/tools/a10/depends/xbmc
 * 3) Header files might not be where they are expected, this can be fixed with symlinks and copying headers, for example...
 * 1) Check the discussion section for more notes.

= Configuring XBMC dependencies for Linux on A10 based devices =

Getting IR (infrared) remotes working on A10 based media players
For getting IR (infrared) remote controls working on the A10 based media players, please see the LIRC (Linux Infrared Remote Control) for the IR receivers and and remotes article in this wiki. Place a suitable Lircmap.xml in userdata-directory.

Configure DPMS if needed
You might suffer from your screen turning black after a certain amount of time. If this is the case, verify if that is because of the DPMS.

First test if DPMS is involved by connecting to your shell or console and type :

DISPLAY=:0 xset dpms force on

If the screen turns back ON then you need to prevent DPMS from trying to save energy by turning of your monitor, so follow the instructions below.

DPMS settings are found in the /etc/X11/xorg.conf file. Add to this file :

Then restart and your screen should not turn black because of DPMS anymore.

= Enabling dirty regions (a.k.a. dirty textures) for XBMC = This dirty region (a.k.a. dirty texture) feature in XBMC is designed to improve XBMC's GUI renderer performance on the GPU by only drawing when something like a texture changes on the screen, that region is then marked as dirty by XBMC's GUI library and only that region is redraw region on the screen.

This feature is however still a little buggy and therefor not enabled by default in XBMC, but all users of XBMC on A10 based devices can try enabling the hidden "dirty regions" (a.k.a. "dirty textures") rendering feature advanced setting themselves manually.


 * http://wiki.xbmc.org/index.php?title=HOW-TO:Enable_dirty_regions
 * http://xbmc.org/theuni/2011/06/19/working-with-dirty-regions/
 * http://wiki.xbmc.org/index.php?title=Advancedsettings.xml#.3Calgorithmdirtyregions.3E

Dirty regions are any parts of the screen that have changed since the last frame. By not re-rendering what hasn't changed, big speed gains can be seen. Because all GPUs work differently, only Mode 3, combined with nofliptimeout=0, is guaranteed to be safe for everyone, but current timing issues with nofliptimeout keep this from being the default. Note that with "dirty regions" your system CPU usage might go up a little (because it is doing the dirty regions calculations) but your GPU usage will be much lower, and since it is the GPU and not CPU that is the bottleneck in XBMC for embedded systems your GUI performance will be better even though the CPU usage is higher.

To enable dirty regions manually you need to create a "advancedsettings.xml" text file youself and put the XML enabling tags in there and copying to your "/userdata/" folder (/home/username/.xbmc/userdata/).

Example:

You could also try to enable the feature but that is even more experimental so know that it can cause even more GUI rendering issues in XBMC

Example:

To have both of these enabled your "advancedsettings.xml" then the finished file should look something like this:

= Stuff left to do for capable C++ developers= This is an informal ToDo list for stuff to do to improve XBMC for Allwinner SoCs, and this list is meant for all capable C/C++ developers, both Allwinner employees as well as any other C/C++ programmer willing to volunteer help develop XBMC for Allwinner SoCs and submit any finished patches upstream to XBMC:

Fix X11 compilation
Running framebuffer version on Linaro with X11 server started leads to segfaults and unpredictable stuff. XBMC should also compile with X11 support using X11 mali libs, but right now we miss proper LDCONFIG - http://pastebin.com/zSdnkSh7

Fully utilize CedarX hardware acceleration of video, audio, and images

 * 1) Implement Allwinner's CedarX hardware engine decoding of JPEG and PNG (and other image / picture formats) decoding, as done by the XBMC for iOS and Sigma Designs ports, as this should noticeably increase the GUI speed/smoothness and image caching/thumbnailing performance immensely. Contact XBMC team developers TheUni and Davilla about how this is done in XBMC for iOS and Sigma Designs ports.
 * 2) Help to improve cedarx by testing and reporting issues or working files/codecs -> CedarXVideoRenderingChart

Improve XBMC for Allwinner A10 ARM SoC with ARMv7 (Cortex-A8) CPU

 * 1) Build XBMC on ARM HardFB (Hard Floating Point), a.k.a. armhfp for the Allwinner A10's SoC VFPv3 - Vector Floating Point (VFP) v3 engine, on top of a Linux distribution with hard float support, for more information see http://www.madeo.co.uk/?p=851
 * 2) MathUtils doesn't build correctly with the native ARM code already in XBMC (probably scratchbox toolchain issue). Notice that sometimes when launching XBMC we get some assert on MathUtils, unclear if it's related or not.
 * 3) Get the Allwinner A10 SoC integrated HDMI CEC (Consumer Electronics Control) to work with the libcec and thus also work with XBMC, see => HDMI CEC (Consumer Electronics Control)

Improve XBMC rendering for Mali 400 GPU

 * 1) Possible try to make XBMC run with DirectFB 2D / 3D graphics engine drivers or a other direct frame buffer support method, to run XBMC without X, (as currently XBMC on Allwinner A10 requires X since it runs over EGL with X backend). This will at least depend on latest DirectFB/Mesa, for more information see https://github.com/xbmc/xbmc/pull/454

Improve XBMC for embedded platforms like Allwinner A10

 * 1) Currently builds for Allwinner A10 using a hack to disable eglCreateContext that graphics library driver does not like, so that needs to be sorted out.
 * 2) Implement the GPU backoff algorithm when playing a video. Since the video is rendering directly via a video overlay, no need for tens of fps for GPU in that time since it might only be used for subtitles. Instead of running tens of fps, lower the fps of the gpu and thus keep more DDR bandwidth for the video engine so higher bitrate content can be played.
 * 3) When playing in 1080p, LCD refreshes the graphics overlay by 1920x1080x60hzx32bpp = ~500MB/sec. While playing the graphics overlay is either 100% transparent, or there are subtitles in the bottom of the screen. Implement a hardware mechanism that checks graphics overlay every one second; and by partitioning it and crc32 (by hardware engine) each part adjust the starting and ending point of the graphics overlay. This should drastically lower the LCD graphics overlay refresh.
 * 4) Assert failures at the beginning when running XBMC. Similar to the item mentioned in XBMC forums here => http://forum.xbmc.org/showthread.php?t=81122
 * 5) * Add an optional auto video out resolution select mode, with the ability to run a split display resolution for GUI and video playback on embedded platforms. On the GUI go for 720p since the graphics is best (images are 720p optimized and fps is faster - more smooth). When playing back switch to either 1080p or to the native resolution of the content with it's corresponding refresh rate, adding the ability to run a split gui/display resolution for embedded platforms, see => https://github.com/xbmc/xbmc/pull/1467
 * 6) Disable Xorg screen blanking when playing a movie.

Improve FFmpeg build toolchain for Allwinner A10

 * 1) Build FFmpeg libraries for XBMC with NEON (Advanced SIMD instruction set) and VFPv3 / VFPv4 (Vector Floating Point) extension support for ARM Cortex-A8 and Cortex-A5 processors and Linux kernel that supports the use of NEON and Vector Floating Point Unit co-processors. However this needs to be fixed as soon as possible in the future as it will increase FFmpeg performance by using Dove vector operations when the audio and/or video codec is not supported by the video engine and instead raw CPU decoding power is required.

Improve XBMC audio output on Allwinner A10

 * 1) asound.conf is not good enough. there are some noises in 44.1KHz and others.

Generic and GStreamer

 * 1) Check to if Rob Clark from Intel's OpenEmbedded project has any other relevant to GStreamer, EGL, ARM, etc. patches in this XBMC fork on GitHub => https://github.com/robclark/xbmc/tree/gstreamer-eglimg

=References=

= See also =
 * CedarX - Library for Allwinner A10 VPU (Video Processor Unit) used for audio and video decoding and encoding hardware off-loading.
 * CedarXVideoRenderingChart - Overview chart of working/ non working video files
 * OpenMAX - Open standard API for cross-platform hardware acceleration of audio, image, and video decoding
 * GStreamer - Cross-platform API and ABI for hardware acceleration of audio, image, and video decoding
 * Stagefright - Google's API for hardware acceleration of audio, image, and video decoding on Android
 * FFmpeg - open source software project that produces libraries and programs for handling multimedia data
 * HDMI CEC (Consumer Electronics Control) - Developers page for development of HDMI-CEC support on Allwinner A10 SoC based devices.
 * LIRC (Linux Infrared Remote Control) for the IR receivers and and remotes
 * Tvheadend TV Tuner Server and PVR backend

=External Links=
 * XBMC Official Community Forum discussion about porting to Allwinner A10
 * Jas Hacks Hackberry A10 - XBMC on Ubuntu 12.10 image
 * Buildroot XBMC on the Mele A1000 (Allwinner A10)
 * XBMC for Linux on AllWinner A10 Devices? It Works! (Sort of)