[FFmpeg-devel] [PATCH][RFC] Indeo3 replacement
Maxim
max_pole
Mon Jul 27 15:25:08 CEST 2009
Michael Niedermayer schrieb:
> On Sun, Jul 26, 2009 at 11:16:22PM +0200, Maxim wrote:
>
>> Michael Niedermayer schrieb:
>>
>>> [...]
>>>
>>>> /* FIXME: I know we already have a bitreader in ffmpeg */
>>>> /* it should be adapted to read ahead only one byte */
>>>> /* otherwise it won't work for indeo3 !!! */
>>>>
>>>>
>>> elaborate please
>>>
>>>
>> Ok, frame data mixes binary tree which is a bitstream with cell data
>> which is a bytestream.
>> Below an example of a typical parsing sequence.
>> Consider the following frame data:
>>
>> Addr
>> 0000 0x11,
>> 0001 0x6C,
>> 0002 0x0,
>> 0003 0x1,
>> 0004 0xFD,
>> 0005 0xFB,
>> 0006 0x3,
>> 0007 0x11
>>
>> We parse them as follows:
>>
>> data_ptr points to the next data code
>> read_bintree_code() reads 2bit codes starting with MSB
>>
>> bs_cache = *data_ptr++; // feed the bitstream reader with the first byte
>> = 0x11 = %00010001
>> code = read_bintree_code(); // we'll get %00 = H_SPLIT, bs_cache = %010001
>> ...process this code...
>> code = read_bintree_code(); // we'll get %01 = V_SPLIT, bs_cache = %0001
>> ...process this code...
>> code = read_bintree_code(); // we'll get %00 = H_SPLIT, bs_cache = %01
>> ...process this code...
>> code = read_bintree_code(); // we'll get %01 = V_SPLIT, bs_cache = empty
>> bs_cache = *data_ptr++; // feed the bitstream reader with the 2nd byte =
>> 0x6C = %01101100
>> ...process "code"...
>> code = read_bintree_code(); // we'll get %01 = V_SPLIT, bs_cache = %101100
>> ...process this code...
>> code = read_bintree_code(); // we'll get %10 = INTRA, bs_cache = %1100
>> ...process this code...
>> code = read_bintree_code(); // we'll get %11 = VQ_DATA, bs_cache = %00
>>
>> at this place we call decode_cell() routine that takes the data_ptr
>> pointed to the cell data starting with the address 0002. The data at
>> this position is treated as bytestream now. After cell decoding we set
>> the data_ptr to the next byte.
>>
>> data_ptr = decode_cell(data_ptr);
>>
>> // data_ptr points to addr 0007 now
>>
>> code = read_bintree_code(); // we'll get %00 = H_SPLIT, bs_cache = empty
>> bs_cache = *data_ptr++; // feed the bitstream reader with the 7th byte =
>> 0x11 = %00010001
>>
>> ... continue processing...
>>
>> So, the code needs to manipulate the internal structs of the FFmpeg's
>> bitreader in order to achieve the same behaviour what's not really safe
>> IMHO. Maybe there is a possibility to do it smart. I don't know...
>>
>
> i dont see why you would have to mess with internal structs to switch betweem
> byte & bit reading
>
>
Not the switch itself is a problem but the bits in the cache of the
reader. I assume the bit reader reads 32bits in advance. Looking at the
example above the reader will place the first four bytes into the cache.
Then s->buffer_ptr will point to the 4th byte of the stream but only
first two bytes belong to the bitstream. So I need to change the
bitreader's internal variables in order to rewind the s->buffer_ptr to
the 2nd byte ( i.e. simulate the "align_get_bits()" behaviour) and flash
16 bits from the cache because these belong to the bytestream.
How can it be done?
Regards
Maxim
More information about the ffmpeg-devel
mailing list