So I managed to find myself yet another 'little' project. I've had an HTPC for years, running Freevo; but that's all it's been, it just plays videos and music. At the very start I had it set up as an analog PVR, and recorded all of two things on it, but then the sound broke and I just didn't care enough to fix it.
Lately I bought a second HD box, as I think I mentioned, and it has a fairly neat feature - if you connect an eSATA hard disk to it, it'll work as a PVR. But of course it's a typical cable network PVR, the files are locked up and there's no commercial skipping or anything. (It is dual-tuner, though). And I don't have any appropriate disks lying around - only an IDE one, and I can't find any enclosure that lets an IDE drive connect via eSATA. So I'd have to buy either Shaw's 'own' disk (apparently it's a rebadged Western Digital), another eSATA disk, or an eSATA enclosure and SATA disk. All those options are over $100, and...meh. I also realized I'm likely going to be in the UK during the NHL playoffs, which is clearly terrible.
So I decided I'd get my HTPC working properly as a PVR again, and see if I can't do something SlingBox-y with it too. (The SlingBox streams live video over the internet, basically, if you've never heard of it). Luckily for me, my older HD box has its own neat feature: it's a Motorola 6200. That box has a Firewire output, and if you hook that Firewire output up to a PC, what you get is the raw, full-quality high definition MPEG-2 stream, complete with audio. Neat, yes? I've known about this for a while but just never bothered hooking it all up. Once or twice Shaw have turned on copy protection on some or all channels, as far as I can gather, but people write angry letters and they generally turn it off again after a bit.
(Apparently, there's a law in the States which says that if you have a box from your TV service which has a Firewire port, they have to enable it and allow you to stream video out of it, if you ask them to. It's been diluted a bit but it more or less still stands. Google it if you're interested.)
This feature is sufficiently cool that people have been using it for years now, and MythTV has fairly mature support for this kind of Firewire input. It even comes with a neat script which changes channels via the Firewire connection (no, I didn't know you could do that either!) The motherboard in my HTPC has no Firewire ports (it's a damn cheap motherboard) so I went out and bought the absolute cheapest yum-cha Firewire adapter I could find - a princely $10, including tax. I followed the MythTV instructions, and damned if...nothing. Nada. Zip. Not a fricking dicky bird. Upon further investigation, it seemed as if the kernel hadn't done anything with the card at all - lspcidrake (the HTPC runs Mandriva) was showing the module as 'unknown'. Crap, I thought. I nearly gave it up as a bad job and got a more expensive card, but happened across a post from a guy who'd had to switch PCI slots to make it work. So I experimented with different PCI card/slot permutations until I got one which got the ohci1394 module loaded and a /dev/raw1394 device showing up. Then started a cycle of twiddling with configuration commands and re-running the connectivity tests, with mixed results. In the end, I think the combination of the super-cheapo card and cheapo motherboard does affect the reliability a bit. I've entirely hung the system by nudging the cable while it's busy streaming TV, and it seems to have an odd habit of switching from node 0 to node 1 (some Firewire thing), which requires a reconfiguration of MythTV's channel-switching script, which is a pain. But basically I've got it working reasonably reliably, now.
Setting up MythTV was actually pretty easy - I just glued together the Firewire instructions and the general MythTV setup instructions from the official docs and pretty much got it working. It has its little idiosyncracies, of course. In a fairly typical way for Linux apps, it's designed to scale to ridiculous levels - it has a client/server architecture and can actually have multiple 'servers', each with multiple video sources, all connected together in a ridiculous giant agglomeration so a single MythTV setup can be recording seventeen shows from ten different cable boxes spread across five machines while simultaneously playing back video on forty different frontends, or something silly like that. Which of course means that various bits of the configuration are way more complex than they need to be, for a simple one-box setup. The options for transcoding recordings down to a reasonable size (the raw HD streams come to 5GB/hour, with surround sound) are pretty bizarre at first sight; only if you imagine configuring one of the ridiculous setups I described above do you suddenly realize 'oh, yeah, that's why it was designed that way'. There's the usual media center knobs to twiddle - getting your remote control set up, setting up the video and music plugins, and so on. You have to set up a third-party TV listings service (it's $20/year, not that terrible). But really it's not bad, certainly less painful than Freevo (which requires you to hand edit its configuration files, which are written in pure Python...) or the MythTV I first tried to set up in 2004 (though you could get listings for free back then).
So right now I'm watching Andy Murray against Mario Cilic in the Australian Open semi-finals; the stream comes into my HD box, gets piped to my PC, and rendered via VDPAU. It looks flawless, just as if I were watching direct via the box (which you can still do even with the Firewire up and running - useful if it all goes pear-shaped). I can do the whole 'pause live TV' thing, and the recording will be available for me to watch tomorrow if I happened to want to, or I can store it for the future. It's really pretty neat and works very well. I also have MythTV configured to let me watch videos and listen to music (though honestly I prefer Freevo's interface for those).
The SlingBox bit may be trickier. There are avenues to explore. There's a neat web interface for MythTV you can set up - it's called MythWeb, it's basically a MythTV frontend that is a web application, you connect to the webserver and can configure recordings and stuff, most of the things you can do from the 'normal' frontend. It also has some neat remote video watching tricks: you can get a direct download or ASX stream of any stored recording. I can actually log in to the web interface from another system on my network and stream a recorded show in full HD quality - pretty cool. Obviously, though, 5GB/hr is far too much for the system to stream over the Internet.
I could transcode a recording down to a reasonable size and stream that, of course, but then you can't use that to stream live TV. What may be the most promising avenue is MythWeb's neatest trick: it actually has an inbuilt Flash streaming server system, so if you click on any recording, besides the ASX and direct download links, you see a Flash streaming player, much like Youtube. There's a configuration widget where you can tell it what resolution and what bitrate to use for that, and MythWeb has the backend transparently transcode whatever it is you want to stream before serving it up through the Flash widget, so it's much more suitable to Internet bandwidth. Some people have reported that they've been able to successfully use this on a currently-recording show - so they can set their box to 'record' something at 9:00pm, then log in to MythWeb at 9:01 and successfully access the Flash stream of that recording, while it carries on being recorded. This is obviously a fairly dodgy chain, but there's no absolute reason it can't work. I tried it briefly and it didn't quite get there, but I'll tinker a bit more and see if I can get it to fly.
So, the final chapter of this little odyssey...when it has fallen over (see above) I suspect it has something to do with resources. My HTPC box is nothing particularly oomphy - it's a Pentium dual-core E2180, which is not a high-end chip (that particular line of 'Pentiums' is essentially the cut-down, 'Celeron' version of the Core Duo), and it's only had 512MB of RAM for years. It never really needed more than that to be a media player, especially since I got VDPAU support working so all the video decoding work happened on the graphics card. But it's pretty borderline for a Myth PVR setup. I noticed it was nudging up against the top end of the RAM.
Then I realized I actually have a couple of gigabytes of RAM lying around the place. Only DDR-1, but the motherboard - being a cheapo one meant for cheapskate upgraders like me - actually does support both DDR-1 and DDR-2 (it's got two pairs of RAM slots...it also has PCI-E and AGP video slots, and can support regular old PCI video cards too. You can have one each of all three if you really like. Crazy.) So I yanked out the 512MB stick and threw the 2GB in there. Thought 'what the hell', cranked the FSB up to 266MHz - many people have the E2180 overclocking easy to 2.66GHz, from 2GHz - and hit the big red button. Well, those successful people are obviously using better motherboards than mine, cos mine doesn't even POST at 266MHz FSB. Did the CMOS jumper reset thing, and the board came back up fine. Reconfigured my BIOS settings, and...
the fucking thing wouldn't boot any more. Just sat there with the Blinking Cursor Of Death at the point it's supposed to load up the bootloader. Now, it's 1:30am at this point and I'm getting cranky. I start swearing under my breath and doing all the usual crap. Reset the BIOS again. Twiddle with the FSB some more. Pull one of the RAM sticks. Pull the other. Go back to the 512MB one. Mess with the RAM speed and timings and voltages. Twiddle all the SATA interface settings I can find. All that crap. Nothing doing. I'm halfway through trying to reinstall the bootloader from a rescue CD (not a simple operation on a system with four hard disks, none of which has the same device node in a rescue environment as it does for realz) when I figure that's a bad idea and it's probably something else. Finally I hit on disconnecting the Silicon Image PCI SATA controller card to which my RAID array disks are all connected. Success! the bloody thing boots fine. Of course, the system's not a hell of a lot of use without the RAID array. Finally I discover that setting the motherboard's SATA controller to RAID mode - even though it's controlling one whole disk, which is not a part of any RAID array - inexplicably makes it work. Even though I never had to do that before, the whole time I've had the freaking setup.
Hardware. I hate hardware.
So I put the 2GB of RAM back in, double-cross my fingers and kick the FSB to 233, and - fricking hallelujah - up it comes. Jebus, that was an hour I'll never get back. Still, it's up now, with four times the memory and a modest 1/6th CPU speed bump. Hopefully that'll help keep it stable and make it do the more demanding PVR-y bits a little quicker.
Despite that last icky hardware crappiness footnote, I'm pretty happy with this project - got the whole thing up and running really quite nicely at minimal expense ($20 in total: $10 for the firewire controller, $10 for the cable) in an afternoon. The SlingBox trick may be harder and I may have to give up and just live with watching the games the morning after they happen, but I'll do my best to hack something up. Never surrender!
(Yes, I did some work today too. Honest!)