[Asterisk-Dev] Re: [Asterisk-cvs] asterisk/channels chan_iax2.c,
1.321, 1.322
SteveK
stevek at stevek.com
Wed Jul 20 18:58:04 MST 2005
On Jul 20, 2005, at 7:39 PM, kpfleming at lists.digium.com wrote:
> Update of /usr/cvsroot/asterisk/channels
> In directory mongoose.digium.com:/tmp/cvs-serv26427/channels
>
> Modified Files:
> chan_iax2.c
> Log Message:
> _really_ fix IAX2 crazy timestamp problem (bug #4747)
>
>
> Index: chan_iax2.c
> ===================================================================
> RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
> retrieving revision 1.321
> retrieving revision 1.322
> diff -u -d -r1.321 -r1.322
> --- chan_iax2.c 19 Jul 2005 23:17:02 -0000 1.321
> +++ chan_iax2.c 20 Jul 2005 22:46:58 -0000 1.322
> @@ -3380,6 +3380,7 @@
> int ms;
> int voice = 0;
> int genuine = 0;
> + int adjust;
> struct timeval *delivery = NULL;
>
>
> @@ -3421,8 +3422,15 @@
> if (p->notsilenttx && abs(ms - p->nextpred) <=
> MAX_TIMESTAMP_SKEW) {
> /* Adjust our txcore, keeping voice and
> non-voice synchronized */
> - p->offset = ast_tvadd(p->offset,
> - ast_samp2tv((ms - p->nextpred)/10,
> 1000)); /* XXX what scale is this ??? */
> + /* We need someone who understands this code to
> comment here on
> + why the 'adjust' value is handled as if it was
> in units
> + of 10,000 microseconds, instead of milliseconds
> + */
> + adjust = (ms - p->nextpred);
> + if (adjust < 0)
> + p->offset = ast_tvsub(p->offset, ast_samp2tv
> (abs(adjust), 10000));
> + else if (adjust > 0)
> + p->offset = ast_tvadd(p->offset, ast_samp2tv
> (adjust, 10000));
I think that this was discussed on the list a few weeks ago.. [off to
google... maybe it was mantis?... yup].
So, it was discussed in http://bugs.digium.com/view.php?id=4493.
I'll paste here for convenience:
From Rizzo:
Description:
this section of code in chan_iax2.c (near line 3458) caught my
attention:
/* Adjust our txcore, keeping voice and
non-voice synchronized */
---> add_ms(&p->offset, (int)(ms - p->nextpred)/10);
i don't understand the division by 10. Dimensionally, the second
argument should be milliseconds, and both p->nextpred and ms
are. The division by 10 changes them to 1/100 of second...
Possibly a false alarm, but just to understand...
======================================================================
----------------------------------------------------------------------
stevekstevek - 06-13-05 17:01
----------------------------------------------------------------------
OK.
So, what's happening here is this:
ms is the "current time" (in relation to the call).
nextpred is the "expected time of the next voice frame".
So, then this:
---> add_ms(&p->offset, (int)(ms - p->nextpred)/10);
adds 1/10 of the difference between the two to the offset.
The units for ms, nextpred, and the second argument to add_ms are still
milliseconds.
===================
What this does, is gradually skew our "offset". Offset is defined by
this
equation:
currenttime - offset = "milliseconds since beginning of call"
If you don't do this, then the problem you see is that sometimes the
system clock (i.e. gettimeofday()), and the source of your audio signal
(e.g. an audio card, the telephone system, a remote phone of some kind),
have a skew relative to each other.
By adjusting "offset" in this way, we effectively clock our outgoing
timestamps to the audio signal, when audio is present.
We only adjust by 1/10 to act as a low-pass filter -- we don't want a
temporary spike to have a huge effect, but want to track continuous
differences.
=======
Hopefully that explains it a bit better?
If you want to put that whole thing in as a comment, consider the
comment to be in the public domain, or disclaimed :)
-SteveK
>
> if (!p->nextpred) {
> p->nextpred = ms; /*f->samples / 8;*/
>
> _______________________________________________
> Asterisk-Cvs mailing list
> Asterisk-Cvs at lists.digium.com
> http://lists.digium.com/mailman/listinfo/asterisk-cvs
>
>
More information about the asterisk-dev
mailing list