HTPC (or HMC, whatever), part deux

Lookie! Explodosions!

Last time I wrote about the HTPC project (though I wrote HMC), nothing was working, today it's quite the opposite. Sometimes, in order to solve a problem, you have to just grind - and if you do that long enough you will solve the problem. At other times, the solution will be quicker/better if you take a step back. The HTPC project is a case of the latter.

Lost in the abbrev. jungle
It seems the abbreviation i used last time (HMC) is not the conventional one. I suppose the correct one is HTPC (as in Home Theater PC), which is less prone to be mistaken for Honda's stock ticker...

Getting a good video signal

It was when I got a link to this forum post , that I decided to make another stab at it. I abandoned mythdora, and installed mythbuntu. Then I followed the instructions in the forum-post, which mainly said "download and install libdrm and intel-driver from git". I used the posted xorg.conf too. The autogen.sh step complained about missing "xorg-macros 1.1.3 or later", but after installing xutils-dev with apt-get - it compiled and it looked quite ok.

...except everything was in black and white. Probably a PAL<->NTSC problem, so I changed the line that set the TV-mode to NTSC M in order to set it to PAL B/G (look at comment #85 in this thread ). But that didn't help. I tried every other PAL mode, but nothing helped. Finally I stumbled on some forum post that indicated that it might be the s-video to SCART conversion that failed. Google seemed to confirm this, by returning lots and lots of pages that tried to sell me (expensive) converters. The cheapest solution though, was a 29SEK ($3.50US) s-video to composite converter, and suddenly the TV had colour! :)

Watching TV

Now I could watch video files on the TV, but the idea is to watch TV. So I started looking for linux drivers for the tuner. But the tuner is a cheap rebranded USB dongle - so the name on the outside didn't say anything about its inside, and it wasn't very googlable either.

The way to solve this (if the driver does not seem to be in mainline already), is to run lsusb from the command prompt to find out the id - and then google for the id. My lsusb output looks like this:

  1. Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
  2. ... (more hubs)
  3. Bus 001 Device 002: ID 18b4:1001

Since there was only one non-hub device, i googled for "18b4:1001". This turned up a lot of people who had failid to get the tuner to work - but also a reference to a development tree with an experimental driver. So, I followed those instructions (much as I did with the video driver), and I actually got TV working too!

Now, this was almost too much success to bear in one day - so I had to start fiddling with stuff. Of course, getting everything working every time we start the box was a priority. But the mythtv-backend (the part that talks to the DVB-T dongle and schedules recordings etc) kept starting before the driver modules were loaded. As the modules are experimental, I'm not quite comfortable installing them over the supplied kernel modules - and so autoloading them wouldn't work. The solution was to put the load instructions in /etc/rc.local - and then reload mythtv-backend:

  1. insmod /lib/modules/`uname -r`/dvb/dvb-core.ko
  2. insmod /lib/modules/`uname -r`/dvb/dvb-usb.ko
  3. insmod /lib/modules/`uname -r`/dvb/ec100.ko
  4. insmod /lib/modules/`uname -r`/dvb/mxl5005s.ko
  5. insmod /lib/modules/`uname -r`/dvb/dvb-usb-ec168.ko
  6. sleep 5
  7. /etc/init.d/mythtv-backend restart

The sleep was added to keep mythtv-backend from restarting before the modules were proberly loaded. I chose to put the modules in /lib/modules/<kernel-version>/dvb - since they are version dependent. `uname -r` is a command that returns the revision of the current kernel. So now I had it working across reboots, without needing to do any special stuff. This project really started to turn into something other family members could use too.

Idling

I started to play around with mythtv, and added stuff to record. This gave me a nice warm feeling, until I realized that I had to leave the box on. That wouldn't be very nice. First, it's not very eco friendly, and second, the chipset fan does produce some sound (too much for it to be bearable 24/7). So I had to find out a way to make it idle when it's not recording and we're not watching TV/listening to music.

Hibernation (suspend to disk and turn the computer off) worked fine before I installed the dvb drivers. But afterwards, it just hung. So I started experimenting with scripts to unload the driver modules and hibernating - and it did work, as long as I removed the modules before calling hibernate. And readded them after thawing (resuming). This kinda defeats the purpose (though not quite - if I script it, the script continues to run at resume). After investigating the matter, I found that scripts in /etc/pm/sleed.d/ are run on both suspend/hibernate and resume/thaw (while scripts in /etc/acpi/suspend.d and /etc/acpi/resume.d does not seem to run at all). So I coded this little script, which removes the modules and stops mythtv-backend on hibernate, and inserts the modules and starts mythtv-backend on resume:

  1. #!/bin/bash
  2. case "$1" in
  3. suspend|hibernate)
  4. echo "Stop mythtv-backend - and then sleep"
  5. /etc/init.d/mythtv-backend stop
  6. sleep 5
  7. echo "Remove offending modules"
  8. rmmod dvb-usb-ec168
  9. rmmod mxl5005s
  10. rmmod ec100
  11. rmmod dvb-usb
  12. rmmod dvb-core
  13. ;;
  14. resume|thaw)
  15. echo "Insert the modules again"
  16. insmod /lib/modules/`uname -r`/dvb/dvb-core.ko
  17. insmod /lib/modules/`uname -r`/dvb/dvb-usb.ko
  18. insmod /lib/modules/`uname -r`/dvb/ec100.ko
  19. insmod /lib/modules/`uname -r`/dvb/mxl5005s.ko
  20. insmod /lib/modules/`uname -r`/dvb/dvb-usb-ec168.ko
  21. echo "Sleep, and then start mythtv-backend"
  22. sleep 5
  23. /etc/init.d/mythtv-backend restart
  24. ;;
  25. *)
  26. echo "Unhandled argument: $1"
  27. ;;
  28. esac

Now, all I had to do was find out a way to set the alarm clock. Googling around pointed me to /proc/acpi/alarm, but that method does not seem to be supported anymore. The replacement is /sys/class/rtc/rtc0/wakealarm, which works fine (from suspend and hibernation - but seemingly not from plain shutdown). There is an excellent document on on mythtv.org.

I set up a script that sets the wakeup time, and added that script and the hibernate command to the sudoers file with visudo (a way to make administrative commands open to mere mortals). Then I set up the commands, and idle time, with mythtv-setup. Here's the wake-up script:

  1. #!/bin/sh
  2. echo 0 > /sys/class/rtc/rtc0/wakealarm
  3. echo $1 > /sys/class/rtc/rtc0/wakealarm
  4. exit 0

After testing, and getting the alarm clock function and the hibernation to work, I sat down and waited for mythtv to suspend.
And I waited.
Nothing happened...
I checked my settings over and over again, and I poured over forum post after forum post - but nothing. Until I realized that I must exit the frontend if mythtv is to realize that the TV is in fact idle. But if I exit the frontend, all I get is an Ubuntu desktop when I resume. If the family is going to watch TV, that won't be ok. After some more reading, I realized that I should make mythwelcome autostart instead of mythtvfrontend (and uncheck the setting which prevents mythbackend from going to sleep unless someone has logged in to the frontend). This way, the user can exit the frontend - but still be able to easily enter it again when he/she wants to watch some TV. And the computer can detect when it is allowed to fall asleep.

Setting up mythwelcome to autostart was easy, making it behave was not quite so easy. During thaw (ie resuming from hibernation) I restart the mythtv backend, but that means mythwelcome doesn't find it - and idles for 5 minutes before retrying. Not ok. I had to amend the wakeup script to kill mythwelcome after the restart, then I made an autostart script which starts mythwelcome over and over again (with a tiny pause in between the tries). Finally, I had to disable automatic start of mythfrontend in mythwelcome (which would prevent re-idling after recording). The last task is acomplished by pressing 'I' at the welcome screen, and uncheck the minuscle checkbox on the third line of options.

Here's the new module-reload script:

  1. #!/bin/bash
  2. case "$1" in
  3. suspend|hibernate)
  4. echo "Stop mythtv-backend - and then sleep"
  5. /etc/init.d/mythtv-backend stop
  6. sleep 5
  7. echo "Remove offending modules"
  8. rmmod dvb-usb-ec168
  9. rmmod mxl5005s
  10. rmmod ec100
  11. rmmod dvb-usb
  12. rmmod dvb-core
  13. ;;
  14. resume|thaw)
  15. echo "Insert the modules again"
  16. insmod /lib/modules/`uname -r`/dvb/dvb-core.ko
  17. insmod /lib/modules/`uname -r`/dvb/dvb-usb.ko
  18. insmod /lib/modules/`uname -r`/dvb/ec100.ko
  19. insmod /lib/modules/`uname -r`/dvb/mxl5005s.ko
  20. insmod /lib/modules/`uname -r`/dvb/dvb-usb-ec168.ko
  21. echo "Sleep, and then start mythtv-backend"
  22. sleep 5
  23. /etc/init.d/mythtv-backend restart
  24. echo "Kill mythwelcome, so it can restart"
  25. killall -15 mythwelcome
  26. ;;
  27. *)
  28. echo "Unhandled argument: $1"
  29. ;;
  30. esac

...and the myth-startup script:
  1. #!/bin/bash
  2. while true; do
  3. /usr/bin/mythwelcome -l /var/log/mythtv/mythwelcome.log
  4. sleep 15s
  5. done

The startup script is placed in ~ (home), then it is added in the autostart panel (on mythbuntu, that's
Applications->Settings->Session in the menu, then click the Autostart tab, and the Add button).

This all leaves the HTPC in a very usable state. The only two hitches left are the noise from the fan, and the lack of a working remote controller (we currently use a keyboard with a looooong cord). I would prefer to have passive cooling for the chipset, but I may settle for something that's just a little bit more quiet than the current fan.

Also, I'd love to get some vinage games going. MythTV has support for mame (emulator for old arcade games) built in, but having vintage DOS games (such as the Ultimas, Monkey Island etc) would be glorious! :)

Here are the pictures taken so far, during this adventure.

Cool project!

Wow! Thanks for sharing your scripts and thoughts about this project! I'm going to try some of it to see if I can get a TV-backend using Ubuntu 9.10 Desktop + We Tech USB DVB-T stick + MythTV, and I'm sure your info here will help!

Regards from Uppsala!

dvb-t modules

Strange, I followed the guide to let it work but after the restart it didn't work and then I saw that you did insmod the modules in rc.local, so I did that to but after a restart the stick didn't work.

What can I do to make it work on a startup, I don't use mythtv just kaffeine to watch tv ?

First things first, have you

First things first, have you been able to make it work at all? If so, would you mind telling me about the steps you have to take manually to make it work?

I'm not familiar with kaffeine, does it rely on a daemon - or is it completely stand alone? It may be that you need to restart/reinit some resource, to be able to get it to work after a restart.

The reference u are pointing

The reference u are pointing at is missing the installation command 'make install'.
Had a failed attempted cos I didnt figure it right away.

Which of the resources? The

Which of the resources? The experimental dvb-t modules lack the install command, but as I explained - I'm not very comfortable installing those over the ones supplied by my distribution. That's why I copied them, and added the insmod statements to rc.local. Still, running the make install-command has other benefits - like making modprobe and udev work with the modules.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>, <xml>. The supported tag styles are: <foo>, [foo].

More information about formatting options