Tuesday, May 20, 2008

Ogg Support on Canola2

With Canola2 beta9 finally out, people have asked about the ogg support for Canola. Well, let me first try to clarify things a bit: ogg support actually has not much to do with Canola itself, but more with lightmediascanner.

In our architecture, the component responsible for scanning the media, amongst other things, is canola deamon (canolad for short). Canola daemon is Free software, released under the GPL license since its very first version. You can get the source with a simple apt-get source command.

When the user marks a folder as "scannable" on the "Media Folder" section in canola settings, it will call canola daemon to add that folder to the list of folders it will have to scan. Canolad then invokes ligthmediascanner (lms for short) which will scan for media on those folders.

LMS makes use of a very clever plugin architecture implementation, where each plugin is responsible for gathering metadata from that specific type of file it was developed for. So far there are implementations for asf, flac, id3, jpeg, m3u, mp4, ogg, pls, png and rm files. Dummy implementations for audio and video files will index files of given file extensions.

The ogg plugin was making use of libvorbis, which provides the reference implementation for the standard, but it was not being installed by Tuomas' packages. At this moment I sent him an email asking if it would be possible to have the package installed on the device. He then said it was perfectly feasible, but not advisable, as the implementation makes heavily use of floating point operations. Everybody knows how floating point operations perform on our target platform. And it doesn't really fit our purposes.

Tuomas suggested that LMS ogg plugin should make use of libvorbisidec, also known as Tremor, which was specially implemented taking into account those performance problems of floating point operations on embedded devices. It provides a fixed-point implementation for the Vorbis decoder.

At first glance, I thought it would be a really trivial task. With a few modifications in the configure.ac file, the ogg plugin would link against libvorbisidec and everything should just work! And of course I was so very wrong... I first spotted some severe bugs in the lms ogg plugin which were causing segfaults. Having those fixed was the easiest part.

The most difficult thing was to find out after some time digging that libvorbis and libvorbisidec implementations are not compatible at all. Only after that I could be able to end up with the final solution for the problem. You can now build lightmediascanner with ogg support using either the regular vorbis or tremor implementations.

With LMS now being able to scan and index ogg files, I came back to Tuomas and provided the patch that creates ogg-support-lightmediascanner meta package, which will install both ogg-support and lms ogg plugin as dependencies.

No change in the canola side was needed, since the whole work of decoding and playing ogg files was already being done by ogg-support packages provided by Tuomas. Big kudos to Tuomas and his hard work and as well to Gustavo for reviewing and pushing my patches for LMS to mainstream.

ogg-support-lightmediascanner.installInstall it now and enjoy!