comparison DOCS/tech/mpcf.txt @ 17532:724816ab19be

add compare_ts
author ods15
date Sat, 04 Feb 2006 08:53:43 +0000
parents c6ad2343ec16
children 86a9a60ef596
comparison
equal deleted inserted replaced
17531:c6ad2343ec16 17532:724816ab19be
410 d1 = from_time_base_denom 410 d1 = from_time_base_denom
411 d2 = to_time_base_nom 411 d2 = to_time_base_nom
412 timestamp = (ln/d1*sn + ln%d1*sn/d1)/d2 412 timestamp = (ln/d1*sn + ln%d1*sn/d1)/d2
413 Note: this calculation MUST be done with unsigned 64 bit integers, and 413 Note: this calculation MUST be done with unsigned 64 bit integers, and
414 is equivalent to (ln*sn)/(d1*d2) but this would require a 96bit integer 414 is equivalent to (ln*sn)/(d1*d2) but this would require a 96bit integer
415
416 compare_ts
417 Compares timestamps from 2 different timebases,
418 if a is before b then compare_ts(a, b) = -1
419 if a is after b then compare_ts(a, b) = 1
420 else compare_ts(a, b) = 0
421
422 Care must be taken that this is done exactly with no rounding errors,
423 simply casting to float or double and doing the obvious
424 a*timebase > b*timebase is not compliant or correct, neither is the
425 same with integers, and
426 a*a_timebase.num*b_timebase.den > b*b_timebase.num*a_timebase.den
427 will overflow. One possible implementation which shouldn't overflow
428 within the range of legal timestamps and timebases is:
429
430 if (convert_ts(a, a_timebase, b_timebase) < b) return -1;
431 if (convert_ts(b, b_timebase, a_timebase) < a) return 1;
432 return 0;
415 433
416 msb_pts_shift 434 msb_pts_shift
417 amount of bits in lsb_pts 435 amount of bits in lsb_pts
418 MUST be <16 436 MUST be <16
419 437