]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fixes for DTC handling in the T.38 gateway
authorSteve Underwood <steveu@coppice.org>
Mon, 28 Jul 2014 15:35:06 +0000 (23:35 +0800)
committerSteve Underwood <steveu@coppice.org>
Mon, 28 Jul 2014 15:35:06 +0000 (23:35 +0800)
libs/spandsp/spandsp/tsb85.xml
libs/spandsp/src/dtmf.c
libs/spandsp/src/hdlc.c
libs/spandsp/src/t30.c
libs/spandsp/src/t38_gateway.c

index 8fa4502444380ccaf15f4f34eb9e9f7bf72621ee..a7111009168caa5da3e79fdf0b036f1ef565653b 100644 (file)
         <step dir="T" type="HDLC" modem="V.21" tag="PPR" value="FF C8 3D 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="HDLC" modem="V.21" tag="CTC" value="FF C8 C8 00 10"/>
+        <step dir="R" type="HDLC" modem="V.21" tag="CTC" value="FF C8 C8 00 00"/>
         <step dir="R" type="SILENCE"/>
 
         <step type="WAIT" value="75"/>
         <step dir="T" type="HDLC" modem="V.21" tag="CTR" value="FF C8 23"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="PP" modem="V.27ter/4800" frame_size="64" timeout="60000"/>
+        <step dir="R" type="PP" modem="V.27ter/2400" frame_size="64" timeout="60000"/>
         <step dir="R" type="HDLC" modem="V.21" tag="PPS-EOP+" value="FF C8 FD F4 ..."/>
         <step dir="R" type="SILENCE"/>
 
         <step dir="T" type="HDLC" modem="V.21" tag="PPR" value="FF C8 3D 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="PP" modem="V.27ter/4800" frame_size="64" timeout="60000"/>
+        <step dir="R" type="PP" modem="V.27ter/2400" frame_size="64" timeout="60000"/>
         <step dir="R" type="HDLC" modem="V.21" tag="PPS-EOP+" value="FF C8 FD F4 ..."/>
         <step dir="R" type="SILENCE"/>
 
         <step dir="T" type="HDLC" modem="V.21" tag="PPR" value="FF C8 3D 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="PP" modem="V.27ter/4800" frame_size="64" timeout="60000"/>
+        <step dir="R" type="PP" modem="V.27ter/2400" frame_size="64" timeout="60000"/>
         <step dir="R" type="HDLC" modem="V.21" tag="PPS-EOP+" value="FF C8 FD F4 ..."/>
         <step dir="R" type="SILENCE"/>
 
         <step dir="T" type="HDLC" modem="V.21" tag="PPR" value="FF C8 3D 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="PP" modem="V.27ter/4800" frame_size="64" timeout="60000"/>
+        <step dir="R" type="PP" modem="V.27ter/2400" frame_size="64" timeout="60000"/>
         <step dir="R" type="HDLC" modem="V.21" tag="PPS-EOP+" value="FF C8 FD F4 ..."/>
         <step dir="R" type="SILENCE"/>
 
         <step dir="T" type="HDLC" modem="V.21" tag="PPR" value="FF C8 3D 00 00 00 00 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="HDLC" modem="V.21" tag="CTC+" value="FF C8 C8 00 10"/>
+        <step dir="R" type="HDLC" modem="V.21" tag="CTC+" value="FF C8 C8 00 00"/>
         <step dir="R" type="SILENCE"/>
 
         <step type="WAIT" value="75"/>
         <step dir="T" type="HDLC" tag="CTR" value="FF C8 23"/>
         <step dir="T" type="POSTAMBLE"/>
 
-        <step dir="R" type="PP" modem="V.27ter/4800" frame_size="64" timeout="60000"/>
+        <step dir="R" type="PP" modem="V.27ter/2400" frame_size="64" timeout="60000"/>
         <step dir="R" type="HDLC" modem="V.21" tag="PPS-EOP+" value="FF C8 FD F4 ..."/>
 
         <step type="WAIT" value="75"/>
index fe235f45a1e6401dd190c2c6c9e29ffb652cf553..48a883633701b4b2f8a12b7123bd7f4b1a674852 100644 (file)
@@ -68,8 +68,6 @@
 #define DEFAULT_DTMF_TX_ON_TIME     50
 #define DEFAULT_DTMF_TX_OFF_TIME    55
 
-#define DTMF_SAMPLES_PER_BLOCK      102
-
 #if defined(SPANDSP_USE_FIXED_POINT)
 /* The fixed point version scales the 16 bit signal down by 7 bits, so the Goertzels will fit in a 32 bit word */
 #define FP_SCALE(x)                 ((int16_t) (x/128.0 + ((x >= 0.0)  ?  0.5  :  -0.5)))
@@ -80,6 +78,7 @@
 #define DTMF_RELATIVE_PEAK_COL      6.309f          /* 8dB [10.0^(8.0/10.0)] */
 #define DTMF_TO_TOTAL_ENERGY        83.868f         /* -0.85dB [DTMF_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */
 #define DTMF_POWER_OFFSET           68.251f         /* 10*log(((32768.0/128.0)^2)*DTMF_SAMPLES_PER_BLOCK) */
+#define DTMF_SAMPLES_PER_BLOCK      102
 #else
 #define FP_SCALE(x)                 (x)
 #define DTMF_THRESHOLD              171032462.0f    /* -42dBm0 [((DTMF_SAMPLES_PER_BLOCK*32768.0/1.4142)*10^((-42 - DBM0_MAX_SINE_POWER)/20.0))^2] */
@@ -89,6 +88,7 @@
 #define DTMF_RELATIVE_PEAK_COL      6.309f          /* 8dB [10.0^(8.0/10.0)] */
 #define DTMF_TO_TOTAL_ENERGY        83.868f         /* -0.85dB [DTMF_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */
 #define DTMF_POWER_OFFSET           110.395f        /* 10*log((32768.0^2)*DTMF_SAMPLES_PER_BLOCK) */
+#define DTMF_SAMPLES_PER_BLOCK      102
 #endif
 
 static const float dtmf_row[] =
@@ -604,7 +604,7 @@ SPAN_DECLARE(int) dtmf_tx_release(dtmf_tx_state_t *s)
 
 SPAN_DECLARE(int) dtmf_tx_free(dtmf_tx_state_t *s)
 {
-    queue_release(&s->queue.queue);
+    dtmf_tx_release(s);
     span_free(s);
     return 0;
 }
index d96609b319adeaf387481c665634e443bc83c092..22589d3ed9716c845af1fcac44be8a91b7f1cef2 100644 (file)
@@ -197,7 +197,7 @@ static void rx_flag_or_abort(hdlc_rx_state_t *s)
             /* Check the flags are back-to-back when testing for valid preamble. This
                greatly reduces the chances of false preamble detection, and anything
                which doesn't send them back-to-back is badly broken. */
-            if (s->num_bits != 7)
+            if (s->flags_seen != s->framing_ok_threshold - 1  &&  s->num_bits != 7)
             {
                 /* Don't set the flags seen indicator back to zero too aggressively.
                    We want to pick up with the minimum of discarded data when there
index 784a146c1cce2685b8c378d5282740e225f17c7f..bd24898b3edcdbfddb4485cc5b6ba10b2a67b1fb 100644 (file)
@@ -152,7 +152,8 @@ static const char *phase_names[] =
 /* These state names are modelled after places in the T.30 flow charts. */
 enum
 {
-    T30_STATE_ANSWERING = 1,
+    T30_STATE_IDLE = 0,
+    T30_STATE_ANSWERING,
     T30_STATE_B,
     T30_STATE_C,
     T30_STATE_D,
@@ -186,7 +187,7 @@ enum
 
 static const char *state_names[] =
 {
-    "NONE",
+    "IDLE",
     "ANSWERING",
     "B",
     "C",
@@ -6402,7 +6403,6 @@ SPAN_DECLARE(void) t30_front_end_status(void *user_data, int status)
             /* Cancel any receive timeout, and declare that a receive signal is present,
                since the front end is explicitly telling us we have seen something. */
             s->rx_signal_present = true;
-            timer_t2_t4_stop(s);
             break;
         }
         break;
@@ -6593,6 +6593,7 @@ SPAN_DECLARE(int) t30_restart(t30_state_t *s, bool calling_party)
 {
     release_resources(s);
     s->calling_party = calling_party;
+    s->state = T30_STATE_IDLE;
     s->phase = T30_PHASE_IDLE;
     s->next_phase = T30_PHASE_IDLE;
     s->current_fallback = 0;
index bb3d02e9024e3bae4ff0bbc6c8dc54c004506541..8233baedf6655dc11f07b2bba8b8f8cc7d14ae8b 100644 (file)
@@ -58,6 +58,7 @@
 #include "spandsp/alloc.h"
 #include "spandsp/logging.h"
 #include "spandsp/queue.h"
+#include "spandsp/vector_int.h"
 #include "spandsp/dc_restore.h"
 #include "spandsp/bit_operations.h"
 #include "spandsp/power_meter.h"
 #define DATA_END_TX_COUNT                       3
 
 /*! The number of consecutive flags to declare HDLC framing is OK. */
-#define HDLC_FRAMING_OK_THRESHOLD       5
+#define HDLC_FRAMING_OK_THRESHOLD               5
 
 enum
 {
@@ -700,7 +701,7 @@ static void monitor_control_messages(t38_gateway_state_t *s,
             /* If we are processing a message from the modem side, the contents determine the fast receive modem.
                we are to use. If it comes from the T.38 side the contents do not. */
             s->core.fast_bit_rate = modem_codes[i].bit_rate;
-            if (from_modem)
+            if ((buf[2] == T30_DTC  &&  !from_modem)  ||  (buf[2] != T30_DTC  &&  from_modem))
                 s->core.fast_rx_modem = modem_codes[i].modem_type;
             /*endif*/
         }
@@ -1863,7 +1864,7 @@ static void rx_flag_or_abort(hdlc_rx_state_t *t)
             /* Check the flags are back-to-back when testing for valid preamble. This
                greatly reduces the chances of false preamble detection, and anything
                which doesn't send them back-to-back is badly broken. */
-            if (t->num_bits != 7)
+            if (t->flags_seen != t->framing_ok_threshold - 1  &&  t->num_bits != 7)
                 t->flags_seen = 0;
             /*endif*/
             if (++t->flags_seen >= t->framing_ok_threshold  &&  !t->framing_ok_announced)
@@ -2070,15 +2071,15 @@ static void update_rx_timing(t38_gateway_state_t *s, int len)
             {
             case TIMED_MODE_TCF_PREDICTABLE_MODEM_START_PAST_V21_MODEM:
                 /* Timed announcement of training, 75ms after the DCS carrier fell. */
-                s->core.timed_mode = TIMED_MODE_TCF_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED;
                 announce_training(s);
+                s->core.timed_mode = TIMED_MODE_TCF_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED;
                 break;
             case TIMED_MODE_TCF_PREDICTABLE_MODEM_START_FAST_MODEM_SEEN:
                 /* Timed announcement of training, 75ms after the DCS carrier fell. */
+                announce_training(s);
                 /* Use a timeout to ride over TEP, if it is present */
                 s->core.samples_to_timeout = ms_to_samples(500);
                 s->core.timed_mode = TIMED_MODE_TCF_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED;
-                announce_training(s);
                 break;
             case TIMED_MODE_TCF_PREDICTABLE_MODEM_START_FAST_MODEM_ANNOUNCED:
                 s->core.timed_mode = TIMED_MODE_IDLE;
@@ -2172,7 +2173,7 @@ SPAN_DECLARE_NONSTD(int) t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], i
     if (s->audio.modems.transmit_on_idle)
     {
         /* Pad to the requested length with silence */
-        memset(&amp[len], 0, (max_len - len)*sizeof(int16_t));
+        vec_zeroi16(&amp[len], max_len - len);
         len = max_len;
     }
     /*endif*/
@@ -2180,7 +2181,7 @@ SPAN_DECLARE_NONSTD(int) t38_gateway_tx(t38_gateway_state_t *s, int16_t amp[], i
     if (s->audio.modems.audio_tx_log >= 0)
     {
         if (len < required_len)
-            memset(&amp[len], 0, (required_len - len)*sizeof(int16_t));
+            vec_zeroi16(&amp[len], required_len - len);
         /*endif*/
         write(s->audio.modems.audio_tx_log, amp, required_len*sizeof(int16_t));
     }