All pastes #885479 Raw Edit

Someone

public text v1 · immutable
#885479 ·published 2008-01-30 22:44 UTC
rendered paste body
        if (ts)
        {
                if ( f && session )
                        session->lastsent = ts;
                return ts;
        }

        /* Otherwise calculate the timestamp from the current time */
        tv = iax_tvnow();

        /* Calculate the number of milliseconds since we sent the first packet */
        ms = (tv.tv_sec - session->offset.tv_sec) * 1000 +
                 (tv.tv_usec - session->offset.tv_usec) / 1000;

        if (ms < 0)
                ms = 0;

        if(voice) {
#ifdef USE_VOICE_TS_PREDICTION
                /* If we haven't most recently sent silence, and we're
                 * close in time, use predicted time */
                if(session->notsilenttx && abs(ms - session->nextpred) <= 240) {
                        /* Adjust our txcore, keeping voice and non-voice
                         * synchronized */
                        add_ms(&session->offset, (int)(ms - session->nextpred)/10);

                        if(!session->nextpred)
                                session->nextpred = ms;
                        ms = session->nextpred;
                } else {
                        /* in this case, just use the actual time, since
                         * we're either way off (shouldn't happen), or we're
                         * ending a silent period -- and seed the next predicted
                         * time.  Also, round ms to the next multiple of
                         * frame size (so our silent periods are multiples
                         * of frame size too) */
                        int diff = ms % (f->samples / 8);
                        if(diff)
                                ms += f->samples/8 - diff;
                        session->nextpred = ms;
                }
                session->notsilenttx = 1;
#else
                if(ms <= session->lastsent)
                        ms = session->lastsent + 3;
#endif
        } else if (video) {
                if ((unsigned int)ms <= session->lastsent)
                        ms = session->lastsent + 3;
        } else {
                /* On a dataframe, use last value + 3 (to accomodate jitter buffer shrinking)
                   if appropriate unless it's a genuine frame */
                if (genuine) {
                        if ((unsigned int)ms <= session->lastsent)
                                ms = session->lastsent + 3;
                } else if (abs(ms - session->lastsent) <= 240) {
                        ms = session->lastsent + 3;
                }

        }

        /* Record the last sent packet for future reference */
        /* unless an AST_FRAME_IAX */