Diary Of An x264 Developer

05/16/2008 (10:02 pm)

Oops

Filed under: bugs,CABAC,chroma,stupidity,x264 ::

Apparently my nnz patch managed to break lossless mode and it took us nearly 2 weeks to realize it! Fortunately, I managed to fix it with this patch only 30 minutes after it was reported and it was soon after put into the official git repository. To begin with, to understand this, one has to understand what my nnz patch did.

CAVLC entropy encoding needs to know the number of nonzero coefficients in a DCT block to choose its variable-length codes properly (among other things, it adapts which VLC table to use based on the characteristics of the DCT block). This is a slightly intensive process; its an extra step to take on every single DCT block to count the number of nonzero values. Its not too slow, but in CABAC its completely unnecessary, so the purpose of the patch was to move all nnz calculations to CAVLC and in the macroblock encoding only calculate a single thing: whether the array had coefficients or not, which is very fast and trivial to calculate.

But in DCT arrays of AC coefficients only, such as in i16x16 and 8×8 chroma blocks (see this post for more info), we need to ignore the first coefficient, the DC coefficient, when doing this math. So the simplest way to do this is to just zero the DC coefficient at the same time we write the coefficients to memory so it doesn’t cause issues later.

But I forgot about lossless mode and forgot to set the DC coefficient to zero in that case. The end result? Well, it broke!

4 Responses to “Oops”

  1. Robert Swain Says:

    Sounds like you guys need some regressions tests.

  2. Multimedia Mike Says:

    If only there were some automated system for testing multimedia code on multiple platforms…

  3. delacroixP Says:

    Superprogrammers also get it wrong sometimes.

    It’s all good !

    :) :devil::D
    Pascal

  4. StemdypeSef Says:

    Thanks authors for the specified materials, a lot of the compelling advice. All good.

Leave a Reply