[Asterisk-code-review] res_fax_spandsp: Add spandsp 3.0.0+ compatibility (asterisk[18])

Dustin Marquess asteriskteam at digium.com
Fri Nov 19 02:15:18 CST 2021


Dustin Marquess has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/17554 )


Change subject: res_fax_spandsp: Add spandsp 3.0.0+ compatibility
......................................................................

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
---
A doc/CHANGES-staging/res_fax_spandsp.txt
M res/res_fax_spandsp.c
2 files changed, 46 insertions(+), 2 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/54/17554/1

diff --git a/doc/CHANGES-staging/res_fax_spandsp.txt b/doc/CHANGES-staging/res_fax_spandsp.txt
new file mode 100644
index 0000000..4ad351f
--- /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 030dfc0..24fcff5 100644
--- a/res/res_fax_spandsp.c
+++ b/res/res_fax_spandsp.c
@@ -167,10 +167,17 @@
 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 @@
  * 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 @@
  *
  * \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 @@
 		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_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 @@
 	}
 
 	/* 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;
 }

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17554
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I3bd74550604ebcf0304528d647fa39abc62fbaa1
Gerrit-Change-Number: 17554
Gerrit-PatchSet: 1
Gerrit-Owner: Dustin Marquess <jailbird at fdf.net>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20211119/c9dfedf9/attachment-0001.html>


More information about the asterisk-code-review mailing list