Saturday, February 17, 2007

My Wii Little Friend


Say hello to my Wii little friend! Happy Valentine's day to me...

It's safe to say my productivity is back down to zero. In fact, my indy development may well just be done now. I'm not sure. You may have noticed my attention has hovered more around video editing, DVR's and gaming itself rather than development. I'm not sure if I'm calling it quits or just taking a break.

We'll see. I've got a few rounds of golf to play now.

Monday, February 12, 2007

The Retelling of a Myth: Fin

My MythBox has been in service for nearly two weeks now - and I haven't had a single problem in nearly as long. It's quite remarkable that I was able to construct such an appliance for under $400 USD, and I owe most of those remarks to VIA and their lovely Mini-ITX EPIA C7 platform. They've crammed ten pounts of digital goodness into a five pound bag, and made it all passively cooled to boot. While it may not benchmark the fastest, it benchmarks as the most useful and power-efficient general purpose plaform I've ever used. The EPIA doesn't work faster - it works smarter by building in acceleration for what you actually need. Cryptography, MPEG2, audio and TV-out are all done intelligently by chipsets design for that specific purpose. That means you, yes you, get to reap the benefits of an extremely fast and jitter-free MythTV box without the cost, power consumption, size or complexity of a regular mobo/CPU combo. And VIA understands how Linux is crucial to their enterprise, and has worked towards providing support likewise. Open-sourcing their driver base is a smart step.. let's just hope they continue to document their chipsets and offer open-source implementation, as well as Linux driver support around every corner. If they do, I promise to keep buying. Deal? Deal.

Also, one should be greatly impressed by the Myth team's gusto. They've brought Linux together and have shown the world that this nimble little behemoth of an OS can really make a tremendous splash. Indeed, one almost gets a feeling as if this was Linux's endgame, and all the pieces of the puzzle are now being assembled; all that remains are the easy pieces inside the corners.

One also should give mad props to the community at large, which has taken it upon their anti-anti-social selves to document every living, breathing attempt to get a myriad of hardware configurations to run Myth. Indeed, these past five blog posts are my contribution back to the lukewarm saline pool that holds our collective brains. Without the dozens of blog, newsgroup and forum posts out in the wild I never would have been able to build this box. Thanks to this modern era of communications, n00bs everywhere are being schooled at the speed of light.

Now if you'll excuse me, I have 20 back episodes of The Daily Show to watch.

Sunday, February 11, 2007

The Retelling of a Myth: The Myth Part

Installing MythTV is fairly easy once the OS & appropriate drivers are installed. Thanks to the all-knowing Packman repository for SuSE, I was able to easily use YaST2 and get the mythfrontend, mythbackend, myth-plugins and myth-themes with a minimum of fuss. Dependencies automagically installed and I was ready to go in a few minutes.

The SuSE packages show a good deal of polish. I installed the Gnome login manager (GDM), since it seemed to be the most lightweight login manager that allowed the mythtv user to auto-login. While I installed FvWM and expected I would need to use .xinitrc to launch mythfrontend upon startup, it turns out SuSE setup GDM to have MythTV as a session choice unto it's own. So instead of needing to specify Gnome, KDE or FvWM as the session to login to I could specify MythTV as a session of its own without a window manager. Very nice!

First, one needs to set a root password for MySQL and create an account for the zap2it Web service. After those accounts were created I followed the universal MythTV installation instructions for openSUSE, started the backend server and began populating the database.

Once the backend was ready to go, the frontend was ready to roll. First thing I did was ensure live TV was rendering correctly; since XvMC wasn't enabled, I had to find alternate ways of doing motion compensation. I ended up using the "standard" MPEG2 decoder library with kernel deinterlacing, which was the only deinterlacer that a) worked and b) reduced blur. Bear in mind the rational option should have been using the VIA XvMC decoder w/ bob 2x deinterlacing, but it just wasn't an option using VIA's X11 drivers. However, MPEG2 playback still only consumes 40% of the CPU. Go figure.

Sound, recording and playback all pretty much worked out of the box. Transcoding and archiving to DVD are still a work in progress for me... I haven't been able to get everything working correctly yet. I was able to transcode using default settings to RJPEG... but that turned a 1.1GB MPEG2 file into a 1.4GB RV file. Umm... wrong way.

I attempted to stream DVD-quality MPEG2 files from my home file server via 802.11b, but of course the latency just didn't agree with that kind of streaming. I replaced the Linksys 802.11b bridge I was using with an old (and I mean old) 10Mb Ethernet hub and the DVD-quality MPEG2 files were rendered via my MythTV box just fine.

While tweaks are still to be had the keyboard has been disconnected, cables tucked away and recordings are now being scheduled. Playback is smooth thanks to the via X11 driver and recording is transferring to ye olde Western Digital nicely thanks to the ATA patch. Lirc is reading remote commands nicely, and the 10M Ethernet line is feeding remote streams just fine.

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.

Wednesday, February 07, 2007

The Retelling of a Myth: Part One

Recently some benevolent sponsors gave me a grant to purchase a DVR for myself. The notion was that I would "lease" a PVR from our local cable provider at their going rate of $10/mo, plus $30 for their digital cable service.

In all honesty, I'm not that big of a TV watcher. However, there are two shows that I go absolutely giddy for... but I constantly and consistently forget that they're on. I actually have... prepare yourselves now... a monaural VHS video cassette recorder that I usually commission to record my show once a week. Yes... I actually have used magnetic tape up 'til now. Magnetic tape that has started to wear very, very thin.

The DVR gift was a great idea. But where my benefactors might expect me to zig, I zagged.

Every Linux zealot wants to build a Myth box. It's become nearly a rite of passage. Nowadays every IT department is brimming with architects who design and provision their own home theater PC to record an entire lifetime of "The Simpsons." Some use Windows Media Center Edition, some use SageTV, but those who have that extra oompah down their pants build a MythTV box.

A lot of people don't realize this, but Linux distributions (and often BSD distributions for that matter) are filled to the brim with building blocks. The basic components for everything you could ever need are all right there. LDAP? Check. An HTTP server? Check. A framework for playback of any number of video codecs? Check. A way to quickly transcode video? Check. The problem with Linux software isn't that things don't exist... it's that there is no glial matter binding it all together.

That's why projects such as QDVDAuthor, Kino and MythTV are so lovingly accepted and absolutely brilliant. They build on existing infrastructure such as MySQL, Xine, ffmpeg, mjpeg tools, lirc and the kernel itself to give the user a single, consistent and logical interface to it all. The Kino authors have written much of their infrastructure itself, but MythTV does a great job of leveraging the given strength of a platform and concentrating on an extremely usable and imminently extensible interface for the user.

I was decided I'd build a MythTV box. The total cost needed to be cheap, the heat & noise needed to be minimal and the form factor had to fit in a narrow cabinent where my VCR resided. High-definition content wasn't (currently) the target... this was simply going to be a replacement for the aging tech that took five minutes to program each time and had to be manually rewound.

I spec'd out two possible hardware platforms: a Mini-ITX setup that was largely integrated and had a very small footprint & power consumption, and a Micro-ATX setup that had some definite beef and a litany of possibile upgrades in the future. In the end, the Micro-ATX setup was nearly twice the cost, five to ten times the power consumption and required a larger footprint. While the Micro-ATX setup would have eventually granted me HD DVR capability in the very near term, all I wanted was lo-res basic cable. The VIA's EPIA CN is a nice all-in-one solution with MPEG2 acceleration, hardware crypto, TV-out, insanely low power requirements and passive cooling for everything - including the CPU. All I needed to add was a case (with included power supply), a Hauppauge PVR-150 for on-board MPEG2 encoding, and some RAM. I found an old 40 GB Western Digital hard drive lurking in my closet, so I blew the dust off and prepped it for service. No CD or DVD drive needed... again, this is just a surrogate VCR.

Whenever I try to build a system, it seems at least on thing needs to be returned or RMA'd. Everything arrived quickly enough... so I began cracking open boxes. When I opened the Happauge box I was surprised to discover they had swapped out the PVR-150 with an HVR-1600. Evidentally Hauppauge has taken it upon themselves to replenish their PVR-150 stock with the more impressive, albeit completely incompatible, HVR-1600. It's a nice tuner, don't get me wrong. It has two on-board tuners: one for standard TV and one for terrestrial HDTV; however the HVR-1600 is completely unsupported in Linux, and doesn't look like it will be obtaining support any time soon. While I'm sure Hauppauge thought they were doing everyone a favor, they forgot that they had a huge following of Linux users. I contacted Hauppauge directly, and they swapped parts with me fairly quickly.

Once the PVR-150 came back, I prototyped the Myth system with my current workhorse workstation. I tossed the PCI card in to my AMD64 system, ensured I was able to receive a terrestrial television signal and confirmed the IR remote worked properly. Once I was satisified that the hardware was sound and Linux was up to the task I began constructing the box.

Of course, whenever you work in a Mini-ITX case you leave yourself zero room or expansion. You'd better hope that any oblong hardware fits like a jigsaw puzzle, otherwise you're hosed. Wire management is key - the first few builds of the box evidently had some wire or component that was unsatisfactorily grounded. One snap of static electricity to the case would cause the entire machine to sieze up. Not good.

A hole was drilled through the plastic cover that would conceal the slot where a small CD/DVD drive would otherwise fit. This would later allow me to route the IR receiver from the PVR-150's PCI slot, through the back of the case, past the innards of the box and out to the front bezel.

The hard drive and PCI card, once mounted, were a tight fit against each other. The hard drive actually ended up pressing against the metal shield surrounding Hauppauge's TV tuner. Not sure if this will cause problems... either due to the heat generated by the drive or the RF leakage that the tuner's shield is supposed to reduce. Luckily the case fan is not far away, so the exhausted air may at least provide some relief for the heat buildup.

Wiring the front bezel to the motherboard's header pins is always fun. It took me nearly 20 minutes to distinguish the orientation and location of the power, reset, HD activity and power LED... but I eventually figured it out. The case emitted a blue light that completely pierced the retina - I yanked that cord fairly quickly. I also discovered by my own error-and-trial that connecting the front bezel's audio ports disabled the rear audio ports. One or the other - not both. I had to take the case back apart and re-jumper the header pins to allow audio to be piped out the back of the box.

Finally after all the lacerations to my hand were mended and all stripped screws were replaced, I was ready to hook 'er up and see if I could get it to POST. Long at last, it did.

I was fairly happy with the form factor. I had routed the IR cable through the case to the front, which helped astetics somewhat. The IR blaster cable was twist-tied in the back, and the IR receiver was adhered to the front with some 3M dual-sided sticky pull stuff they use for posters or coat hangers or whatever. With all said and done. I ended up with a case that was about 1/3rd the size of my original VCR. Not to shabby.

Now on to installing the OS itself... the most heinous of all acts...