Integrating Skype with a MythTV system

From MythTV Official Wiki
Revision as of 21:34, 11 June 2007 by Biercenator (talk | contribs) (Setup)

Jump to: navigation, search


Introduction

The approach to integrating Skype with a MythTV system described here is an attempt to get these two pieces of software to play nicely with one another inside a home entertainment PC. Please note that the "integration" described here does not involve cluttering up MythTV with an additional "Skype management screen" or the like. On the contrary, the aim is to get Skype working smoothly through an ordinary telephone and remove it from the computer display, to prevent it from interfering with the operation of MythTV.

This document assumes the use of an external piece of hardware (see below) that is used to connect an ordinary telephone to the USB port of a PC. This relevant hardware costs 40 to 50 dollars US new --- and I hasten to add that I have no connection with any of the firms that make or market this item, nor with Skype. I just find that a telephone, MythTV and Skype make a handy combo, and imagine that others might find it useful as well. So here goes with the explanation.

In their initial version, these instructions assume the use of the Ubuntu Linux distribution. They should also work for GNU/Linux (Debian) systems. If you run a different distribution and find that some parts of the instructions need to be modified, feel free to amend this document for the benefit of others.

What we're after

As a learning-averse modern consumer, my needs are very simple. To me, "making a call" means picking up a telephone, dialing a number, talking with the person on the other end of the line, and hanging up. Conversely, "receiving a call" means that the telephone rings, and I answer by picking it up and speaking into the receiver. Notice that the words "keyboard", "monitor" and "mouse" do not figure in this description. As an aspiring Luddite, when I come home from work and flop down in front of the telly, I want --- however briefly --- to be able to forget what those terms mean.

On the other hand, I have more technology-tolerant friends who do make calls, using Skype from their computer monitors. When I find myself sitting at home getting reacquainted with subtle plot twists in The Brady Bunch or admiring the fine dramatic performances of David Hasselhoff, I would like Skype to broadcast my online status as Online [1]. When the Myth box is busy recording programs, but the front end is not in use, the world should be told that I am Not Available. And stuff.

That is the target feature set in a nutshell: a telephone that can be used for ordinary inbound and outbound calls via Skype or the landline, and which gives a hint to other Skype users about whether I'm around and likely to pick up the phone if they should ring.

This scenario can be realized by matching Skype with a small device that we will call a "telbox", using a small amount of software glue.

Software

You will need three pieces of software to connect the telbox to Skype:

  • usbb2k_api A small driver daemon that converts simple human-friendly commands to the binary whatsit language used by the telbox, and likewise returns responses sent back by the box in human-friendly form. Fetch the latest binary distribution of this item.
  • kb2kskype A bridge application that, using the simplified command set groked by usbb2k_api on one side, and the Skype Public API on the other, causes incoming Skype calls to ring the phone, and keypresses on the telephone to be fed through to Skype. Fetch the latest binary distribution of this item, as well.
  • skype You will need to install version 1.3 or 1.4 of Skype. Version 1.4.0.64 or higher is recommended. (As of this writing, Skype version 1.4 is currently available only as an Alpha preview.

Hardware

Once you have grabbed the usbb2k_api and kb2kskype packages, and checked that the two main apps (Skype and Myth) will both run in your environment, you will need the following hardware in order to proceed:

  1. USB-B2K telbox The original manufacturer is Yealink, but the same product has been rebranded as OEM equipment by several other firms. Here are a few links to check for information:
  2. Open USB port This will be used to connect the telbox to your computer. The USB-B2K uses USB 1.1, so any USB port should work.
  3. Ordinary telephone You probably already have one of these lying around. The phone will be used for both PSTN (landline) and Skype calls, so your existing phone will continue to work.
    Note: If you don't have a landline, you can set up the software for USB (Skype) mode only.

Setup

With software and hardware in hand, you're ready to put it all together. As indicated above, these instructions assume the use of the Ubuntu or GNU/Linux (Debian) distribution of the Linux OS. Some details (particularly the startup scripts) may need to be modified when working with another distribution.

Hardware installation

The first step is refreshingly simple. Connect the USB cable to the USB-B2K box, and plug the other end into a free USB port on your PC. Connect your telephone to the appropriate phone jack on the box (on mine, it is labeled "TEL"). If you use a landline, connect the line to the other phone jack on the box (on mine, this one is labeled "LINE"). The telbox draws its power from the USB cable, so that's all you need to do.

When the telbox has no power (i.e. when your PC is turned off) the phone should work normally for landline calls. To get Skype working, we have to attend to that software.

Starting usbb2k_api at boot time

The usbb2k_api driver expects the telbox to remain connected when it is running. Its behaviour if the USB cable of the telbox is disconnected while it is running is undefined --- which is to say, something will probably crash if you suddenly yank the USB cable out of your PC before shutting down the driver. So we'll assume that the telbox remains hooked up while the PC is running. In that case, running usbb2k_api automatically at boot time will serve our purposes.

If you have copied the usbb2k_api binary to /usr/local/sbin, you can use the following as a startup script:

#!/bin/sh
#
#

test -f /usr/local/sbin/usbb2k_api || exit 0

case "$1" in
  start)
    echo -n "Starting usbb2k_api:"
    echo -n " usbb2k_api"
    start-stop-daemon --start --quiet --exec /usr/local/sbin/usbb2k_api \
      < /dev/null
    echo "."
    ;;
  stop)
    echo -n "Stopping usbb2k_api:"
    echo -n " usbb2k_api"
    start-stop-daemon --stop --quiet --exec /usr/local/sbin/usbb2k_api \
      < /dev/null
    test -f /var/run/usbb2k_api.pid && rm /var/run/usbb2k_api.pid
    echo "."
    ;;
  reload|force-reload|restart)
    $0 stop
    $0 start
    ;;
  *)
    echo "Usage: /etc/init.d/usbb2k_api {start|stop|reload|restart|force-reload}"
    exit 1
esac
  
exit 0

Using cut and paste, save the text above to a file named usbb2k_api. As the root user, make the script executable and move it to the directory /etc/init.d:

 prompt$ su
 Password:
 prompt# chmod uog+x usbb2k_api
 prompt# mv usbb2k_api /etc/init.d
 prompt# exit
 prompt$

To get the startup script to run at boot time on an Ubuntu or GNU/Linux (Debian) system, use the update-rc.d system configuration command (note that a different procedure may well be required for this step on other systems):

 prompt$ su
 Password:
 prompt# update-rc.d -f usbb2k_api start 90 2 3 4 5 . stop 90 0 1 6 .
  Adding system startup for /etc/init.d/usbb2k_api ...
    /etc/rc0.d/K90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc1.d/K90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc6.d/K90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc2.d/S90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc3.d/S90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc4.d/S90usbb2k_api -> ../init.d/usbb2k_api
    /etc/rc5.d/S90usbb2k_api -> ../init.d/usbb2k_api
 prompt# exit
 prompt$

To confirm that the driver is working and set to run at boot time, restart your system and then look for usbb2k_api in the process table:

 prompt$ ps ax | grep usbb2k_api
 11496 pts/0    S+     0:00 grep usbb2k_api
 prompt$

Running Skype and kb2kskype in a virtual X server window

Skype is a GUI application that likes to make its presence known when it performs operations. There are at least reasons for this. There is a very vocal population of users clamouring for video in Skype for Linux, so the pressure is for more on-screen activity, not less. Even without video, Skype has more features than can be easily controlled through a 12-key handset, so in most environments, putting the GUI in front of the user when it might be needed is convenient. There are security concerns as well. Skype can be accessed and controlled by other applications via a hidden communication channel (the Skype Public API), and in many environments it is a good thing for the user to be made aware of what these programs are doing. When MythTV has control of the display, however, the Skype client can be a distraction.

The simplest and most comprehensive way of keeping Skype off the screen is to route its GUI to a virtual X server (a Virtual Network Console, or VNC). This is a display separate from the physical screen(s) on your PC that exists as a daemon process, and can be accessed using a special VNC viewer client. When an X application is attached to a virtual X server, it is for practical purposes invisible; its windows and whatnot will only be shown if the user connects to the virtual display with a VNC viewer.

Installing necessary support packages

The first step is to install a VNC server and client. There are several in circulation. The one I use is the Debian/Ubuntu package vnc4server for the server, and xvncviewer for the viewer client. Unless you have a strong preference for another combination of VNC tools, use the package manager to install these two packages.

The VNC server, just like the server that runs the physical X display on the monitor, needs to have a window manager. Gnome is much too heavy for a server that will only run a couple of applications. There are many lightweight window managers around. The one I use is blackbox. If you don't feel like shopping around and tinkering with the setup, use your package manager to install this package as well.

Configuring the server

The VNC server uses its own xstartup script, located at ~/.vnc/xstartup. Here is a copy of the one that I use, with commands and options explained in the comments. (Note that the VNC server display name is "bigbox". More on where that comes from in the next section.)

#!/bin/sh

## Allow connections from this computer (possibly not required)
xhost +localhost

## A grey background is easier on the eyes than the default
## hash pattern used by X
xsetroot -solid grey

## Force the VNC server configuration widget to the virtual display
vncconfig -display bigbox:1 &

## Possibly gratuitous pause inserted to give Skype a comfortable
## startup environment
/bin/sleep 1

## Skype accepts the usual X11 options.  We force it to use
## the virtual display
/usr/bin/skype -display bigbox:1 &

## Several options are used with kb2kskype
## --cmap forces kb2kskype to use a private colormap, to avoid overburdening
##     the server colormap
## --geometry just sizes and positions the kb2kskype GUI widget inside
##     the virtual display
## --display just forces the widget to display in the virtual server
## --offhook-stamp causes the named file to be created when the
##     telephone is off-hook, and deleted when the telephone is
##     placed on-hook
## --status-script causes the last-named script to be run every
##     ten seconds, and the Skype online status to be set to
##     according to its exit status.  An exit status of 0 uses
##     the first option, 1 the second, and so on
/usr/local/bin/kb2kskype --cmap --geometry 50x50+200x+0 --display bigbox:1 \
  --offhook-stamp /tmp/CALL_IN_PROGRESS \
  --status-script na,online,/usr/local/bin/MyB2Kcheckstatus.sh &

## Run the window manager!
blackbox -display bigbox:1 &


If you have installed the blackbox window manager package, and both usbb2k_api and kb2kskype are in place, you should be able to use this script, too. Create a subdirectory .vnc in the account used by MythTV, and use cut and paste to copy the text above into a file xstartup in that subdirectory.

A few comments about the last two options fed to kb2kskype are in order. These options were added specifically to support MythTV. With the --offhook-stamp option, a MythTV shutdown script can check for the named file, and postpone a shutdown when it is found. This can be used to prevent the Myth box from suddenly shutting down in the middle of a Skype call. The --status-script option can be used to set Skype's online status using a script that is run periodically (every 10 seconds). In my installation, mythfrontend sets a pid file when it is running. The script invoked in the example checks for the pid file, and sets the user status to online when it is found, na otherwise.

(more coming soon ...)

Notes

[1] The current version of Skype for Linux does not offer a Desperate for Something Else to Do setting.