Tuesday, January 18, 2005

Adding Menu Commands

But I don't know C++!
No problem... MythTV's menus aren't created in code - they're built from XML documents, and if you're familiar with XML, then you can edit your menus, create new ones, etc. I'll briefly discuss how I was able to 'hack' my menus to add a couple commands that I needed. This isn't textbook, it's just the way I've found to do this through looking through some of the code, and tinkering. Cause, isn't that what this project is all about?

How Do Menus Work?
If you'd like to check out the menu-building XML documents, browse through /usr/share/mythtv/*.xml. Start with mainmenu.xml, and branch out from there. Here's a snippet from mainmenu.xml:

----------------* snippet

<text>Media Library</text>
<action>MENU library.xml</action>

----------------* /snippet

This example is pretty straight forward. Each button/menu item gets a "button" entry.

Menu Themes
Inside, you'll need to include the "type" of button - in this case, it's "MENU_MEDIA_LIBRARY." This is used to determine how to render the page - what image to use and where to put it. In this case, if you look in /usr/share/mythtv/themes, you'll see how each theme implements this button type. For example, in the "blue" theme, in /usr/share/mythtv/themes/blue/theme.xml, this button type is described as:

----------------* snippet

<buttondef name="MENU_MEDIA_LIBRARY">

----------------* /snippet

In that directory you'll find cd.png. I haven't spent any time with the themes, so this is as far as I'll go into themes.

Menu Entry Text
The "text" element describes the text to display on the page. I've found that there is a maxium number of characters you can use, but haven't checked what that number is. You'll notice that the menu supports different languages. I haven't bothered with translations.

Menu Actions
And last and most important, you'll notice the "action" element. This tells MythTV what to do when you select this menu entry. I've found the following to be valid:
* Menu Command
- usage: MENU [some menu xml file]
- purpose: To tell redirect MythTV to another menu. This is useful for subdividing your actions into different, specific pages.
- example (omit the quotes): "MENU library.xml"

* Plugin Command
- usage: PLUGIN [plugin name]
- purpose: I haven't used this yet, but it apparently launches a MythTV plugin
- example (omit the quotes): "PLUGIN mythgame"

* Built-In Actions:
- purpose: to launch an action built into MythTV
- example (omit the quotes): "TV_WATCH_RECORDING"

* Execute a Command:
- usage: EXEC [some command path]
- purpose: to launch an external command
- example (omit the quotes): "EXEC /usr/local/bin/mythtv_rip_cd"

I've only really worked with the "EXEC" action. For example, I'm finding it useful to write Perl scripts to handle stuff in the background that normally occupies MythTV's display, such as ripping/encoding CDs to mp3/ogg. I wrote a simple Perl script that rips & encodes a CD off in another process, letting me continue to use MythTV while the CD is being worked on. As I find the time, I'll write several more of these commands, and eventually post them all here on the blog to share.

Menu Dependencies
There's one more element inside a "button" group - "depends." I haven't looked into this, but it seems that this refers to a module. I would imagine if the specified MythTV module isn't loaded, the menu item will not appear, but I'm not yet sure.

Customizing Your Menus
I need to hand it to the MythTV crew - the menuing system seems to have been done really well. I'm impressed that the menus are rendered from XML rather than compiled (you'd be surprised how often that's the case), and this next bit of information impresses me even further... Each user can keep their own copy of the menu XML files.

Rather than edit the files in /usr/share/mythtv/, you can (and I would strongly encourage you to) copy the XML documents that you want to edit into your MythTV user's "~/.mythtv/" directory. If MythTV finds an XML file here, it uses it rather than the ones found in /usr/share/mythtv/.

So, for a little fun, try editing one of the menus:

1. Copy the mainmenu.xml file from /usr/share/mythtv/mainmenu.xml to ~mythuser/.mythtv/
(assumes that "mythuser" is your MythTV user)
2. Edit ~mythuser/.mythtv/mainmenu.xml
3. Replace "Watch TV" with "MythTV Rocks!"
4. Restart MythTV and get a chuckle...
5. When you're all done, remove the overriding XML file to go back to the normal menus

Kudos to the MythTV developers, they've done a great job with the menus! They've given us a way to really make this system our own. It's easy to add and remove commands and menus - we can add anything we need without any worry of screwing up the system, thanks to the home directory menu overriding. Spend a little time playing with this, and you'll think of all sorts of interesting ways to use it. When you do, please let me know what you've come up with!

Wednesday, January 12, 2005

Dual Input Hauppauge 250 PVR Card for Recording Digital & Analog Cable

Recording Digital Cable
I've been using the coaxial cable inputs at Tuner0 on both my Hauppauge 250 and my Hauppauge 350 thus far, but wanted to be able to record my digital cable as well. There's two problems to overcome for this task: getting the audio & video from my digital cable into MythTV, and changing the channel on my Motorola Digital Cable box. I'll start with the latter problem.

Changing the Channel on My Motorola Digital Cable Box
I bought myself a MyBlaster Serial IR Blaster from My.Tv store for $40 (plus tax & shipping). It's a pretty cool little box that I have sitting next to my MythTV box. It plugs into the computer's serial port, and faces the back wall of my family room.

I decided to go with this device rather than a simple short-range IR blaster that I could tape in front of the cable box because this one has a long range and I'd like to be able to control more than just the cable box. The signals are bouncing off of my back wall and back at the entertainment center without any problems.

I downloaded the user-contributed script for the MyBlaster, written by William Munson -- thanks William - excellent script. I made some small mods to it for my purposes -- I think the only changes I made were timing and device settings. The script one of several commands as the first parameter. For example, to turn on the device, use:

/usr/local/bin/IRBlaster_DigitalCable.pl power

or, to change the channel to channel 33:

/usr/local/bin/IRBlaster_DigitalCable.pl 33

So, I had to start by figuring out what my MyBlaster device code was, so I could enter that in William's script. I did some digging around, and found that this box wasn't actually made by Motorola, but by GE (as far as I can remember). The MyBlaster code for my cable box is "0276".

The script works great! I'm able to change channels on my cable box using MythTV without any problems. I'm very happy with my $40 purchase.

The Hauppauge 250's Inputs
This card has three video inputs it may choose from:
   * Tuner0 (coaxial cable)
   * Composite4 (A/V cables)
   * SVideo# (I haven't used this)

Tuner0 on the 250 has been working great to bring in the analog coaxial cable into the MythTV box, but I needed a way to bring the Digital Cable into the MythTV box. My digital cable box has two outputs: one for coaxial cable, and one for composite A/V cables. I did some rewiring so that the coax goes into the TV, and the composite A/V cables go into the Hauppauge 250's composite input. From trial and error, I found that this input is Composite4 (not Composite0, which would seem to make sense).

DataDirect for Digital Cable
Now that I have this new Video Source with several new channels, I have to tell MythTV what those channels are. To do so, I logged back into my DataDirect account, and added the new channel list. I had to unselect the channels I didn't purchase, including the HDTV channels and other premium channels. No reason to let MythTV think it can record a movie, only to tape 2 hours of "Premium Service Channel" error message.

Putting It All Together
I ran mythtvsetup to enter my new DataDirect channel list and map it to my Hauppauge 250. First, I entered the channel list in the "Video Sources" section. I named this new section "DataDirect Digital Cable" (the other was named "DataDirect"). Then, I mapped this new channel list to Composite4 on /dev/video1 (the Hauppauge 250 is my second card. If you only have one card, then you'll map to /dev/video0. If you have two cards, you'll have to figure out if it's /dev/video0 or /dev/video1 -- I think the standard is that /dev/video0 is the card closer to the AGP slot on your board. Here's also where you need to tell MythTV how to change channels using the IRBlaster script. I entered:


Since you can't splice digital cable like you can with analog, I'd like the Hauppauge 250 to use the coaxial analog cable whenever it can, and only hit the digital cable when absolutely necessary, so I can still use my digital cable box when it's taping something on network tv. There are two options for this:
* when setting up the DataDirect channel list, only select the channels that aren't on analog tv
* give the analog tv Data Source a higher priority than the digital cable source

I'm too lazy to unselect 78 checkboxes, so I chose the latter solution. If a recording is scheduled on ABC, MythTV will use the coaxial cable input. The preferences will probably also push off digital cable recordings if they're going to repeat on analog cable -- it's a great feature.

I then ran mythfilldatabase to go out and populate the database with the new channels and their line-ups. Last, but not least... I restarted mythbackend. If you don't do that, then the change-channel script won't be called. I'm not sure you'd even have access to the new channels if you didn't restart mythbackend.

Productive night... worth the extra work. I'm sure being able to tape all of my premium movie channels won't help my storage situation though...

** I'll include my IRBlaster_DigitalCable.pl script soon.

Monday, January 10, 2005

Quiet Case & Overheating

Initial Setup
I'll spare the details of my initial setup -- I followed Jarod's amazing HOWTO (thanks Jarod). I'm running Fedora Core 3, with the Linux 2.6.9-1.681_FC3 kernel grabbed from ATRPMS using apt-get.

Antec's Piano Black Quiet Media Case
I decided to get a new case that's not a tower, and looks a little better on top of my entertainment center. Noise is a big factor too - I wanted the box to be very quiet, so I settled on Antec's Piano Black Quiet Media Case. The 380W power supply is absolutely silent. It's even got a washable filter in front of the air intake to keep it clean -- NICE. And, there's two low-voltage power cables inside to power the quiet fans.

The only noise coming from the case was from the 4 hard drives and the processor fan. It was amazingly quiet -- until I started having overheating problems. I decided to give the outtake fan on the right of the box full voltage to bring some of the hot air out, because the processor was getting up over 60 degrees Celcius, and the hard drives could cook a slab of ground beef. I wasn't happy about this, but it was necessary. The box is still pretty quiet.

I bought rounded IDE cables to further help the air flow, since the cables were right in front of the outtake fan.

Hauppauge 350 Card Overheating
Since I've been up and running, I've had two full lockups -- the whole system froze. It's been years since Linux has completely frozen up for me -- it looks like an overheat of the Hauppauge 350 card. The heatsink on the Hauppauge 350 would get extremely hot, almost burning my hand. It's no surprise, I'm using the card for the TV Out for both the mpeg2 TV recordings and for X as my primary graphics card.

So, to bring more air across the heatsink on the 350 I dropped a big fan in the box, blowing air across the PCI cards at low voltage to keep it quiet. So far, so good, but we'll see over the next week if this helps.

Sunday, January 09, 2005

Building the ReiserFS LVM at /var/storage

450GB ReiserFS LVM
When you configure MythTV, you select your folder for storing recordings. That's great if you have one monster hard drive -- or, if you use LVM. In my case, I have both :)

Basically LVM lets you put several drives together, making it look like one drive. You can add new drives to the volume, and even (carefully) remove them. I'd recommend backing up anything you have that you need before trying this. I screwed up and ended up losing some digital camera photos. Since then I was able to rebuild most of the lost data, and retrieve partial images (they're each missing about 1/4 of the image). But, in any case -- backup, backup, backup... then experiment.

I used the LVM HOWTO to setup my drive array. I chose ReiserFS because I read it's much better than ext3, and that there are really good tools for managing ReiserFS drives (which I found out when trying to rebuild lost data). I meant to use ReiserFS version 4, but I think I got 3 -- it's whatever ATRPMS gave me.

My current volume contains three 160GB Western Digital 7200 hard drives which I got at Best Buy each for $30 after the insane rebates on Black Friday. I named the volume VGForMythTVStorage, and mounted it at /var/storage.

So far, it's working great - and, if 200 hours of recording time aren't enough, then I could always add another. Hopefully I'd come to my senses by then, and start cleaning off the old episodes of Three Stooges.