From 3162f6dfdd1f193bce855a9367936f17e52f2521 Mon Sep 17 00:00:00 2001 From: Dustin Marquess Date: Mon, 8 Nov 2021 18:30:00 -0600 Subject: [PATCH] res_fax_spandsp: Add spandsp 3.0.0+ compatibility Newer versions of spandsp did refactoring of code to add new features like color FAXing. This refactoring broke backwards compatibility. Add support for the new version while retaining support for 0.0.6. ASTERISK-29729 #close Change-Id: I3bd74550604ebcf0304528d647fa39abc62fbaa1 --- doc/CHANGES-staging/res_fax_spandsp.txt | 3 ++ res/res_fax_spandsp.c | 45 +++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 doc/CHANGES-staging/res_fax_spandsp.txt diff --git a/doc/CHANGES-staging/res_fax_spandsp.txt b/doc/CHANGES-staging/res_fax_spandsp.txt new file mode 100644 index 0000000000..4ad351fb8e --- /dev/null +++ b/doc/CHANGES-staging/res_fax_spandsp.txt @@ -0,0 +1,3 @@ +Subject: res_fax_spandsp + +Adds support for spandsp 3.0.0. diff --git a/res/res_fax_spandsp.c b/res/res_fax_spandsp.c index 030dfc0f85..24fcff5395 100644 --- a/res/res_fax_spandsp.c +++ b/res/res_fax_spandsp.c @@ -167,10 +167,17 @@ struct spandsp_pvt { static int spandsp_v21_new(struct spandsp_pvt *p); static void session_destroy(struct spandsp_pvt *p); static int t38_tx_packet_handler(t38_core_state_t *t38_core_state, void *data, const uint8_t *buf, int len, int count); -static void t30_phase_e_handler(t30_state_t *t30_state, void *data, int completion_code); -static void spandsp_log(int level, const char *msg); static int update_stats(struct spandsp_pvt *p, int completion_code); static int spandsp_modems(struct ast_fax_session_details *details); +#if SPANDSP_RELEASE_DATE >= 20120902 +/* for spandsp shaphots 3.0.0 and higher */ +static void t30_phase_e_handler(void *data, int completion_code); +static void spandsp_log(void *user_data, int level, const char *msg); +#else +/* for spandsp release 0.0.6 */ +static void t30_phase_e_handler(t30_state_t *t30_state, void *data, int completion_code); +static void spandsp_log(int level, const char *msg); +#endif static void set_logging(logging_state_t *state, struct ast_fax_session_details *details); static void set_local_info(t30_state_t *t30_state, struct ast_fax_session_details *details); @@ -375,13 +382,23 @@ static int update_stats(struct spandsp_pvt *p, int completion_code) * This function pulls stats from the spandsp stack and stores them for res_fax * to use later. */ +#if SPANDSP_RELEASE_DATE >= 20120902 +/* for spandsp shaphots 3.0.0 and higher */ +static void t30_phase_e_handler(void *data, int completion_code) +#else +/* for spandsp release 0.0.6 */ static void t30_phase_e_handler(t30_state_t *t30_state, void *data, int completion_code) +#endif { struct ast_fax_session *s = data; struct spandsp_pvt *p = s->tech_pvt; char headerinfo[T30_MAX_PAGE_HEADER_INFO + 1]; const char *c; t30_stats_t stats; +#if SPANDSP_RELEASE_DATE >= 20120902 + /* for spandsp shaphots 3.0.0 and higher */ + t30_state_t *t30_state = p->t30_state; +#endif ast_debug(5, "FAX session '%u' entering phase E\n", s->id); @@ -430,7 +447,13 @@ static void t30_phase_e_handler(t30_state_t *t30_state, void *data, int completi * * \note This function is a callback function called by spandsp. */ +#if SPANDSP_RELEASE_DATE >= 20120902 +/* for spandsp shaphots 3.0.0 and higher */ +static void spandsp_log(void *user_data, int level, const char *msg) +#else +/* for spandsp release 0.0.6 */ static void spandsp_log(int level, const char *msg) +#endif { if (level == SPAN_LOG_ERROR) { ast_log(LOG_ERROR, "%s", msg); @@ -449,7 +472,13 @@ static void set_logging(logging_state_t *state, struct ast_fax_session_details * level = SPAN_LOG_DEBUG_3; } +#if SPANDSP_RELEASE_DATE >= 20120902 + /* for spandsp shaphots 3.0.0 and higher */ + span_log_set_message_handler(state, spandsp_log, NULL); +#else + /* for spandsp release 0.0.6 */ span_log_set_message_handler(state, spandsp_log); +#endif span_log_set_level(state, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | level); } @@ -479,7 +508,13 @@ static void set_file(t30_state_t *t30_state, struct ast_fax_session_details *det static void set_ecm(t30_state_t *t30_state, struct ast_fax_session_details *details) { t30_set_ecm_capability(t30_state, details->option.ecm); +#if SPANDSP_RELEASE_DATE >= 20120902 + /* for spandsp shaphots 3.0.0 and higher */ + t30_set_supported_compressions(t30_state, T4_COMPRESSION_T4_1D | T4_COMPRESSION_T4_2D | T4_COMPRESSION_T6); +#else + /* for spandsp release 0.0.6 */ t30_set_supported_compressions(t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); +#endif } static int spandsp_v21_new(struct spandsp_pvt *p) @@ -1256,7 +1291,13 @@ static int load_module(void) } /* prevent logging to stderr */ +#if SPANDSP_RELEASE_DATE >= 20120902 + /* for spandsp shaphots 3.0.0 and higher */ + span_set_message_handler(NULL, NULL); +#else + /* for spandsp release 0.0.6 */ span_set_message_handler(NULL); +#endif return AST_MODULE_LOAD_SUCCESS; }