Thursday, January 14, 2010

Adventures in building an HTPC

It's 2010, and like a lot of folks I'm a bit disappointed the future was not available as advertised. No rocket packs, no flying cars, no moon bases, no androids, no space hotels, no Martian colonies, nor any eerie black monoliths igniting Jupiter into a sun (that we know of). Watching TV hasn't evolved very much either. Ok, so we got digital broadcasts and widescreen flat panel televisions and the CES show out in Vegas was loaded with 3D TV hype - but the basic way most people watch TV isn't all that futuristic. Sure, some people have Tivo or a DVR from their cable or satellite company, but that's just the digital version of time-shifting your viewing with a VCR - and people were doing that back in the mid-80s. If you've got digital cable or satellite you can watch some stuff sort-of "on demand" which is a good start at living in the future. . .which is now the present.

But the obvious "future" of television is the complete convergence of the Internet and Television. They (the mysterious "they" who know all, see all) have been telling us for years that is what's going to happen, but the TV networks are obviously resistant to it, lest they go the way of so many newspapers. You can now get shows on from half a dozen networks, and the ones who aren't there provide them on their own web sites. That's if you like professionally produced corporate sanctioned content. There are, of course, tons of amature videos out on the Web too, and it's not unheard of for "made for web" content to be high quality too (I'm looking at you "Dr. Horrible's Sing-Along Blog").

My desktop computer sits in a corner of the living room and has a graphics card in it with S-Video output. I ran long audio and video lines around the edge of the room so I can switch the living room TV to the "Line Input" and have my computer set up to use the TV screen as an additional monitor. For years now I've been dragging media players and browser windows over to the TV and popping them full screen. That's also how I play DVDs. I've never actually owned a stand-alone DVD player since I could just use the one in my computer on the living room television. While this is kind of cool, it does tie up my desktop computer as a "media center."

So, I thought, why not just HAVE a dedicated media center computer? Well, cost is part of the reason. So I asked some friends and family for their broken or obsolete compters and components just to see if I could manage to build up a workable HTPC ("Home Theater PC" or "Media Center PC" if you prefer) out of cast-off parts. Here's what I ended up with:

Full ATX tower with a 500 W power supply
1.25 GB DDR Memory
Abit IS7-E2 motherboard
Pentium 4 CPU
ATI Radeon X1300 Graphics card (2 DVI ports, 1 S-Video output)
ATI TV Wonder Pro Tuner Card (Coax and S-Video inputs)
DVD-ROM drive
DVD+RW drive
Floppy Drive
Microsoft wireless keyboard and mouse
80 GB Seagate SATA Hard Drive

For the underlying operating system I wanted something stable and free so I went with the Ubuntu 8.04 LTS "Hardy Heron" version of Linux, and installed XBMC (X-Box Media Center) on top of that. Which all sounds well and good, except that's my FINAL configuration. It took a week of failed attempts to find hardware/software combinations that would actually work together.

Attempt #1
Installed the XBMC Live 9.04 to the drive. Included ATI drivers didn't work. Underlying system is Ubuntu with Flux (which I hate) and X-server conflicts or frankly I'm not sure what all - I just couldn't get it to work. I could run XBMC windowed in Flux, but couldn't make it work fullscreen nor get TV-out to work. DVD playback also wouldn't work. Wiped the drive, time to start over.

Attempt #2
Installed the XBMC Live 9.11 to the drive. Same results as the older version, except a second attempt to install legacy ATI drivers screwed up the system so badly I couldn't get anything to work. Wiped the drive started over.

Attempt #3
Decided I needed to forget the prebuilt live cds and build a live system myself. Following instruction for "XBMCbuntu" I installed the minimal version of Ubuntu "Karmic" and got XBMC installed on top of that. I decided it would be easier to configure things if I installed an underlying desktop system, so I went with XFCE since it's light-weight. After fighting with various configuration issues and repeatedly having to install additonal software just to do that I realized I probably just should have started with Xubuntu. So I wiped the drive again.

Attempt #4
Installed Xubuntu "Karmic" and put XBMC on top of that. Had problems with the ATI drivers though. The Radeon X1300 is no longer supported by the drivers from ATI so I had to use the Open Source drivers, but the TV output support on that is not quite fully baked yet. I couldn't install the older ATI drivers that did support the card because they don't work on the X-Server used by Karmic. So I had to decide if I was going to try and "downgrade" the X-Server or if I should just downgrade to an older version of *buntu that had a compatible X-Server already. I opted for the latter. Wiped the drive once again.

Attempt #5
Decided to just go with the most "vanilla" option and installed Ubuntu "Hardy" 8.04 Long Term Support on the drive. It's stable and problems are well documented in the support forums, often with multiple solutions. The Proprietary ATI drivers offered up by Ubuntu ended in a "White Screen of Death." If I disabled direct rendering I could get a usable desktop, but XBMC requires direct rendering for OpenGL so I HAD to have it working. I tried using the EnvyNG installer and forgot to remove the drivers installed by Synaptic first, which led to some install errors and a broken X-Server that I tried and tried to reconfigure, but whatever got hosed up it was bad. Got mad, wiped the drive and started over. Again.

Attempt #6
Again, with the same version of Ubuntu, only this time I didn't install the drivers presented by Ubuntu, and I didn't use EnvyNG. I went to the AMD/ATI web site and found the last driver (Catalyst 9.2) that supported my card and downloaded it. Backed out to a command line, stopped the X-Server, and ran the installer. That got me to a desktop, and I could run the Catalyst Control Center for the ATI card, but it reported it was using the "mesa" software acceleration for OpenGL. XBMC didn't care for that - in fact it refuses to run. I was able to get DVDs to play, even full screen, and could choose between the monitor and the TV, but not both at once. I later realized it was because the DVI-0 and S-Video ports are "shared" so you have to pick and choose. However, when I moved the monitor to DVI-1 so I could have cloned video on both screens the auto-detection would default to using the VESA drivers! I went through several guides online on how to "fix" various ATI issues on Linux and eventually got to a point where I could either have XBMC working, but DVD playback was just a black screen or get DVD playback working and XBMC was a black screen. It seemed no matter what I did I could never get them both to work.

Attempt #6.5
After spending a couple days trying to sort it out I uninstalled everything ATI from the system and booted with the VESA drivers. I downloaded the next older ATI driver from the AMD/ATI web site and installed that. When I ran the installer I made sure the monitor was connected on DVI-1 and the TV was on and connected to the S-Video port. FINALLY the configuration worked! I had cloned video on both screens, I had hardware accelerated OpenGL graphics for XBMC, and DVDs would play full screen.

The next issue was to get the ATI Wonder Pro TV Tuner working. XBMC actually doesn't have ANY support for TV tuners! Crazy, huh? The recommended solutions are to either use XBMC as a "front end" to access a MythTV server (MythTV is sort-of an open-source Tivo thing), or use a program called "TVheadend" which can create a "media stream" for TV tuner channels that XBMC can be configured to play. The "TVheadend" routes sounded easier so I tried that first.

I was getting errors such as "/dev/video0 doesn't exist" because Ubuntu auto-detects the hardware for video capture and the device map isn't even created unless the device is detected as usable. Without a signal source a TV card is useless, so Ubuntu would just pretend it wasn't there. Once I realized that and rebooted and the /dev/video and /dev/video0 existed. I eventually created the files manually as root and now they "stick" even when the card doesn't have a signal. In order to ACCESS the card I needed to go into the "Authorizations" control panel and release access to the device and then, with the "Users & Groups" make sure my user account was part of the "video" group. Failing to do those things resulted in "access denied" permissions errors. But there was another problem (I'll get to in a moment). Oh, and since it is an analog capture card and TV broadcasting over the air has all gone digital, I had to connect it to the Cable TV coax to make it work.

TVheadend wouldn't work for me. In reading the FAQ on the developer's site I found out it only supports the PAL broadcast standard for analog TV capture cards. Since I'm in the United States I needed something that could work with NTSC.

So the other alternative is MythTV. I hadn't heard good things about it. I'd heard it was difficult to set up and the interface sucked. The criticisms were correct. The installer failed to set up the SQL server backend and I had to manually configure it. The front-end interface is as clunky as I'd heard, especially after the slick "Confluence" interface of XBMC 9.11. MythTV's setup showed my card by the correct name and let me select it, but then acted like it didn't exist. I never did get MythTV to work and uninstalled it.

It would be nice if I could also record live TV shows to the hard drive (something MythTV is designed to do) but the hard drive is only 80 GB, which is far too small a capacity for real duty as a DVR. But I figured if I could get it working maybe I'd pick up a larger drive in the future. So far I haven't been able to get Gstreamer, Transcoder, or Mencoder to record from the card. The closest I've gotten is white noise sound and a scrambled picture. I've decided it's not worth my time to try and get a feature working I'll likely never use.

I realized that I didn't actually NEED the ability to record TV shows. I know if I miss a show I can usually catch it online anyway, so I literally haven't recorded a TV show in YEARS. All I really needed was the ability to watch live TV! I reasoned that if I could find a TV Tuner program that would see the card I could just "launch" it from within XBMC. I knew there were launchers for game emulators, and a generic one to launch any binary so I just needed the tuner program.

KDETV was my first stop. It saw the card, but the channel scanning wizard didn't work. The sound didn't work. I also had zero luck with XawTV, Zapping, or Mplayer. In looking for solutions I ran across mention of another program called "TVtime." I downloaded it and lo-and-behold it WORKED! Right from the start it not only saw the card but when I launched TVtime I was watching channel 2 on my Cable TV.

So I installed the "Launcher" plug-in for XBMC and configured a launcher for TVtime, then added that launcher to my Favorites. From the main page of XBMC I can hit my Favorites and select "TV Tuner" and BAM! TV Time opens up and I can watch TV.

Other plug-ins I installed that worked for me (ones with "*" by them also worked in XBMC 9.04):
SVN Installer
XBMC-Zone Installer
National Geographic*

These ones didn't work right and I uninstalled them:
Animeseed (plugin works, but folders were empty)
InstanzAnime (plugin doesn't die, but couldn't find any content in the folders)
Veoh (crashes during video buffering)
Navi-X (hit and miss with content)
VideoMonkey (hit and miss with content working)
Yahoo Music Videos
myTV (python script error)
ABC (Australia) and CBC (die with a script error)
Accuweather (script freezes while retrieving data)

I didn't even bother finding a plugin or script for because I know none of them work right now. Hulu has been in sort of a war with "scrapers" and changed how their site worked in a way that broke the Hulu plug-ins. But I watch a lot of stuff on Hulu, so what am I gonna do?

I created a launcher for Firefox with Hulu set as the home page. I can launch it from within XBMC and hit F11 to pop the browser full screen. I tweaked the settings to over-ride the fonts with some GIGANTIC ones I can actually see on a TV screen from across the room. A good work-around, I figured, until a working Hulu plugin or script surfaces again, right? Well, not as good a work-around as I'd have liked.

Adobe Flash Player on Linux SUCKS. Especially for full-screen playback, where it turns everything into an unwatchable slide-show. This appears to be more of a problem on system withotu Nvidia cards because of the stupid way Adobe decided to check for hardware direct rendering with the "SGI" vendor flag. SGI contributed code to the OpenGL project a long time ago, so just about any cards out there that aren't Nvidia (and I've heard evne some of them) report the vendor string as "SGI." But Flash on Linux turns off hardware support if it sees that and forces you to use the software rendering, which is CPU intensive - no, make that VERY CPU intensive - and makes for unwatchable fullscreen videos. I obviously have harware accelerated direct rendering working or XBMC wouldn't even start, so I found out you're supposed to be able to over-ride the shoddy detection by creating a folder and file at /etc/adobe/mss.cfg and inside that file put the line OverrideGPUvalidation=1. Does it work? Not very well. It slightly improved playback, but not in full-screen mode. Ok, the videos play decent at their original embedded size on the Hulu pages, but that's kind of tiny. Here's what I have to do to watch it any larger:

1. Quit XBMC because no other OpenGL programs can be running
2. Use the "Pop-Out" option instead of the "Full Screen" option.
3. Once the littel pop-out window has loaded I have to close the window from which it popped - you can't even have another instance of Flash running because it's using OpenGL too.
4. Hit F11 on the Pop-Out window. I get a bigger version that still has slightly choppy playback and I have to live with the "playhead" bar across the bottom of the screen, but it's still better than watching a postage stamp sized video.

Can we say "Pain in the ass?" This isn't likely to be "fixed" until a couple of things happen. Either Hulu has to stop breaking the XBMC plugins and let them scrape the video content (unlikely), XBMC developers need to come up with an unbreakable way of scraping content (unlikely), or Adobe needs to rewrite the Flash Player for Linux so it actually works as well as the one for Windows (unlikely).

SO, if you like to watch a lot of videos you will want to watch them on a Windows system, since that's the only platform on which Adobe cares to make their player function properly. If you want to build an XBMC system and use Windows as the desktop system underneath I'd recommend only doing that with a Windows 7 machine. I couldn't get XBMC 9.11 to work on a Windows XP system at all. Apparently XBMC 9.04 does work (because it uses OpenGL rather than DirectX), but I also found almost none of the plugins work under 9.04 which makes the whole idea of using XBMC kind of pointless. To summarize:

Use LINUX if you want:
Stable, Free, Secure
Don't care so much about Hulu content
Don't have an ATI graphics card

Use Windows 7 if you want:
Hulu has to play smoothly in Flash
You have an ATI graphics card
You have any other hardware that's poorly supported on Linux

What I ended up with is a system I can use to:
Watch DVDs
Watch YouTube videos
Watch Free Movies
Catch TV shows from a number of networks
Watch Live TV
Stream Net Radio
Play MP3s and CDs
Play retro video games
Get my local weather instantly
Access the Internet on my TV
Do this all with a keyboard and mouse across the room on the couch

I'll save anyone with an ATI TV Wonder Pro tuner card a lot of trouble setting up the audio. Apparently only SOME of the cards have PCI Audio enabled, the rest will ONLY output sound through the (green) line jack on the back of the card. Here's how you find out which one you have:

1. Open a Terminal
2. Type: lspci -n
3. Look for: 14f1:8801 or 14f1:8811 (Hooray! You have PCI sound enabled card!)
4. If it says 14f1:8800 you're out of luck. Gotta patch sound physically OUTSIDE the computer.

You have a couple of options to patch sound physically:

Connect a set of amplified speakers to the sound output of the TV card, or run a patch cable to a stereo receiver and select that input when you want TV sound. You'll have to have ANOTHER set of speakers, or ANOTHER patch cable running from the sound output of your computer audio card. In other words, your TV and Computer sound outputs are not connected to each other in any way! If you have set up the 3 jacks on your sound card for Surround Sound you will HAVE to run independent audio connections.

You can only do this if you either have more than one audio card in your computer OR if you only have one audio card that you are NOT using it for Surround Sound output! You'll need a small 1/8" male to 1/8" patch cable long enough to run from the (green) audio output on the TV card to the "Line In" port on your audio card. Then in the ALSA Mixer make sure that "Line In" is not muted and has full volume.

The last piece of the Live TV puzzle was to get Television Listings on my TV I can browse (similar to the on-screen listings you get with digital TV or satellite). The main script used on XBMC for that purpose is called "myTV" but it would kick out a Python scripting error when I tried to run it. I couldn't even get to the configuration screen. "TVtime" can incorporate XMLTV data into its on-screen display, if you can actually GET the XMLTV data. Part of the problem is in finding FREE listing services. Most plugins, programs, and scripts out there use "Schedules Direct" which has gone to a subscription service for $20/year. They also apparently own Zap2It, and so I've read on the XBMC forums the "Zap2It Labs" supports open-source projects and there IS an authorization code for XBMC software to get the listing data, but the only two listing scripts or plugins I could find were "myTV" and "WebScheduler" - neither of which would work (the latter wouldn't even install). XMLTV is available from the Ubuntu repositories, but that really is just a collection of EPG scripts. The "North America" ones access Schedules Direct, so those were useless to me. Then I found "mc2xml" which is a small stand-alone program that can access different EPG providers and generate an XMLTV-complient file. To get free listings the program accesses "TitanTV" which is also a problem. TitanTV's EPG service requires a 30 digit ID number to work, and the ID provided with "mc2xml" has been deactivated. Apparently the manufacturers of tuner cards pay TitanTV for access (and that cost is figured into the price of the card when you buy it). The ID number is a UUID related to the hardware (not exactly easy to get because you have to use a packet sniffer to capture it). In theory there is one ID per card, so only one user per ID. If they detect too many users with the same ID then TitanTV deactivates that ID number and it no longer works. Which is why nobody who HAS one of these ID number will let anyone else use it!

However, you can go to or and put in your information (without even needing to register for an account) and get your local TV listings in a web browser. So my solution was to just bookmark those sites in Firefox and when I want the on-screen listings I just use my Firefox launcher. The "myTV" listings looked pretty good in the screen-shots I've found, so it would be great if that would work within XBMC, but until the plug-in gets fixed on Linux the browser work-around will have to do.

Obviously building a HTPC out of cast-off parts isn't the ideal way to do it, and there are still a lot of issues with "scraping" content (audio, videos, TV listings) from web sites. If I had money for an HTPC it would be hard to argue with just BUYING a "media center" computer that already has all the software and hardware working together.

1 comment:

Off World Girl said...

As I mentioned in the post above, the XBMC plug-ins only keep working if the structure of the site they're scraping doesn't change, and lots of sites providing content regularly change the structure to thwart scrapers. As a result, I have an update to the working/non-working plug-ins list:


Animeseed now works!
Anivide (pulls from multiple sources)


Animefreak (directory listings work but videos are now on a server requiring requester authentication, and only the actual Animefreak web site can authenticate).

Just because a plug-in works, though, doesn't mean EVERY video it finds will play. And some of the sources for videos have time limits - for example one will let you watch 71 minutes and then cuts you off for a while. Veoh will only let you watch the first 5 minutes of a feature-length video.