A computer as a home media center

Notes published the
8 - 10 minutes to read, 2091 words
Categories: assembly debian linux music photo video
Keywords: assembly debian linux music photo reuse video

Recently (which in the meantime is one year ago) I helped to set up a new computer, and shortly after we asked ourselves, what to do with the old one.

The old computer is a Toshiba Satellite C660, according to some websites it was released in 2010, which means that it has been used at least for 10 years.

It came with Windows 7 preinstalled and was updated to Windows 10. It got replaced because it was extremely slow at every operation, even idling.

After taking dust for a couple of months in a box, I decided to play with it and create a home theatre and backup service.

The easiest media-station

If your PC happens to be a Raspberry, there are a lot of already packaged solutions that require little to no configuration.

For example, just download LibreELEC, flash it on the SD card, insert it into the Raspberry, and connect the Raspberry with an HDMI cable to the TV.

Done.

With the TV remote it is possible to control the whole UI thanks to CEC.

But LibreELEC is too minimal

Librelec is indeed a minimal system.

If you plan to do something else (it is a computer after all!), LibreELEC and similar systems might not be enough.

But I have an old PC, not a raspberry

The good thing is that on a PC, contrary to smart devices, you can nearly do anything you want.

No need to root or hack it, just install the operating system or programs you like.

Unfortunately, contrary to the Raspberry, I did not find a preconfigured solution similar to LibreElec.

A minimal home theatre system

For experimenting, I choose to stick with Debian.

I’ve downloaded the ISO from cdimage, flashed it on a USB stick, and booted the PC from it.

During the installation process, I avoided setting a root password (this way sudo is automatically enabled, and the root user is disabled), configured a user called toshiba (not very creative), and avoided installing a graphical environment (remember, I want a minimal system).

I’ve just installed ssh as it makes it easier to configure the PC.

set-up ssh keys

vim ~/.ssh/config # add values for the new machine, for example, the username
ssh-keygen
# reply to questions
ssh-copy-id toshiba

Now I can log on to the machine with just ssh toshiba, without needing to type the password or the name of the user/machine.

Install and setup Kodi

This is pretty much straightforward

sudo aptitude install kodi;

You might want to install additional packages like kodi-imagedecoder-raw, kodi-vfs-libarchive, kodi-peripheral-joystick, kodi-pvr-iptvsimple, and so on. Just do aptitude search kodi and see what packages are available and what might look interesting.

After installing Kodi, as the PC will be connected to a TV most of the time, it would make sense to log in automatically and start-up Kodi immediately.

lightdm is a standalone login manager, and can be configured easily to accomplish both tasks.

Also for making the system a little more secure, it makes sense to create a separate Kodi user.

Execute as an administrator following commands

# add group for graphical login without password, see https://wiki.debian.org/DebianDesktopHowTo for details
addgroup --system nopasswdlogin;
if ! grep --quiet --fixed-strings nopasswdlogin /etc/pam.d/lightdm;  then :;
  sed -i '/^@include common-auth/i auth sufficient pam_succeed_if.so user ingroup nopasswdlogin\n' /etc/pam.d/lightdm;
fi

# add restricted user kodi
adduser --disabled-password --comment "" kodi;
usermod -a -G cdrom,video,plugdev,users,dialout,dip,input,netdev,nopasswdlogin kodi;


# add autologin with kodi program
printf '[Seat:*]

# autologin user kodi by default
autologin-user=kodi
autologin-session=kodi
user-session=kodi

# show user list, remove the need to type name in case of logout
greeter-hide-users=false
' > /etc/lightdm/lightdm.conf.d/99-home-theatre.conf;

And that’s it.

Reboot the PC and it will start Kodi automatically.

Except that contrary to the Raspberry, you will not be able to control it with the TV remote. It does not matter how hard I search, there is no PC on the market that supports CEC (the hardware is simply missing).

If you happen to have a PC that does support CEC (please contact me in that case, I was not able to find anything) or a dongle like the CEC adapter of pulse-eight (currently the adapter I was able to find), then CEC will work out of the box.

It might make sense to install the package cec-utils, but it seems to be optional.

Also, Kodi has no GUI for managing the network (especially WiFi), and Bluetooth devices. LibreElec has preinstalled some addons done directly by the team for adding those functionalities.

If your PC can be connected with an ethernet cable, it should be the preferred solution, as it works out-of-the-box.

Otherwise, it is possible to configure the Wi-Fi manually by adding a configuration file under /etc/network/interfaces.d

An alternative is to use an interactive program from the command line.

Network Manager has also a command line interface (nmtui) available after sudo aptitude install network-manager.

This is probably more user-friendly if there are multiple networks, or if the PC might need to change from one network to the other because it is moved from one location to another.

As a Bluetooth manager, one can use bluetoothcl from the command line, or install blueman as a lightweight graphical alternative.

Install and setup Kodi with Openbox

From Kodi, it is possible to execute external programs, for example with the Advanced Emulator Launcher plugins

There are multiple reasons you might want to execute something else, it could be

  • execute a native game

  • a browser instance pointed to www.netflix.com (as there are no native and official clients for GNU/Linux systems)

  • a graphical Wi-Fi/Bluetooth manager

  • or something else entirely

By executing some programs, I’ve encountered at least a couple of issues.

The first is that with some programs, after closing them, the keyboard did not work anymore in Kodi. I had to log out and log in again.

The second one is that some programs have difficulties determining the screen size. Thus even if executed as full-screen programs, they won’t be.

The third is that the is no close button (for those programs that are not fullscreen).

Adding a window manager solved all those issues. Openbox is pretty minimal and can be configured, so it seems a good fit.

There are surely others that are as good, maybe even better.

# install openbox
apt install openbox

# configure it to start Kodi automatically
sudo -u kodi sh -c 'mkdir -p ~/.config/openbox/; printf "kodi --fs --standalone\nopenbox --exit\n">~/.config/openbox/autostart'

# add autologin with Openbox program instead of starting Kodi directly
printf '[Seat:*]

# autologin kodi with openbox by default
autologin-user=kodi
autologin-session=openbox
user-session=openbox

# show user list, remove the need to type name in case of logout
greeter-hide-users=false
' > /etc/lightdm/lightdm.conf.d/99-home-theatre.conf;

Thus instead of executing Kodi directly from the login manager, Openbox is started. Openbox will then execute Kodi on startup, and exit after Kodi is closed.

With those changes

  • Applications do not have any more issues determining the size of the monitor, and full-screen programs are actually fullscreen

  • there is a close button for every non-full-screen program

  • never had an issue with the keyboard anymore

Disable standby

What happens when the lid of a laptop is closed?

Even if connected to an external monitor, it puts the machine on standby, at least this was my case.

This can be changed by adding the following command

# from https://wiki.debian.org/SystemdSuspendSedation
printf '[Login]
HandleLidSwitch=ignore
HandleLidSwitchDocked=ignore
HandleLidSwitchExternalPower=ignore
' > /etc/systemd/logind.conf.d/99-disable-suspend.conf;

If you want to disable suspend and hibernation completely, you should also add the following lines

AllowSuspend=no
AllowHibernation=no
AllowSuspendThenHibernate=no
AllowHybridSleep=no

The ugly truth

While the instructions for setting up a minimal home theatre are short, I was a little bit unlucky, as I had several issues with the hardware, which means it took me much more time than expected (multiple days), to settings up the system.

Maybe using another operating system would have helped, but maybe not.

Network

At first, I thought how lucky I was that the machine had an ethernet port. Just attach the cable and no need to think about Wi-Fi.

Unfortunately, it turned out that the ethernet port disappeared every second boot. I do not know if this is a software or hardware issue but using the network card (which worked out of the box) solved the issue.

Monitor/HDMI

I also had issues with the monitor.

Even if standby was disabled, starting the PC with a closed lid did not send the video signal through HDMI, except once. I was never able to reproduce it.

The laptop has an Nvidia card, and the correct packages are currently unavailable, the main reason is unsolved security issues. The open-source driver seems to work well enough, but not so much when using both monitors at the same time. After trying (and failing) to install the official Nvidia package, I decided to keep the open-source variant, as normally I am going to use only one monitor (the external one).

I solved the monitor issue by turning off the internal monitor and activating the monitor attached via HDMI. As the values are hardcoded, it does not make my solution portable between TVs and devices, but it is also true that it is attached to only one and I have no intention to move it.

My ~/.config/openbox/autostart file currently looks like

xrandr --output LVDS-1 --off
xrandr --output HDMI-1 --mode 1920x1080
kodi --fs --standalone
openbox --exit

The program xrandr is packaged in x11-xserver-utils.

Note that it also works correctly if the machine starts while the TV is turned off, and turned on after the boot is completed.

Disable all suspensions

From Kodi, it is possible to configure after how much time the monitor should be turned off. But even if you disable all screensaver settings, the monitor will turn itself off after a given period of "inactivity".

With xset s off -dpms it is possible to disable the screensaver and DPMS (Energy Star) features.

If using a window manager, it should be trivial to add such a command after logging in, for example with Openbox it can be added in ~/.config/openbox/autostart.

But an even better approach would be to start the X server with those features disabled, this can be done for example in lightdm, by adding

[Seat:*]
# keep the screen on all the time
xserver-command=X -s 0 -dpms

to the other (for example autologin) options.

Audio

Alsa

At last, I also had an issue with the audio. It did not matter how loud I turned the volume in Kodi, no sound came out of the machine.

It turns out that with some audio cards, the audio is muted (unfortunately I cannot find the reference anymore).

With alsamixer (from the package alsa-utils) I unmuted the audio, and the issue did not reappear anymore.

PulseAudio

Because of reasons, I’ve switched from alsa to pulseaudio.

For Kodi this is not an issue, there is a graphical interface for configuring the output device.

But if you are starting other programs from Kodi, those will not necessarily use the same output device.

Thus I wanted to set the default audio device globally.

With pacmd list-sinks | grep -e 'name:' -e 'index:' it is possible to list the output devices; in my case, the output looked like

    index: 0
        name: <alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3>
    index: 1
  *     name: <alsa_output.pci-0000_00_1b.0.analog-stereo>

Since I want, by default, to output everything over HDMI, I created the configuration file

/etc/pulse/default.pa.d/hdmi.pa
set-default-sink alsa_output.pci-0000_01_00.1.hdmi-stereo-extra3

Conclusion

Even if has been harder than thought, the "old" PC is still in use.

While experimenting I put more focus on Video files, but Kodi offers a very decent interface for also handling music files and pictures.

The machine is even more than powerful enough for handling other jobs, installing a minimal system can really revive old hardware.

It could be used for automating tasks, like creating backups of content over the network, sharing files, and downloading (or uploading) data…​


Do you want to share your opinion? Or is there an error, some parts that are not clear enough?

You can contact me anytime.