Sunday, May 15, 2011

Multichannel decoder madness

I think I'm doing like 12 hour days on this project and multichannel already came into my dreams today, but can have a rest after a while. Today I worked on finding out about AC-3 and DTS decoders that are common formats for multichannel audio. Adding AC-3 was pretty straightforward using the avcodec plugin, but it did have a small problem in that it required full frames while avcodec plugin occasionally provided partial frames. This was not a big deal and avcodec plugin needed cleaning up anyway.

Adding DTS should be quite easy using the avcodec plugin as well, but another problem came up in addition to the partial frame issue. The ffmpeg DTS decoder was buggy and didn't return the consumed input bytes correctly, instead it always returned the input buffer length. The correct frame size value is always in a fixed offset in the DTS headers so parsing it in the avcodec plugin wasn't that big of a deal, although it is hacky.

I also noticed there was a new bug 2437 in mantis saying that the avcodec plugin doesn't compile with the latest libavcodec version. I found out that the libavcodec version 53 has changed the API again and CODEC_TYPE_AUDIO is now AVMEDIA_TYPE_AUDIO. Slightly bigger change was that function avcodec_decode_audio2 was changed to avcodec_decode_audio3 with different parameters. This is already the second time avcodec_decode_audio has been replaced during the lifetime of avcodec plugin, that's pretty good for a function that only takes 5 parameters. Make up your mind already ffmpeg guys... But I wrote the backwards compatibility macros and now avcodec plugin should compile cleanly with all libavcodec versions again, yay!

Problem when playing the files was that channel mapping in pulseaudio was wrong, I patched it to use mostly the channel mapping introduced in last blog post, including some sensible defaults for each channel number. I will write more about those defaults later, but they follow quite closely the channel assignment of FLAC.

So long story short, XMMS2 avcodec plugin now compiles with all libavcodec versions and supports AC-3 and DTS and pulse output plugin handles multichannel audio nicely. Hopefully available in upstream soonish.

No comments:

Post a Comment