demux_mkv.c: Make some time arithmetic more precise
commitbb6c06d17f661ff99edb0eb1dc9c0a12770f887f
authorUoti Urpala <uau@glyph.nonexistent.invalid>
Fri, 10 Jul 2009 16:53:26 +0000 (10 19:53 +0300)
committerUoti Urpala <uau@glyph.nonexistent.invalid>
Fri, 10 Jul 2009 19:58:56 +0000 (10 22:58 +0300)
tree087a3ed68a314c2dd4f2f8613fa2e8d13fa8557c
parent3f75062ca65cea46fa9e06ab5f5271ad310440fd
demux_mkv.c: Make some time arithmetic more precise

Some calculations in the demuxer that are in principle integer
arithmetic use float divisions instead of 64-bit integer ones (as in
(int64_t)(x / 1000000.0) ).  When compiled with -ffast-math gcc replaces
the division with multiplication by inverse. The calculation of the
inverse can introduce rounding error even for divisions that would
have been exact, and any rounding error down from an exact integer
result in the division makes the result after cast one smaller. This
caused some inaccuracy in seeking due to timecodes in the index not
quite matching those calculated for actual packets. Add 0.5 to such
expressions before casting to round instead of truncating, which
should be enough to avoid the problem. Also replace some
non-performance-critical use of float types by doubles.
libmpdemux/demux_mkv.c