Sunday, August 01, 2010

ALSA Good in MythTV, I do the Hulu!

I'm a very happy puppy. Now at least.

There's a re-occurring mystery that happens with my MythTV boxes. Several versions and several builds of Myth work fantastically when suddenly KAPOW - the recording stops. Oh sure, it says it records crap, but then I try to take a look and nuttin' is on the file system. The only recourse I've been able to find so far is to drop the entire database and re-build it from scratch. Ick.

This happened to me recently and I took the opportunity to take a deeper dive on getting the hardware working correctly. When I first configured my latest Myth box I settled with a non-working ALSA configuration and just piped audio to the OSS compatibility device at /dev/adsp. It worked, even though the DTS or AC3 surround sound pass-thru didn't work. This time I hunkered down and really tried to get the thing to work.

I dug deeper into ALSA's digital out documentation, going through every step they illustrated to find how I could patch MythTV's audio to ALSA. I pointed MythTV directly to spdif by specifying ALSA:plug:spdif for the audio output device. It works fantastically now and feeds pristine audio from the pcHDTV HD-5500.

Once audio worked I wanted to up the ante a bit. I've given up on my cable television service and wanted to see if I could supplant it with Netflix and Hulu. Netflix works great through the Wii and Hulu's Desktop app works amazingly well on Linux. It was a straight-forward process to launch Hulu Desktop right from within MythTV and even bind the same remote commands in Hulu. At first sound did not work: Hulu Desktop uses the default ALSA output instead of letting me explicitly define the spdif channel. No matter - after a little bit of checking I just created a PCM default by feeding the mythtv user account its own, custom ~/.asoundrc containing:
pcm.!default {
type plug
slave.pcm "iec958"

This had ALSA make spdif the default output and Hulu Desktop was happy. Woohoo!

One additional problem however... for some reason both Hulu Desktop and MythTV rendered a bigger window than my TV could display. For some odd reason my TV only displays 97% of the content rendered by my video card. For example, if I tried to set my resolution to 1920x1080 (the maximum supported by my television), then MythTV's interface would be slightly too big to fit the screen - 57 pixels would be cut away at the left & right, 32 pixels trimmed from the top & bottom. To get around this I had to tell both Hulu Desktop and MythTV to shrink by 3% and then re-center themselves. For a 1920x1080 resolution this meant having MythTV shrink to 1863x1048 with an x,y offset (a.k.a. window origin) at 29,16. For performance reasons I switch to a 960x540 resolution for Hulu Desktop, which means a 932x524 window size starting at 14,8. Once I made those size & position tweaks everything fit perfectly.

After a ton of trial and error I now have 5.1 channel surround sound for recorded HDTV broadcast streams (when available) and have Hulu Desktop & Netflix running on the living room television. Now I'm happy... no more cable TV, less commercials and tons of stuff on demand. If only Netflix would provide a Linux-friendly player the living room setup would be in pure harmony. Until then, I've got the closest thing to it and a smaller bill every month.