Work in progress: LiveTV for XBMC on Android

Post Reply
Nuems
Posts: 134
Joined: Thu Sep 19, 2013 3:50 am
languages_spoken: english, german
ODROIDs: xu, c1
Has thanked: 0
Been thanked: 2 times
Contact:

Work in progress: LiveTV for XBMC on Android

Unread post by Nuems » Fri Aug 01, 2014 5:50 pm

Work in progress – LiveTV for XBMC on Android

In this thread, I'll desribe what I've been doing to get LiveTV in XBMC on my Odroid-XU running the official Android-4.4.2 image with a custom kernel. No extra machine as a PVR backend is required.
There are (at least) two reasons why I don't provide any images so far:
  • I don't have adequate webspace. It's either fast, but too small or unlimited but too slow :(
  • The variety of DVB hardware and variants (DVB-T(2)/DVB-S(2)/DVB-C) as well as the different services available depending on the region you live in make it virtually impossible to create something that would work out-of-the-box for just anyone.
Please note that this should be considered work in progress, so there's no guarantee for anything.
Also make sure that you know how to re-flash your emmc and micro-sdcard in case anything goes wrong. If you don't know how to do that, don't proceed any further. You've been warned!
If you already have a PVR backend for XBMC up and running on another machine and you're happy with your setup, you can stop reading now. This is about running Android, XBMC and VDR [7] on just one Odroid-XU.

Disambiguation: In this post “PVR” refers to a TV-backend for XBMC. It has nothing to do with the gpu on the Odroid-XU.

Don't get confused: If you decide to start your own experiments based on this post, make sure not to confuse the different terminals. Some commands have to be entered into Android's terminal emulator (or, if you're totally masochistic, over a serial connection to your Odroid-XU). Others need to be run in an ssh session that connects your PC with the Odroid-XU running Ubuntu either natively or in a chroot environment. And thirdly, there are a few things you'll do on your Linux PC (e.g. recompile the Android kernel).
With regard to the Android terminal, I'd like to point out that it might be more comfortable to install an SSH server app in Android, grant root permissions to the app and use it side-by-side with the aforementioned Linux ssh session instead of the Android terminal. Depending on where your devices are located, this may save you some running back and forth.

General idea
XBMC supports a number of PVR backends, however, by default there's no support for dvb in the Android images. And even if there was such support, AFAIK the available Linux PVR backends wouldn't run on Android directly. Therefore, a chroot environment is needed. There are various ways of achieving that – some apps provide such a Linux environment, you could use an Ubuntu image as described in [1] or you can use a Linux filesystem on a micro sdcard, which is what I've been doing. My way was mostly inspired by [2]. In this chroot environment, it's not too hard to get VDR to work as a TV server. The result is LiveTV including EPG in XBMC on Android. Recording is also possible in principle, but I haven't tested that yet in detail. All I can say right now is that slow micro sdcards are not optimal as targets for recordings – surprise, surprise...
BTW: While I'm writing this on my PC, LiveTV is running on my Odroid-XU in the background, so it's not just theory!
And please: Read everything before doing anything. I've spend quite a bit of time on my experiments and some more on writing this. I don't think I'll react too gracefully on questions that could be answered by reading this or the links at the end of this post. But of course I will try to remove errors or provide clarification where needed.
Most importantly: If you already have an Android installation with your favourite apps and tweaks on your emmc module, you should definitely make a full backup with dd or a similar tool. If you don't do it, don't blame me if you lose your precious installation and your data – there's a chance your system won't boot and needs to be recovered if anything goes wrong with the custom kernel.

What you need
  • an Odroid-XU (other Odroids might work, too, but keep in mind that DVB-MPEG2-streams will be decoded in software – at least in XBMC/Android. Furthermore, I don't have other Odroid boards, so I can't test)
  • Android 4.4.2 with XBMC on emmc (other Android versions should also work, but I haven't tested that)
  • a micro sd card
  • a USB DVB receiver (other standards might be possible, but I've only tried dvb-t)
  • a Linux PC (or a VM) to recompile the Android kernel. It's also useful for doing a few things via ssh.
  • The serial-to-usb dongle for your Odroid-XU is optional, however, if you run into problems booting your custom kernel, you'll have a very hard time finding the cause if you don't have that piece of hardware.
Step-by-step
Install Android on emmc. Download the latest stable XBMC from [3] and install it. At the time of writing, that's Gotham 13.1.

Install Ubuntu on a micro sdcard. [2] describes a Debian chroot and several ideas in the following description were taken from that source. However, when I tried using the resulting Debian rootfs for this pupose, I ran into some VDR related problems later, so I decided to take Catalinii's Ubuntu image as a convenient starting point. In order to avoid misunderstandings, I'd like to point out explicitly that the extras in this Ubuntu image (XBMC, libhybris etc.) are unnecessary for the purposes of this how-to. On the other hand, it would be easier to enable LiveTV for XBMC on Linux than doing it on Android. If you understand this guide, you should be able to do so on your own. If not, you'll have to wait. One thing at a time...
Put the image on a micro sdcard, set the dip switch on your Odroid-XU to boot from micro sdcard, apply power (watch output on serial console if available) and login as “root“ via ssh (password odroid) - there's no console output on hdmi! Also note that this image doesn't support the USB3 gigabit dongle sold by Hardkernel, so you need to use the built-in network port (temporarily).
Then follow the instructions in Catalinii's post regarding ssh/keys. It's also a good idea to change the root password (but then make sure to use it in the following instead of “odroid”).

Run “apt-get update“ and “apt-get upgrade“ before you install anything. If you want to install additional packages, this is a good time to do so. I'd like to have nano as an editor as well as mc for file management and (although that's pretty stupid), you'll definitely need dos2unix. You shouldn't forget to set your timezone correctly either. If not, the EPG in XBMC won't be displayed correctly.
When you're sure that Ubuntu runs the way you want it to (apart from dvb and VDR), shut it down for the moment:

Code: Select all

shutdown -hP now
and set the dip switch to boot from emmc - we'll boot into Android from now on.

Recompile kernel
As mentioned above, a custom kernel is needed. My kernel is based on the default Android configuration, however, I've enabled the dvb modules I need for my hardware (plus some modules which I actually don't need, but I wasn't sure at configuration time ;) ). A rather simple way to find out about the necessary modules is this:
Run "lsmod" on a Linux PC. Then connect your usb dvb receiver and run "lsmod" again. Provided that the hardware is supported, you should see a few new modules in lsmod's output. It's a good idea to write them down/copy the output into a text file/... You should also run “dmesg” and look for lines regarding dvb firmware. Even if the necessary file hasn't been found, you should be able to find out the name of the file you need. For questions on Linux hardware support, visit [4] – especially if you haven't bought a receiver yet. There are some receivers that aren't supported in kernel 3.4 and while you might be able to build the necessary modules with newer sources from LinuxTV.org, it would definitely mean some more work.
While your dvb receiver is connected to your PC, also have a look at /dev/dvb (assuming that your hardware was recognized and properly set up):

Code: Select all

ls -lR /dev/dvb
You should see something like this:

Code: Select all

root@Beagleboard:~# ls -lR /dev/dvb
/dev/dvb:
insgesamt 0
drwxr-xr-x 2 root root 120 Aug  1 10:43 adapter0

/dev/dvb/adapter0:
insgesamt 0
crw-rw---T 1 root video 212, 0 Aug  1 10:43 demux0
crw-rw---T 1 root video 212, 1 Aug  1 10:43 dvr0
crw-rw---T 1 root video 212, 3 Aug  1 10:43 frontend0
crw-rw---T 1 root video 212, 2 Aug  1 10:43 net0
Write the output down or copy it into a file – you'll need it later. A possible problem (in my experience) is that the minor device numbers vary between kernel versions and/or distros - in my case 0,1,3,2 on Debian7/kernel 3.7 vs. 4 5,3,7 on Ubuntu14.04/kernel 3.4.5. You might have to poke around a little bit.

Follow the instructions on how to build an Android kernel on a Linux PC and how to install it on the Odroid-XU: [5], [6], but before you run “make”, you'll have to enable the necessary dvb modules. In order to do so, run “make menuconfig” and enable dvb support in general as well as the modules for your hardware. You'll find the respective options in the section Device Drivers/Multimedia Support. I've attached my configuration as a reference. Compile and install the Android kernel and modules, then make sure that your Odroid-XU can properly boot Android with this new kernel. If your kernel doesn't boot, try being systematic about finding the error. Here are a few things I'd try:
  • Make sure that you've properly copied and installed/flashed the modules and zImage – cf. [5], [6]
  • Are there any useful hints in the Odroid-XU's serial output?
  • Recover Android.
  • Go back to the kernel's Android default configuration and enable options one by one (i.e. recompile in between). A working installation of ccache on your Linux PC might come in handy at this point.
  • Run make without -j[3|4|5|...|n] because parallel threads and their respective output might make it less clear where an error occurs.
If none of this helps, Google is a much better friend for you than I could ever be – I'm not an expert kernel hacker, I just know how to run “make ARCH=arm odroidxu_android_defconfig && make menuconfig”. As a general rule for dealing with the configuration dialogue, don't touch anything you are not sure about.

Copy modules and script to Ubuntu rootfs
The modules are also necessary in the Ubuntu filesystem. Therefore insert the micro sdcard into your PC. I've written a little script to copy the modules to the right places. Make sure that the path to the micro sdcard (here: /media/rootfs) and the kernel version string (here: 3.4.5-dvb) are correct. The script is supposed to be run from the root of your kernel sources (e.g. ~/linux-odroidxu-3.4.y)

cp_modules.sh

Code: Select all

#!/bin/sh

for i in $(find ./ -name "*.ko"); do
	module_dir=$(echo $(dirname $i)|cut -d "/" -f2-)
	[ -d /media/rootfs/lib/modules/3.4.5-dvb/kernel/${module_dir} ] || mkdir -p /media/rootfs/lib/modules/3.4.5-dvb/kernel/${module_dir}
	cp $i /media/rootfs/lib/modules/3.4.5-dvb/kernel/${module_dir}
done
cp ./modules.* /media/rootfs/lib/modules/3.4.5-dvb
As mentioned above, dvb hardware usually requires a firmware file. Copy the respective file(s) to <path-to-micro-sdcard/partition-2>/lib/firmware. Later, we'll copy it into the Android filesystem.

In order to set up the necessary environment for the Linux programs in the chroot environment, here's a script:
chroot_start

Code: Select all

!/bin/sh 
# 
# Script called by sh/busybox from OUTSIDE the chroot-enviroment - no normal init script! 
# Based on example from http://evilzone.org/android/debian-on-android/ 

export PATH=/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:$PATH 
export TERM=linux 
export HOME=/root 
export USER=root 
mkdir -p /dev/pts 
mount -t devpts devpts /dev/pts 
mount -t proc proc /proc 
mount -t sysfs sysfs /sys 
[ -h /dev/fd ] || ln -s /proc/self/fd /dev/fd 

# Create DVB devices – edit and remove leading “#”
#[ -d /dev/dvb/adapter0 ] || mkdir -p /dev/dvb/adapter0 
#[ -c /dev/dvb/adapter0/demux0 ] || mknod -m 666 /dev/dvb/adapter0/demux0 c 212 4 
#[ -c /dev/dvb/adapter0/dvr0 ] || mknod -m 666 /dev/dvb/adapter0/dvr0 c 212 5 
#[ -c /dev/dvb/adapter0/frontend0 ] || mknod -m 666 /dev/dvb/adapter0/frontend0 c 212 3 
#[ -c /dev/dvb/adapter0/net0 ] || mknod -m 666 /dev/dvb/adapter0/net0 c 212 7 
#chmod 777 /dev/dvb 
#chmod 777 /dev/dvb/adapter0 
#chmod 666 /dev/dvb/adapter0/* 

# cf. Odroid Magazine 1/2014
# fix some issues with up-start 
dpkg-divert --local --rename --add /sbin/initctl > /dev/null 2>&1 
ln -s /bin/true /sbin/initctl > /dev/null 2>&1 
# This doesn't work here – we're not using bash yet, are we?
# create /etc/mtab file with the mounted filesystems 
#grep -Ev “rootfs|tmpfs|cgroup|mmcblk|usbfs|asec|storage|media_rw” /proc/mounts | sort -r | uniq > /etc/mtab 

# load DVB modules – edit and remove leading “#”
#modprobe dvb-usb-dib0700 
# Start VDR
#/etc/init.d/vdr start 

# Start ssh 
/etc/init.d/ssh start
Copy it to <path-to-micro-sdcard/partition-2>/etc/init.d.
There are two other scripts that you should you should copy to the sdcard now because that facilitates transferring them to/using them in Android later:

my-chroot-start.sh:

Code: Select all

#!/system/bin/sh
[ -d /storage/sdcard0/Ubuntu ] || mkdir /storage/sdcard0/Ubuntu
# Mount Ubuntu partitions - mind the trailing “\”!
[ -d /storage/sdcard0/Ubuntu/bin ] || \
 mount -rw -t ext4 -o noatime /dev/block/vold/179:10 /storage/sdcard0/Ubuntu && \
 mount -o bind /mnt/media_rw/sdcard1 /storage/sdcard0/Ubuntu/media/boot
# Mount bind devices:
mount -o bind /dev /storage/sdcard0/Ubuntu/dev
cd /storage/sdcard0/Ubuntu
# cf. Odroid Magazine 1/2014:
busybox sysctl -w net.ipv4.ip_forward=1
busybox chroot /storage/sdcard0/Ubuntu /etc/init.d/chroot_start
unchroot.sh:

Code: Select all

#!/system/bin/sh
rmmod dvb_usb_dib0700
for module in $(lsmod|cut -d " " -f1|grep dib); do
	rmmod ${module}
done
rmmod dvb_usb
rmmod dvb_core
rm -R /dev/dvb
umount /storage/sdcard0/Ubuntu/sys
umount /storage/sdcard0/Ubuntu/proc
umount /storage/sdcard0/Ubuntu/dev/pts
umount /storage/sdcard0/Ubuntu/dev
umount /storage/sdcard0/Ubuntu/media/boot
umount /storage/sdcard0/Ubuntu
Copy them <path-to-micro-sdcard/partition-1>

First start of chroot environment
Unmount the micro sdcard on the PC and insert it into the Odroid-XU. Android will mount the first partition as an external sdcard because it's FAT32-formatted. This wouldn't be optimal if we wanted to use the sdcard regularly as a Linux boot medium, but from here on, this shouldn't be much of a problem. A Linux boot from micro sdcard might only be necessary for administration or maintenance purposes (but then again, it might come in handy if you want to check your Android filesystems on emmc). As long as the normal odroidxu.fstab is used, Android will not automount the ext4 partition containing the Ubuntu rootfs which is just the way we want it.

In Android, open a terminal and become root by typing “su”. Then run “/storage/sdcard1/my-chroot.sh” (Later, you may copy the script to a different location, but as you might want to edit it, the sdcard's FAT32-partition is a good place for now.)
This script will prepare the environment and call the script previously copied to <path-to-micro-sdcard/partition-2>/etc/init.d from its new path: /storage/sdcard0/Ubuntu/etc/init.d/chroot_start. As a result, you'll have an ssh server running in your chroot environment.

Chroot login
While you could do this with an ssh client app such as ConnectBot directly on Android, it might be more comfortable to use a PC for the next steps:
Log into the chroot environment via ssh as root, password odroid (unless you've already changed it). Prior to installing and running vdr, you have to run “depmod -a” to make sure that the modules will be loaded properly.

Before you proceed, you should consider the following:
The default way of making XBMC and VDR cooperate is the vnsiserver plugin [8] for VDR and the respective PVR addon for XBMC. When I run VDR on another machine, this works like a charm with XBMC on Android. The advantages of this solution are HD compatibilty, rather short channel switching times and perfect integration of recordings and timers. However, at least my very preliminary tests with a vnsiserver setup in a chroot environment weren't very successful (choppy video, fairly high cpu load, XBMC becomes unresponsive or even makes the entire system crash). While this might be just a configuration problem involving timeshift settings (still investigating...), another aspect of vnsiserver can't be overcome by simply editing conf files: It's intended as a PVR backend for XBMC – meaning that there's no easy way for other clients to connect to the live stream. Yet another aspect to consider is that this VDR plugin is not available from the official Ubuntu repositories, although compiling it is pretty easy [8].
At the moment, the slightly less elegant solution with vdr's streamdev-server plugin has the advantage of fluent (SD) video, considerably lower cpu load and higher stability. In addition, the streams can be accessed by all sorts of clients on your LAN (e.g. VLC on any platform, mplayer on Linux, MXPlayer on Android devices that can't run XBMC etc.). Furthermore, everything can be installed from the Ubuntu repositories, so no compilation is needed. The downsides are less perfect integration of recordings and fairly long channel switching times. Another thing is that for creating timers, an additional Android app [9] and/or additional VDR-related software are needed [10]. What's probably worst, however , is that AFAIK streamdev doesn't support HD – correct me if I'm wrong, I don't have any way of testing that.
On the XBMC side, you've got the choice between the “IPTV Simple PVR” addon[11] or using streamdev's VTP-protocol for integrating it as a video source. This latter solution comes at the cost of not having an EPG, but it can be done very quickly: Add "vtp://127.0.0.1:2004" as a video source. XBMC automatically recognizes VDR/streamdev and will offer your live channels without further ado.
According to the XBMC wiki, the IPTV simple addon can't be run alongside other activated PVR addons. Similarly, although you can install both VDR plugins simultaneously, you shouldn't run them in parallel. The easiest way to do so is to disable one of them via /etc/vdr/plugins/order.conf. So make up your mind.

a) streamdev (currently recommended)
In your ssh session, run:

Code: Select all

apt-get install vdr vdr-plugin-streamdev-server
If you want allow other computers on your LAN to access live tv streams, you'll have to edit /etc/vdr/plugins/streamdevhosts.conf
In order to make LiveTV and EPG work in XBMC, another script is needed. It converts VDR's channel list and epg data to extm3u and xmltv formats as needed by the XBMC addon. It's a bit clumsy right now because I quickly derived it from another script doing a roughly similar job – feel free to post a better version!

mk_epg_vdr2:

Code: Select all

#!/bin/sh
#
# Convert VDR's epg.data and channels into an xmltv formatted epg and an EXTM3U file
# for use with streamdev in conjunction with XBMC's "Simple IPTV" PVR addon

write_epg()
{
	while read akt_line; do
		type_of_line=${akt_line:0:1}
		case ${type_of_line} in
			C)
				# Set channel name and id
				this_id=$(echo ${akt_line}|cut -d " " -f2)
				this_chan=$(echo ${akt_line}|cut -d " " -f3-)
				echo "Reading epg data for ${this_chan} now..."
			;;
			c)
				# Channel done
				echo "${this_chan} done."
				this_chan=""
				this_id=""
			;;
			E)
				# New epg entry - reset ${title}, ${episode} and ${description}
				title=""
				episode=""
				description=""
				unix_time=$(echo ${akt_line}|cut -d " " -f3)
				epg_start_time=$(date -d @${unix_time} +%Y%m%d%H%M)
				duration=$(echo ${akt_line}|cut -d " " -f4)
				let epg_end_time=${unix_time}+${duration}
				epg_end_time=$(date -d @${epg_end_time} +%Y%m%d%H%M)
			;;
			e)
				# End of entry - write epg information
				# EOF doesn't like tabs
cat << EOF >> /var/tmp/programmes.tmp
  <programme start="${epg_start_time}" stop="${epg_end_time}" channel="${this_id}">
   <title lang="de">${title}</title>
    <desc lang="de">
     ${episode}
     ${description}
    </desc>
  </programme>
EOF
			;;
			T)
				# title
				title=$(echo ${akt_line}|cut -d " " -f2-)
			;;
			S)
				# episode
				episode=$(echo ${akt_line}|cut -d " " -f2-)
			;;
			D)
				# description
				description=$(echo ${akt_line}|cut -d " " -f2-)
			;;
			*)
				echo "Undefined"
			;;
		esac
	done < ${epg_file}
}

epg_filter()
{
	# As long as certain information from epg.data isn't used at all
	# it's best to discard it right away:
	cat ${epg_file}|grep -v "^X"|grep -v "^V"|grep -v "^G" >> /var/tmp/filtered_epg
	epg_file=/var/tmp/filtered_epg
}

channel_url()
{
	echo "${id_lines}"|head -n ${1}|tail -n1 >> /var/tmp/channels.m3u
}

channel_name()
{
	this_chan=$(echo "${chan_lines}"|head -n ${n}|tail -n 1|cut -d "," -f2|cut -d " " -f2-)
	this_id=$(echo "${id_lines}"|head -n ${n}|tail -n 1|cut -d "/" -f4)

	echo "#EXTINF:-1 tvg-id=\"${this_id}\" tvg-name=\"${this_chan}\" tvg-logo=\"${this_chan}.png\" group-title=\"Group 1\",${this_chan}" >> /var/tmp/channels.m3u
cat << EOF >> /var/tmp/epg.xml
  <channel id="${this_id}">
   <display-name lang="de">${this_chan}</display-name>
  </channel>
EOF
}

get_channels()
{
	wget -O /var/tmp/vdr.m3u ${dl_url}
	# Why, oh why:
	dos2unix /var/tmp/vdr.m3u
	chan_lines=$(cat /var/tmp/vdr.m3u|grep EXTINF)
	id_lines=$(cat /var/tmp/vdr.m3u|grep http)
}

clean_stage()
{
	[ -f /var/tmp/channels.m3u ] && rm /var/tmp/channels.m3u
	[ -f /var/tmp/epg.xml ] && rm /var/tmp/epg.xml
	[ -f /var/tmp/vdr.m3u ] && rm /var/tmp/vdr.m3u
	echo "#EXTM3U tvg-shift=0" > /var/tmp/channels.m3u
	echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" > /var/tmp/epg.xml
	echo " <tv>" >> /var/tmp/epg.xml
}

##############
# Main
##############
dl_url="http://127.0.0.1:3000/channels.m3u"
epg_file=/var/cache/vdr/epg.data
epg_lines=$(wc -l ${epg_file}|cut -d " " -f1)

clean_stage

get_channels
epg_filter

n=1
# no_of_channels: All or arbitrary limit:
no_of_channels=$(echo "${chan_lines}"|wc -l)
#no_of_channels=28
while [ ${n} -le ${no_of_channels} ]; do
	channel_name
	channel_url
	let n=${n}+1
done
write_epg

cat /var/tmp/programmes.tmp >> /var/tmp/epg.xml
echo " </tv>" >> /var/tmp/epg.xml

rm /var/tmp/programmes.tmp
rm /var/tmp/filtered_epg
rm /var/tmp/vdr.m3u
Copy that script to /usr/local/bin in the Ubuntu chroot and make sure it's executable.

b) vnsiserver (currently not recommended)
In your ssh session, run:

Code: Select all

apt-get install vdr vdr-dev
Then follow the instructions in [8] for compiling/installing the vnsiserver plugin for VDR. Once again, there's a conf file for allowing access over the network. Edit it according to your needs: /var/lib/vdr/plugins/vnsiserver/allowed_hosts.conf

a) and b)
VDR's init script is disabled by default in Ubuntu. Enabled it by editing /etc/default/vdr. You should also make sure that VDR is NOT allowed to shutdown the system. I'd expect unwanted behaviour when doing so from inside the chroot environment.
Now it's time to edit /etc/init.d/chroot_start. Adjust the lines concerning dvb modules and devices according to your previous findings, but don't remove the “#” in front of “/etc/init.d/vdr start” yet – VDR's first start will be done manually for safety's sake.
By now, you should have a new kernel + dvb modules, a couple of scripts and a vdr installation with at least one plugin. It's time to shutdown the chroot environment for the moment and then to start over. In your ssh session, run:

Code: Select all

/etc/init.d/ssh stop
exit
In the future, you shouldn't forget to run “/etc/init.d/vdr stop” before you try to shutdown the chroot environment. Failing to do so will prevent you from unmounting the micro sdcard's ext4 partition in the step after the next one.

This one time, you need to run a few commands in the Android terminal:

Code: Select all

mount -rw -o remount /dev/root
cp /storage/sdcard0/Ubuntu/lib/firmware/<your-dvb-firmware-file> /vendor/firmware
mount -r -o remount /dev/root
Author's confession: At the moment, I'm not sure whether the firmware file is loaded from the Android filesystem or from the Ubuntu one. Apparently, in one of the locations the file isn't necessary.

For the routine jobs, the last of the scripts listed above is used. In your Android terminal, run:

Code: Select all

/storage/sdcard1/unchroot.sh
Make sure that /storage/sdcard0/Ubuntu and everything below that has been unmounted properly. If not, do so manually. If nothing else helps, shutdown Android. Depending on what happened, running fsck on the micro sdcard might be a good idea.

Getting there...
Connect your usb receiver to the Odroid-XU. Once again, become root and run “/sdcard/storage1/my-chroot-start.sh” in your Android terminal. Apart from starting the Ubuntu ssh server, this time it will also create the dvb devices and load the dvb modules. Connect to the chroot environment via ssh as above and run (if an error occurs, don't proceed. Find the cause instead!):

Code: Select all

# Check modules:
lsmod
# You should see the modules for your usb receiver in the output
ls -lR /dev/dvb
# You should see a list of dvb devices with permissons 666
# Check whether you can derive a channels.conf from the examples in 
# /usr/share/vdr/channels.conf-examples or create one using the wscan utility
# (which you'd have to install from the Ubuntu repositories).
# Only proceed after putting a vaild channels.conf in /var/lib/vdr
/etc/init.d/vdr start
# You should see vdr's startup messages. However, sometimes they're deceptive. Run:
ps -A
# You should see vdr in the process list
# If not, check VDR's log in /tmp
If you use streamdev rather than vnsiserver, you'll have to wait a bit as it takes a few minutes until the EPG data is fully there. Because VDR only writes /var/cache/epg.data when the program is closed, you'll have to issue /etc/init.d/vdr restart before you can run “mk_epg_vdr2”. In the future, this won't be necessary as long as VDR runs rather regularly and keeps its epg.data up-to-date. The epg export itself needs to be automated, but I haven't done that yet. Fortunately, the epg data covers several days ;)
If everything is working, you can now automate VDR's start by removing the leading “#” in the respective line of /etc/init.d/chroot_start.
You should also edit /media/boot/unchroot.sh (aka /storage/sdcard1/unchroot.sh in Android) now so that the right modules will be unloaded and the right devices will be deleted.
Although it's not a must, it might be clever to test your Linux/VDR stuff for a last time before turning to the Android side of things. In your ssh session, run:

Code: Select all

/etc/init.d/vdr stop
/etc/init.d/ssh stop
exit
In your Android terminal, be(come) root and run:

Code: Select all

/storage/sdcard1/unchroot.sh
Once again: If there's an error, find its cause and remove it before proceeding.
Assuming that everything worked as expected, restart the whole chroot stuff including VDR:

Code: Select all

/storage/sdcard1/my-chroot-start.sh
This is what will be done from now on, but rest assured that there are more elegant ways of doing this than typing commands into an Android terminal. It's going to be fully living room compatible (see below).

Now it's time to start XBMC in Android. If you haven't done the initial setup yet, do it now. Then go to System/Settings/Addons and enable the PVR addon you need (VDR vnsiserver or IPTV Simple Client). Either of the addons has to be configured in the addon's dialogue. While the VNSI version is self explaining, for IPTV you'll have to point XBMC to the channels.m3u and epg.xml files created by mk_epg_vdr2. From XBMC's perspective, the path is /storage/sdcard0/Ubuntu/var/tmp/channels.m3u|epg.xml
Then enable LiveTV in System/Settings/LiveTV. For me it's been useful to disable the messages about lost connections – when you're experimenting quite a bit, they are rather annoying. For a proper look and feel, you should also provide channel logos in png format which are available on the internet for many channels. Note that that logos need to be named just like the channels they represent (e.g. the logo for “BBC World” must be called “BBC World.png”). In some cases, that creates problems of its own – I've got channel names with “/” and “*” in my list. If you don't like that, you'll have to edit mk_epg_vdr2 to make it churn out something that suits you better. Please don't forget to post your solution in this thread.
If you're planning to use AndroVDR (e.g. for setting timers), it'll be useful to know that XBMC and AndroVDR can share the same logo folder/files.
When using streamdev, you'll have to add VDR's recording folder to XBMC's Video file section just like any other video folder. If you want more comfort, have a look at [12].
Restart XBMC now. For reasons I have neither understood nor delved into yet, you'll probably have to re-enable your PVR addon on this restart. Fortunately, this has only happened to me whenever I've activated a PVR addon for the first time in an XBMC installation, or in other words: you won't have to do that every time you start XBMC.
There are a few options in XBMC that affect video quality. What's useful and what's not largely depends on the TV standard in your country and on your dvb version – obviously, interlaced DVB-T MPEG2 streams in SD (some channels/programmes anamorphic 16:9, others 4:3) are quite different from H264 1080p HD material. In case your TV signal comes with a framerate of 25 fps, the biggest single improvement can be made outside XBMC: Use the Odroid Utility app to change your display rate to 1080p@50Hz (or 720p@50Hz if you prefer that). In my experience, 60Hz and 25 fps video are not optimal. If your TV/monitor supports it, you might also try 25Hz by editing boot.ini accordingly but I've never done that. Changing the display settings might also require some adjustments of your TV/monitor settings.
When you're happy with your settings, make sure to shut down XBMC properly so that the settings will be saved. You could now edit/create an AdvancedSettings.xml for XBMC – e.g. for tweaking video cache settings [14].
If you like typing commands into the Android terminal, you can stop here. However, if you're not called Sheldon Cooper, you should consider installing “Script Manager” [13] in Android because this app can run scripts at boot time or at certain events. It also provides addons for clickable widgets so that you can start the chroot environment automatically or by clicking an icon.

In the long run (i.e. when you've finished tweaking the setup), there might be better places for my-chroot-start.sh and unchroot.sh than /storage/sdcard1 – in that location, they're prone to be deleted by accident. In order to prevent that and to make them accessible without having to type the full path, you might want to copy/move the two scripts to a folder included in $PATH such as /system/bin. If you want to do that, you'll temporarily have to make Android's root file system writable. In your Android terminal (as root) run:
mount -rw -o remount /dev/root

Don't forget to undo this as soon as you've copied the scripts to /system/bin:
mount -r -o remount /dev/root

Closing remarks:
If you use DVB-T, make sure your reception is good. Placing indoor antennas correctly sometimes feels like the 21st century equivalent of searching water with a divining rod. Nevertheless, this is the most important step for a good picture. A surprisingly simple but yet effective and as-cheap-as-it-gets/as-ugly-as-it-gets antenna is described here [15] – the page is in German, though.

That's it for the moment. Next, I'll try to fix the issue with vnsiserver. If it is what I suspect, you should hear from me shortly, however, if it's something else, it might well be beyond my abilities.

Sources / useful links:
[1] Odroid Magazine 1/2014 - http://magazine.odroid.com/assets/20140 ... 201401.pdf
[2] Debian chroot on Android from scratch - https://evilzone.org/android/debian-on-android/
[3] XBMC Download - http://xbmc.org/download/
[4] LinuxTV.org http://linuxtv.org/
[5] Android Kernel - http://forum.odroid.com/viewtopic.php?f=51&t=83
[6] Android Kernel - http://odroid.com/dokuwiki/doku.php?id= ... -xu#kernel
[7] VDR Wiki - http://www.linuxtv.org/vdrwiki/index.php/Main_Page
[8] VNSI-Server on XBMC-Forum - http://forum.xbmc.org/showthread.php?tid=147852
[9] AndroVDR - https://code.google.com/p/androvdr/ (also on Google Play)
[10] VDRAdmin-AM - http://andreas.vdr-developer.org/vdradmin-am/index.html
[11] XBMC IPTV Simple Client - http://wiki.xbmc.org/index.php?title=Ad ... ple_Client
[12] VDRNFOFS - http://projects.vdr-developer.org/projects/vdrnfofs
[13] Script Manager - http://smanager.wikidot.com/ (also on Google Play)
[14] XBMC video cache - http://wiki.xbmc.org/index.php?title=Video_cache
[15] DVB-T antenna - http://www.vdr-wiki.de/wiki/index.php/DVB-T_Antennen

To whom it may concern: I'm sorry for accidentally posting an early and incomplete version of this post yesterday. I meant to save it as a draft, but I clicked "Submit".
Attachments
config-3.4.5-dvb.tar.bz2
(17.94 KiB) Downloaded 112 times
Last edited by Nuems on Fri Aug 01, 2014 8:53 pm, edited 3 times in total.

fbeer
Posts: 8
Joined: Sun Feb 24, 2013 1:31 am
languages_spoken: english, german
ODROIDs: X2, XU, XU4
Location: Austria
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by fbeer » Fri Aug 01, 2014 6:48 pm

Awesome post! Thanks for going through the effort of documenting all these steps!

vtrambovetsky
Posts: 4
Joined: Fri Sep 20, 2013 6:23 pm
languages_spoken: english, russian
ODROIDs: XU
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by vtrambovetsky » Mon Aug 04, 2014 12:17 am

Could you test https://github.com/Owersun/xbmc instead xbmc.org? Owersun version has some improvements to MFC decoding for 1080i content. This can be useful when used with with "XBMC IPTV Simple Client" and HD IPTV multicast/unicast content.

Nuems
Posts: 134
Joined: Thu Sep 19, 2013 3:50 am
languages_spoken: english, german
ODROIDs: xu, c1
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by Nuems » Mon Aug 04, 2014 1:04 am

I think you're confusing things:
a) Im talking about feeding Linux based DVB into Android based XBMC. Android XBMC IS hardware accelerated - in fact, the Ubuntu XBMC images with HW acceleration use Android stuff via libhybris.
b) Owersun's branch is meant for Ubuntu (and possibly other Linuxes), not Android. Apart from that - I don't see a point in setting up the whole Android build environment if it's just about recompiling XBMC - I'm perfectly happy with the official apk.

Having said all that, Ubuntu/XBMC/VDR is something I want to try, but I hope that vnsiserver will work in that setup.
One question in this context: Can't you simply enable IPTV Simple client in a working installation of Owersun's (or Memeka's) XBMC?

Cheers,

Thomas

User avatar
OverSun
Posts: 1493
Joined: Mon Apr 29, 2013 5:12 pm
languages_spoken: english
Has thanked: 0
Been thanked: 19 times
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by OverSun » Mon Aug 04, 2014 1:25 am

the decoding is native in my XBMC, hybris is used only for display output on -XU. everything else is indeed like this

valexi
Posts: 91
Joined: Thu Apr 04, 2013 10:55 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by valexi » Fri Nov 28, 2014 10:48 pm

Which USB DVB adapter did you use? After enabling DVB support from kernel was it recognized immediately?

Nuems
Posts: 134
Joined: Thu Sep 19, 2013 3:50 am
languages_spoken: english, german
ODROIDs: xu, c1
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by Nuems » Sat Dec 13, 2014 3:49 am

Sorry for not answering earlier - I didn't notice your post previously.
My USB dongle is a "Hauppauge Nova-T Stick 3" (USB id: 2040:7070). Obviously, it's easiest to use a device that's supported in the Android kernel source, i.e. 3.4.x. If not, you might try the linux media stuff from http://linuxtv.org but I don't have any experience with cross-compiling those drivers. All I know is that building them natively on ARM under Linux usually works properly, provided the the build dependencies are met. Android is a different story, though.
Recognition is a bit tricky. Check the script "chroot_start" in my first post (you might have to scroll to the lower part of the script): device nodes are created by this script. So no, it's not plug and play, but the necessary steps are automated.
Inserting the kernel modules could be skipped by compiling them into the kernel, but at least for testing purposes I prefer modules because it helps me find out where things go wrong...

valexi
Posts: 91
Joined: Thu Apr 04, 2013 10:55 pm
languages_spoken: english
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by valexi » Mon Dec 15, 2014 10:42 pm

So, if we have the adapter now. We just need a backend for Android that is supported by plugin for Kodi/XBMC. Right?

Nuems
Posts: 134
Joined: Thu Sep 19, 2013 3:50 am
languages_spoken: english, german
ODROIDs: xu, c1
Has thanked: 0
Been thanked: 2 times
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by Nuems » Tue Dec 16, 2014 6:22 pm

Long story: First post
Short story: You need Android, a USB DVB adapter, a chroot-environment in which the backend will run and the necessary kernel modules. The kernel sources for Odroid-Android can be used, but the default Android kernel for the XU doesn't come with dvb modules.

If you just want XBMC+LiveTV, I'd recommend to use a Linux based image with XBMC as a starting point.

bmentink
Posts: 387
Joined: Sat Dec 13, 2014 1:47 pm
languages_spoken: english
ODROIDs: XU3, XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by bmentink » Sun Jan 25, 2015 8:03 am

I have LiveTV working on ODROID-XU3 with tvheadend and Kodi, it works well for SD, HD not useable at present, but I think that is because
I am not using accelerated ffmpeg at present ..

I had to compile tvheadend from git and also the kodi hts plugin from git ..
I also compiled kodi as per instructions on the "XBMC/Kodi status on -XU3" thread ..

Cheers,
B.

PS: This is on linux

bmentink
Posts: 387
Joined: Sat Dec 13, 2014 1:47 pm
languages_spoken: english
ODROIDs: XU3, XU4
Has thanked: 0
Been thanked: 0
Contact:

Re: Work in progress: LiveTV for XBMC on Android

Unread post by bmentink » Tue May 05, 2015 4:48 am

Hey guys,

I have had a go at tvheadend/kodi on android and have had mixed results:

Instead of using a chroot environment like the OP, I have just simply done the following:

1. cross-compiled the kernel on my host machine (ubuntu 14.04 based) and included the kernal modules for my USB TV tuner (Sony PlayTV/WinTV Nova-T)
2. Used ADB to copy modules to /system/lib/modules on device, also re-flashed the kernel to match modules with fastboot.
3. Modified init.odroidxu3.rc to insmod all the modules needed .... now I have the correct /dev/dvb/adapter0/1 devices.
4. Got hold of a binary of tvheadend for arm, it picks up my adapter just fine. (from another thread)
5. Setup the tvheadend plugin for kodi and connected to tvheadend.
6. Setup an epg, I did this with an XMLTV python script and installed qpython for android ... now I have epg

The results are mixed though, this is what I have observed:

1. With tvheadend running on odroid, I can pull up the tvheadend web page on another machine, select a channel and play it just fine, including HD content
However, if I try this on the odroid machine, play is blocky even on SD

2. Kodi on android can play on-line streaming movies just fine including 1080p, so graphics is not the issue. However, playing content from tvheadend is again blocky.
3. If I run tvheadend on my linux box and stream to odroid/kodi, I can watch TV just fine including 1080i

So the problem is when I run tvheadend AND kodi on the same machine (odroid) I have un-watchable TV, separate them and all is just fine.

Anyone have an idea on what the issue could be? Maybe it's something to do with process allocation/priorities or memory, buffering?

Cheers,
Bernie

Post Reply

Return to “Android”

Who is online

Users browsing this forum: No registered users and 1 guest