RTMP client seems to work fine, RTMP support in FFserver is not that close, so I work on REing some codec which seems to be rather widespread in games.
OK, now to technical details. ‘Lossless’ coefficient coding is similar but a bit more complicated.
For each 8×8 block there is 7-bit number specifying number of masks to read (mask = part of the coefficient), slightly resembling progressive JPEG coding; coefficient value may be composed from several masks, high bits are decoded first. Decoding continues until all masks are read.
Coding method is not that comprehensible though: there is list of start coefficient and modes, so decoding iterates over this list and performs some action depending on mode. Have I mentioned that aforementioned list may change during operation?
And here’s decoding algorithm (if I got it right):
mask = 1 < < get_bits(3)
iterate over already decoded coefficients, if read bit = 1 then add mask to the coefficient
iterate over list of modes until end is reached, if (coef,mode)==(0,0) or read bit = 0 then skip current entry:
mode = 0:
set current entry to (cur_coef+4; mode = 1)
for(i=0;i<4;i++, cur_coef++){
if(get_bit()) prepend list with (cur_coef, mode = 3)
else coeffs[cur_coef] = get_bit() ? -mask : mask;
}
mode = 1:
set current entry to (cur_coef; mode = 2)
append (cur_coef+4; mode = 2), (cur_coef+8; mode = 2), (cur_coef+12; mode = 2) to the list
mode = 2:
set current entry to (0; mode = 0)
for(i=0;i<4;i++, cur_coef++){
if(get_bit()) prepend list with (cur_coef, mode = 3)
else coeffs[cur_coef] = get_bit() ? -mask : mask;
}
mode = 3:
coeffs[cur_coef] = get_bit() ? -mask : mask;