px
px
border
px
   
px
div
Information
null.gif Home

null.gif News
 Topics
 Stories Archive
null.gif Content
 Articles
 Tutorials
 Downloads
 Web Links
 Forums
null.gif Other Stuff
interdit Feedback
 Recommend Us
 Statistics
 Search
 RSS
 Your Account

Digital Video
Installing MythTV
MythWeb Hacks
Remote Control
Hardware Kit
Complete System

Digital Surveillance
Installing Zoneminder
Hardware Kit

VIA EPIA
Comparison Chart
Performance
Optimizing

Store Information
Shipping & Returns
Privacy Notice
Conditions of Use
Contact Us

div
  TopMy Account  |  Cart Contents  |  Checkout   
Installing MythTV - Part 6
Advanced Configuration

Table of Contents

Now that we have MythTV running, there are a few things we can do to improve our system. First, we should get rid of the border around the MythTV window. Second, it would be nice for MythTV (specifically mythfrontend) to start automatically when the system boots. Since we want to run this as a dedicated box without an attached monitor or keyboard, this is pretty much a requirement. Finally we need a way to control it other than a keyboard.

You may have noticed in the earlier chapters we didn't install the infrared remote control. I have enough infrared remotes and don't want another one. Also my MythTV box isn't near my TV so an infrared remote would be impractical. Instead I want to control MythTV via a web interface accessible from a PC, wireless laptop, or wireless Pocket PC.

Windowless MythTV

We'll tackle the window part of the problem first. When you start an application in an X session, it is placed in a window with title bar and border. We don't need these for our MythTV system. There are window managers that will reduce the border to one pixel and remove the title but we don't really need a window manager either. We only have one window, not a lot to manage there.

It turns out an X session has what it calls a "root window." This is the window that starts up with the X session and contains all other windows. Window managers run as the root window. If we could get MythTV to run in the root window, that would take care of our requirements. Let's take a quick look at how X starts up.

X-Window has a client-server architecture. The XServer works with device drivers to draw stuff on your monitor. XClient builds the window, border and contents, buttons, menus, etc. and issues commands to XServer to draw these on the screen. When X starts it first starts the server and then the client. These are hidden behind the “startx” script but they are there. Thus there are two "init" scripts for X-Window; one for the client and one for the server. What we want is mythfrontend to start when XClient starts.

Both of these scripts live in the $HOME directory for the user. Since we're going to run all this as root, the scripts will live in our /root directory. The next two sections will look at these scripts and show what they need to contain for our purposes.

XServer Init Script

The XServer init script is .xserverrc. Note the leading period, it is a hidden file. As mentioned previously this file will be in our /root directory. All it needs to do is start the XServer application. Let's edit that file with the following:

nano -w /root/.xserverrc

Enter this command in the file:

#!/bin/sh
exec /usr/bin/X11/X -dpi 100 -nolisten tcp

Press ctrl-X when you are done and save the file. Notice the two command line parameters we entered. The first sets the font pitch to 100 dpi. The MythTV themes are created assuming 100 dpi so this is necessary for them to look good. The second parameter turns off the network feature of XServer. With this feature on, the XServer and XClient can run on different machines and communicate over a network connection. We don't need this feature and since we're running the XServer as root, it is really a good idea to turn it off.

XClient Init Script

The XClient init script is .xinitrc. Like the XServer file this one is also a hidden file in the /root directory. Create this file with the command:

nano -w /root/.xinitrc

The contents you need to type into this file are:

[ -f $HOME/.Xdefaults ] && xrdb $HOME/.Xdefaults
/usr/X11R6/bin/xsetroot -solid #000000 -cursor_name watch
/usr/X11R6/bin/xset s noblank
/usr/X11R6/bin/xset s off
/usr/X11R6/bin/xset dpms off
/usr/X11R6/bin/xhost +
(sleep 2; /usr/local/bin/mythfrontend)

We will discuss each line in detail.

1. This checks for the file .Xdefaults and, if found, runs the xrdb commnad. xrdb is the XServer resource database utility. It sets the RESOURCE_MANAGER and SCREEN_RESOURCES properties for user preferences. Most XClients use these for things like color and fonts. There isn't anything we're going to put in Xdefaults but if we ever do, this line will make sure it is loaded.

2. This sets the properties of the root window. In our case a solid black background with the "watch" shaped cursor. The idea behind the watch cursor (representing wait or busy) is this. If the root window displays before mythfrontend starts, it will show the watch cursor which is appropriate for an application starting up.

3 and 4. These lines set the screen saver. Since our dedicated MythTV box won't have a keyboard or mouse, the system isn't going to detect any user activity. We don't want it going into screen saver mode as a result. Line 3 tells the screen saver to not blank the screen. Line 4 turns off the screen saver altogether. These are probably redundant but seemed like a good idea at the time.

5. This turns off the power management (EnergyStar) features of the monitor. If we're using a monitor we don't want it going into power save mode and blank the screen.

6. xhost is the X Window access control program. The command on line 6 gives access to XServer for everyone on this computer and is needed for the web-based remote control application we will introduce later.

7. Finally we wait a couple seconds then start mythfrontend.

Starting mythfrontend as part of the XClient init script makes it run in the root window. No window border, no title, no window managers. To start up X and mythfrontend you can enter startx at a shell prompt.

Automatic Startup

Automatic startup by itself isn't hard. The challenging part is starting the session logged in as root without, well, logging in. To begin we will take a quick look at the Linux init process. This is optional and you can skip down to the /etc/conf.d/local.start discussion if you want. There is a more complete discussion of the init process on the desktop-linux.net website.

When you turn on your system it first goes through a power-on self-test. It then runs the boot loader (Grub in our case) which starts the kernel. The kernel does some preliminary kernel stuff then executes the init process. init is the root process. All processes are children of init. If you list your running processes with ps x you will see it at the top with process id (PID) #1.

The init process first looks at the file /etc/inittab. This file describes how init should setup the system. In inittab there is a line that defines "sysinit" and associates a script to it. In our case for Gentoo the sysinit script is /sbin/rc sysinit.

One function of the sysinit script is to run all of the daemon and server startup scripts associated with the current runlevel. (Runlevels are outside the scope of our discussion here. The link above gives more information about runlevels.) These scripts are found in /etc/init.d. The ones that run for a given runlevel are found in /etc/runlevels. For Gentoo the default scripts, corresponding to runlevel 3 (full multi-user mode with networking), are found in /etc/runlevels/default. (Unlike most other distributions you don't place links in this directory directly. Instead you use the rc-update command.) You also don't have to worry about dependencies between the runlevel init scripts, e.g. start Apache after networking. The Gentoo init process figures that out for you.

After the init scripts associated with the runlevel are run, the init process starts the consoles. In our case this is a program called agetty. The console process displays the login message, prompts for the username, then invokes the login process when a user attempts to login.

Ok, that was a little intense and probably confusing. We'll summarize the steps so it may be easier to understand:

1. Computer power-on self-test
2. Find hard drive and run boot loader (Grub) on hard drive's master boot record.
3. Boot loader starts kernel.
4. Kernel does stuff then runs the program "init".
5. init looks for the file /etc/inittab and then the line that defines sysinit.
6. init executes the script associated with sysinit
7. sysinit does stuff then executes the scripts linked in /etc/runlevels/default.
8. init starts up the consoles (agetty) defined in /etc/inittab.
9. agetty prompts for a username then runs /bin/login.

Hopefully that's a little better. So what's the point of this dicussion? It tells us there is an initialization process that starts daemons and system services. Then console processes are started that permit users to login to the system. If we start our X session and mythfrontend as part of the init process, not only will it start automatically but it won't require us to login with a username and password. That's what we want.

Most Linux distributions have a mechanism for the user to specify things he or she would like run as part of the init process. In Gentoo this is the /etc/conf.d/local.start file. Gentoo runs this file as the last step of the init process. To get X running as part of the init process, edit local.start with the following command:

nano -w /etc/conf.d/local.start

Then add these lines to the file:

source /etc/profile
HOME=/root
export HOME
startx &

Press ctrl-X and save the file. That's it. Reboot your system and it should automatically startup in MythTV.

MythWeb

Before we can disconnect the keyboard and monitor, we need some way of interacting with our MythTV system. Normally one would do this with an infrared remote control. However we have other plans for our system and intend to use a wireless PocketPC to control the system. The easiest way to accomplish this goal is through a web interface. MythWeb will be our starting point.

To run a web application on our MythTV system we will need a web server. MythWeb is written in PHP so our web server will need the ability to process PHP scripts. This is easy on a Gentoo system. Simply type the following:

#emerge apache
#emerge mod_php
rc-update add apache2 default

These commands will install the Apache2 web server along with its PHP module. The last line will cause Apache to start automatically when the system boots. (If you want to tie this back into our init process discussion, you can see that installing Apache put a script in /etc/init.d. When you ran rc-update it created a link to that script in /etc/runlevels/default.)

There is one configuration item I've found doesn't get set correctly when you install mod_php. To fix this edit the apache2 configuration file as follows:

nano -w /etc/conf.d/apache2

Find the line that says APACHE2_OPTS, uncomment it and set it to:

APACHE2_OPTS="-D PHP4"

Press ctrl-X and save the file. Without this modification Apache won't understand what to do with PHP files. When you point your browser to a file with a .php extension, Apache will just display the code as text instead of executing it. Not what we want.

If you don't want to reboot your system right now then you should manually start apache with this:

/etc/init.d/apache2 start

Next we need to install MythWeb. From a shell prompt on your MythTV system, execute the following:

cd /root
wget http://www.mythtv.org/modules.php?name=Downloads&d_op=getit&lid=100
bunzip2 mythweb-0.17.tar.bz2
tar xvf mythweb-0.17

These commands will retrieve the source and unpack it in your root directory. Now we need to move the source to the directory where the web server serves files.

cd /var/www/localhost/htdocs
rm -fr *
mv -R /root/mythweb-0.17/* .
mkdir image_cache
chown -R apache:apache *

Note the trailing period "." on the "mv" line. What these commands do is change to the directory where apache serves files. Then we remove anything there that apache installed. Next we move the MythWeb files and directories over, create a directory MythWeb needs and set the ownership of everything to "apache".

MythWeb needs a little configuring to connect to the MythTV database. Edit the file config/conf.php for your database:

nano -w config/conf.php

You will probably only need to change the "db_password" value for your system. Everything else can be left at the default values.

Now you can go to a computer on your network and point its browser to http://<mythtv server ip>. You should see the MythWeb program listing page. If it says file not found or displays php code, scroll back to the top of this page and make sure you set APACHE2_OPTS correctly.

MythTV Control Via MythWeb

MythWeb only deals with the MythTV database and mythbackend. We're going to extend it to also control mythfrontend. The only mechanism mythfrontend has for control is the keyboard. So what we need is a way to feed keyboard events to mythfrontend. (Note: The infrared remote does the same thing. Convert remote control keys to keyboard events.)

Sending keyboard events to an application running under X-Window isn't has hard as it might seem. There is a little utility from the LIRC (Linux Infrared Control) project that does just that - sendxevent. The version we have is from Doug McClendon and is available on the Download page. To install it on our system do the following:

cd /usr/local/src
wget http://www.magicitx.com/pub/utils/sendxevent.tar
tar xvf sendxevent.tar
cd sendxevent
make
make install

That's it. Now all we need is a web page to accept our inputs and send them to mythfrontend with the sendxevent utility. It just so happens that we've created a patch for MythWeb to give us just such a page. One you install it you will find a new menu item called “control.” Selecting that menu will give you an image of a remote control. Click on the buttons with your mouse to invoke the functions.

You can do lots of stuff with the sendxevent utility. Any script that can invoke a shell command can use it. Here is the calling convention:

export DISPLAY=:0.0; sendxevent "Key <key name> CurrentWindow"

The DISPLAY export tells the utility which X session gets the key event. The key names are the same ones used by "irxevent" from the LIRC project. Here are some important ones:

/* TTY Functions */

BackSpace       /* back space, back char */
Tab             
Linefeed        /* Linefeed, LF */
Clear           
Return          /* Return, enter */
Pause           /* Pause, hold */
Scroll_Lock     
Sys_Req         
Escape          
Delete          /* Delete, rubout */

/* Cursor control & motion */

Home            
Left            /* Move left, left arrow */
Up              /* Move up, up arrow */
Right           /* Move right, right arrow */
Down            /* Move down, down arrow */
Prior           /* Prior, previous */
Page_Up         
Next            /* Next */
Page_Down       
End             /* EOL */
Begin           /* BOL */

You can find the full list at http://www.wh9.tu-dresden.de/~heinrich/lirc/irxevent/irxevent.keys.

TV-Out

The back of your VIA M-series mainboard has two connectors for video output. One for composite video (the RCA connector) and another for S-video. The RCA connector serves double duty between video and digital audio (S/P DIF) output. If you want to use the RCA connector for video you need to set the jumper shown in the image below.

The setting shown here (pins 1-2) is for video output. Whichever connector you use for video, you will use the line-out (middle) audio connector for audio.

Unless you've changed the BIOS default, there isn't anything else you need to do to get tv-out functioning. Simply connect either the RCA connector or S-video to your television's video input. Then connect the line-out audio connector to your television's audio input and you're all set.

Conclusion

This pretty much gives us a MythTV box that we can integrate into our home entertainment system. In the next part of the tutorial we will discuss the kind of performance we're getting from our system.

Next: Part 7 – Conclusion

History
9 Feb 2005Initial Publication
16 May 2005Added links to table of contents. Updated remote control section to reference our MythWeb patch.









Tim

Copyright © by MagicITX All Right Reserved.

Published on: 2005-02-21 (9848 reads)

[ Go Back ]
div
Survey
Are you doing a Car-PC project?

Yes, active now
Yes, planning stage
Thinking about it
No, not interested



Results
Polls

Votes: 328
Comments: 0

Login
Login Name

Password

Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Who's Online
There are currently, 4 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here

div



MagicITX Logo © 2004.
All other logos and trademarks in this site are property of their respective owner. Comments are the property of their poster.
PHP-Nuke Copyright © 2005 by Francisco Burzi. This is free software and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty for details see the license.
Page Generation: 0.124 Seconds