A Bit More about UnclearVideo

So, in the course of cleaning-up program I’ve looked at ClearVideo again.

Intraframes decoding has been REd long time ago—it’s merely DCT-coded blocks. They happen quite often and it’s possible to watch it somehow.

Interframes coding is what makes this codec unique. And if you expected real fractal coding then you’re wrong (and that’s expected—processing power needed to restore even 320×240 frame from seed by applying iterations might be too much even for today). Instead you have quadtree with square blocks. Do you know what information it stores there? Subtree flags (i.e. if you need to divide it further), motion vector and brightness control. So the block is copied and its brightness might be adjusted too, that’s all. There’s no residue coding. And tree information can be coded in four different ways (I’ve seen four out of about six different tree decoding functions being employed), properties are coded with variable-length codes that I fear may be autogenerated.

So what prevents me from finishing it? A very horrible design. It’s written in Very Objective C++ dialect. Every piece of code is wrapped into its own class with possible overloading, so instead of calling a function you retrieve class pointer from some subclass of current context and invoke function from vtable there. Which will not be the real function but rather a thunk that will jump to the real function (even better, some functions calling themselves do it through that thunk too). And yet they use global variables! This is impossible to analyse with static analysis (like I mostly do), it’s nightmare for debugger as well (but a hack to MPlayer loader that displayed calls and indirect jumps was very useful here) and I suspect it won’t get much better even if I get original source code (which I’ll never get of course).

A small example of design: tree decoding uses several GetBitContexts stored in more generic TreeDecodingContext, which is a subclass to FrameType2 context, which is a subclass of DecoderContext. And I’m pretty sure I forgot some levels of indirections in-between.

Time to give up? Time to give up.

4 Responses to “A Bit More about UnclearVideo”

  1. compn says:

    “(but a hack to MPlayer loader that displayed calls and indirect jumps was very useful here)”

    can you share this hack?

  2. Kostya says:

    It’s all described in
    http://multimedia.cx/eggs/category/reverse-engineering/callret-monitor/

    Basically it’s just setting debug flag plus trap handler and then do something (if you like) on every instruction.

  3. compn says:

    i always thought the fractal stuff was just marketing.

  4. Kostya says:

    Yes and no. call it semi-fractal if you like.

    It employs the essential step of fractal compression (copy block from elsewhere and translate it) but not in full (i.e. no scaling or restoring by iterating till it converges). Yet no other codec does it like this one (and maybe for a good reason).