Showing posts with label lirc. Show all posts
Showing posts with label lirc. Show all posts

Saturday, August 02, 2008

Everything Breaks at Once

It seems that when one thing breaks, everything breaks. Ceiling starts leaking, TV loses convergence, power supply on computer goes out, server's UPS battery dies, the lithium battery pack for a portable DVD player starts to swell and explode, iPod ends up in the toilet, phone LCD cracks. It's partly because I'm over-tired and accidentally breaking crap, but it also appears that entropy has hit my living room en force.

I re-caulked the upstairs shower, replaced the TV, dug a new power supply out of the closet and got a new iPod. However - I've been busy with other stuff, so I haven't swapped the PSU in the workstation yet and I haven't completely re-installed all the home theater stuff, including MythTV box. And since I've already reduced every other electrical doodad in my house to its bare components, I might as well strip apart the Myth box and update it as well.

I have a pcHDTV card, now sitting dormant in the aforementioned workstation with a fried PSU. I'm thinking of ripping it out of the workstation and placing it into the MythTV Mini-ITX box. There's only room for one PCI card... so I'll have to remove the old Hauppauge cable TV tuner. Yet the Hauppauge WinTV-PVR-150 is also the IrDA receiver for my remote control - so replacing the tuner card would mean losing the DVR's infrared receiver.

I started looking around for alternatives and found a whole slew of Linux-ready solutions. An easy solution that I didn't think of at first was using a generic HID Windows Media Center remote, since it just pretends to be a USB keyboard. Re-map the keycodes and you're pretty much ready to go... assuming you're willing to re-map a universal remote and the Myth keyboard bindings to accommodate the case-sensitivity.

One could also use the receiver from a SnapStream Firefly Mini - they appear to be well supported by MythTV and would be a nice out-of-the-box alternative, given that everything is ready to go. Hopefully the reports of limited range wouldn't be a problem given my spartan living room setup.

Of course, like every self-respecting home theater geek, I already have a programmable universal remote that controls my whole setup. I don't need the additional remote that the previous two solutions bring, so it seems unnecessary. The first thing I would do is throw away the packaged remote, re-program my Harmony 670 and just use the new IR receiver. So it probably makes sense to just buy the receiver if at all possible.

There is a fairly flexible Linux-happy USB infrared receiver/transmitter that is supported by recent versions of lirc and MythTV, but it might be more hardware than I need.

IguanaWorks makes some powerful receivers and transmitters as well, in both serial and USB flavors. Considering serial access is considered the "legit" way for IrDA access, it seems like the cleanest way to go. They are evidently fairly powerful and receptive, but I would still need to get an extension USB cable to rope around to the front of the MythTV box.

Another cottage shop sells a RS232 LIRC receiver built into a DB9 backshell. It's much cheaper and much lower profile and designed to work with lirc natively. The most simple solution to the problem it seems.

I'll probably wander around the local electronics shops looking for a Firefly Mini or MCE remote. If I can't find one this week I might put in an order for a serial port receiver. Never figured I'd use a 9-pin serial port again, that's for sure.

Saturday, February 10, 2007

The Retelling of a Myth: Happy Hauppauge, Very VIA

The Hauppauge PVR-150 kit is fairly nice, assuming you actually get one in the box. It comes with a remote that works with lirc, and the on-board MPEG2 encoding means you can barf CATV streams directly into memory without tying up the CPU. It also has S-Video and composite inputs, although I haven't tried them.

After I put in the PCI card I expected to just run through the YaST2 TV card module and be done with it - it marches you through configuring TV cards fairly effectively. Much to my chagrin it didn't work however - the hotplug manager needed firmware downloaded and installed before it could load the device. There were two separate files that needed to be installed - one for the MPEG2 video stream, one for audio.

Once the firmware was installed I moved on to the infrared remote control. For some odd reason, the YaST2 screen that configures TV cards wouldn't let me select the correct driver for the PVR-150... instead it gave me two (what appeared to be) infrared keyboard drivers. Ummm.... no.

In fact, it appears that the correct version of the lirc driver for the new "gray / black" Happauge remotes isn't included with openSUSE 10.2. Instead, I had to jump on lirc's download page and obtain the source distro myself. I have to give a hand to the lirc maintainers however - they came up with a fantastic means of building from source. When building from source you first enter a menu screen that allows you to select the appropriate card & ir type. This pipes out a script that runs ./configure with the appropriate arguments, which you can then modify if you need (i.e. if you need to change the --prefix). The Makefile correctly builds & installs the kernel modules and userspace tools, and does so with minimal fuss or manual intervention. It even placed the kernel modules in a different location than SuSE's lirc modules, so it didn't run a chance of clobbering existing drivers. Of course, I needed to remove SuSE's lirc and lirc kernel packages to ensure the correct version(s) were invoked... but that was small potatoes. Lirc was probably one of the easiest from-source builds I've done in a long time.

After the modules were installed I had to change SuSE's sysconfig for lirc. I modified /etc/sysconfig/lirc to include LIRCD_DEVICE="/dev/lirc" and LIRC_MODULE="lirc_i2c". Another nicety of the source distribution was a universal Hauppauge configuration file - remotes/hauppauge/lircd.conf.hauppauge appears to support all the different Hauppauge remotes currently in the wild, and all in one file. I just dropped it over into /etc/lircd.conf and restarted the lirc daemon. The /dev/lirc device spawned, and all was good.

To map the actual keys I just used irw to tell me what the individual keys I pressed corresponded to. As I did that, I created a spreadsheet of remote buttons, the lirc code and the MythTV keyboard command. After I had exhausted all the MythTV/button permutations, I went through and created a .lircrc file. Each button press was defined as:

# Mute
begin
prog = mythtv
button = MUTE
repeat = 3
config = |
end

It took a while to define each key - to save time one can search for other people's posted configs as reference and adapt as necessary. After the file was set, I created a symbolic link from .lircrc to .mythtv/lircrc so MythTV's frontend could appropriately parse it.

Finally we have the hardware built, case constructed, OS installed, capture card configured and IR remote sending events. It may seem like a lot of effort, but think about it this way: we, lowly consumers, are creating a digital appliance out of naught but thin air. The very fact that we have such a flexible yet coherent construct in the first place is pretty remarkable. We've been able to pull parts off the shelf and build the foundations of a DVR without writing a single line of code!

Now on to actually orchestrating our products and convincing them to cooperatively put our favorite TV shows in its little robot brain...

Friday, February 09, 2007

The Retelling of a Myth: The OS

Now that I have built my Mini-ITX box, it was time to install the OS.

The platform I had chosen would be a bit more difficult than installing on a vanilla x86 machine. Since I was using a VIA EPIA board, this was choc-full of coprocessors, crazy chipsets and the like. The C7 1GHz processor would be ample to do most things, but I needed to ensure that everything ran comfortably in 512MB and didn't otherwise sap the juice from my CPU.

The biggest issue would be the S3 Unichrome graphics chipset. It absolutely had to work, since I needed MPEG2 acceleration and XvMC, not to mention TV-out. VIA has recently decided to open up the source to its Linux drivers, and since then the OpenChrome project has released the open-source versions that most distributions use. It appeared several had success with previous iterations, so I felt confident the C7 could be done as well.

Ubuntu is an extremely nice and light-weight distro. Since it can run on a minimum of packages, I decided to try it out first. MythTV packages abounded, and I was able to install everything quite easily. Ubuntu had decent support for Unichrome, and evidently installing the X11 drivers was just an apt-get away. However, actually building the X11 xorg.conf configuration file proved to be way too much of a headache. I love Ubuntu, don't get me wrong. But they need some decent administrative tools. I can hack an xorg.conf if I need to, but dammit I just don't have the time anymore. I was still able to glean some good information from those who did.

I eventually settled with OpenSUSE 10.2, which also has ready-made repositories for MythTV and OpenChrome (including a new repository by openSUSE itself). Of course at this point I have no DVD or CD to boot off of - I didn't purchase a drive to go with the box. Luckily with SuSE you can easily install without a CD... instead I took my bargain-bin 32M USB stick and built a USB boot disk. I was able to connect to a repository over the Internet, perform an install (albeit with GRUB errors) and come back the next morning with SuSE nearly ready to go.

One problem during USB installation is that the installer believes your USB stick is installable media - so GRUB becomes confused and assumes your hard drive is a secondary device. It's not of course... so when the SuSE installer attempts to install GRUB to your system several errors come spewing back to you. At this point you have no choice but to ignore them and press on. After the installer boots your system, you need to boot off your USB drive once again then, via the boot disk's installer menu, tell the disk to "Boot [the] Installed System." Afterwards your previous installer can resume & complete, at which point you can manually fix GRUB. For me, this meant opening up /boot/grub/device.map and removing /dev/sda as a mounted device. My primary IDE HD - /dev/hda - became the primary device for GRUB. After that was tweaked, I jumped into /boot/grub/menu.lst and made the appropriate changes whenever I saw hd0 or hd1. I re-ran grub-install and things booted swimmingly afterwards.

I followed the advice of ExtremeTech and created two partitions: one smaller 8 GB partition formatted with ext3, and a second XFS partition that occupied the remainder of the drive. The ext3 partition would be used for the OS and all system files, while the XFS /video partition would be used to store the large MPEG2 files that Myth would be generating. XFS works best with large files, and reportedly has faster write speeds than JFS. While it may not be as failsafe as ext3's journaling capabilites, I wasn't as worried about losing a recorded CATV stream as much as I worried about read/write performance.

There were a few minor hacks that appeared to be needed with earlier versions of openSUSE, but I'm not sure if they're needed anymore. I applied 'em anyway.

We move on to the Unichrome drivers next. Installing the OpenChrome drivers will do just fine... as long as you're using DVI or VGA outputs on the board. TV-out is a different animal altogether. The EPIA CN10000EG uses a VT1625 TV-out chipset, which currently isn't supported by the OpenChrome drivers. I spent nearly 20 hours trying an unbounded number of modelines and configuration tweaks in my xorg.conf, all to no avail. I ended up downloading and attempting to install VIA's own Linux drivers, but their installer never installed things correctly. It appeared to be looking for old XFree86 directories and files... ones that had since gone the way of the XOrg. I eventually had to tell VIA's installer to extract the files, build what it needed but then not to clean up its temporary installation directory with --keep. Once I had all the files to peruse, I was able to take XServer/via_drv.so from the installation script and manually copy it over to /usr/lib/xorg/modules/drivers/. Once I moved VIA's own drivers over and followed the expert advice of those before me, TV-out finally worked. I used the modeline's that VIA's installer automagically inserted in my xorg.conf file - the standard list of built-in modelines didn't seem to fill the entire screen. Finally, three days of tearing my hair out came to an end.

Unfortunately, I was never able to get XvMC successfully installed. I specified the driver library (in this case libviaXvMCPro.so in the config file /usr/etc/X11/XvMCConfig. For the life of me I don't know why Myth looks in the /usr/etc directory instead of /etc - so I just made a symbolic link between the two. Nevertheless, the VIA drivers didn't seem to provide the necessary XvMC libraries... even though the OpenChrome packages did. Maybe once OpenChrome catches up I'll be ablet o use their X11 driver and enable XvMC support for better MPEG2 acceleration and motion compensation... until then my workaround is disabling glx in xorg.conf (so that I didn't get lags from weird cache timeouts) and enabling kernel deinterlacing in MythTV (more on that later). Even without XvMC, however, I'm only using 40-45% of the CPU decoding MPEG2 files. No complaints there.

The VIA installer script also had extracted libddmpeg.so along with the X11 drivers. Not sure if it helped... but I replaced the existing /usr/X11R6/lib/libddmpeg.so with this version. We'll see if it breaks anything.

Next I needed to improve hard drive performance. UltraDMA/100 was enabled for my old WD 40GB drive, but performance from hdparm -Tt was still slow. The ATA drivers that shipped with SuSE's default kernel worked passably, but they weren't fast enough to read/write large MPEG2 streams. It turns out that there is a known issue with openSUSE 10.2 and VIA's VT8237 southbridge doesn't perform appropriately with it. Again I had to return to VIA's driver site and download a kernel patch to fix SuSE 10.2's ATA support. Once I installed the kernel sources, patched the appropriate files, rebuilt the kernel modules and reinstalled kernel/drivers/ata/libata.ko and kernel/drivers/ata/sata_via.ko. Once the modules were reloaded my IDE speed problems cleared up.

Sound would sometimes work, sometimes not. Occasionally sound would skip, crackle and pop with horrible results due to interrupt conflicts. I modified my GRUB boot parameters to include pci=noapic so that ACPI wouldn't allocate the IRQ's for the sound card. After that, sound worked consistently fine.

Now to give Myth a little extra juice, let's tweak the Myth frontend to run with higher priority. Just modify /etc/security/limits.conf and add the entries
mythtv     -      rtprio       50
and
mythtv     -      nice         0
, if mythtv is the user logging in and launching the front-end. This should give Myth higher priority over other system processes, just in case resource contention should become a problem.

Aight... VIA's chipsets were now covered... graphics, TV-out, MPEG2 and ATA works. Now time to turn our attention to the PVR-150.