Boot-to-Kodi, 2019 edition

This weekend I’m oncall for work, so between me and my girlfriend we decided to take a few chores off our to-do lists. One of the things for me was to run the now episodic maintenance over the software and firmware of the devices we own at home. I call it episodic, because I no longer spend every evening looking after servers, whether at home or remote, but rather look at them when I need to.

In this case, I honestly forgot when it was the last time that I ran updates on the HTPC I use for Kodi and for the UniFi controller software. And that meant that after the full update I reached the now not uncommon situation that Kodi refused to start at boot. Or even when SSH’ing into the machine and starting the service by hand.

The error message, for ease of Googling, is:

[  2092.606] (EE) 
Fatal server error:
[  2092.606] (EE) xf86OpenConsole: Cannot open virtual console 7 (Permission denied)

What happens in this case is that the method I have been using to boot-to-Kodi was to use a systemd unit lifted from Arch Linux, that started a new session, X11, and Kodi all at once. This has stopped working now, because Xorg no longer can access the TTY, because systemd does not think it should access the console.

There supposedly are ways to convince systemd that it should let the user run X11 without so much fluff, but after an hour trying a number of different combinations I was not getting anywhere. I finally found one way to do it, and that’s what I’m documenting here: use lightdm.

I have found a number of different blog posts out there that try to describe how to do this, but none of them appear to apply directly to Gentoo.

These are the packages that would be merged, in order: 
 
Calculating dependencies... done! 
[ebuild   R    ] x11-misc/lightdm-1.26.0-r1::gentoo  USE="introspection -audit -gnome -gtk -qt5 -vala" 0 KiB

You don’t need Gtk, Qt or GNOME support for lightdm to work. But if you install it this way (which I’m surprised is allowed, even by Gentoo) it will fail to start! To configure what you need, you would have to manually write this to /etc/lightdm/lightdm.conf:

[Seat:*] 
autologin-user=xbmc 
user-session=kodi 
session-wrapper=/etc/lightdm/Xsession

In this case, my user is called xbmc (this HTPC was set up well before the rename), and this effectively turns lightdm into a bridge from systemd to Kodi. The kodi session is installed by the media-tv/kodi package, so there’s no other configuration needed. It just… worked.

I know that some people would find the ability to do this kind of customization via “simple” text files empowering. For me it’s just a huge waste of time, and I’m not sure why there isn’t just an obvious way for systemd and Kodi to get along. I would hope somebody builds one in the future, but for now I guess I’ll leave with that.

XBMC part 2

I have posted about me setting up a new box for XBMC and here is a second part to that post, now that I arrived to Dublin and I actually set it up on my living room as part of my system. There are a few things that needs better be described.

The first problem I had was how to set up the infrared receiver for the remote control. I originally intended to use my Galaxy Note as it has an IR blaster for I have no idea what reason; but then I realized I have a better option.

While the NUC does not, unfortunately, support CEC input, my receiver, a Yamaha RX-V475 comes with a programmable remote controller, which – after a very quick check cat-ing the event input device node – appeared sending signals in the right frequency for the built-in IR sensor to pick it up. So the question was to find a way to map the buttons on the remote to action to XBMC.

Important note: a lot of the documentation out there tells you that the nuvoton driver is buggy and requires to play with /sys files and the DSDT tables. This is outdated, just make sure you use kernel version 3.15 or later and it works perfectly fine.

The first obvious option, which I have seen documented basically everywhere, is to use lirc. Now that’s a piece of software that I know a little too well for comfort. Not everybody knows this, both because I went by a different nickname at the time, and because it happened a long time before I joined Gentoo, and definitely before I started keeping a blog. But as things are, back in the days when Linux 2.5 was a thing, I did the first initial port of the lirc driver to a newer kernel, mostly as an external patch to apply on top of the kernel. I even implemented devfs, since while I was doing that I finally moved to Gentoo. and I needed devfs to use it.

I wanted to find an alternative to using lirc for this and other reasons. Among other things, last time I have used it, I was using it on computer that was not dedicated as an HTPC, so this looked like a much easier task with a single user-facing process in the system. After looking around quite a bit I found that you can make the driver output X-compatible key events instead of IR events by loading the right keymap. While there are multiple ways to do this, I ended up using ir-keytable which comes in v4l-utils.

The remote control only had to be set to send codes for a VDR for the brand “Microsoft” — which I assume puts it in a mode compatible with Windows XP Media Center Edition. Funnily enough they actually put a separate section for Apple TV codes. After that, the RC6/MCE table can be used, and that will send proper keypresses fr things like the arrows and the number buttons.

I only had to change a couple of keys, namely Enter and Exit to send KEY_RETURN and KEY_BACKSPACE respectively, so that they map to actions in XBMC. It would probably be simple enough to change the bindings to XBMC directly, but I find it more reliable for it to send a different key altogether. The trick is to edit /etc/rc_keymaps/rc6_mce to change the key that is sent, and then re-run ir-keytable -a /etc/rc_maps.cfg, and the problem is solved (udev rules are in place so that the map is loaded at reboot).

And this is one more problem solved, now I’m actually watching things with XBMC so it seems to be working fine.

A new XBMC box

A couple of months ago I was at LinuxTag in Berlin with the friends from VIdeoLAN and we shared a booth with the XBMC project. It was interesting to see the newest version of XBMC running, and I decided that it was time for me to get a new XBMC box — last time I used XBMC was on my AppleTV and while it was not strictly disappointing it was not terrific either after a while.

At any rate, we spoke about what options are available nowadays to make a good XBMC set up, and while the RaspberryPi is all the rage nowadays, my previous experience with the platform made it a no-go. It also requires you to find a place where to store your data (the USB support on the Pi is not good for many things) and you most likely will have to re-encode animes to the Right Format™ so that the RPi VideoCore can properly decode them: anything that can’t be hardware-accelerated will not play on such a limited hardware.

The alternative has been the Intel NUC (Next Unit of Computing), which Intel sells in pre-configured “barebone” kits, some of which include wifi antennas, 2.5” disk bays, and a CIR (Consumer Infrared Receiver) that allows you to use a remote such as the one for the XBox 360 to control the unit. I decided to look into the options and I settled on the D54250WYKH which has a Core i5 CPU, space for both a wireless card (I got the Intel 7260 802.11ac which is dual-radio and supports the new 11ac protocol, even though my router is not 11ac yet), and a mSATA SSD (I got a Transcend 128GB one), as well the 2.5” bay that allows me to use a good old spinning-rust harddrive to store the bulk of the data.

Be careful and don’t repeat my mistake! I originally ordered a very cool Western Digital Caviar Green 2TB HDD but while it is a 2.5” HDD, it does not fit properly in the provided cradle; the same problem used to happen with the first series of 1TB HDDs on PlayStation 3s. I decided to keep the HDD and bring it with me to Ireland, as I don’t otherwise have a 2TB HDD, instead I opted for a HGST 1.5TB HDD (no link for this one as I bought it at Fry’s the same day I picked up the rest, if nothing else because I had no will to wait, and also because I forgot I needed a keyboard).

While I could have just put OpenELEC on the device, I decided instead to install my trusted Gentoo — a Core i5 with 16GB of RAM and a good SSD is well in its ability to run it. And since I was finally setting something up that needs (for myself) to turn on very quickly, I decided to give systemd a go (especially as Robbins is now considered a co-maintainer for OpenRC which drains all my will to keep using it). The effect has been stunning, but there are a few issues that needs to be ironed out; for instance, as far as I can tell, there is no unit for rngd which means that both my laptop (now converted to systemd) and the device have no entropy, even though they both have the rdrand instruction; I’ll try to fix this lack myself.

Another huge problem for me has been getting the audio to work; while I’ve been told by the XBMC people that the NUC are perfectly well supported, I couldn’t for the sake of me get the audio to work for days. At the end it was Alexander Patrakov who pointed out to intel_iommu=on,igfx_off as a kernel option to get it to work (kernel bug #67321 still unfixed). So if you have no HDMI output on your NUC, that’s what you have to do!

Speaking about XBMC and Gentoo, the latest version as of last week (which was not the latest upstream version, as a new one got released exactly while I was installing the box), seem to force you to install FFmpeg over libav – I honestly felt a bit sorry for the developers of XBMC at LinuxTag while they were trying to tell me how the multi-threaded h264 decoder from FFmpeg is great… Anton, who wrote it, is a libav developer! – but even after you do that, it seems like it does not link it in, preferring a bundled copy of it instead. Which also doesn’t seem to build support for multithread (uh?). This is something that I’ll have to look into once I’m back in Dublin.

Other than that, there isn’t much to say; the one remaining big issue is to figure out how to properly have XBMC start up at boot without nasty autologin hacks on systemd. And of course finding a better way than using a transmission user to start the Transmission daemon, or at least find a better way to share the downloads with XBMC itself. Probably separating the XBMC and Transmission users is a good idea.

Expect more posts on what’s going on with my XBMC box in the future, and take this one as a reference about the NUC audio issue.

Rygel; replacing MediaTomb?

I’ve ranted about overlays leaving notes about Gnome overlay I had to fight with that because of Rygel which reportedly needed the new (testing) version of Gtk+.

Now, my interest in Rygel is so that we can rid of MediaTomb in Portage; I added it myself, when I tried to make use of my PlayStation 3 for streaming video (mostly anime and Real Time with Bill Maher). It actually never worked as well as I itnended for very long; it needed proper transcode support, and what was there was incomplete. Also, the code itself was messy and hacky, with commented-out code still there, and bundled libraries. When I replaced my Samsung TV with a Sony Bravia last year, I was also hoping MediaTomb worked with that (because it actually supports UPnP by itself alone), but that wasn’t the case.

At any rate, with MediaTomb failing to keep up with releases, cleanup code, and so on so forth, I gave up vastly on the UPnP idea; even using the XBMC instance on my AppleTV, the best seems to be using Samba instead. This until a couple of weeks ago when I started worrying about my bedroom’s media outlets. I have three UPnP-enabled devices (Bravia TV, PlayStation 3 and XBox 360), but I use an always-on AppleTV to play my stuff; that really wounds like a waste.

Even more so given that the AppleTV doesn’t really play Full HD content, not with XBMC at least; and my hopes for it to become useful, actually trusting in Apple’s declaration that they would have brought TV series to the iTunes Store in Europe vanished quite a long time ago. And to reinforce the fact that I made a totally shitty deal when I bought this AppleTV, rumors have that the new version of it will be a totally different product, cheaper and with no on-board storage… now I can guess the reason for that; as I said I stream my video from my main storage (Yamato itself), but I actually am glad that the AppleTV I have has 160GB storage so I can keep a copy of my photos, and of all the music I have, in lossless format (ALAC).

At any rate, I wanted to give UPnP/PlayStation 3 another chance; and the current way to do that is using Rygel, developed by the Gnome community and tied to GStreamer (even though I have a number of personal reserves against it). Now, thankfully, most of the needed code was already around in Portage, and Petteri had a partial ebuild for an older Rygel version, so I spent a night trying to work it out. It needs the GUPnP stack that is developed together with it obviously, and it relies on Vala for a big part of it including the GUI.

The “stable’ version is from quite a long time ago; and if you know software enough, you know that ”stable” means “unmaintained” when its release version ends with a “.0”. So I went for the development series, 0.7. And updating the dependencies, it turned out to need Gtk+ 2.21, with all the related trouble. Funnily, Arun notified me that the configure.ac script actually outright lies, it requires 2.21 just because it can, but it does not need it, and works fine with 2.20; I haven’t had much time to update the ebuilds so that they ignore the dependency, but I was able to test it for a little while with 2.21.

I’m sincerely not excessively impressed with it; of course it works definitely better than MediaTomb, and I guess that UPnP/DLNA are messed up enough that they have trouble to actually get them working properly, but… it seems like for the European version of the Bravia TV they always transcode to mpeg2/mp3 (which I’ll tell you, is crappy quality; the TV can do DVB-T HD out of the box, I guess it has support for decoding H.264/AAC), and even the PlayStation3 has trouble identifying some files, even when they should play correctly on local storage; and PS3 is declared to be their platform of choice.

The interface itself is quite difficult to work on, it has no way to monitor the scan status; it also only index files if the extension is one of those they recognize and…. funnily enough they recognize .mp4 files but not .m4v files, which are just the same thing; rename the latter to the former, and voiltà, it works… so you got a possible bug there. I haven’t reported it but on IRC, where I was suggested to check the config files that… are quite a bit messed up.

I’ll fix up in tree some ebuilds for Rygel at some point this weekend if I can get the time to, it’s still a pretty good replacement for MediaTomb, it’s just something I’d probably use rather than XBMC-over-Samba.

Of course this is still not solving my problem with video playback; especially since it does not work with softsub that are overly common with J-Drama…

Playing subtitles nicely with Boxee (and XBMC) on AppleTV

I have written yesterday that I had some issues with Boxee and subtitles . It turns out that my Matroska muxing was not needed and indeed it plays .srt subtitles just fine, but the default install of Boxee selects a font that is not installed by the AppleTV OS. At least not in the 2.3.1 software I’m running; probably this is quite the same problem I encountered with XBMC, which disappeared after tinkering with the settings.

There are two ways to solve the issue properly? Well, the AppleTV software provides the Times New Roman font, but I don’t really like serif fonts, in general. I tend not to use them at all, finding sans-serif much more readable. None of my systems have serif as default font. Since copying over the Microsoft fonts is not something I’m likely to do (I don’t like them that much that I’d go as far as breaking an EULA to have them), I just took the latest tarball of DejaVu fonts and copied over the DejaVuSans.ttf file in my AppleTV’s /Library/Fonts (scp’d over; luckily the OpenSSH installed by the new patchsticks support that; I remember the first patchsticks for software 1.1 used the copy from Tiger and only supported protocol version 1), and then changed the configuration file.

If you’re interested in what the change consists, the file you need is AppleTV.local:~/Library/Application' 'Support/BOXEE/UserData/guisettings.xml (remember to quote the space twice, since it needs to be quoted on both command-line and remote server), replacing BOXEE with XBMC if you’re using the latter. You can download the file on a different box and then the value to change, using XPath to represent the path (because it makes sense to humans too) is /settings/subtitles/font . Set it to the name of the .ttf file (without extension) you uploaded in /Library/Fonts and the trick is done.

Now, while Boxee has some proprietary stuff and I don’t really like that tremendously, it still is based upon XBMC which seems quite nice; also, it seems to be more oriented toward the six buttons interface of the Apple Remote that the AppleTV uses, which is a nice thing since I run it there. The subtitles’ fonts problem is probably the only one that is very bad; the skin I don’t like but I guess that’s not much of a problem by itself; the fact that it still does not start up and stop together with the AppleTV is nitpicking…

Altogether, I’m quite happy since it actually allows me to watch my stuff on the TV almost flawlessly!

The mad muxer

I have expressed my preference for the MP4 format some time ago, which was to be meant mostly over the Ogg format from Xiph, most of the custom audio container formats like FLAC and WavPack (to a point; WV’s format could be much worse), and of course the AVI format. Although I do find quite a few advantages of MP4 over Matroska, I don’t despise that format at all.

The main problem I see with Matroska, actually, is the not so widely available implementation; I cannot play a Matroska video on either my cellphone (which, if somewhere were to think about it, is a Nokia E71 right now, not an iPhone, and will probably never be, I have my limits!), the PlayStation3 or the PSP. Up to last month, I couldn’t play it with my AppleTV either, which was quite a bit of a problem. Especially considering a lot of Anime fansubbers use that.

Now, since I was actually quite bored by the fact that, even though I was transcoding them, a lot of subtitles didn’t appear properly, I decided to try out XBMC; it was quite a pleasing experience actually, the Linux-based patch stick works like a charm, without going too much in the way of infringing Apple’s license as far as I can see, and the installation is quite quick. Unfortunately the latest software update on AppleTV (2.3.1) seems to have broken xbmc, which now starts no longer in fullscreen but rather in a Quartz window in the upper half of the screen.

So I ditched also XBMC (for now) for a derivative, boxee which, while being partially proprietaryware, seems to be a little more fine-tuned for AppleTV; it’s still more free software than the original operating system. Both XBMC and Boxee solve my subtitles problem since they both have a video calibration setup that allows to tell the software how much overscan the LCD panel is doing, and which pixel size ratio it has. Quite cool, Apple should really have done that too.

Also, I started using MediaTomb to serve my content without having to copy it on the AppleTV itself; this is working fine since I’m using ethernet-over-powerline adapters to connect the office with my bedroom, and thus there is enough bandwidth to stream it over. Unfortunately, here starts the first problem: while I was able somehow to get XBMC to play AVI files with external .srt subtitles, it fails on Boxee. Since the whole thing is bothersome anyway, I wanted to try an alternative: remux the content without re-encoding it, in Matroska Video files, with the subtitles embedded in them as a third track.

This seems to work fine from an AVI file, but fails badly when the source is an MP4 file, the resulting file seems corrupted with MPlayer and crashes Totem/GStreamer (that’s no news, my dmesg output fills easily with Totem’s thumbnailer’s crashes when I open my video library). Also, I have been yet unable to properly set the language of the tracks, which would help me to have the jap-sub-eng setup automatic on XBMC. If somebody knows how to do that properly, I’d be glad.

Anyway, there it goes another remuxing of the video library…