diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c index c9da32ea92463851c44a3dada5221b1c88789b1c..cf92a1cf18b98d77c52a2639dcbcc547c72a3359 100755 --- a/channels/chan_iax2.c +++ b/channels/chan_iax2.c @@ -1581,27 +1581,30 @@ static int schedule_delivery(struct iax_frame *fr, int reallydeliver, int update IAX thread, with iaxsl lock held. */ ms = calc_rxstamp(iaxs[fr->callno]) - fr->ts; - fr->af.delivery.tv_sec = iaxs[fr->callno]->rxcore.tv_sec; - fr->af.delivery.tv_usec = iaxs[fr->callno]->rxcore.tv_usec; - fr->af.delivery.tv_sec += fr->ts / 1000; - fr->af.delivery.tv_usec += fr->ts % 1000; - if (fr->af.delivery.tv_usec >= 1000000) { - fr->af.delivery.tv_usec -= 1000000; - fr->af.delivery.tv_sec += 1; - } - if (ms > 32767) { /* What likely happened here is that our counter has circled but we haven't gotten the update from the main packet. We'll just pretend that we did, and update the timestamp appropriately. */ ms -= 65536; + fr->ts += 65536; } if (ms < -32768) { /* We got this packet out of order. Lets add 65536 to it to bring it into our new time frame */ ms += 65536; + fr->ts -= 65536; } + + fr->af.delivery.tv_sec = iaxs[fr->callno]->rxcore.tv_sec; + fr->af.delivery.tv_usec = iaxs[fr->callno]->rxcore.tv_usec; + fr->af.delivery.tv_sec += fr->ts / 1000; + fr->af.delivery.tv_usec += (fr->ts % 1000) * 1000; + if (fr->af.delivery.tv_usec >= 1000000) { + fr->af.delivery.tv_usec -= 1000000; + fr->af.delivery.tv_sec += 1; + } + /* Rotate our history queue of "lateness". Don't worry about those initial zeros because the first entry will always be zero */