Fix timestamp delivery calculation in IAX... Still might be some mess left...
authorMark Spencer <markster@digium.com>
Tue, 16 Mar 2004 22:55:05 +0000 (22:55 +0000)
committerMark Spencer <markster@digium.com>
Tue, 16 Mar 2004 22:55:05 +0000 (22:55 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@2449 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_iax2.c

index c9da32e..cf92a1c 100755 (executable)
@@ -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 */