Kodi Community Forum

Full Version: Generic XBMCBuntu Fixes & Tweaks
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, all!

The following is an (I believe) hardware-agnostic list of fixes applicable to the latest XBMCbuntu release (12.2 at the time of this writing). It covers topics such as:
  1. Activating the latest & greatest repositories
  2. Fixing the failure to reboot
  3. Fixing the failure to wake from S3 (suspend) from CEC events
  4. Enabling fetch of XMLTV Listings from a URL for TVHeadend
Ok...first and foremost, XBMCbuntu is a specialized Ubuntu installation. You already know this. However, it's still a full-blown, Ubuntu Linux installation. Most (if not all) of the commands listed here must be executed in a shell prompt. This can be done by SSH, or locally on the console. I recommend sticking to SSH.

Being that XBMCbuntu is a full-blown Linux install, that means that you should keep it up to date to ensure the latest security fixes are applied. Therefore, the first thing you should do is run all updates (you may copy + paste the lines in the Code block below to your shell):

Code:
# Update the APT repository info
sudo apt-get update
# Apply the latest updates and fixes
sudo apt-get upgrade

Once that's done, we can move on to the different items we mentioned above.

1. Activating the latest and greatest repositories

XBMCbuntu doesn't include these out of the box. They are the repositories for libCEC (from Pulse-Eight), XBMC (from Team-XBMC), and TVHeadend (from Adam Sutton's very own repository).

Code:
# Add the libCEC repository
apt-add-repository ppa:pulse-eight/libcec

# Add the XBMC repository
apt-add-repository ppa:team-xbmc/ppa

# Add the GPG key for Adam Sutton's TVHeadend repository
curl http://apt.tvheadend.org/repo.gpg.key | sudo apt-key add -
# Add the TVHeadend repository
apt-add-repository http://apt.tvheadend.org/stable

# Update the APT repository info
sudo apt-get update
# Apply the latest updates and fixes
sudo apt-get upgrade

At the end of this process, you should have the latest and greatest XBMC, TVHeadend and libCEC code installed.

2. Fixing the failure to reboot

NOTE: This should only affect you if you're using the PVR functionality. But, if you're also having this issue, this might be worth a shot since TVHeadend is installed as part of the base install

In my case, my XBMCbuntu installations would fail to reboot expeditiously. I tried every trick I knew, including using the "reboot=XXX" kernel parameters. I had no luck with that. It dawned on me that the only reason that wasn't working, is because upstart/init were unable to get to a point where they were actually "permitted" (so to speak) to reboot the machine. That meant that there was a process hanging things, keeping the system from being rebooted. Upon further investigation I found that "for some reason" TVHeadend was failing to shut down properly, and would instead hang. It took me quite a while to narrow down this as the culprit.

The main change is changing the stop condition to on starting shutdown instead of on runlevel [!2345]. The latter appeared to not be working properly.

The fix is applied in the TVHeadend upstart configuration. This file is stored in /etc/init/tvheadend.conf, and you can replace its contents with the following:

Code:
# tvheadend - DVB/IPTV streaming server
#
# Tvheadend is a TV streaming server for Linux supporting DVB, ATSC, IPTV,
# and Analog video (V4L) as input sources.

description "Tvheadend DVB/IPTV streaming server"
author      "Adam Sutton <[email protected]>"

start on (local-filesystems and net-device-up and started udev-finish)
stop  on starting shutdown

expect fork
respawn

pre-start script
  [ -r /etc/default/tvheadend ] && . /etc/default/tvheadend
  if [ "$TVH_ENABLED" != "1" ] ; then
    stop
    exit 0
  fi

  # Use the old variable, in case the config hasn't been updated
  [ -z "${TVH_DELAY_DVB}" ] && TVH_DELAY_DVB=${TVH_DELAY}
  [ -z "${TVH_DELAY_DVB}" ] && TVH_DELAY_DVB=0
  for n in $(seq 1 ${TVH_DELAY_DVB}) ; do
    DEVICES="$(find /dev -type c -path '/dev/dvb/adapter*/frontend*' | wc -l)"
    [ ${DEVICES} -gt 0 ] && break
    sleep 1 || true
  done
end script

script
  [ -r /etc/default/tvheadend ] && . /etc/default/tvheadend
  if [ "$TVH_ENABLED" != "1" ] ; then
    stop
    exit 0
  fi

  ARGS="-f"
  [ -z "$TVH_USER"      ] || ARGS="$ARGS -u $TVH_USER"
  [ -z "$TVH_GROUP"     ] || ARGS="$ARGS -g $TVH_GROUP"
  [ -z "$TVH_ADAPTERS"  ] || ARGS="$ARGS -a $TVH_ADAPTERS"
  [ "$TVH_IPV6" == "1"   ] && ARGS="$ARGS -6"
  [ -z "$TVH_HTTP_PORT" ] || ARGS="$ARGS --http_port $TVH_HTTP_PORT"
  [ -z "$TVH_HTTP_ROOT" ] || ARGS="$ARGS --http_root $TVH_HTTP_ROOT"
  [ -z "$TVH_HTSP_PORT" ] || ARGS="$ARGS --htsp_port $TVH_HTSP_PORT"
  [ "$TVH_DEBUG" == "1"  ] && ARGS="$ARGS -s"
  [ -z "$TVH_CONF_DIR"  ] || ARGS="$ARGS -c $TVH_CONF_DIR"


  exec tvheadend $ARGS $TVH_ARGS
end script

You should also remove the TVH_DELAY variable from the /etc/default/tvheadend file, and replace it with this:
Code:
# TVH_DELAY_DVB
#   The maximum number of seconds to wait for DVB hardware to become available.
#   Devices will be sought (using find) in /dev/dvb/adapter*/frontend* every second
#   until at least one becomes available, or the timer expires. At that point, startup
#   will continue normally. This has the added benefit of allowing hardware to initialize
#   prior to startup, but also eliminating the delay altogether when it is not needed, or
#   cutting it short as appropriate.
TVH_DELAY_DVB="30"

Alternatively, if you're not running DVB devices on that box, you can set that delay to 0. Reboot and suspend will now be as fast as they're ever going to be!

3. Fixing the failure to wake from S3 (suspend) from CEC events

If you're like me, you're using XBMC as (part of) your home theater setup. That means TV's, remote controls, etc. In my case, my TV's all support sending CEC over HDMI, so it made my life easier in that I could buy Pulse-Eight's HDMI-to-USB adapters and get CEC events delivered right to my Linux install. That's exactly what I did, and it worked like a charm out of the box, except for one little detail.

I wanted my setup to suspend (not shut down!) my XBMC boxes whenever the TV's were turned off, and likewise wake those boxes up when necessary. Essentially: keep things "off" when they need to be, and only turn them "on" when they're needed. The first part worked great out of the box. But for the life of me I couldn't get it to work in the reverse: powering things on.

I found my answer in the fact that in Linux, one must explicitly allow devices to wake the computer. In this particular case, adding a simple file to /etc/udev/rules.d did the trick (I added the file as /etc/udev/rules.d/90-cec-wakeup.rules , you can choose any name):

Code:
# /etc/udev/rules.d/90-cec-wakeup.rules
# Enable wake from S3 for the Pulse-Eight USB CEC adapter

# Enable the device itself
SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="2548", ENV{ID_MODEL_ID}=="1002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/power/wakeup'"
# Enable the bus that the device is on
SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="2548", ENV{ID_MODEL_ID}=="1002" RUN+="/bin/sh -c 'echo enabled > /sys$env{DEVPATH}/../power/wakeup'"

Once rebooted, things worked flawlessly. What this rules file does is tell Linux that it should continue to power the CEC adaptor and its parent bus (very important!) while in S3 state. Thus, if CEC events are received - such as the "wake up" event -, the machine's hardware can now respond to those events by waking the O/S up from S3 sleep.

Problem solved! Everything now works like a charm! I don't waste (too much) power, and I can use my TVs' remotes to control everything!

4. Enabling fetch of XMLTV Listings from a URL for TVHeadend

This is likely an unnecessary step for most people in the developed world. You see, in the "far reaches" of the planet, accurate XMLTV listings are few and far between. TVGuide offers a good service from which to find listings, but it's not in XMLTV format and all my research into the subject yielded no results. However, I was able to build a miner script to generate XMLTV data from that feed. That's a story for another day.

The important thing is that I have a Raspberry PI box on the network whose "sole" job is to keep that listing up to date. It queries the TVGuide listings and generates an XMLTV file with its contents once a day.

The problem is: how do I import that into TVHeadend? XMLTV Utilities only include grabbers for well-established services.

The answer is simple: put a file named "tv_grab_(whatever-you-want)" in the path available to the TVHeadend process (/usr/bin works well) that does what you want. This file should support a "--description" parameter to output a short, concise description of how it provides its listings.

In my case, this is my /usr/bin/tv_grab_url script:

Code:
#!/bin/bash

case "${1}" in
    --description ) echo "Fetch XMLTV from a URL" ; exit 0 ;;
    * ) ;;
esac

get_url() {
    (
        . /etc/tv_grab_file.conf &>/dev/null
        [ -z "${URL}" ] && exit 1
        echo "${URL}"
    ) 2>/dev/null
    return $?
}

URL="$(get_url)"
if [ ${?} -ne 0 ] ; then
    echo "ERROR: Failed to determine the URL to fetch the listings from"
    exit 1
fi

case "${URL}" in
    file:///* ) URL="${URL:7}" ;;
    file:/* ) URL="${URL:5}" ;;
    /* ) ;;
    * ) exec wget -O - "${URL}" ;;
esac

# URL is now a local path, so just cat it
if [ ! -e "${URL}" ] ; then
    echo "ERROR: path '${URL}' could not be found"
    exit 1
fi
if [ ! -f "${URL}" ] ; then
    echo "ERROR: path '${URL}' is not a regular file"
    exit 1
fi
exec cat "${URL}"

This script uses a configuration file stored in /etc/tv_grab_file.conf, with a single parameter: the URL to read the file from. The URL can be any of an absolute path (/a/b/c.file), a local URL (file:///a/b/c.file or file:/a/b/c.file), or any other URL supported by wget (http://... ftp://...):

Code:
URL="http://xmltv.local/~listings/xmltv.xml"

Final thoughts

I hope these come in handy to other users out there. In particular, item #3 (Fix for S3 wakeup) should be added as part of the base distribution, for future reference. Arguably, this should be added by the libcec package, but somebody should do it Smile.

All in all, I'm EXTREMELY happy with the smoothness of the process (barring the above hiccups, which hopefully others will no longer have to endure). I'm migrating away from OpenELEC, simply because XBMCbuntu gives me greater possibilities for expansion. In particular, Console Emulators Wink

I will fill you all in with the results of that when I have them!

Cheers!
Thanks, sounds helpful. One minor addition: The apg-get update and apt-upgrade (first code block) should be done on a regular base, like every week or so.And, of course, after adding repositories.