Sunday, June 24, 2012

A few Myth TV tips for Ubuntu 12.04

Good morning all!

I've been using MythTV 0.25 on Ubuntu 12.04 for a little over a month now, and while pleased overall, there were a few annoyances that caused me to scour the Interwebs for a solution. Things are working better now, so I wanted to share my tips for others out there!

1) Legacy Full Screen Support

If you are using Ubuntu with Unity, you may notice the MythTV interface doesn't completely go "full screen". That is, it's somewhat shadowed by the Unity bar and top bar.

To fix this, you'll need the CompizConfig Settings Manager. I don't think this is installed by default, so find it in the Ubuntu Software Center. Note that this is an advanced tool to mess with your settings, and while there is some pretty cool stuff in here, do be careful.

To get MythTV full screen over the Ubuntu panels, use "Legacy Full Screen" support.

1) Under CompizConfig Settings Manager, go to "Utility"
2) Go to "Work arounds"
3) Check "Legacy Full Screen" support.

After that, your MythTV should go properly full screen. Restart if necessary.

Reference: http://www.thegoss.com.au/content/ubuntu-1204-precise-pangolin-mythtv

2) Mythfilldatabase takes forever to run

(Note: These seems to have been fixed in a recent version of mythfilldatabase. A fresh MythTV install on Ubuntu 12.04 seems to no longer have this issue, but the instructions are still here for reference).

One bizarre thing I noticed is that mythfilldatabase never seems to end (actually, my girlfriend pointed out that hard drive was clicking loudly causing me to investigate and finding mythfilldatabase and mysql hogging the I/O. Hint: iotop is a cool program).

This is apparently due to a mythfilldatabase bug, and is fixed in the newest builds, but if you need a work around, here it is:

1) Set up a TMPFS for /tmp
Add the following to '/etc/fstab':

tmpfs   /tmp   tmpfs   nodev,nosuid    0 0

2) Change MYSQL configuration parameter:

Add the following to '/etc/mysql/conf.d/mythtv.cn':

default_storage_engine=MyISAM

Note: It's important to know that in step 1, you are actually switching your /tmp to a TMPFS file system. This means that any data written to /tmp is written to your RAM, and not to your hard disk as usual.

This can have both positive and negative consequences.

Using a tmpfs for /tmp can have some all around nice performance improvements since writing to RAM is far faster than writing to disc. Therefore, programs using /tmp will have their write operations quicker, therefore improving performance.

The downside is that the side of /tmp will be limited to the size of available RAM. This can be issue if /tmp ever becomes full, writes will fail. So, if you run into this issue, your programs may stop working.

If this becomes a recurring problem, you might need to revert your /tmp back to the HD and use the bug fixed version of mythfilldatabase. But, I've been using /tmp as a tmpfs for a good month now and have had no ill effects with moderate usage (I also have 6GB of RAM...just saying.)

Tip: Keep track of /tmp usage with the df command on the command line. Mine is currently only at 1% full.

References:
http://ubuntuforums.org/showthread.php?t=1991684
http://ubuntuforums.org/showpost.php?p=11918589&postcount=35

3) Mythweb PHP errors

I noticed some unusual errors in Mythweb. Simple functions like setting up recordings didn't seem to take, and there were some php error message along the top of some of the pages. This was a bit irritating to fix.

Rather than repeat everything I did, I'll just point you to the official ticket:
http://code.mythtv.org/trac/ticket/10142

I just manually clicked on the individual *.patch files and applied the changes by hand. There's probably a better way to do it, but that worked for me. Hope you find it useful.

4) A new Remove_Commercials script

My first attempt to use my old remove_commercials script failed miserably. Not surprising, since some of the command line parameters changed between versions. But, there's an updated one you can use here:

http://www.mythtv.org/wiki/Script_-_RemoveCommercials 

The script didn't quite work out of the box for me. A few tweaks I made:

1) Replacing all of the usages of $START with "$START"
2) Adding --user=mythtv --password=PASSWORD (where PASSWORD is your mysql password, from the mythbackend settings) to the mysql command
3) You might also get better results if you use -f on mythcommflag instead of --chanid and --starttime, but if they work for you then great.

I'm still playing with the commercial cut script a bit, so I may make some more updates, but hopefully that'll give you something to start with.




One issue I still have is the display mythfrontend runs on. I haven't yet been able to control what display it opens on from the command line as setting $DISPLAY has no effect. But I'll keep trying!

If you have any of your own tips, let us know. Take care, and have a great day!

Sunday, June 3, 2012

Configuring LIRC for HVR-1600 in Ubuntu 12.04




As promised, here is the recipe I followed to get LIRC working for my Hauppauge HVR1600 card on Ubuntu 12.04. This includes both the IR Receiver and the IR Blaster. This may work for other Hauppauge cards as well. The hard work was all done by others, for Ubuntu 10.04, this just serves as an updated reference for Ubuntu 12.04. As usual, this info is provided with NO warranty of any kind, so use at your own risk! It's assumed you have basic knowledge of Linux/LIRC/Scripts/etc.

The secret to the HVR1600 is the lirc_zilog kernel module. Once this kernel module is loaded and LIRC is configured, the HVR1600's IR capabilities should work.

Step One: Install LIRC

Step one is easy, just install standard LIRC! You can install it from the Ubuntu Software Center, or, install (or build) it from the command line if you are so inclined. The LIRC version that was installed for me was 0.9.0.

Step Two: Install lirc_zilog

(Note: you might already have lirc_zilog installed, see below).

This part is a bit tricky. The "proper" way to do it would be to install the lirc-modules-source package, apply the lirc_zilog patch, then reconfigure the package to build the kernel modules. The Ubuntu 10.04 recipe for this is here.

However, it does not yet appear that the lirc-modules-source package is available for Ubuntu 12.04. If it were, you would likely have to make some changes to the patch file to get it building under 12.04 (you might find some hints here).

As a shortcut, I found a complied version of lirc_zilog that appears to be 12.04 compatible here. There is a *.deb file for both i386 and 64-bit version (disclaimer: I can't vouch for the security of this site of the files). I find it strange that these files appear in this package but aren't actually in Ubuntu by default - but I'm sure there is an answer to that (if you know, feel free to share).

Download the version applicable to you and open the *.deb file with the Archive Manager (not the Ubuntu Software Center, which it opens with by default).

Find the lirc_zilog.ko file in the archive here: /lib/modules/3.2.0-24-generic/kernel/drivers/staging/media/lirc/

Extract it, and copy it to the following location in your system:
/lib/modules/3.2.0-24-generic/updates/dkms/lirc_zilog.ko

To load the module: sudo modprobe lirc_zilog

If all was successful, you shouldn't get any errors. At this point, you should be able to do lsmod | grep -i lirc_zilog and see:

lirc_dev               19204  1 lirc_zilog

Pro-Tip: To have lirc_zilog automatically inserted into the kernel on boot, add it to /etc/modules

Pro-Tip:  You might already have lirc_zilog installed. As an easy check, in a Terminal, go to /lib/modules and run find . -name "lirc_zilog*. If it finds lirc_zilog, already, you shouldn't have to copy one from another source. However, you'll still have to modprobe lirc_zilog to get it loaded and add it to /etc/modules to have it run boot.


Step Three: Install the HVR1600 IR Firmware files

I believe this can be found here, and a few other locations on the web.

This file needs to be copied here: /lib/firmware


Step Four: Configuration Files

You need to modify the following two files:

/etc/lirc/hardware.conf
/etc/lirc/lircd.conf


First, we modify hardware.conf to get lirc_zilog to be loaded. Add or modify the following lines (if necessary):

REMOTE_MODULES="lirc_dev lirc_zilog"
REMOTE_DEVICE="/dev/lirc0"
START_LIRCD="true"
LOAD_MODULES="true"

As for lircd.conf, again, a working one for my card was found here. I believe you can even put the relevant parts in its own file and use an include directive if you'd like.

Step Five: Take a deep breath

You're almost there! At this point, the following two things should work:

From a terminal, run "irw". Point your HVR1600 at the IR Receiver and press some buttons! If irw is working correctly, you should see some response, like:

$ irw
00000000000017a5 00 OK Hauppauge_350
0000000000001795 00 Down Hauppauge_350
0000000000001794 00 Up Hauppauge_350

This means your IR Receiver is working.

To test the IR Blaster, use the irsend command. At this point, it doesn't matter what code set you use, you just want to get the light to blink. For example:

$ irsend SEND_ONCE blaster 0_130_KEY_0

Note that the name "blaster" was the name chosen in "lircd.conf" from above....if you used another name insert it there.

Step Six: Final configuration

If the IR Blaster and Receiver are responsive, you're pretty much golden. All that remains is a bit of extra configuration.

To get the IR Receiver to do "cool" things (e.g. work MythTV and/or launch applications), you want to configure a ".lircrc" file. This should be in your Home directory.

Each command to be sent to a specific application has an entry that looks like this:

begin
prog = mythtv
button = LEFT
repeat = 3
config = Left
end

Each starts with "begin" and ends with "end".

button = The button on the remote which will cause the command
prog = The program to send the command too.
config = The command to send to the program
repeat = What to do when a key is repeated. 0 ignores repeats. A positive value (n) sends the command to the program every "nth" times.

Obviously, you need a lot of commands to get various buttons working. To get you started, here is a .lircrc file very similar to the one I use.

Pro-Tip: To get a remote button to start a program, instead of just being interpreted by one, set "prog" to irexec and "config" to the command line-method of starting the program. Remember that irexec must be running in the background for this to work, so you can set it up as an Ubuntu start-up application.

For the receiver, you need to figure out what code set the device you are sending commands to uses. One again, a script is already developed for this. This will send the Power command to the device. Once you see it respond, you've found the right code set. For example, in the command I have above, the code set being used was 0_130 code set.

You'll most often be using this to change the channel, but you can do other things as well. You can find some example change_channel scripts here. Don't forget that in order for MythTV change the channel, you need to configure the backend to post to the script.

At this point you should be in good shape, but you might require some additional modifications to get things "quite right" (geeks are never happy, are we?)

My only concern is that some point along the line, a Linux kernel change will cause lirc_zilog to stop working. But I'll cross that bridge when I come to it...either by getting it building from source or finding it compiled elsewhere. I hope you found this guide helpful.

References and special thanks!
http://wilsonet.com/?p=40
http://www.blushingpenguin.com/mark/blog/?p=24
http://www.bsntech.com/bsntech-blog-mainmenu-321/computers-mainmenu-281/1762-getting-your-hauppauge-hvr-1600-remote-control-to-work-in-ubuntu-1004-lucid.html
http://pkgs.org/download/linux-image-3.2.0-24-generic