Patch from Søren Bøg <avacore@videolan.org> GSoC 2007