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…

MythTV PC Build

The bits for my new build, which is my 3rd MythTV box, arrived on Saturday. My first box was based on an Asus Pundit barebones chassis and was built ten years ago in 2004. A couple of years later I built a silent PC around a Scythe Ninja cooled Athlon CPU, which I’ve been using ever since.

The spec of the new one is posted below. I haven’t built a PC in years so it was great fun. Things haven’t changed that much and it screwed together very easily. In my view, the case is one of the most important factors when building your own PC. I admit that I did skimp on cost when selecting the Fractal Designs 1000 case, which appeared a bit flimsy in places when I opened the box. However, as I had hoped, the case is a triumph of design over budget and it’s very well thought out. It’s a small case, but still takes a full size ATX power supply. With a micro-ATX motherboard there’s still plenty of space inside. It helps that I didn’t bother with an optical drive, so any spare cables can be tucked up into the drive bays (I also saved some cash by not getting a modular PSU).

I intend to just velcro the tiny SSD in place and put the 2 big 3.5″ drives in the vertical bays.

The system powered up first time and into the new UEFI BIOS. Very snazzy. I was dying to move onto the Mythbuntu install but my Saturday night was taken up by a LAN party with my brothers, consisting of plenty of beer, Grid, Modern Warfare and Left 4 Dead. On Sunday night I was distracted by the World Cup final. Oh well, I’m sure I’ll get round to it eventually…

Is MythTV still relevant?

One question you may be asking yourself is whether MythTV is still relevant in the era of internet TV and cheap freeview HDD recorders.

It’s actually a very good question because it’s certainly less relevant than it used to be. I’ve been using Myth for 10 years and in the early days there was no substitute. It pre-dated Sky Plus, Amazon instant, Youtube, etc.

My family still use Myth a lot, but we also watch plenty of content streamed from the internet on our Smart TV. As my current MythTV system is broken, we’ve been getting by with that and BBC iPlayer for most of our viewing needs. That, along with a cheap HDD recorder would be enough for a lot of people.

For me, though, the MythTV server is the hub of the house, it doesn’t just record TV, it acts as NAS, it stores our photos, it hosts our entire music collection. It stores gigabytes of DVDs which I’ve ripped from my collection. No to mention way too many TV recordings which the kids want to keep forever.

It does all of this way better than any NAS or generic media server could ever hope to do, because its running Linux and I can set it up exactly how I want.

So, maybe MythTV itself isn’t as essential as it used to be, but as one component in a Linux based home hub, it still does a great job.

New MythTV Build

I’ve ordered the hardware for my new build!

MythTV is pretty versatile and can be tailored to meet your viewing needs. It consists of “backend” computers which do the recording and storage and “frontends” which do the playback. As the content can be shared using standard technologies such as DLNA, other devices can also be used to watch it, such as smart TVs, PS3s, smartphones, etc.

For my setup, I use a combined backend/frontend connected to my main TV. I find this to be the most complete way to run Myth, as everything can be done easily and cheaply. When I built my last system, the big concern was how quiet the PC was. Depending on the layout of your living room, it may be easy to hide even a large box. Alternatively, you could go for a stylish media centre case and have it on display. Or a tiny separate frontend. That’s the beauty of Myth – choices.

In my new house, I actually have the PC in the attached garage, connected to my TV through a hole in the wall! With this setup, I have no worries about how noisy or big or ugly the box is, and the living room is as neat as could be. My wife used to hate all the cables nested behind the TV gathering dust!

So, for my new build I decided to go for state of the art, but very generic hardware. When you try to do things pretty or quiet they start to get more expensive. So, with a budget of about £400 I just picked what seemed reasonable…

The design brief was a combined backend/frontend, dual tuner Freeview HD (DVB-S2), decent storage for videos. Connected to a TV over HDMI.

With HD playback required, the biggest question was what to do for the graphics. In the past, I have always gone for AMD CPUs and nVidia graphics. nVidia have always had the best support within Myth and HD works well. However, things change.

I am intrigued by the latest Intel kit, which has a combined CPU/GPU. There are open source drivers and excellent Linux compatibility. In theory, it sounds perfect. So, I will give it a try. Worst case, I can always stick an nVidia card in there!

CPU: Intel Pentium G3420 Dual Core
Intel’s 4th gen processor Haswell CPU for about £45. Should be super speedy and do the HD decoding using the in-build GPU. We will see.

Motherboard: Gigabyte B85M-HD3
Micro ATX, Socket 1150, USB3, SATA 600 and the right price. £45.

Memory: Corsair CMZ8GX3M2A1600C9 DDR3
I splashed out and went for 8GB of RAM. Probably overkill, but 4GB just didn’t seem enough on a modern PC. £60.

PSU: Corsair Builder Series CX 430W
Cheap and good quality power supply. Not modular, but the interior of this PC won’t be entering any beauty contests. £30

SSD: Corsair CSSD-F60GBLS
The disk for the Mythbuntu OS install will be a small (60GB) SSD for speed and reliability. All the content will be on a couple of big 3.5 inch disks. £40

HDD: Western Digital Green 2TB
I already have one of these from my old machine, so this one will make a pair. Did think of getting the WD Red but read that they are more intended for RAIDS and these are better for a second drive. £60

Case: Fractal Design Core 1000
Fairly small case with room for a full size PSU. Looks nice in the pictures and from a respectable company. Looking forward to seeing this. May be a little squashed with 3 drives in but there won’t be an optical drive so there should be just enough space. £30

Tuner: TBS TBS6280 PCI-E DVB-T2 Dual
2 tuners in a tiny footprint. This will replace the 2 Hauppauge cards I currently use (which don’t do HD). Linux support is good, even though the drive is proprietary. Only drawback is that the supplied remote is not supported. No big deal ads there are plenty of other nicer remotes on the market. £72

So, that lot should be winging its way to me from Amazon as we speak. Looking forward to putting it together…