Category Archives: Ubuntu

TBS 6281 Tuner Card fails after a few days: Solved!

The biggest issue I’ve had with my new Myth build is that after a few days all recordings would fail. There wasn’t much evidence in the mythbackend logs. All I got was something like this when trying to record:

Aug 28 10:40:18 ripley mythbackend: mythbackend[10907]: E DVBRead mpeg/mpegstreamdata.cpp:365 (AssemblePSIP) MPEGStream[3](0x7fcde016faa8): Error: offset>181, pes length & current cannot be queried

In the end, it turned out that the clue was the following crash shown in /var/log/syslog:

Aug 23 07:46:24 ripley kernel: [385041.373970] irq 17: nobody cared (try booting with the "irqpoll" option)
Aug 23 07:46:24 ripley kernel: [385041.373975] CPU: 0 PID: 0 Comm: swapper/0 Tainted: PF IO 3.13.0-30-generic #55-Ubuntu
Aug 23 07:46:24 ripley kernel: [385041.373977] Hardware name: Gigabyte Technology Co., Ltd. B85M-HD3/B85M-HD3, BIOS F7 03/11/2014
Aug 23 07:46:24 ripley kernel: [385041.373978] ffff88022f24a29c ffff88023e203e68 ffffffff8171a324 ffff88022f24a200
Aug 23 07:46:24 ripley kernel: [385041.373981] ffff88023e203e90 ffffffff810c19e2 ffff88022f24a200 0000000000000011
Aug 23 07:46:24 ripley kernel: [385041.373984] 0000000000000000 ffff88023e203ed0 ffffffff810c1e7c 000000003e203eb0
Aug 23 07:46:24 ripley kernel: [385041.373986] Call Trace:
Aug 23 07:46:24 ripley kernel: [385041.373988] [] dump_stack+0x45/0x56
Aug 23 07:46:24 ripley kernel: [385041.373997] [] __report_bad_irq+0x32/0xd0
Aug 23 07:46:24 ripley kernel: [385041.373999] [] note_interrupt+0x1ac/0x200
Aug 23 07:46:24 ripley kernel: [385041.374001] [] handle_irq_event_percpu+0xd9/0x1d0
Aug 23 07:46:24 ripley kernel: [385041.374003] [] handle_irq_event+0x3d/0x60
Aug 23 07:46:24 ripley kernel: [385041.374005] [] handle_fasteoi_irq+0x5a/0x100
Aug 23 07:46:24 ripley kernel: [385041.374009] [] handle_irq+0x1e/0x30
Aug 23 07:46:24 ripley kernel: [385041.374012] [] do_IRQ+0x4d/0xc0
Aug 23 07:46:24 ripley kernel: [385041.374015] [] common_interrupt+0x6d/0x6d
Aug 23 07:46:24 ripley kernel: [385041.374016] [] ? cpuidle_enter_state+0x52/0xc0
Aug 23 07:46:24 ripley kernel: [385041.374021] [] cpuidle_idle_call+0xb9/0x1f0
Aug 23 07:46:24 ripley kernel: [385041.374024] [] arch_cpu_idle+0xe/0x30
Aug 23 07:46:24 ripley kernel: [385041.374026] [] cpu_startup_entry+0xc5/0x290
Aug 23 07:46:24 ripley kernel: [385041.374030] [] rest_init+0x77/0x80
Aug 23 07:46:24 ripley kernel: [385041.374033] [] start_kernel+0x438/0x443
Aug 23 07:46:24 ripley kernel: [385041.374036] [] ? repair_env_string+0x5c/0x5c
Aug 23 07:46:24 ripley kernel: [385041.374038] [] ? early_idt_handlers+0x120/0x120
Aug 23 07:46:24 ripley kernel: [385041.374040] [] x86_64_start_reservations+0x2a/0x2c
Aug 23 07:46:24 ripley kernel: [385041.374042] [] x86_64_start_kernel+0x143/0x152
Aug 23 07:46:24 ripley kernel: [385041.374043] handlers:
Aug 23 07:46:24 ripley kernel: [385041.374050] [] saa716x_tbs6281_pci_irq [saa716x_tbs_dvb]
Aug 23 07:46:24 ripley kernel: [385041.374051] Disabling IRQ #17

There was some kind of IRQ issue with the TBS card. I found the solution to the problem here:

http://www.tbsdtv.com/forum/viewtopic.php?f=52&t=7631#p24903

It turns out to be an incompatibility between my up-to-date motherboard and the legacy interrupts the TBS card uses by default. The solution is to instruct the TBS driver to use the new MSI interrupts, which is very easy to do. Just create the following file:

/etc/modprobe.d/tbs.conf

Containing the following:

options saa716x_tbs-dvb int_type=1

After a reboot, run this command to check that it’s worked, you should see “PCI-MSI-edge”:

cat /proc/interrupts | grep SAA
45: 134857 0 PCI-MSI-edge SAA716x Core

My system has been fine since I did the above, so I’m pretty sure it’s fixed it for me. It’s nice to have a fully working Myth box again!

VAAPI

VAAPI provides hardware video decoding on Intel graphics. When I decided to base my new MythTV system around Intel’s new integrated CPU/GPU architecture, I did some research to make sure this worked under Linux and MythTV. As far as I could tell it did, but you never really know until you’ve tried it yourself…

I’m pleased to report that it works brilliantly.

The only caveat is that if you simply select VAAPI from MythFrontend -> Setup -> Video -> Playback it will happily let you do it but it won’t actually use VAAPI unless you have installed the VAAPI driver. This was not obvious on my system because it’s pretty powerful and could play HD pretty well without any acceleration. However, it was taking 40+% CPU, which seemed too high to me.

All you have to do to get it to work is follow the instructions on the MythTV WIKI:

http://www.mythtv.org/wiki/VAAPI#Configure_MythTV_for_VAAPI

It basically says the following:

Install the appropriate drivers:
sudo apt-get install i965-va-driver libva-intel-vaapi-driver vainfo

Test using:
vainfo

Use OpenGL or Auto as the painter:
MythFrontend -> Setup -> Appearance, make sure Painter is set to Auto or OpenGL (not Qt)

Select the VAAPI Playback Profile from Mythfrontend:
MythFrontend -> Setup -> Video -> Playback -> (Screen 3/8) -> Select “VAAPI normal” profile in list

Once I’d done this, the CPU usage when playing HD stuff dropped from 40-50% down to around 10%. Live HD TV was also smoother. I’m pretty amazed that this all works so easily and I’d highly recommend going the Intel route if you’re building a new HTPC.

Goodbye, lirc

The initial method I’ve been using to control MythTV on my new build is my trusty Logitech S10 RF keyboard and mouse. It’s very handy as a fallback and when I want to type something.

I have also been using the Mythmote android app, which works fine, but a smartphone, whilst great for many things, just doesn’t hack it as a TV remote. Especially when the TV is used by all the family.

So, I bit the bullet and purchased a new remote control. The main requirement was USB. As the PC is behind a wall I have run a USB cable, with a hub on the end, so I can connect any peripherals I like behind the TV.

After minutes of deliberation, I decided to go for a Hama MCE remote control. These function exactly like a mini keyboard and mouse and are supported by Linux out-of-the box. Lo and behold, it worked out-of-the box and I could control Myth and even use the in-built pad to move the mouse cursor on the desktop.

I had a half-hearted attempt at getting lirc working, as I’m a geek and must have been feeling masochistic. The trick is to stop the remote from being recognised as a keyboard and use lirc instead. However, in the end, I found that working like a keyboard isn’t that bad after all. Most of the buttons work straight away. Any that don’t can usually be mapped in the frontend Setup->Edit Keys utility. For example, the “Back” button is actually a “Backspace” key, so for it to be used to return to the previous menu, you can map it as an alternative to the Escape key. Also, you can add a “delete” shortcut by adding an alternative to the “D” key. It works well and is extremely easy.

The other thing I wanted lirc for was mapping some shell commands to remote control buttons, but this can be done using the Xfce keyboard settings. Just add a new shortcut and you are prompted to press the button to map it. Almost too easy!

As for the remote itself, it’s not perfect. The mouse pad thing is fairly unusable and takes up a lot of real estate, while a lot of the other buttons are very small and fiddly, especially the directional keypad, which is used a lot in Myth. Still, it works and will do the job.

All in all, I’m happy that my wife and kids and I have a nice new remote control and to fight over.

MythTV Setup

The configuration of my new MythTV box went extremely smoothly. I just ran up MythTV Setup and added the 2 tuner cards and a Freeview EIT source and scanned for channels. They all appeared including the HD stuff. I set the playback settings to use VAAPI and it could immediately records and playback both SD and HD. Very impressive.

The only issue was that live TV didn’t work, but that turned out to be write permissions to my custom recording directory. Even sound over HDMI worked once I’d selected it from the audio setup menu. It even told me which HDMI output my TV was connected to on the settings screen.

I did have a few small niggles, though. The first was that the metadata and artwork for MythVideo was not working. This was sorted by an upgrade to the latest MythTV verson, 0.27.3. I’m quite surprised that Mythbuntu 14.04 ships with MythTV 0.27.0, which is a pretty old version. Anyway, at least the latest version is available to be installed easily from the Mythbuntu repos.

The second problem is a pretty bad one. If I change the TV input away from MythTV, or turn the TV off, when I go back to the MythTV input it has often lost the signal and I get a blank screen. I have searched and searched for a resolution to this to no avail. For now, I have implemented a horrible bodge which restarts X when I hit F12 on the keyboard. Not great, but the machine is so fast it only takes a coupe of seconds.

So, finally, my family can get back to using MythTV!

TBS 6281 Driver

Next step was to get the TBS card working. First problem: it wasn’t recognised; there was nothing under lspci at all. You should see this:

lspci
05:00.0 Multimedia controller: Philips Semiconductors SAA7160 (rev 03)

Taking the card out and re-seating it fixed that issue. Phew!

I then followed these instruction to download and compile the drivers:

http://linuxtv.org/wiki/index.php/TBS6280

They compiled OK, but after the make install and a reboot there were no devices in /dev/dvb.

I was getting the following error in /var/log/kern.log

[ 1.666293] saa716x_tbs_dvb: disagrees about version of symbol stv090x_attach

After a bit of Googling, the consensus seemed to be that it was an error with compiling against the wrong kernel headers and that deleting the following modules should sort it out:

rm /lib/modules/$(uname -r)/kernel/drivers/media

There were some old kernel headers installed, so I removed that package leaving only the correct headers. Still, it didn’t seem quite right to me. There are a lot of other modules under there and, also, why did recompiling against the correct headers and re-installing not overwrite the old modules? In the end, despite my concerns, I went ahead and deleted the module directory and recompiled and it all burst into life. Oh well, as long as it works I’m happy.

UPDATE
Niel C has kindly commented below with a method of identifying the offending module, so the following should be enough:

rm /lib/modules/3.13.0-39-generic/kernel/drivers/media/dvb-frontends/stv090x.ko
(Note that I haven’t tested it myself yet)

Archiving Old Recordings as Videos

I had way too many old recordings on my broken system, most of which belonged to the kids, and they did’t want to part with them. I didn’t really want to restore the old database onto the new system, as it’s been going for 8 years and I wanted to start from scratch. So, my plan was to archive all the old recordings as videos.

The only problem with this was that MythTV the file names aren’t descriptive, so I had to somehow access the old database to get them out. The plan was to load the old dump into a different database and use that to extract the file names and rename the files. Here’s what I did:

Create the database “old”

mysql -u root -p
(my user's password)
create database old;

Load the dump into database “old”

mysql -u root -p old < mythconverg-1299-20140629075054.sql

Run the following perl script to rename the files. Note that this moves the files rather then renames them, as for so many gigabytes that would have taken way too long. Moving is instantaneous as long as it's on the same disk. Also, make sure you change the directory names to match your system:


#!/bin/bash

# Directory containing MythTV recordings
export MYTHDIR=/mnt/storeold/mythtv

# Directory to hold renamed files
export TVDIR=/mnt/storeold/oldtv

# Run mysql query and pipe into Perl
mysql -u root -p old --execute "select chanid,starttime,endtime,title,subtitle,basename from recorded" |
perl -w -e '
use File::Copy qw(move);

my $mythpath=$ENV{MYTHDIR};
my $tvpath=$ENV{TVDIR};
my $n=1;

<>;
while (<>) {
chomp;
# Get row from database
my ($chanid,$start,$end,$title,$subtitle,$basename) = split /\t/;

if (!defined $subtitle) {$subtitle = ""}
if (! -e "$mythpath/$basename") {print "Skipping $mythpath/$basename\n"; next}

# Generate new filename
my $dir = "${title}";
my $nfn = "${title}";
if ($subtitle) {$nfn="${nfn}__${subtitle}"}

$dir =~ s/ /_/g;
$dir =~ s/&/+/g;
$dir =~ s/[^+0-9a-zA-Z_-]+/_/g;

$nfn =~ s/ /_/g;
$nfn =~ s/&/+/g;
$nfn =~ s/[^+0-9a-zA-Z_-]+/_/g;

$nfn = sprintf "%s.mpg", $nfn;

if (!-d "$tvpath/$dir") {mkdir "$tvpath/$dir" or die "Failed to make directory: $tvpath/$dir\n";}

print "$mythpath/$basename $tvpath/$dir/$nfn\n";
move "$mythpath/$basename", "$tvpath/$dir/$nfn" or die "Failed to move file $tvpath/$dir/$nfn: $!";
}'

Mythbuntu Install

I finally had a spare couple of hours to do the Mythbuntu 14.04 install last night. I used a USB stick containing the ISO image, which booted first time.

Unfortunately, the installation crashed half way through, which turned out to be a known issue with selecting the VNC server option. Trying again without this option selected worked fine. This is a pretty major bug to allow through into the final release.

Upon first boot I discovered that my new machine is blindingly fast. It boots from the BIOS into mythfrontend in 13 seconds, which is pretty amazing.

The second issue I had was when I was prompted to install software updates. As it’s a new install I said yes and waited. Unfortunately, the screensaver kicked in half way through and corrupted the update window so I could not tell if the update had finished. I eventually realised it had got stuck and had to kill it. Again, a screensaver isn’t something you really want to be enabled by default on a MythTV distribution, especially if it doesn’t work well with running apps.

Other than that, the OS is installed and running fine. Next step is to install the TBS DVB-T2 card and get Myth configured. Then I need to try to recover all my data from the old system…

As luck would have it…

Things seemed to be going so badly. I did a really stupid thing – the nVidia graphics card failed in one of my desktop machines. The one I use all day during the week. It was producing blue artifacts on the screen and it definitely wasn’t software related. So I bought a new card, but like an idiot, I bought the wrong type. I was sure that this machine was old so I got an AGP card. Only when I came to fit it did I realise that it was a PCI-E slot! Bugger. PCI-E cards are cheaper and better than AGP cards, so I got one with HDMI and VDPAU for £25.

I decided to keep the AGP card because they’re getting hard to come by and will fit in my old MythTV box, which is still plodding along. I seem to go through quite a lot of graphics cards on boxes which are left on all the time. Especially passively cooled cards.

Anyway, a few weeks later, without me making any changes to it, my MythTV box suddenly started playing up. The only change really is that it’s now connected to a HD TV, so it’s putting out full HD resolution, which must put extra strain on the card. X would go really slow, even in lightdm straight after bootup, and there were weird artefacts on the screen. Also, and this is weird, when typing at a console, the odd letter would not appear! Plus, the mouse and keyboard were unresponsive and it would not switch to the F1 console. It spewed out these messages into kern.log:

Sep 3 20:59:03 ripley kernel: [ 159.488221] NVRM: Xid (0000:01:00): 13, 0002 beef3901 00000039 00000328 00000000 00004000
Sep 3 20:59:23 ripley kernel: [ 177.448028] NVRM: os_schedule: Attempted to yield the CPU while in atomic or interrupt context

I tried all sorts of nVidia drivers, nvidia-current, nvidia-current-updates and even the latest x-swat driver. All of them gave the same results.

It really did not look like a hardware fault, but I tried blowing and reseating the existing 6200 card. Then, as a last resort, I stuck in the new 6200 card which I accidentally bought a month earlier and, hey presto, it worked perfectly.

As the 2 cards are pretty much identical, I can only assume that it really was a hardware fault. So it just goes to show, when life deals you a bad hand – stick hold of it – it may come in useful in the future!

Povray on Ubuntu 12.04 (precise pangolin)

Povray combines two of my interests quite nicely: programming and art. Unfortunately, it’s been dropped from the standard Ubuntu repositories for licensing reasons. Luckily, it’s pretty easy to compile from source. The following method shows how to do it with X support so the graphical preview window works…

sudo apt-get install build-essential libx11-dev libxt-dev

wget http://www.povray.org/redirect/www.povray.org/ftp/pub/povray/Official/Unix/povray-3.6.tar.gz

tar xf povray-3.6.tar.gz

cd povray-3.6.1

./configure COMPILED_BY="Your Name <yourname@example.com>" --with-x

make

sudo make install

Happy ray tracing!