[x264-devel] patch for: alignment problem on sparc (maybe others 32bit archs, too)

Chris Fensch c at fens.ch
Fri Mar 6 12:28:28 CET 2009


Hi,

> This is not an appropriate fix.  The bitstream pointer itself should
> always be aligned, and if it is not, the bitstream writer should be
> modified to ensure that it is.

Well, I do agree to some extend. The fix does not affect architectures 
that can cope with unaligned memory access (such as x86), but allows to 
x264 to run on machines which are not that flexible. As such it fixes the 
symtoms but not the cause: The problem is caused by the current 
implementation of:

/* Write the rest of cur_bits to the bitstream; results in a bitstream no 
longer 32/64-bit aligned. */
static inline void bs_flush( bs_t *s )

I, unfortunately, do not know enough about the underlying semantics of the 
bitstream writer and feel not confident of submitting a patch that changes 
the semantics. I see one possible solution (but that changes the 
semantics):

Instead of writing cur_bits to the bitstream, just change i_left in such a 
way that it is byte aligned and shift the bits in cur_bits by the same 
amount. The resulting bitstream should be the same, if cur_bits is written 
to the bitstream at later point. Of course, if no further bits are written 
to the bitstream, then that write might never happen...

Maybe the person who wrote the current implementation of bs_flush can fix 
this method in a way that the semantics is preserved.

Cheers
   Chris


More information about the x264-devel mailing list