Sunday, January 1, 2012

Installing WINE on CentOS 6

There really isn't too much to installing and setting up WINE on CentOS 6, just make sure to setup the EPEL and ATrpms repositories as described in my The OS Install post and run:
[root@htpc ~]# yum install wine
Since the /home/mythtv directory doesn't really have much space allocated to it, I wanted to change the location of the C: drive to /var/lib. First, login to the Gnome desktop as the mythtv user and run the following to create the hidden /home/mythtv/.wine folder (there is also the Wine Configuration launcher under Applications -> Wine which does the same thing)
[mythtv@htpc ~]# winecfg
In the window that popped up, I selected Windows 7 as the windows version in the Applications tab and then clicked on the Audio tab and allowed Wine the select the best driver for my setup. I didn't play around with any other settings and hit the OK button to save my settings and close the window.

Now that the /home/mythtv/.wine folder has been created, I performed the following to move the C: drive to /var/lib.

As root:
[root@htpc ~]# mkdir -p /var/lib/wine/mythtv
[root@htpc ~]# chown mythtv:mythtv /var/lib/wine/mythtv
As mythtv:
[mythtv@htpc ~]$ mv /home/mythtv/.wine/drive_c /var/lib/wine/mythtv
[mythtv@htpc ~]$ rm '/home/mythtv/.wine/dosdevices/c:'
[mythtv@htpc ~]$ ln -s /var/lib/wine/mythtv/drive_c '/home/mythtv/.wine/dosdevices/c:'
Finally, I wanted to test to see if the free version of Trackmania Forever worked. I downloaded the installer and ran:
[mythtv@htpc ~]$ wine tmnationsforever_setup.exe
The installer created a handy desktop launcher when it was done and I simply double clicked on it and the game started up and ran without any issues. Sweetness.

Now the challenge will be to get some of my other games to work, however, that may be difficult since the WINE version on EPEL is kind of old. I'll tackle that another day.

Wednesday, December 28, 2011

Configuring the MythTV Frontend

There really isn't much to setting up the MythTV frontend. The main things that I want to do were to setup the remote control to work with MythTV, enable VDPAU, and setup GDM to login as the mythtv user.

To start the MythTV, you can either do it from the Applications menu on the Gnome desktop while logged in as the mythtv user, or from the command line terminal while logged into the Gnome desktop as the mythtv user. During the initial setup I like to start the frontend from the command line because I can see if there are any errors when running the frontend on the console.
[mythtv@htpc ~]# mythfrontend
Provided that mythfrontend started up without any issues, you can navigate around using the keyboard directional keys. One of the first things that I did was to change the theme because the default theme is pretty hideous. Go to Setup -> Theme Chooser and select MythCenter-wide 1.1 (provided that you have a widescreen TV). I also like to change the menu theme to something that I'm used to by going to Setup -> Appearance and selecting Default for the Menu theme.

The next step is to get the remote control working with the frontend. Exit out of the frontend by hitting the Esc key a few times and create the lircrc file in the .mythtv folder
[mythtv@htpc ~]# vi ~/.mythtv/lircrc
Rather than taking up a whole lot of space on this post for the lengthy config file, I decided to post the config for my remote on Pastebin. You can view it here. I used the MythTV key bindings as a reference. Save the file and launch the frontend again. You should now be able to navigate the menu's using the remote control.

The next thing that I wanted to enable is VDPAU, which allows the majority of video rendering to be offloaded from the CPU onto the nVidia GPU. Navigate to Utilities/Setup -> Setup -> TV Settings -> Playback and hit next a couple of times until you get to the Playback Profiles (3/8) screen. Select VDPAU High Quality for the Current Video Playback Profile. As far as I know this only works for nVidia cards. You can find a good list of video cards that support VDPAU here.

Lastly, I wanted the mythtv user to automatically log into the Gnome desktop. As root, edit /etc/gdm/custom.conf and add the following under the daemon section.
TimedLoginEnable=true
TimedLogin=mythtv
TimedLoginDelay=10
The above settings will automatically login the mythtv user into the Gnome desktop after a 10 second delay.

That's really about it. There are lots of other settings to play around with and I'll post any tweaks that I make over time. For now, sit back and try watching some live TV and play around with recording stuff.

Saturday, December 24, 2011

Configuring the MythTV Backend

Now that everything is installed and hopefully working properly, the next step is to configure the MythTV backend. Login to the Gnome desktop as the mythtv user, open a terminal session, and create the recordings directory:
[mythtv@htpc ~]# mkdir /var/lib/mythtv/recordings
Then run  mythtv-setup. For this post, I'm just going to do a basic configuration with just the digital portion of the capture card. I'm not going to do any extensive tweaking, I'll save that until later. I just want to do a basic setup to make sure that the basics are working as expected.
[mythtv@htpc ~]# mythtv-setup
Inside the GUI, I performed the following tasks. First, I had to tell MythTV what type of capture card I had. Since the WinTV-HVR-2250 has two digital tuners, I setup two DVB capture cards. I'm not going to setup the analog tuners for now.
  • Capture Cards > (New capture card) 
    • Card type: DVB DTV capture card (v3.x)
    • DVB device number: /dev/dvb/adapter0/frontend0
    • Finish
  • Capture Cards > (New capture card) 
    • card type: DVB DTV capture card (v3.x)
    • DVB device number: /dev/dvb/adapter1/frontend0
    • Finish
For the next step, you'll need to setup an account in Schedules Direct, which is a service that MythTV uses to get channel and program data for your area. The service costs $25 a year and has a 7 day free trial. You'll need to add at least one lineup that is appropriate for your area and the TV service that you have.

In my case, I have the cheapest Comcast service that is available in the Seattle area, which basically allows me to watch unencrypted local channels over the cable wire plus some additional channels that I don't really care about. I attempted to setup an over the air (OTA) antenna a couple of years ago but found that I couldn't get very good reception for some channels so I bit the bullet and went with the Compcast service because I didn't have the motivation to mess with OTA antennas. I might revisit it at some point in the future.

I should also mention that if you have a more extensive service with a cable or satellite provider, then all of the channels, with the exception of the local channels and maybe some music channels, will be encrypted, so the capture card will not be able to tune into them. I believe the way that people have gotten around this issue is to hook up their HTPC to the cable/satellite box (which unencrypts the signal), and then use an IR blaster to change the channel on the cable/satellite box whenever the channel is changed in MythTV. I've never set this up before, so I can't speak too much about it. I'm sure there's plenty of articles on the Internet that talk about this topic.

Going back to Schedules Direct, I basically created a new lineup for my zip code and selected the "Local Broadcast Listings - Antenna" lineup. Most of the channels that I watch are in the lineup, however, when I did a channel scan using my capture card (later on in this post), there were a number of channels that the capture card picked up that were not listed in Schedules Direct.
  • Video Sources > (New Video source)
    • Video Source name: (I called mine Seattle Digital. You can name it whatever is appropriate for you)
    • North America (SchedulesDirect.org) (Internal)
    • User ID: (SchedulesDirect username)>
    • Password: (Schedules Direct password)
    • Retrieve Lineups
    • Data Direct lineup: <select the lineup that you setup in Schedules Direct>
    • Finish
Now that MythTV knows about the capture card and the Schedules Direct lineup, the next step is to tie the two together and to scan for channels.
  • Input Connections > [DVB: /dev/dvb/adapter0/frontend0] (DVBInput) -> (None)
    • Display name (optional): (I called mine Digital Tuner 1. You can call it whatever you like)
    • Video Source: Seattle Digital
    • Scan For Channels
      • Desired Services: TV
      • Scan Type: Full Scan
      • Frequency Table: Cable
      • Modulation: Cable (QAM-256)
      • Next
      • Finish
    • Next
    • Finish
As I mentioned before, the were a number of channels that the capture card picked up which were not listed in my Schedules Direct lineup, but for the most part, the channels that I cared about were there. I'll tweak with the channel list at some point in the future. For now, I'm going to tie the second tuner to the Schedules Direct lineup.
  • Input Connections > [DVB: /dev/dvb/adapter1/frontend0] (DVBInput) -> (None)
    • Display name (optiona): Digital Tuner 2
    • Video Source: Seattle Digital
    • Next
    • Finish
And finally, tell MythTV where the recordings should be stored
  • Storage Directories > Default > (Add New Directory)
    • /var/lib/mythtv/recordings
Exit out of mythtv-setup and run mythfilldatabase, which will pull the listing data from Schedules Direct and put it in the MySQL database. This can take a while to run the first time around.
[mythtv@htpc ~]# mythfilldatabase
Then set mythtvbackend to start at boot and start up the service
[root@htpc ~]# chkconfig mythbackend on
[root@htpc ~]# service mythbackend start
Next up, configuring mythfrontend...



Installing MythTV on CentOS 6

Now that OS environment is ready and all of the drivers have been installed and working properly, it's time to install MythTV. As a recap, here's everything that was done to get to this point:


First thing is to install MySQL and start it up
[root@htpc ~]# yum install mysql mysql-server
[root@htpc ~]# chkconfig mysqld on
[root@htpc ~]# service mysqld start
Next, secure MySQL. I basically answered all the questions with a 'Y'
[root@htpc ~]# /usr/bin/mysql_secure_installation
Enter current password for root (enter for none): <enter>
Set root password? [Y/n] y
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Install QT 4.7. Needed to remove qt-x11 because it was conflicting with QT 4.7.
[root@htpc ~]# yum remove qt-x11
[root@htpc ~]# yum install qt47 qt47-x11 qt47-webkit qt47-mysql
Install MythTV
[root@htpc ~]# yum install mythtv-backend mythtv-frontend mythtv-docs mythtv-setup 
Create the MythTV database and user in MySQL.
[root@htpc ~]# mysql -u root -p < /usr/share/doc/mythtv-docs-0.24.1/database/mc.sql
For performance reasons, it is recommended to tweak some MySQL settings. Simply edit /etc/my.cnf and add the following values:
  key_buffer = 16M
  table_cache = 128
  sort_buffer_size = 2M
  myisam_sort_buffer_size = 8M
  query_cache_size = 16M 
And restart MySQL for the changes to take effect
[root@htpc ~]# service mysqld restart
Finally, I like to do one last system update and reboot to make sure that all the necessary services start at boot time.
[root@htpc ~]# yum update
[root@htpc ~]# reboot
And test to make sure that MySQL and lirc are working
[root@htpc ~]# mysql -p
[root@htpc ~]# irw
Next up, configuring the MythTV backend...


Friday, December 23, 2011

The Remote Control

As I mentioned in my hardware post, I got a pretty generic Vista MCE Remote Control. By far, this was the most time consuming and frustrating piece of the install up to this point mainly because lirc is kind of a black box for me and guides for setting it up are scattered. Another problem that I ran into is that the USB IR receiver shows up as two devices. I finally got it working and minimized the process to a few basic steps, but a lot of blood and sweat went into the next set of instructions.

First off, install lirc. No additional drivers or kernel modules are necessary since I will be using /dev/input
[root@htpc ~]# yum install lirc
Next, get the generic lirc.conf for devinput from the lirc web site
[root@htpc ~]# wget http://lirc.sourceforge.net/remotes/devinput/lircd.conf.devinput -O /etc/lirc/lircd.conf
Then, because there are two devices in /dev/input, I needed a way to tie them together in lircd. I did this by editing the /etc/sysconfig file and putting in the following lines. The device names will be different depending on the remote, but these work for the one that I got.
LIRCD_OPTIONS_1="--driver=devinput --device=/dev/input/by-id/usb-05a4_9881-event-kbd  --pidfile=/var/run/lirc1.pid --listen=9988"
LIRCD_OPTIONS_2="--driver=devinput --device=/dev/input/by-id/usb-05a4_9881-event-if01 --pidfile=/var/run/lirc2.pid --connect=localhost:9988"
Finally, edit the lircd init script and modify the start function so that two lircd daemons are started up with the options from /etc/sysconfig
daemon lircd $LIRCD_OPTIONS_1
daemon lircd $LIRCD_OPTIONS_2
All that's left is to set lircd to start at boot and start the service
[root@htpc ~]# chkconfig lircd on
[root@htpc ~]# service lircd start
And of course test
[root@htpc ~]# irw 
Pressing the buttons on the remote control should show up in the output of irw.

References:
http://www.gossamer-threads.com/lists/mythtv/users/430004
http://old-de.opensuse.org/Linux_Infrared_Remote_Control


The Capture Card

Getting the Hauppauge WinTV-HVR-2250 to work on CentOS 6 wasn't as painful as I thought it would be. The IR port doesn't work in Linux and the analog support is questionable, but those aren't showstoppers for me since I have a separate remote and analog TV is pretty much dead. The digital portion of the card works perfectly.

First install the Video4Linux drivers
[root@htpc ~]# yum install libv4l video4linux video4linux-kmdl-$(uname -r)
Next, install the firmware for the card

[root@htpc ~]# wget http://www.steventoth.net/linux/hvr22xx/22xxdrv_27086.zip
[root@htpc ~]# wget http://www.steventoth.net/linux/hvr22xx/HVR-12x0-14x0-17x0_1_25_25271_WHQL.zip
[root@htpc ~]# wget http://www.steventoth.net/linux/hvr22xx/firmwares/4019072/NXP7164-2010-03-10.1.fw
[root@htpc ~]# wget http://www.steventoth.net/linux/hvr22xx/extract.sh
[root@htpc ~]# sh extract.sh
[root@htpc ~]# cp *.fw /lib/firmware
[root@htpc ~]# reboot
Finally, check dmesg to see if the kernel recognizes the card, uploads the firmware, and registers the mpeg and vbi devices.
[root@htpc ~]# dmesg
...
saa7164 driver loaded
saa7164 0000:05:00.0: PCI INT A -> GSI 19 (level, low) -> IRQ 19
CORE saa7164[0]: subsystem: 0070:8851, board: Hauppauge WinTV-HVR2250 [card=7,autodetected]
saa7164[0]/0: found at 0000:05:00.0, rev: 129, irq: 19, latency: 0, mmio: 0xfe800000
saa7164 0000:05:00.0: setting latency timer to 64
IRQ 19/saa7164[0]: IRQF_DISABLED is not guaranteed on shared IRQs
saa7164_downloadfirmware() no first image
saa7164_downloadfirmware() Waiting for firmware upload (NXP7164-2010-03-10.1.fw)
saa7164 0000:05:00.0: firmware: requesting NXP7164-2010-03-10.1.fw
saa7164_downloadfirmware() firmware read 4019072 bytes.
saa7164_downloadfirmware() firmware loaded.
Firmware file header part 1:
 .FirmwareSize = 0x0
 .BSLSize = 0x0
 .Reserved = 0x3d538
 .Version = 0x3
saa7164_downloadfirmware() SecBootLoader.FileSize = 4019072
saa7164_downloadfirmware() FirmwareSize = 0x1fd6
saa7164_downloadfirmware() BSLSize = 0x0
saa7164_downloadfirmware() Reserved = 0x0
saa7164_downloadfirmware() Version = 0x1661c00
saa7164_downloadimage() Image downloaded, booting...
saa7164_downloadimage() Image booted successfully.
starting firmware download(2)
saa7164_downloadimage() Image downloaded, booting...
saa7164_downloadimage() Image booted successfully.
firmware download complete.
tveeprom 1-0000: Hauppauge model 88061, rev C4F2, serial# 7964330
tveeprom 1-0000: MAC address is 00:0d:fe:79:86:aa
tveeprom 1-0000: tuner model is NXP 18271C2_716x (idx 152, type 4)
tveeprom 1-0000: TV standards NTSC(M) ATSC/DVB Digital (eeprom 0x88)
tveeprom 1-0000: audio processor is SAA7164 (idx 43)
tveeprom 1-0000: decoder processor is SAA7164 (idx 40)
tveeprom 1-0000: has radio, has IR receiver, has no IR transmitter
saa7164[0]: Hauppauge eeprom: model=88061
tda18271 2-0060: creating new instance
TDA18271HD/C2 detected @ 2-0060
DVB: registering new adapter (saa7164)
DVB: registering adapter 0 frontend 0 (Samsung S5H1411 QAM/8VSB Frontend)...
tda18271 3-0060: creating new instance
TDA18271HD/C2 detected @ 3-0060
tda18271: performing RF tracking filter calibration
tda18271: RF tracking filter calibration complete
DVB: registering new adapter (saa7164)
DVB: registering adapter 1 frontend 0 (Samsung S5H1411 QAM/8VSB Frontend)...
saa7164[0]: registered device video0 [mpeg]
saa7164[0]: registered device video1 [mpeg]
saa7164[0]: registered device vbi0 [vbi]
saa7164[0]: registered device vbi1 [vbi]
...
That's about it really. I did need to do a bunch of research to get this to work. I've included some sources that I found useful below. 

Next up, the remote control.

References:
http://linuxtv.org/wiki/index.php/Hauppauge_WinTV-HVR-2250
http://linuxtv.org/wiki/index.php/Hauppauge_WinTV-HVR-2200
http://ubuntuforums.org/showthread.php?t=1567490

The OS Install

My goal here is to talk about doing a basic Operating System (OS) installation so that it's ready for the installation of subsequent drivers and packages.

Originally, I wanted to install the latest version of CentOS, which is 6.2 at this time, however I ran into some issues when running the 6.2 installer. As soon as the installer went into the pretty GUI portion of the installation, the computer would freeze up. I'm pretty sure it's a kernel panic and that the issue is with the 2.6.32-220 kernel not liking the nVidia graphics card. I decided to install 6.1 x86_64 and update to 6.2 later on, without updating to the 2.6.32-220.whatever kernel. This could be an issue specific to my setup so anyone else reading this might not run into the same problem. At some point in the near future I plan on revisiting this to see if there are any updated kernels that fix this issue, but then again, I might not bother. If it ain't broke, don't fix it.

I didn't do anything fancy during the installation. I performed a basic install with the following options:
  • Minimal Desktop
  • Enable NTP
  • Disable Kdump
  • Create a user for myself

The disk partitioning ultimately wound up looking like this
[root@htpc ~]# fdisk -l
Disk /dev/sda: 1000.2 GB, 1000204886016 bytes
255 heads, 63 sectors/track, 121601 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000845ca
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        8486    67108864   83  Linux
/dev/sda3            8486        9530     8388608   82  Linux swap / Solaris
/dev/sda4            9530      121602   900214784   83  Linux

[root@htpc ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              63G  2.2G   58G   4% /
tmpfs                 2.0G   88K  2.0G   1% /dev/shm
/dev/sda1            1008M   59M  899M   7% /boot
/dev/sda4             846G  249M  802G   1% /var/lib
First thing I did was add the mythtv user. I may need to add additional groups to this user if I run into any permissions issues, but so far, the groups below seem to work out OK.
[root@htpc ~]# useradd -G audio,video,games,cdrom mythtv
[root@htpc ~]# passwd mythtv
I then disabled the firewall and SELinux. If you're not behind a router with a firewall, then you should probably leave the firewall enabled but you may need to do some research to figure out what, if any, ports need to be opened up for MythTV. Since everything is running on the same host, I don't think any ports will need to be opened, but I can't say for sure. SELinux is a totally different beast and I think disabling it will avoid headaches down the road. I like using vi and doing most stuff on the command line, but any text editor should work just fine.
[root@htpc ~]# vi /etc/selinux/config
(change SELINUX parameter from enabled to disabled)
[root@htpc ~]# system-config-firewall-tui
        (go through the menu to disable firewall)
Update to 6.2, without updating the kernel, due to the issue I described earlier.
[root@htpc ~]# vi /etc/yum.conf
     (put in "exclude=kernel*" under [main])
 
[root@htpc ~]# yum update
[root@htpc ~]# reboot
Setup the EPEL and ATrpms repositories
[root@htpc ~]# wget http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-5.noarch.rpm
[root@htpc ~]# rpm -ivh epel-release-6-5.noarch.rpm
[root@htpc ~]# rpm --import http://packages.atrpms.net/RPM-GPG-KEY.atrpms
[root@htpc ~]# wget http://dl.atrpms.net/all/atrpms-repo-6-4.el6.x86_64.rpm
[root@htpc ~]# rpm -ivh atrpms-repo-6-4.el6.x86_64.rpm
[root@htpc ~]# vi /etc/yum.repos.d/atrpms-testing.repo
(change enabled from 0 to 1 under [atrpms-testing])
Update to the latest kernel in the 6.1 tree since ATrpms doesn't have modules for the stock 6.1 kernel
[root@htpc ~]# wget http://centos.vipernetworksystems.com/6.1/updates/x86_64/Packages/kernel-2.6.32-131.21.1.el6.x86_64.rpm
[root@htpc ~]# wget http://centos.vipernetworksystems.com/6.1/updates/x86_64/Packages/kernel-devel-2.6.32-131.21.1.el6.x86_64.rpm
[root@htpc ~]# wget http://centos.vipernetworksystems.com/6.1/updates/x86_64/Packages/kernel-firmware-2.6.32-131.21.1.el6.noarch.rpm
[root@htpc ~]# wget http://centos.vipernetworksystems.com/6.1/updates/x86_64/Packages/kernel-headers-2.6.32-131.21.1.el6.x86_64.rpm
[root@htpc ~]# vi /etc/yum.conf
(comment out exclude=kernel*)
[root@htpc ~]# yum install kernel*
[root@htpc ~]# vi /etc/yum.conf
(uncomment out exclude=kernel*)
[root@htpc ~]# reboot
[root@htpc ~]# yum remove kernel-2.6.32-131.0.15.el6.x86_64
And finally, install the nVidia driver. I wanted to do this as soon as possible because it slows down the speed of the GPU fan, which makes a lot of noise when it spins at full speed. I needed to blacklist the nouveau module in grub.conf since it conflicted with the nVidia driver.
[root@htpc ~]# yum install nvidia-graphics290.10 nvidia-graphics290.10-kmdl-$(uname -r)
[root@htpc ~]# vi /boot/grub/grub.conf
add "rdblacklist=nouveau vga=794" to the end of the kernel options
[root@htpc ~]# reboot
Next up, getting the capture card working in CentOS 6 ...