On 04.04.20 at 15:33 Michael Maier wrote: > Hello! > > I'm facing a massive problem during sending or receiving of fax (spandsp, > pjsip, > asterisk 16.9 bundled pjsip). Affected are always the packages sent by > asterisk. > The packages received are pretty perfect. > > Tracetool is pcapsipdump. > > Problem can't be seen that massive during "normal" (non) fax calls (maybe > just a > little bit). > > > What can be seen? > > Inbound fax: > - Fax passthrough (alaw) > - Fax received by asterisk > - no Jitterbuffer > - after about 1 minute of duration (> 6100 packages): > skew rises from +-0 to -30 (from one package to the > other) and all following packages afterwards have -19.9 > ms (one package seems to be just dropped without any > sequence error (sequence counter is ok)) > - Another 4000 packages later one more dropped package > (without sequence error) from -19.9 to -52 and > afterwards all following packages -39.9 ms (sampling > rate: 20 ms) -> exactly the same as before but from -19 > to - 40 ms. > - Duration: ~ 2 minutes > - always reproducible
After I could resolve the problem for outgoing faxes (see below), I'm wondering how skewing is done when asterisk / spandsp does the fax handling. Asterisk itself uses res_timing_timerfd.so. But if I understand [1] correctly, asterisk doesn't do any timing for fax handling (and therefore no skew related jobs at all). This would mean, spandsp has to do it. But spandsp doesn't seem to use timerfd. At the moment I'm struggling at this point. How can I improve skewing for asterisk / spandsp? Where is it done in general? > > Outbound fax > - Fax passthrough (alaw) > - sent via iaxmodem through asterisk (iaxmodem connected > to asterisk via iax). No jitterbuffer! > - skew is rising continuously (+362 ms after 363 s > duration -> every second +1 ms) > - always reproducible I could find the problem for outbound faxes via iaxmodem. Version 1.2.0 introduced improved skew behavior, which unfortunately breaks things here. After reverting this new feature, sending outgoing faxes via iaxmodem works as expected again. Attached you can find the patch to remove the improved skewing feature again based on iaxmodem 1.3.1 Thanks Michael [1] https://wiki.asterisk.org/wiki/display/AST/Timing+Interfaces
--- 1/iaxmodem.c 2016-02-07 02:24:28.000000000 +0100 +++ 2/iaxmodem.c 2020-04-10 10:38:55.484000000 +0200 @@ -140,8 +140,6 @@ static int dspdebug = 0; static int nodaemon = 0; static int commalen = 2; -static int defskew = 0; -static int skew; struct modem { struct modem *next; @@ -420,12 +418,6 @@ nodaemon = 1; printlog(LOG_INFO, "This modem is exempt from daemon use.\n"); } - if (strncasecmp(line, "skew", 4) == 0) { - line += 4; - while (*line == '\t' || *line == ' ') line++; - defskew = atoi(line); - printlog(LOG_INFO, "Setting skew = %d\n", defskew); - } } void @@ -544,7 +536,7 @@ if (!info) t31_call_event(s, AT_CALL_EVENT_ANSWERED); modemstate = MODEM_CONNECTED; gettimeofday(&nextaudio, NULL); - nextaudio.tv_usec += (VOIP_PACKET_LENGTH + skew); + nextaudio.tv_usec += VOIP_PACKET_LENGTH; if (nextaudio.tv_usec >= 1000000) { nextaudio.tv_sec += 1; nextaudio.tv_usec -= 1000000; @@ -932,8 +924,7 @@ t31_state.audio.modems.fast_modems.v27ter_rx.logging.level = loglevel; } - int selectfd, selectretval, selectblock, avail, audiobalance = 0; - skew = defskew; + int selectfd, selectretval, selectblock, avail, audiobalance = 0, skew = 0; struct timeval tv; fd_set select_rfds; for (;;) { @@ -970,7 +961,7 @@ } if (modemstate == MODEM_CONNECTED) { tv.tv_sec = 0; - tv.tv_usec = timediff(nextaudio, now) - window; + tv.tv_usec = timediff(nextaudio, now) - (window + skew); } else if (modemstate == MODEM_RINGING) { tv.tv_sec = 5; tv.tv_usec = 0; /* ring every 5 seconds */ timeradd(&lastring, &tv, &tv); @@ -1067,8 +1058,8 @@ /* * Is it time to send more audio? (This comes first for a reason, as it's our priority.) */ - if (modemstate == MODEM_CONNECTED && timediff(nextaudio, now) <= window) { - nextaudio.tv_usec += (VOIP_PACKET_LENGTH + skew); + if (modemstate == MODEM_CONNECTED && timediff(nextaudio, now) <= (window + skew)) { + nextaudio.tv_usec += VOIP_PACKET_LENGTH; if (nextaudio.tv_usec >= 1000000) { nextaudio.tv_sec += 1; nextaudio.tv_usec -= 1000000; @@ -1093,14 +1084,11 @@ if (audiobalance > 5) { /* * We seem to be getting ahead in our audio transmissions, relative - * to the audio receptions. So we lengthen the time between transmissions - * (by increasing our perception of VOIP_PACKET_LENGTH), hoping to improve the ratio. - * - * We are deliberately less-sensitive to getting ahead than we are to getting behind - * because having a little bit of buffer in-front of us is better than not. + * to the audio receptions. So we lengthen the time (shorten the window) + * between our transmissions, hoping to improve the ratio. */ audiobalance = 0; /* don't try to make up */ - skew += 10; + skew -= 50; printlog(LOG_INFO, "Adjusting skew to %d.\n", skew); } if (codec == AST_FORMAT_SLINEAR) { @@ -1229,7 +1217,7 @@ printlog(LOG_INFO, "Remote answered.\n"); t31_call_event(&t31_state, AT_CALL_EVENT_CONNECTED); gettimeofday(&nextaudio, NULL); - nextaudio.tv_usec += (VOIP_PACKET_LENGTH + skew); + nextaudio.tv_usec += VOIP_PACKET_LENGTH; if (nextaudio.tv_usec >= 1000000) { nextaudio.tv_sec += 1; nextaudio.tv_usec -= 1000000; @@ -1237,7 +1225,7 @@ modemstate = MODEM_CONNECTED; audiobalance = 0; audiobufpos = audiobuf; - skew = defskew; + skew = 0; if (record) { if (dspaudiofd > 0) { close(dspaudiofd); @@ -1286,7 +1274,7 @@ } audiobufpos = audiobuf; audiobalance = 0; - skew = defskew; + skew = 0; last_ts = 0; phonestate = PHONE_CONNECTED; modemstate = MODEM_RINGING; @@ -1401,17 +1389,14 @@ if (modemstate == MODEM_CONNECTED) { audiobalance--; - if (audiobalance < -1) { + if (audiobalance < -5) { /* * We seem to be getting behind in our audio transmissions, relative - * to the audio receptions. So we decrease our perception of VOIP_PACKET_LENGTH, - * hoping to improve the ratio. - * - * We are deliberately very sensitive to getting behind because in many cases - * this will result in missing audio (possibly an unintended carrier drop). + * to the audio receptions. So we increase the window for our + * transmissions, hoping to improve the ratio. */ audiobalance = 0; /* don't try to make up */ - skew -= 10; + skew += 50; printlog(LOG_INFO, "Adjusting skew to %d.\n", skew); } } @@ -1489,7 +1474,7 @@ case IAX_EVENT_TRANSFER: last_ts = 0; audiobalance = 0; - skew = defskew; + skew = 0; printlog(LOG_INFO, "Call transfer occurred.\n"); session[0] = iaxevent->session; break;
-- _____________________________________________________________________ -- Bandwidth and Colocation Provided by http://www.api-digital.com -- asterisk-dev mailing list To UNSUBSCRIBE or update options visit: http://lists.digium.com/mailman/listinfo/asterisk-dev