HTPCHouse.com

  • Increase font size
  • Default font size
  • Decrease font size
Home Configuration Components >>

Separate HTPC functions into components

E-mail Print PDF

Configuration of modular HTPC which will run multiple multimedia applications at one hides many challenges two biggest one being that at any time only application windows from component in the foreground must be visible (including popup modular windows from components in the background) and only that component should be heard while all other components are muted. There are many different ways of accomplishing these goals and I've tried many of them (including running applications inside Xnest/Xephyr "virtual" X window servers) before I've settled upon sandboxing components each on one virtual desktop and configuring ALSA output one per component so each one can be easily programatically muted.

To simplify programmatic access to components, we'll give them all unique, one-word names: tv (for TV playback), cinema (for video playback), gallery (for picture viewer), jukebox (for music player) etc. These names are, of course, arbitrary but have to be consistent among scripts and configuration files, so I suggest you stick with these names until you get everything working and then tweak them as needed.

Virtual desktops

Since almost all window managers for Linux support virtual desktops, I suppose that you are quite familiar with the concept. Functions that your virtual manager must however support is support for changing active virtual desktop via wmctrl utility and it should support "real" virtual desktops that perform real sandboxing of application windows and not the one that are just placed at some offset from first desktop (they can be distinguished by the fact that first ones do not support dragging windows from one desktop to another by mouse). Openbox support both these features any they are easily configurable in its ~tv/.config/openbox/rc.xml file - look for <desktops> section. Desktops order is not important, but each desktop must be named after a name of the components it will contain.

Virtual sound mixers

ALSA is a bit trickier to setup. We'll need to edit file /etc/asound.conf (create it if it does not exist) and add one virtual audio mixer for every component we have using ALSA's softvol plugin naming it htpc-<component name>, for example:

pcm.htpc-tv {

type plug
slave {
pcm {
type softvol
slave.pcm "default"
control {
name "htpc-tv"
card 0
}
}
}

}

Do the same for every component you plan do configure or download asound.conf from my setup in download section. That will give you one ALSA PCM for use by one HTPC component - just configure your TV application to use ALSA PCM device named "htpc-tv" instead of "default" one, video player to use "htpc-player" etc. Consult your application's manual on how to route sound output through specific ALSA PCM device.

For some wild reason, ALSA devices created this way will not become visible in mixers immediately, but after first usage. For example, to initialize htpc-tv volume mixer after adding it to asound.conf file, find some wav file and play it with:

aplay --device=htpc-tv something.wav

After this, you will see newly added mixer in every ALSA compatible mixer (try alsamixer from terminal or alsamixergui

from graphical console).

Now, muting single HTPC component becomes an easy task using utility amixer - to mute for example mixer htpc-tv and thus TV playback component of your HTPC, simply call:

amixer sset htpc-tv,0 0%,0%

I'm using this, among other things, in script ~tv/bin/switch-mode for changing currently active HTPC component that mutes all known components and unmutes only selected one.

Adding new component

To add new component, either for production or just experimental use, follow these steps:

  1. Add new virtual desktop to window manager (file ~tv/.config/openbox/rc.xml for OpenBox) and name it after that component's unique configuration name.
  2. Add new ALSA mixer to file /etc/asound.conf naming it htpc-<component's configuration name>
  3. According to applications you wish to run, add one or more lines to ~tv/etc/pids.conf and specify paths to PID files for all programs used.
  4. Add script for starting component's applications, name it start-<component's configuration name> and add call to it to startup script ~tv/.xsession.
  5. Add script for activating component and name it switch-mode-<component's configuration name> - you will probably want to map some global remote key to this script.
  6. Add configuration for remappable keys on your remote(s) to file ~tv/etc/xkb-<component's configuration name>.
  7. Enumerate this new component in script that displays popup dialog for switching components - ~tv/bin/switch-mode-ask.
  8. Add line to file ~tv/etc/window-names.conf describing main window of application used for this component.
Last Updated on Thursday, 14 February 2008 21:50