From 11cc9773918da7f65ff108c447d5d0df892ee7ca Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Mon, 27 Aug 2012 23:04:05 +0800 Subject: [PATCH 1/5] More cleanups of fax modem stuff --- libs/spandsp/src/fax.c | 89 ++++++++-------------------------- libs/spandsp/src/fax_modems.c | 5 -- libs/spandsp/src/t31.c | 63 +++++++++--------------- libs/spandsp/src/t38_gateway.c | 43 ++++++++-------- 4 files changed, 62 insertions(+), 138 deletions(-) diff --git a/libs/spandsp/src/fax.c b/libs/spandsp/src/fax.c index 0b53b11c4b..2a2b6437b8 100644 --- a/libs/spandsp/src/fax.c +++ b/libs/spandsp/src/fax.c @@ -176,19 +176,6 @@ static int v17_v21_rx(void *user_data, const int16_t amp[], int len) } /*- End of function --------------------------------------------------------*/ -static int v17_v21_rx_fillin(void *user_data, int len) -{ - fax_state_t *t; - fax_modems_state_t *s; - - t = (fax_state_t *) user_data; - s = &t->modems; - v17_rx_fillin(&s->fast_modems.v17_rx, len); - fsk_rx_fillin(&s->v21_rx, len); - return 0; -} -/*- End of function --------------------------------------------------------*/ - static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len) { fax_state_t *t; @@ -215,19 +202,6 @@ static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len) } /*- End of function --------------------------------------------------------*/ -static int v27ter_v21_rx_fillin(void *user_data, int len) -{ - fax_state_t *t; - fax_modems_state_t *s; - - t = (fax_state_t *) user_data; - s = &t->modems; - v27ter_rx_fillin(&s->fast_modems.v27ter_rx, len); - fsk_rx_fillin(&s->v21_rx, len); - return 0; -} -/*- End of function --------------------------------------------------------*/ - static int v29_v21_rx(void *user_data, const int16_t amp[], int len) { fax_state_t *t; @@ -254,19 +228,6 @@ static int v29_v21_rx(void *user_data, const int16_t amp[], int len) } /*- End of function --------------------------------------------------------*/ -static int v29_v21_rx_fillin(void *user_data, int len) -{ - fax_state_t *t; - fax_modems_state_t *s; - - t = (fax_state_t *) user_data; - s = &t->modems; - v29_rx_fillin(&s->fast_modems.v29_rx, len); - fsk_rx_fillin(&s->v21_rx, len); - return 0; -} -/*- End of function --------------------------------------------------------*/ - SPAN_DECLARE_NONSTD(int) fax_rx(fax_state_t *s, int16_t *amp, int len) { int i; @@ -383,8 +344,6 @@ SPAN_DECLARE_NONSTD(int) fax_tx(fax_state_t *s, int16_t *amp, int max_len) static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc) { fax_state_t *s; - put_bit_func_t put_bit_func; - void *put_bit_user_data; fax_modems_state_t *t; s = (fax_state_t *) user_data; @@ -396,36 +355,34 @@ static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_t t->rx_bit_rate = bit_rate; if (use_hdlc) { - put_bit_func = (put_bit_func_t) hdlc_rx_put_bit; - put_bit_user_data = (void *) &t->hdlc_rx; + fax_modems_set_put_bit(t, (put_bit_func_t) hdlc_rx_put_bit, &t->hdlc_rx); hdlc_rx_init(&t->hdlc_rx, FALSE, TRUE, HDLC_FRAMING_OK_THRESHOLD, t30_hdlc_accept, &s->t30); } else { - put_bit_func = t30_non_ecm_put_bit; - put_bit_user_data = (void *) &s->t30; + fax_modems_set_put_bit(t, (put_bit_func_t) t30_non_ecm_put_bit, &s->t30); } switch (type) { case T30_MODEM_V21: - fsk_rx_init(&t->v21_rx, &preset_fsk_specs[FSK_V21CH2], FSK_FRAME_MODE_SYNC, (put_bit_func_t) hdlc_rx_put_bit, put_bit_user_data); + fsk_rx_init(&t->v21_rx, &preset_fsk_specs[FSK_V21CH2], FSK_FRAME_MODE_SYNC, (put_bit_func_t) hdlc_rx_put_bit, t->put_bit_user_data); fsk_rx_signal_cutoff(&t->v21_rx, -45.5f); fax_modems_set_rx_handler(t, (span_rx_handler_t) &fsk_rx, &t->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &t->v21_rx); break; case T30_MODEM_V27TER: v27ter_rx_restart(&t->fast_modems.v27ter_rx, bit_rate, FALSE); - v27ter_rx_set_put_bit(&t->fast_modems.v27ter_rx, put_bit_func, put_bit_user_data); - fax_modems_set_rx_handler(t, &v27ter_v21_rx, s, &v27ter_v21_rx_fillin, s); + v27ter_rx_set_put_bit(&t->fast_modems.v27ter_rx, t->put_bit, t->put_bit_user_data); + fax_modems_set_rx_handler(t, &v27ter_v21_rx, s, &fax_modems_v27ter_v21_rx_fillin, t); break; case T30_MODEM_V29: v29_rx_restart(&t->fast_modems.v29_rx, bit_rate, FALSE); - v29_rx_set_put_bit(&t->fast_modems.v29_rx, put_bit_func, put_bit_user_data); - fax_modems_set_rx_handler(t, &v29_v21_rx, s, &v29_v21_rx_fillin, s); + v29_rx_set_put_bit(&t->fast_modems.v29_rx, t->put_bit, t->put_bit_user_data); + fax_modems_set_rx_handler(t, &v29_v21_rx, s, &fax_modems_v29_v21_rx_fillin, t); break; case T30_MODEM_V17: v17_rx_restart(&t->fast_modems.v17_rx, bit_rate, short_train); - v17_rx_set_put_bit(&t->fast_modems.v17_rx, put_bit_func, put_bit_user_data); - fax_modems_set_rx_handler(t, &v17_v21_rx, s, &v17_v21_rx_fillin, s); + v17_rx_set_put_bit(&t->fast_modems.v17_rx, t->put_bit, t->put_bit_user_data); + fax_modems_set_rx_handler(t, &v17_v21_rx, s, &fax_modems_v17_v21_rx_fillin, t); break; case T30_MODEM_DONE: span_log(&s->logging, SPAN_LOG_FLOW, "FAX exchange complete\n"); @@ -439,8 +396,6 @@ static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_t static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_train, int use_hdlc) { fax_state_t *s; - get_bit_func_t get_bit_func; - void *get_bit_user_data; fax_modems_state_t *t; int tone; @@ -450,15 +405,9 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t if (t->current_tx_type == type) return; if (use_hdlc) - { - get_bit_func = (get_bit_func_t) hdlc_tx_get_bit; - get_bit_user_data = (void *) &t->hdlc_tx; - } + fax_modems_set_get_bit(t, (get_bit_func_t) hdlc_tx_get_bit, &t->hdlc_tx); else - { - get_bit_func = t30_non_ecm_get_bit; - get_bit_user_data = (void *) &s->t30; - } + fax_modems_set_get_bit(t, (get_bit_func_t) t30_non_ecm_get_bit, &s->t30); switch (type) { case T30_MODEM_PAUSE: @@ -479,9 +428,9 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t t->transmit = TRUE; break; case T30_MODEM_V21: - fsk_tx_init(&t->v21_tx, &preset_fsk_specs[FSK_V21CH2], get_bit_func, get_bit_user_data); + fsk_tx_init(&t->v21_tx, &preset_fsk_specs[FSK_V21CH2], t->get_bit, t->get_bit_user_data); /* The spec says 1s +-15% of preamble. So, the minimum is 32 octets. */ - hdlc_tx_flags(&t->hdlc_tx, 32); + fax_modems_hdlc_tx_flags(t, 32); /* Pause before switching from phase C, as per T.30 5.3.2.2. If we omit this, the receiver might not see the carrier fall between the high speed and low speed sections. In practice, a 75ms gap before any V.21 transmission is harmless, adds little to the overall length of @@ -494,9 +443,9 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t case T30_MODEM_V17: silence_gen_alter(&t->silence_gen, ms_to_samples(75)); /* For any fast modem, set 200ms of preamble flags */ - hdlc_tx_flags(&t->hdlc_tx, bit_rate/(8*5)); + fax_modems_hdlc_tx_flags(t, bit_rate/(8*5)); v17_tx_restart(&t->fast_modems.v17_tx, bit_rate, t->use_tep, short_train); - v17_tx_set_get_bit(&t->fast_modems.v17_tx, get_bit_func, get_bit_user_data); + v17_tx_set_get_bit(&t->fast_modems.v17_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v17_tx, &t->fast_modems.v17_tx); t->transmit = TRUE; @@ -504,9 +453,9 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t case T30_MODEM_V27TER: silence_gen_alter(&t->silence_gen, ms_to_samples(75)); /* For any fast modem, set 200ms of preamble flags */ - hdlc_tx_flags(&t->hdlc_tx, bit_rate/(8*5)); + fax_modems_hdlc_tx_flags(t, bit_rate/(8*5)); v27ter_tx_restart(&t->fast_modems.v27ter_tx, bit_rate, t->use_tep); - v27ter_tx_set_get_bit(&t->fast_modems.v27ter_tx, get_bit_func, get_bit_user_data); + v27ter_tx_set_get_bit(&t->fast_modems.v27ter_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v27ter_tx, &t->fast_modems.v27ter_tx); t->transmit = TRUE; @@ -514,9 +463,9 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t case T30_MODEM_V29: silence_gen_alter(&t->silence_gen, ms_to_samples(75)); /* For any fast modem, set 200ms of preamble flags */ - hdlc_tx_flags(&t->hdlc_tx, bit_rate/(8*5)); + fax_modems_hdlc_tx_flags(t, bit_rate/(8*5)); v29_tx_restart(&t->fast_modems.v29_tx, bit_rate, t->use_tep); - v29_tx_set_get_bit(&t->fast_modems.v29_tx, get_bit_func, get_bit_user_data); + v29_tx_set_get_bit(&t->fast_modems.v29_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v29_tx, &t->fast_modems.v29_tx); t->transmit = TRUE; diff --git a/libs/spandsp/src/fax_modems.c b/libs/spandsp/src/fax_modems.c index 0eba221e3e..46524b4e0f 100644 --- a/libs/spandsp/src/fax_modems.c +++ b/libs/spandsp/src/fax_modems.c @@ -257,11 +257,6 @@ SPAN_DECLARE_NONSTD(int) fax_modems_v29_v21_rx_fillin(void *user_data, int len) static void v21_rx_status_handler(void *user_data, int status) { -#if 0 - fax_modems_state_t *s; - - s = (fax_modems_state_t *) user_data; -#endif } /*- End of function --------------------------------------------------------*/ diff --git a/libs/spandsp/src/t31.c b/libs/spandsp/src/t31.c index 6f041a6b2f..f8a2b07966 100644 --- a/libs/spandsp/src/t31.c +++ b/libs/spandsp/src/t31.c @@ -1764,7 +1764,7 @@ static int restart_modem(t31_state_t *s, int new_modem) case FAX_MODEM_V17_RX: if (!s->t38_mode) { - fax_modems_set_rx_handler(t, (span_rx_handler_t) &v17_v21_rx, s, (span_rx_fillin_handler_t) &fax_modems_v17_v21_rx_fillin, &s->audio.modems); + fax_modems_set_rx_handler(t, (span_rx_handler_t) &v17_v21_rx, t, (span_rx_fillin_handler_t) &fax_modems_v17_v21_rx_fillin, t); v17_rx_restart(&t->fast_modems.v17_rx, s->bit_rate, s->short_train); /* Allow for +FCERROR/+FRH:3 */ t31_v21_rx(s); @@ -1801,7 +1801,7 @@ static int restart_modem(t31_state_t *s, int new_modem) case FAX_MODEM_V27TER_RX: if (!s->t38_mode) { - fax_modems_set_rx_handler(t, (span_rx_handler_t) &v27ter_v21_rx, s, (span_rx_fillin_handler_t) &fax_modems_v27ter_v21_rx_fillin, &s->audio.modems); + fax_modems_set_rx_handler(t, (span_rx_handler_t) &v27ter_v21_rx, t, (span_rx_fillin_handler_t) &fax_modems_v27ter_v21_rx_fillin, t); v27ter_rx_restart(&t->fast_modems.v27ter_rx, s->bit_rate, FALSE); /* Allow for +FCERROR/+FRH:3 */ t31_v21_rx(s); @@ -1838,7 +1838,7 @@ static int restart_modem(t31_state_t *s, int new_modem) case FAX_MODEM_V29_RX: if (!s->t38_mode) { - fax_modems_set_rx_handler(t, (span_rx_handler_t) &v29_v21_rx, s, (span_rx_fillin_handler_t) &fax_modems_v29_v21_rx_fillin, &s->audio.modems); + fax_modems_set_rx_handler(t, (span_rx_handler_t) &v29_v21_rx, t, (span_rx_fillin_handler_t) &fax_modems_v29_v21_rx_fillin, t); v29_rx_restart(&t->fast_modems.v29_rx, s->bit_rate, FALSE); /* Allow for +FCERROR/+FRH:3 */ t31_v21_rx(s); @@ -2298,12 +2298,11 @@ static int cng_rx(void *user_data, const int16_t amp[], int len) static int v17_v21_rx(void *user_data, const int16_t amp[], int len) { - t31_state_t *t; fax_modems_state_t *s; - t = (t31_state_t *) user_data; - s = &t->audio.modems; + s = (fax_modems_state_t *) user_data; v17_rx(&s->fast_modems.v17_rx, amp, len); + fsk_rx(&s->v21_rx, amp, len); if (s->rx_trained) { /* The fast modem has trained, so we no longer need to run the slow @@ -2311,16 +2310,12 @@ static int v17_v21_rx(void *user_data, const int16_t amp[], int len) span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.17 + V.21 to V.17 (%.2fdBm0)\n", v17_rx_signal_power(&s->fast_modems.v17_rx)); fax_modems_set_rx_handler(s, (span_rx_handler_t) &v17_rx, &s->fast_modems.v17_rx, (span_rx_fillin_handler_t) &v17_rx_fillin, &s->fast_modems.v17_rx); } - else + else if (s->rx_frame_received) { - fsk_rx(&s->v21_rx, amp, len); - if (t->rx_frame_received) - { - /* We have received something, and the fast modem has not trained. We must - be receiving valid V.21 */ - span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.17 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); - fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); - } + /* We have received something, and the fast modem has not trained. We must + be receiving valid V.21 */ + span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.17 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); + fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); } return len; } @@ -2328,12 +2323,11 @@ static int v17_v21_rx(void *user_data, const int16_t amp[], int len) static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len) { - t31_state_t *t; fax_modems_state_t *s; - t = (t31_state_t *) user_data; - s = &t->audio.modems; + s = (fax_modems_state_t *) user_data; v27ter_rx(&s->fast_modems.v27ter_rx, amp, len); + fsk_rx(&s->v21_rx, amp, len); if (s->rx_trained) { /* The fast modem has trained, so we no longer need to run the slow @@ -2341,16 +2335,12 @@ static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len) span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.27ter + V.21 to V.27ter (%.2fdBm0)\n", v27ter_rx_signal_power(&s->fast_modems.v27ter_rx)); fax_modems_set_rx_handler(s, (span_rx_handler_t) &v27ter_rx, &s->fast_modems.v27ter_rx, (span_rx_fillin_handler_t) &v27ter_rx_fillin, &s->fast_modems.v27ter_rx); } - else + else if (s->rx_frame_received) { - fsk_rx(&s->v21_rx, amp, len); - if (t->rx_frame_received) - { - /* We have received something, and the fast modem has not trained. We must - be receiving valid V.21 */ - span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.27ter + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); - fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); - } + /* We have received something, and the fast modem has not trained. We must + be receiving valid V.21 */ + span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.27ter + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); + fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); } return len; } @@ -2358,12 +2348,11 @@ static int v27ter_v21_rx(void *user_data, const int16_t amp[], int len) static int v29_v21_rx(void *user_data, const int16_t amp[], int len) { - t31_state_t *t; fax_modems_state_t *s; - t = (t31_state_t *) user_data; - s = &t->audio.modems; + s = (fax_modems_state_t *) user_data; v29_rx(&s->fast_modems.v29_rx, amp, len); + fsk_rx(&s->v21_rx, amp, len); if (s->rx_trained) { /* The fast modem has trained, so we no longer need to run the slow @@ -2371,16 +2360,12 @@ static int v29_v21_rx(void *user_data, const int16_t amp[], int len) span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.29 (%.2fdBm0)\n", v29_rx_signal_power(&s->fast_modems.v29_rx)); fax_modems_set_rx_handler(s, (span_rx_handler_t) &v29_rx, &s->fast_modems.v29_rx, (span_rx_fillin_handler_t) &v29_rx_fillin, &s->fast_modems.v29_rx); } - else + else if (s->rx_frame_received) { - fsk_rx(&s->v21_rx, amp, len); - if (t->rx_frame_received) - { - /* We have received something, and the fast modem has not trained. We must - be receiving valid V.21 */ - span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); - fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); - } + /* We have received something, and the fast modem has not trained. We must + be receiving valid V.21 */ + span_log(&s->logging, SPAN_LOG_FLOW, "Switching from V.29 + V.21 to V.21 (%.2fdBm0)\n", fsk_rx_signal_power(&s->v21_rx)); + fax_modems_set_rx_handler(s, (span_rx_handler_t) &fsk_rx, &s->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &s->v21_rx); } return len; } diff --git a/libs/spandsp/src/t38_gateway.c b/libs/spandsp/src/t38_gateway.c index 96b700fa92..200bdcfde7 100644 --- a/libs/spandsp/src/t38_gateway.c +++ b/libs/spandsp/src/t38_gateway.c @@ -347,11 +347,10 @@ static int set_next_tx_type(t38_gateway_state_t *s) { int indicator; fax_modems_state_t *t; - get_bit_func_t get_bit_func; - void *get_bit_user_data; t38_gateway_hdlc_state_t *u; - int short_train; int bit_rate; + int short_train; + //int use_hdlc; t = &s->audio.modems; t38_non_ecm_buffer_report_output_status(&s->core.non_ecm_to_modem, &s->logging); @@ -393,14 +392,14 @@ static int set_next_tx_type(t38_gateway_state_t *s) { span_log(&s->logging, SPAN_LOG_FLOW, "HDLC mode\n"); hdlc_tx_init(&t->hdlc_tx, FALSE, 2, TRUE, hdlc_underflow_handler, s); - get_bit_func = (get_bit_func_t) hdlc_tx_get_bit; - get_bit_user_data = (void *) &t->hdlc_tx; + fax_modems_set_get_bit(t, (get_bit_func_t) hdlc_tx_get_bit, &t->hdlc_tx); + //use_hdlc = TRUE; } else { span_log(&s->logging, SPAN_LOG_FLOW, "Non-ECM mode\n"); - get_bit_func = t38_non_ecm_buffer_get_bit; - get_bit_user_data = (void *) &s->core.non_ecm_to_modem; + fax_modems_set_get_bit(t, (get_bit_func_t) t38_non_ecm_buffer_get_bit, &s->core.non_ecm_to_modem); + //use_hdlc = FALSE; } /*endif*/ switch (indicator) @@ -445,7 +444,7 @@ static int set_next_tx_type(t38_gateway_state_t *s) t->tx_bit_rate = (indicator == T38_IND_V27TER_4800_TRAINING) ? 4800 : 2400; silence_gen_alter(&t->silence_gen, ms_to_samples(75)); v27ter_tx_restart(&t->fast_modems.v27ter_tx, t->tx_bit_rate, t->use_tep); - v27ter_tx_set_get_bit(&t->fast_modems.v27ter_tx, get_bit_func, get_bit_user_data); + v27ter_tx_set_get_bit(&t->fast_modems.v27ter_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v27ter_tx, &t->fast_modems.v27ter_tx); fax_modems_set_rx_active(t, TRUE); @@ -456,7 +455,7 @@ static int set_next_tx_type(t38_gateway_state_t *s) t->tx_bit_rate = (indicator == T38_IND_V29_9600_TRAINING) ? 9600 : 7200; silence_gen_alter(&t->silence_gen, ms_to_samples(75)); v29_tx_restart(&t->fast_modems.v29_tx, t->tx_bit_rate, t->use_tep); - v29_tx_set_get_bit(&t->fast_modems.v29_tx, get_bit_func, get_bit_user_data); + v29_tx_set_get_bit(&t->fast_modems.v29_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v29_tx, &t->fast_modems.v29_tx); fax_modems_set_rx_active(t, TRUE); @@ -505,7 +504,7 @@ static int set_next_tx_type(t38_gateway_state_t *s) t->tx_bit_rate = bit_rate; silence_gen_alter(&t->silence_gen, ms_to_samples(75)); v17_tx_restart(&t->fast_modems.v17_tx, t->tx_bit_rate, t->use_tep, short_train); - v17_tx_set_get_bit(&t->fast_modems.v17_tx, get_bit_func, get_bit_user_data); + v17_tx_set_get_bit(&t->fast_modems.v17_tx, t->get_bit, t->get_bit_user_data); fax_modems_set_tx_handler(t, (span_tx_handler_t) &silence_gen, &t->silence_gen); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &v17_tx, &t->fast_modems.v17_tx); fax_modems_set_rx_active(t, TRUE); @@ -2020,8 +2019,6 @@ static void t38_hdlc_rx_put_bit(hdlc_rx_state_t *t, int new_bit) static int restart_rx_modem(t38_gateway_state_t *s) { fax_modems_state_t *t; - put_bit_func_t put_bit_func; - void *put_bit_user_data; if (s->core.to_t38.in_bits || s->core.to_t38.out_octets) { @@ -2049,21 +2046,19 @@ static int restart_rx_modem(t38_gateway_state_t *s) s->t38x.current_tx_data_type = T38_DATA_V21; fsk_rx_init(&t->v21_rx, &preset_fsk_specs[FSK_V21CH2], FSK_FRAME_MODE_SYNC, (put_bit_func_t) t38_hdlc_rx_put_bit, &t->hdlc_rx); #if 0 - fsk_rx_signal_cutoff(&t->v21_rx, -45.5f); + fsk_rx_signal_cutoff(&t->v21_rx, -39.09f); #endif if (s->core.image_data_mode && s->core.ecm_mode) { - put_bit_func = (put_bit_func_t) t38_hdlc_rx_put_bit; - put_bit_user_data = (void *) &t->hdlc_rx; + fax_modems_set_put_bit(t, (put_bit_func_t) t38_hdlc_rx_put_bit, &t->hdlc_rx); } else { if (s->core.image_data_mode && s->core.to_t38.fill_bit_removal) - put_bit_func = non_ecm_remove_fill_and_put_bit; + fax_modems_set_put_bit(t, (put_bit_func_t) non_ecm_remove_fill_and_put_bit, s); else - put_bit_func = non_ecm_put_bit; + fax_modems_set_put_bit(t, (put_bit_func_t) non_ecm_put_bit, s); /*endif*/ - put_bit_user_data = (void *) s; } /*endif*/ to_t38_buffer_init(&s->core.to_t38); @@ -2072,21 +2067,21 @@ static int restart_rx_modem(t38_gateway_state_t *s) { case FAX_MODEM_V27TER_RX: v27ter_rx_restart(&t->fast_modems.v27ter_rx, s->core.fast_bit_rate, FALSE); - v27ter_rx_set_put_bit(&t->fast_modems.v27ter_rx, put_bit_func, put_bit_user_data); + v27ter_rx_set_put_bit(&t->fast_modems.v27ter_rx, t->put_bit, t->put_bit_user_data); set_rx_handler(t, &v27ter_v21_rx, t, &fax_modems_v27ter_v21_rx_fillin, t); - s->core.fast_rx_active = FAX_MODEM_V27TER_RX; + s->core.fast_rx_active = s->core.fast_rx_modem; break; case FAX_MODEM_V29_RX: v29_rx_restart(&t->fast_modems.v29_rx, s->core.fast_bit_rate, FALSE); - v29_rx_set_put_bit(&t->fast_modems.v29_rx, put_bit_func, put_bit_user_data); + v29_rx_set_put_bit(&t->fast_modems.v29_rx, t->put_bit, t->put_bit_user_data); set_rx_handler(t, &v29_v21_rx, t, &fax_modems_v29_v21_rx_fillin, t); - s->core.fast_rx_active = FAX_MODEM_V29_RX; + s->core.fast_rx_active = s->core.fast_rx_modem; break; case FAX_MODEM_V17_RX: v17_rx_restart(&t->fast_modems.v17_rx, s->core.fast_bit_rate, s->core.short_train); - v17_rx_set_put_bit(&t->fast_modems.v17_rx, put_bit_func, put_bit_user_data); + v17_rx_set_put_bit(&t->fast_modems.v17_rx, t->put_bit, t->put_bit_user_data); set_rx_handler(t, &v17_v21_rx, t, &fax_modems_v17_v21_rx_fillin, t); - s->core.fast_rx_active = FAX_MODEM_V17_RX; + s->core.fast_rx_active = s->core.fast_rx_modem; break; default: set_rx_handler(t, (span_rx_handler_t) &fsk_rx, &t->v21_rx, (span_rx_fillin_handler_t) &fsk_rx_fillin, &t->v21_rx); From be5fc2c0c51581db4aa7d57ffe23d6f4372c37ce Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Aug 2012 12:38:42 -0500 Subject: [PATCH 2/5] enable debug --- src/mod/endpoints/mod_sofia/sofia_presence.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index 066f3c6b90..cf7159ab45 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1226,7 +1226,7 @@ static void actual_sofia_presence_event_handler(switch_event_t *event) if (call_info) { -#if 0 +#if 1 if (mod_sofia_globals.debug_sla > 1) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n"); DUMP_EVENT(event); From a0f752c5640247cd492c86d6e303d5a2d1e9f180 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Aug 2012 12:50:51 -0500 Subject: [PATCH 3/5] FS-4561 revert --- src/mod/endpoints/mod_sofia/sofia_presence.c | 25 ++++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index cf7159ab45..fc7c195e53 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -3320,7 +3320,7 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t "hostname='%q' and profile_name='%q' " "and sub_to_user='%q' and sub_to_host='%q' " - "and event='line-seize'", (long) switch_epoch_time_now(NULL) + 2, + "and event='line-seize'", (long) switch_epoch_time_now(NULL), mod_sofia_globals.hostname, profile->name, to_user, to_host ); @@ -3349,6 +3349,17 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t switch_safe_free(sql); } + + sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and profile_name='%q' and " + "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') " + "and call_info_state='seized'", mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host); + + + if (mod_sofia_globals.debug_sla > 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql); + } + sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); + switch_safe_free(sql); } @@ -3415,20 +3426,8 @@ static int sync_sla(sofia_profile_t *profile, const char *to_user, const char *t sh = NULL; switch_core_destroy_memory_pool(&pool); - - if (clear) { - sql = switch_mprintf("delete from sip_dialogs where hostname='%q' and profile_name='%q' and " - "((sip_from_user='%q' and sip_from_host='%q') or presence_id='%q@%q') " - "and call_info_state='seized'", mod_sofia_globals.hostname, profile->name, to_user, to_host, to_user, to_host); - if (mod_sofia_globals.debug_sla > 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CLEAR SQL %s\n", sql); - } - sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE); - switch_safe_free(sql); - } - return total; From 90e637cc2fcd16115aae6b687349357d05a60482 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Aug 2012 12:55:34 -0500 Subject: [PATCH 4/5] FS-4561 more debug --- src/mod/endpoints/mod_sofia/sofia_presence.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/sofia_presence.c b/src/mod/endpoints/mod_sofia/sofia_presence.c index fc7c195e53..d7f6d22303 100644 --- a/src/mod/endpoints/mod_sofia/sofia_presence.c +++ b/src/mod/endpoints/mod_sofia/sofia_presence.c @@ -1224,15 +1224,16 @@ static void actual_sofia_presence_event_handler(switch_event_t *event) continue; } + + if (mod_sofia_globals.debug_sla > 1) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n"); + DUMP_EVENT(event); + + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "CHECK CALL_INFO [%s]\n", switch_str_nil(call_info)); + } + if (call_info) { -#if 1 - if (mod_sofia_globals.debug_sla > 1) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SLA EVENT:\n"); - DUMP_EVENT(event); - } -#endif - if (uuid) { sql = switch_mprintf("update sip_dialogs set call_info='%q',call_info_state='%q' where " "hostname='%q' and profile_name='%q' and uuid='%q'", From a8b89bcc1e6d0e5363e7e1ff08d325297568e4eb Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 27 Aug 2012 16:13:21 -0500 Subject: [PATCH 5/5] add cache param to httapi --- src/mod/applications/mod_httapi/mod_httapi.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/mod/applications/mod_httapi/mod_httapi.c b/src/mod/applications/mod_httapi/mod_httapi.c index 0dbb722f5e..887dae3891 100644 --- a/src/mod/applications/mod_httapi/mod_httapi.c +++ b/src/mod/applications/mod_httapi/mod_httapi.c @@ -2276,7 +2276,9 @@ static char *load_cache_data(http_file_context_t *context, const char *url) if ((p = strchr(meta_buffer, ':'))) { *p++ = '\0'; - context->expires = (time_t) atol(meta_buffer); + if (context->expires != 1) { + context->expires = (time_t) atol(meta_buffer); + } context->metadata = switch_core_strdup(context->pool, p); } } @@ -2522,7 +2524,7 @@ static switch_status_t locate_url_file(http_file_context_t *context, const char load_cache_data(context, url); - if (context->expires && now < context->expires) { + if (context->expires > 1 && now < context->expires) { return SWITCH_STATUS_SUCCESS; } @@ -2614,7 +2616,13 @@ static switch_status_t http_file_file_open(switch_file_handle_t *handle, const c switch_event_create_brackets(pdup, '(', ')', ',', &context->url_params, &parsed, SWITCH_FALSE); if (context->url_params) { + const char *var; context->ua = switch_event_get_header(context->url_params, "ua"); + + if ((var = switch_event_get_header(context->url_params, "cache")) && !switch_true(var)) { + context->expires = 1; + } + } if (parsed) path = parsed;