GNU/Linux

Martin's
GNU/Linux Projects

To Home Page

Media PC - one device and one remote for all media

Last modifications: 27 December 2019

Introduction

On this page I describe how I built my media PC. With this PC you can watch television, watch movies from DVD and hard disk, listen to music and view photo's. My media PC can be controlled with an infrared remote control.

All the information on this page is about a setup using:

Do you also like to build your own remote controlled media PC? Read on and hopefully you will find some useful information here.

Some notes on LIRC

  • LIRC stopped working from kernel version 4.12 (maybe earlier).
  • From version 4.12, module lirc_serial is renamed to serial_ir.
  • From version 4.17, LIRC should work again.

Why using a media PC?

Remote controll stress

Now that photo's, music and video (including television) are all available in digital format, you actually need only one device to have access to all this media: a computer!

Still, people try to sell us smart TV's, DVD and Blu-ray players, hard disk recorders and streaming media players. All these devices come with their own remote control and their own user interface. I do not like that. Furthermore, the use of these devices is restricted by the features built in by the manufacturer. I do not like that either!

So when I decided to replace my old bulky cathode ray tube television, it was clear to me I would not buy an expensive smart TV. Instead I bought a second hand computer and a HD LCD computer monitor to build my own ultra smart media PC!

What it looks like

Below you can see some (older) screen shots of my media PC to give you an idea what it looks like. Click on an image to view a larger version.

My media PC desktop with media shortcuts (Xfce desktop environment):

My media PC desktop (Xfce desktop environment)

Watching television:

Watching television with Me TV

Listening to my music:

Listening to music using Banshee media player

Watching a DVD with VLC media player:

Watching a DVD with VLC media player

Enjoying my pictures:

Enjoying my pictures with Ristretto photo viewer

Switching between open application windows:

Switching between open windows

My hardware setup

Below you find a picture of my hardware setup. It consists of:

  • Dual core PC
  • High-definition LCD/LED computer monitor (28 inch)
  • Stereo amplifier
  • Great sounding speakers (JBL LX44)
  • DVB-T USB stick with antenna (DVB stands for Digital Video Broadcasting)

My infrared receiver and remote control are not shown in the picture below. They are described in the next section.

My hardware setup

Some remarks:

  • I use a Ultra-Small Form Factor PC with a horizontal desktop case, that fits easily in my TV rack.
  • With the DVB-T USB stick and a small antenna, I receive 4 Dutch channels from the air for free. That is enough TV for me. If you need more channels or better quality, use a DVB device for cable (DVB-C) or satellite (DVB-S).
  • I really like my two JBL speakers so I chose for a stereo setup. But you can also make a surround sound setup, if you like.
  • My media PC is connected to my home network so I can access all the media files on my NAS (and other computers). Surfing the Internet is also possible (of course!).

Controlling my media PC

To control my media PC I use a home made infrared receiver and a universal infrared remote control. The software I use is LIRC (Linux Infrared Remote Control). Read more about this software in the section How does LIRC work?

Remote control

You need quite a lot of commands to control a computer. So I chose a universal remote control with enough buttons to configure all the commands I like to use (41 all together!).

General commands:

Universal remote control
  • enter
  • escape
  • go up, down, left, right
  • page up, down
  • go one level up in file browser
  • enter numbers 0-9 (to choose TV channel)
  • delete

Desktop commands:

  • show main/start menu
  • show application menu
  • show context menu
  • show window menu
  • show desktop (hide all windows)
  • switch between application windows
  • go to next, previous window (or window panel)
  • close window
  • show window in full screen mode

Media commands:

  • play/pause
  • stop
  • forward or next
  • rewind or previous
  • record
  • show TV program guide or DVD menu
  • raise, lower volume
  • mute sound

Infrared receiver

Receiver built in serial connector

I have built the infrared receiver myself. It is cheap and fun to do (if you like soldering). To be able to use this receiver, you need a computer with a serial port. The receiver is very small and fits into a serial connector (see image). It works great with the LIRC software and my remote.

Read how to build your own serial receiver.

You can plug in the receiver directly into the serial port on the back of your computer. This will work well if the wall behind the computer is light enough to reflect the infrared signals from your remote.

Choosing your remote & receiver

If you are planning to use LIRC, make sure your remote and receiver are supported.

See "Supported Hardware" on the LIRC homepage.

Mouse & keyboard

In stead of using a remote, you could also use a wireless mouse (and maybe a keyboard) to control your media PC. This will save the effort of configuring LIRC and making it work.

I hooked up a wired mouse and keyboard. I use them in case controlling with a remote becomes to cumbersome. For example, if I want to do a quick search on the web.

How does LIRC work?

LIRC

Before actually setting up LIRC, first let's see how it works. In the picture on the right you can see the data flow between the hardware and software components of my LIRC setup.

When you push a button on your remote control, it sends out an infrared data signal. The infrared receiver receives this data signal and via the serial port and the lirc_serial device driver the data is sent to the lircd daemon.

The lircd daemon translates the "infrared data" into the name of the remote control button that was pushed. The translation (decoding) is defined in the configuration file lircd.conf. Each type of remote has its own lircd.conf file.

See my lircd.conf file to get an idea how a configuration file looks like.

Applications with LIRC support receive the name of the pushed button from the lircd daemon and a specific action is executed. For each button on your remote control you can configure an application and the action it has to execute. This is done in the .lircrc configuration file.

Take a look at my .lircrc file and see how applications and actions are assigned to remote control buttons.

LIRC configuration

As stated in the previous section, LIRC uses the configuration files lircd.conf and .lircrc.

Configuration file "lircd.conf"

The LIRC daemon lircd uses the lircd.conf configuration file to translate "infrared data" sent by your remote, into the names of the remote control buttons. On the LIRC website you can find configuration files for about 2500 different types of remote controls.

If your remote control is not in the list, you can create your own configuration file. You need the tool irrecord (part of LIRC) to do this. Typical usage:

   $ irrecord -d /dev/lirc0 lird.conf

The tool irrecord will ask you to push buttons on your remote and will also ask you to enter the names of the buttons. This whole procedure will take some time! The output is written to the file lird.conf in the current directory. Read more about irrecord on the LIRC website.

Configuration file ".lircrc"

Applications with LIRC support use the .lircrc configuration file to see what action has to be taken when a certain remote button is pushed. Below you find some examples. A more detailed explanation about the .lircrc file format can be found on the LIRC website.

.lircrc example (1)

Play the next song in Banshee music player with the forward button on your remote:

   begin
     button = forward
     prog = banshee
     config = next
   end

A special application is the LIRC tool irexec. It is used to execute other applications.

.lircrc example (2)

Start VLC media player using the AV button:

   begin
     button = av
     prog = irexec
     config = vlc &
   end

I mainly use irexec in combination with xte to generate fake keyboard strokes. For example, if you want to close a window using your keyboard, you press Alt+F4. To close a window with a button on your remote, you can use irexec and xte to fake the Alt+F4 keyboard strokes.

.lircrc example (3)

Close a window with the power button, using xte:

   begin
     button = power
     prog = irexec
     config = xte 'keydown Alt_L' 'key F4' 'keyup Alt_L'
   end

You can also use the LIRC tool irxevent to generate fake keyboard presses. But I find this tool more complicated than xte and it does not offer extra features that I need.

Setting up LIRC

The default so called unit file that systemd uses to start the LIRC daemon, /lib/systemd/system/lircd.service, does not work for my setup. Therefore I made my own startup script and I changed the systemd unit file so it calls this startup script (see How to set up LIRC). You can easily test the script by running it from a terminal as root.

Startup script LIRC daemon

#!/bin/bash

# Startup script for LIRC daemon with home-brew serial port IR receiver

# Create directory /var/run/lirc/ (needed by lircd)
# This directory may already exist (but sometimes not)
mkdir /var/run/lirc/

# Free serial port
setserial /dev/ttyS0 uart none

# Load serial_ir module (driver for IR receiver)
# This will create device /dev/lirc0
modprobe serial_ir

# Start LIRC daemon
/usr/sbin/lircd --device=/dev/lirc0 --driver=default /path/to/my/lircd.conf

Finally a summary how to install, configure and start LIRC.

How to set up LIRC

  • Use your package manager to install the packages setserial and lirc.
  • If you want to use xte, install the package xautomation. If you prefer irxevent, install the package lirc-x.
  • Create a .lircrc file and place it in your home directory.
  • Find the right lircd.conf file for your remote control in the LIRC remote database and place it anywhere you want. If you can not find a configuration file for your remote, use irrecord to create one.
  • Create the startlirc.sh script and place it anywhere you want. Edit the path to lircd.conf in this script.
  • Edit the unit file that systemd uses to start the LIRC daemon: /lib/systemd/system/lircd.service. Only change the following section:
  • [Service]
    Type=forking
    ExecStart=/path/to/startlirc.sh
    
  • Use the autostart feature of your desktop to start irexec. In this way irexec runs as a regular user, as it should (at least in my opinion...). Do the same for irxevent if you want to use this tool.
  • Do not forget to connect your serial infrared receiver to the serial port of your computer!

Tear-free video

If you experience video tearing, you may try the compositor Compton to solve this. The setup below worked for me.

How to set up Compton for tear-free video

  • Use your package manager to install the package compton.
  • Make sure that no other compositor is running (in Xfce use Window Manager Tweaks to disable compositing).
  • Start Compton as follows:
    $ compton --backend glx --paint-on-overlay \
              --glx-no-stencil --vsync opengl-swc -b
    
    Call this command using the autostart feature of your desktop.