[asterisk-dev] [Code Review] rtp timestamp to timeval calculation fix

Dan Evans devans at invores.com
Thu Jan 21 11:19:16 CST 2010


> The usec value is incorrect for both the 16000kHz and 32000kHz calculation.  This results in 16000kHz delivery looking like it contains twice as much audio than it does, and 32000kHz containing 4 times as much.  In fact, the usec values for 16000kHz and 32000kHz are even above the max usec value allowed.  We attempt to account for this error by using the sanitize_tv function.
> 
> -----New method of timestamp to timeval calculation
> 
>     -- Method 1: modifying current method.
>         sec = timestamp / rate
>         usec = (((timestamp % rate) / (rate / 8000))) * 125
> 
>     -- Method 2: use time.h api.
>         timeval = ast_samp2tv(timestamp, rate);
> 
> 
> Method 2 is the one this patch currently implements.  Unless the rtp timestamp does not always reflect the number of samples incremented, I don't see any reason not to use this method.  Both methods have been tested.

It seems like assuming the rate is a multiple of 8000 doesn't add any value.  Why not:

  ds = div(timestamp, rate);  /* div() (or ldiv()) from C stdlib */
  sec = ds.quot;
  usec = ds.rem * (1000000 / rate); /* can be changed to avoid truncating nanos if necessary */

Dan



More information about the asterisk-dev mailing list