diff --git a/src/mod/applications/mod_spandsp/Makefile.am b/src/mod/applications/mod_spandsp/Makefile.am index 98b781bd7d..0c78e46367 100644 --- a/src/mod/applications/mod_spandsp/Makefile.am +++ b/src/mod/applications/mod_spandsp/Makefile.am @@ -12,7 +12,7 @@ SPANDSP_LA=$(SPANDSP_BUILDDIR)/src/libspandsp.la mod_LTLIBRARIES = mod_spandsp.la mod_spandsp_la_SOURCES = mod_spandsp.c udptl.c mod_spandsp_fax.c mod_spandsp_dsp.c mod_spandsp_codecs.c mod_spandsp_modem.c mod_spandsp_la_CFLAGS = $(BUILD_CFLAGS) $(AM_CFLAGS) -I$(SPANDSP_DIR)/src -I$(TIFF_DIR)/libtiff -I$(SPANDSP_BUILDDIR)/src -I$(TIFF_BUILDDIR)/libtiff -I. -mod_spandsp_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(SPANDSP_LA) $(TIFF_LA) $(SPANDSP_LA_JBIG) -ljpeg -lz -lutil +mod_spandsp_la_LIBADD = $(switch_builddir)/libfreeswitch.la $(SPANDSP_LA) $(TIFF_LA) $(SPANDSP_LA_JBIG) $(SPANDSP_LA_LZMA) -ljpeg -lz -lutil mod_spandsp_la_LDFLAGS = -avoid-version -module -no-undefined -shared $(SPANDSP_LA): $(TIFF_LA) $(SPANDSP_DIR) $(SPANDSP_DIR)/.update diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.2010.vcxproj b/src/mod/applications/mod_spandsp/mod_spandsp.2010.vcxproj index 9ba48566d7..c5477e8527 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.2010.vcxproj +++ b/src/mod/applications/mod_spandsp/mod_spandsp.2010.vcxproj @@ -66,7 +66,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -82,7 +82,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -96,7 +96,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -112,7 +112,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.2012.vcxproj b/src/mod/applications/mod_spandsp/mod_spandsp.2012.vcxproj index 3d92fae094..351ef2cf78 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.2012.vcxproj +++ b/src/mod/applications/mod_spandsp/mod_spandsp.2012.vcxproj @@ -70,7 +70,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -86,7 +86,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -100,7 +100,7 @@ - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) @@ -116,7 +116,7 @@ X64 - %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(AdditionalIncludeDirectories) + %(RootDir)%(Directory)..\..\..\..\libs\spandsp\src\msvc;%(RootDir)%(Directory)..\..\..\..\libs\spandsp\src;%(RootDir)%(Directory)..\..\..\..\libs\tiff-4.0.2\libtiff;%(RootDir)%(Directory)..\..\..\..\libs\jpeg-8d;%(AdditionalIncludeDirectories) diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.c b/src/mod/applications/mod_spandsp/mod_spandsp.c index 51e2505758..b6ff1771de 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp.c @@ -577,6 +577,26 @@ switch_status_t load_configuration(switch_bool_t reload) spandsp_globals.disable_v17 = 1; else spandsp_globals.disable_v17 = 0; + } else if (!strcmp(name, "enable-colour")) { + if (switch_true(value)) + spandsp_globals.enable_colour_fax = 1; + else + spandsp_globals.enable_colour_fax = 0; + } else if (!strcmp(name, "enable-image-resizing")) { + if (switch_true(value)) + spandsp_globals.enable_image_resizing = 1; + else + spandsp_globals.enable_image_resizing = 0; + } else if (!strcmp(name, "enable-colour-to-bilevel")) { + if (switch_true(value)) + spandsp_globals.enable_colour_to_bilevel = 1; + else + spandsp_globals.enable_colour_to_bilevel = 0; + } else if (!strcmp(name, "enable-grayscale-to-bilevel")) { + if (switch_true(value)) + spandsp_globals.enable_grayscale_to_bilevel = 1; + else + spandsp_globals.enable_grayscale_to_bilevel = 0; } else if (!strcmp(name, "enable-t38")) { if (switch_true(value)) { spandsp_globals.enable_t38= 1; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp.h b/src/mod/applications/mod_spandsp/mod_spandsp.h index 323ff07a45..5f5a038c43 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp.h +++ b/src/mod/applications/mod_spandsp/mod_spandsp.h @@ -60,6 +60,10 @@ struct spandsp_globals { short int use_ecm; short int verbose; short int disable_v17; + short int enable_colour_fax; + short int enable_image_resizing; + short int enable_colour_to_bilevel; + short int enable_grayscale_to_bilevel; short int enable_t38; short int enable_t38_request; short int enable_t38_insist; diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c index 0958c8c310..42e31d1ef5 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_dsp.c @@ -150,11 +150,11 @@ static int get_v18_mode(switch_core_session_t *session) { switch_channel_t *channel = switch_core_session_get_channel(session); const char *var; - int r = V18_MODE_5BIT_45; + int r = V18_MODE_5BIT_4545; if ((var = switch_channel_get_variable(channel, "v18_mode"))) { if (!strcasecmp(var, "5BIT_45") || !strcasecmp(var, "baudot")) { - r = V18_MODE_5BIT_45; + r = V18_MODE_5BIT_4545; } else if (!strcasecmp(var, "5BIT_50")) { r = V18_MODE_5BIT_50; } else if (!strcasecmp(var, "DTMF")) { @@ -206,7 +206,7 @@ switch_status_t spandsp_tdd_send_session(switch_core_session_t *session, const c return SWITCH_STATUS_FALSE; } - tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), put_text_msg, NULL); + tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL); v18_put(tdd_state, text, -1); @@ -253,7 +253,7 @@ switch_status_t spandsp_tdd_encode_session(switch_core_session_t *session, const } pvt->session = session; - pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), put_text_msg, NULL); + pvt->tdd_state = v18_init(NULL, TRUE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, NULL); pvt->head_lead = TDD_LEAD; v18_put(pvt->tdd_state, text, -1); @@ -331,7 +331,7 @@ switch_status_t spandsp_tdd_decode_session(switch_core_session_t *session) } pvt->session = session; - pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), put_text_msg, pvt); + pvt->tdd_state = v18_init(NULL, FALSE, get_v18_mode(session), V18_AUTOMODING_GLOBAL, put_text_msg, pvt); if ((status = switch_core_media_bug_add(session, "spandsp_tdd_decode", NULL, tdd_decode_callback, pvt, 0, SMBF_READ_REPLACE | SMBF_NO_PAUSE, &bug)) != SWITCH_STATUS_SUCCESS) { diff --git a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c index e16a57c562..c76fda6637 100644 --- a/src/mod/applications/mod_spandsp/mod_spandsp_fax.c +++ b/src/mod/applications/mod_spandsp/mod_spandsp_fax.c @@ -89,6 +89,10 @@ struct pvt_s { int use_ecm; int disable_v17; + int enable_colour_fax; + int enable_image_resizing; + int enable_colour_to_bilevel; + int enable_grayscale_to_bilevel; int verbose; int caller; @@ -423,12 +427,12 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int msg) switch_channel_set_variable(channel, "fax_longest_bad_row_run", fax_longest_bad_row_run); } - fax_encoding = switch_core_session_sprintf(session, "%d", t30_stats.encoding); + fax_encoding = switch_core_session_sprintf(session, "%d", t30_stats.compression); if (fax_encoding) { switch_channel_set_variable(channel, "fax_encoding", fax_encoding); } - switch_channel_set_variable(channel, "fax_encoding_name", t4_encoding_to_str(t30_stats.encoding)); + switch_channel_set_variable(channel, "fax_encoding_name", t4_compression_to_str(t30_stats.compression)); fax_document_transferred_pages = switch_core_session_sprintf(session, "%d", (pvt->app_mode == FUNCTION_TX) ? t30_stats.pages_tx : t30_stats.pages_rx); if (fax_document_transferred_pages) { @@ -438,10 +442,10 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int msg) switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "==== Page %s===========================================================\n", pvt->app_mode == FUNCTION_TX ? "Sent ====": "Received "); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Page no = %d\n", (pvt->app_mode == FUNCTION_TX) ? t30_stats.pages_tx : t30_stats.pages_rx); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image type = %s (%s in the file)\n", t4_image_type_to_str(t30_stats.type), t4_image_type_to_str(t30_stats.image_type)); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image type = %s (%s in the file)\n", t4_image_type_to_str(t30_stats.type), t4_image_type_to_str(t30_stats.image_type)); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image size = %d x %d pixels (%d x %d pixels in the file)\n", t30_stats.width, t30_stats.length, t30_stats.image_width, t30_stats.image_length); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Image resolution = %d/m x %d/m (%d/m x %d/m in the file)\n", t30_stats.x_resolution, t30_stats.y_resolution, t30_stats.image_x_resolution, t30_stats.image_y_resolution); - switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Compression = %s (%d)\n", t4_encoding_to_str(t30_stats.encoding), t30_stats.encoding); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Compression = %s (%d)\n", t4_compression_to_str(t30_stats.compression), t30_stats.compression); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Compressed image size = %d bytes\n", t30_stats.image_size); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Bad rows = %d\n", t30_stats.bad_rows); switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Longest bad row run = %d\n", t30_stats.longest_bad_row_run); @@ -462,7 +466,7 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int msg) switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-bad-rows", fax_bad_rows); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-longest-bad-row-run", fax_longest_bad_row_run); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-encoding", fax_encoding); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-encoding-name", t4_encoding_to_str(t30_stats.encoding)); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "fax-encoding-name", t4_compression_to_str(t30_stats.compression)); switch_event_fire(&event); } @@ -693,6 +697,7 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) const char *tz; int fec_entries = DEFAULT_FEC_ENTRIES; int fec_span = DEFAULT_FEC_SPAN; + int compressions; session = (switch_core_session_t *) pvt->session; @@ -872,11 +877,43 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) t30_set_phase_b_handler(t30, phase_b_handler, pvt); t30_set_supported_image_sizes(t30, - T30_SUPPORT_US_LETTER_LENGTH | T30_SUPPORT_US_LEGAL_LENGTH | T30_SUPPORT_UNLIMITED_LENGTH - | T30_SUPPORT_215MM_WIDTH | T30_SUPPORT_255MM_WIDTH | T30_SUPPORT_303MM_WIDTH); - t30_set_supported_resolutions(t30, - T30_SUPPORT_STANDARD_RESOLUTION | T30_SUPPORT_FINE_RESOLUTION | T30_SUPPORT_SUPERFINE_RESOLUTION - | T30_SUPPORT_R8_RESOLUTION | T30_SUPPORT_R16_RESOLUTION); + T4_SUPPORT_LENGTH_US_LETTER + | T4_SUPPORT_LENGTH_US_LEGAL + | T4_SUPPORT_LENGTH_UNLIMITED + | T4_SUPPORT_WIDTH_215MM + | T4_SUPPORT_WIDTH_255MM + | T4_SUPPORT_WIDTH_303MM); + t30_set_supported_bilevel_resolutions(t30, + T4_RESOLUTION_R8_STANDARD + | T4_RESOLUTION_R8_FINE + | T4_RESOLUTION_R8_SUPERFINE + | T4_RESOLUTION_R16_SUPERFINE + | T4_RESOLUTION_200_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_200_400 + | T4_RESOLUTION_400_400); + compressions = T4_COMPRESSION_T4_1D + | T4_COMPRESSION_T4_2D + | T4_COMPRESSION_T6 + | T4_COMPRESSION_T85 + | T4_COMPRESSION_T85_L0; + if (pvt->enable_colour_fax) { + t30_set_supported_colour_resolutions(t30, T4_RESOLUTION_100_100 + | T4_RESOLUTION_200_200 + | T4_RESOLUTION_300_300 + | T4_RESOLUTION_400_400); + compressions |= (T4_COMPRESSION_COLOUR | T4_COMPRESSION_T42_T81); + } else { + t30_set_supported_colour_resolutions(t30, 0); + } + if (pvt->enable_image_resizing) + compressions |= T4_COMPRESSION_RESCALING; + if (pvt->enable_colour_to_bilevel) + compressions |= T4_COMPRESSION_COLOUR_TO_BILEVEL; + if (pvt->enable_grayscale_to_bilevel) + compressions |= T4_COMPRESSION_GRAY_TO_BILEVEL; + + t30_set_supported_compressions(t30, compressions); if (pvt->disable_v17) { t30_set_supported_modems(t30, T30_SUPPORT_V29 | T30_SUPPORT_V27TER); @@ -887,11 +924,10 @@ static switch_status_t spanfax_init(pvt_t *pvt, transport_mode_t trans_mode) } if (pvt->use_ecm) { - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION | T30_SUPPORT_T85_COMPRESSION | T30_SUPPORT_T85_L0_COMPRESSION); t30_set_ecm_capability(t30, TRUE); switch_channel_set_variable(channel, "fax_ecm_requested", "1"); } else { - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION); + t30_set_ecm_capability(t30, FALSE); switch_channel_set_variable(channel, "fax_ecm_requested", "0"); } @@ -1212,6 +1248,30 @@ static pvt_t *pvt_init(switch_core_session_t *session, mod_spandsp_fax_applicati pvt->disable_v17 = spandsp_globals.disable_v17; } + if ((tmp = switch_channel_get_variable(channel, "fax_enable_colour"))) { + pvt->enable_colour_fax = switch_true(tmp); + } else { + pvt->enable_colour_fax = spandsp_globals.enable_colour_fax; + } + + if ((tmp = switch_channel_get_variable(channel, "fax_enable_image_resizing"))) { + pvt->enable_image_resizing = switch_true(tmp); + } else { + pvt->enable_image_resizing = spandsp_globals.enable_image_resizing; + } + + if ((tmp = switch_channel_get_variable(channel, "fax_enable_colour_to_bilevel"))) { + pvt->enable_colour_to_bilevel = switch_true(tmp); + } else { + pvt->enable_colour_to_bilevel = spandsp_globals.enable_colour_to_bilevel; + } + + if ((tmp = switch_channel_get_variable(channel, "fax_enable_grayscale_to_bilevel"))) { + pvt->enable_grayscale_to_bilevel = switch_true(tmp); + } else { + pvt->enable_grayscale_to_bilevel = spandsp_globals.enable_grayscale_to_bilevel; + } + if ((tmp = switch_channel_get_variable(channel, "fax_verbose"))) { pvt->verbose = switch_true(tmp); } else { diff --git a/src/mod/applications/mod_spandsp/udptl.c b/src/mod/applications/mod_spandsp/udptl.c index 22b6e67d1b..553e4135e3 100644 --- a/src/mod/applications/mod_spandsp/udptl.c +++ b/src/mod/applications/mod_spandsp/udptl.c @@ -205,7 +205,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) /* Save the new packet. Pure redundancy mode won't use this, but some systems will switch into FEC mode after sending some redundant packets. */ x = seq_no & UDPTL_BUF_MASK; - memcpy(s->rx[x].buf, msg, msg_len); + if (msg_len > 0) + memcpy(s->rx[x].buf, msg, msg_len); s->rx[x].buf_len = msg_len; s->rx[x].fec_len[0] = 0; s->rx[x].fec_span = 0; @@ -288,7 +289,8 @@ int udptl_rx_packet(udptl_state_t *s, const uint8_t buf[], int len) return -1; /* Save the new FEC data */ - memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]); + if (s->rx[x].fec_len[i]) + memcpy(s->rx[x].fec[i], data, s->rx[x].fec_len[i]); #if 0 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FEC: "); for (j = 0; j < s->rx[x].fec_len[i]; j++)