From 1147f856c08e7e8d076d3cb0a5161de13e90f94b Mon Sep 17 00:00:00 2001 From: Richard Fuchs Date: Mon, 10 Aug 2020 10:02:15 -0400 Subject: [PATCH] TT#14008 support building against FreeSwitch version of SpanDSP Change-Id: I472161e6368886240a4ba08e269542fd3f6e4d41 --- daemon/.gitignore | 1 + daemon/Makefile | 2 +- daemon/t38.c | 7 ++++--- include/t38.h | 1 + lib/common.Makefile | 2 +- lib/dtmf_rx_fillin-01.h | 1 + lib/dtmf_rx_fillin-02.h | 1 + lib/spandsp_logging-01.h | 8 ++++++++ lib/spandsp_logging-02.h | 8 ++++++++ lib/spandsp_logging-test.c | 20 ++++++++++++++++++++ t/.gitignore | 1 + t/Makefile | 2 +- t/spandsp_recv_fax_pcm.c | 12 +++++++++--- t/spandsp_recv_fax_t38.c | 8 +++++++- t/spandsp_send_fax_pcm.c | 12 +++++++++--- t/spandsp_send_fax_t38.c | 8 +++++++- t/test-dtmf-detect.c | 1 + 17 files changed, 81 insertions(+), 14 deletions(-) create mode 100644 lib/spandsp_logging-01.h create mode 100644 lib/spandsp_logging-02.h create mode 100644 lib/spandsp_logging-test.c diff --git a/daemon/.gitignore b/daemon/.gitignore index 5d1fc90c9..1b18e6eac 100644 --- a/daemon/.gitignore +++ b/daemon/.gitignore @@ -19,3 +19,4 @@ dtmflib.c *-test dtmf_rx_fillin.h *-test.c +spandsp_logging.h diff --git a/daemon/Makefile b/daemon/Makefile index d5c83938e..c15730cc2 100644 --- a/daemon/Makefile +++ b/daemon/Makefile @@ -140,7 +140,7 @@ MANS= $(PODS:.pod=.8) include ../lib/common.Makefile ifeq ($(with_transcoding),yes) -.depend: dtmf_rx_fillin.h +.depend: dtmf_rx_fillin.h spandsp_logging.h endif include .depend diff --git a/daemon/t38.c b/daemon/t38.c index 1162db55a..69051c684 100644 --- a/daemon/t38.c +++ b/daemon/t38.c @@ -8,6 +8,7 @@ #include #include #include +#include "spandsp_logging.h" #include "codec.h" #include "call.h" #include "log.h" @@ -76,7 +77,7 @@ static void g_string_null_extend(GString *s, size_t len) { memset(s->str + oldb, 0, newb); } -static void spandsp_logging_func(int level, const char *text) { +static void spandsp_logging_func(SPAN_LOG_ARGS) { if (level <= SPAN_LOG_PROTOCOL_ERROR) level = LOG_ERR; else if (level <= SPAN_LOG_PROTOCOL_WARNING) @@ -407,7 +408,7 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, t38_set_max_datagram_size(t38, opts.max_ifp); logging_state_t *ls = t38_gateway_get_logging_state(tg->gw); - span_log_set_message_handler(ls, spandsp_logging_func); + my_span_set_log(ls, spandsp_logging_func); span_log_set_level(ls, span_log_level_map(get_log_level())); packet_sequencer_init(&tg->sequencer, (GDestroyNotify) __udptl_packet_free); @@ -769,7 +770,7 @@ void t38_gateway_stop(struct t38_gateway *tg) { void t38_init(void) { - span_set_message_handler(NULL); + my_span_mh(NULL); } diff --git a/include/t38.h b/include/t38.h index a36dab418..d95716862 100644 --- a/include/t38.h +++ b/include/t38.h @@ -33,6 +33,7 @@ struct t38_options { #include #include +#include #include #include #include diff --git a/lib/common.Makefile b/lib/common.Makefile index 0abed7cc5..986fa60e0 100644 --- a/lib/common.Makefile +++ b/lib/common.Makefile @@ -11,7 +11,7 @@ debug: dep: .depend -BUILD_TEST_ALTS = fix_frame_channel_layout.h dtmf_rx_fillin.h +BUILD_TEST_ALTS = fix_frame_channel_layout.h dtmf_rx_fillin.h spandsp_logging.h clean: rm -f $(OBJS) $(TARGET) $(LIBSRCS) $(DAEMONSRCS) $(MANS) $(ADD_CLEAN) .depend core core.* diff --git a/lib/dtmf_rx_fillin-01.h b/lib/dtmf_rx_fillin-01.h index ce062b0e1..42330c7ff 100644 --- a/lib/dtmf_rx_fillin-01.h +++ b/lib/dtmf_rx_fillin-01.h @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/lib/dtmf_rx_fillin-02.h b/lib/dtmf_rx_fillin-02.h index 0d5528b64..34efcbb89 100644 --- a/lib/dtmf_rx_fillin-02.h +++ b/lib/dtmf_rx_fillin-02.h @@ -1,5 +1,6 @@ #include #include +#include #include #include #include diff --git a/lib/spandsp_logging-01.h b/lib/spandsp_logging-01.h new file mode 100644 index 000000000..c3d53c207 --- /dev/null +++ b/lib/spandsp_logging-01.h @@ -0,0 +1,8 @@ +#define SPAN_LOG_ARGS int level, const char *text +#define PHASE_E_HANDLER_ARGS t30_state_t *s, void *user_data, int result +INLINE void my_span_set_log(logging_state_t *ls, message_handler_func_t h) { + span_log_set_message_handler(ls, h); +} +INLINE void my_span_mh(message_handler_func_t h) { + span_set_message_handler(h); +} diff --git a/lib/spandsp_logging-02.h b/lib/spandsp_logging-02.h new file mode 100644 index 000000000..bcc5368fa --- /dev/null +++ b/lib/spandsp_logging-02.h @@ -0,0 +1,8 @@ +#define SPAN_LOG_ARGS void *user_data, int level, const char *text +#define PHASE_E_HANDLER_ARGS void *user_data, int result +INLINE void my_span_set_log(logging_state_t *ls, message_handler_func_t h) { + span_log_set_message_handler(ls, h, NULL); +} +INLINE void my_span_mh(message_handler_func_t h) { + span_set_message_handler(h, NULL); +} diff --git a/lib/spandsp_logging-test.c b/lib/spandsp_logging-test.c new file mode 100644 index 000000000..698c9c405 --- /dev/null +++ b/lib/spandsp_logging-test.c @@ -0,0 +1,20 @@ +#include +#include +#include +#include +#include +#include +#include "compat.h" +#include "spandsp_logging.h" + +void logfunc(SPAN_LOG_ARGS) { + return; +} + +int main(void) { + return 0; + logging_state_t *ls = NULL; + my_span_set_log(ls, logfunc); + my_span_mh(NULL); + return 0; +} diff --git a/t/.gitignore b/t/.gitignore index 74e4d8496..453cf88cc 100644 --- a/t/.gitignore +++ b/t/.gitignore @@ -59,3 +59,4 @@ spandsp_recv_fax_pcm spandsp_recv_fax_t38 spandsp_send_fax_pcm spandsp_send_fax_t38 +spandsp_logging.h diff --git a/t/Makefile b/t/Makefile index 027426676..005c45f12 100644 --- a/t/Makefile +++ b/t/Makefile @@ -153,5 +153,5 @@ tests-preload.so: tests-preload.c $(CC) -g -D_GNU_SOURCE -std=c99 -o $@ -Wall -shared -fPIC $< -ldl ifeq ($(with_transcoding),yes) -.depend: dtmf_rx_fillin.h +.depend: dtmf_rx_fillin.h spandsp_logging.h endif diff --git a/t/spandsp_recv_fax_pcm.c b/t/spandsp_recv_fax_pcm.c index dc09c5c00..ab9b3f467 100644 --- a/t/spandsp_recv_fax_pcm.c +++ b/t/spandsp_recv_fax_pcm.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,11 +12,16 @@ #include #include #include +#include "compat.h" +#include "spandsp_logging.h" #define SAMPLES_PER_CHUNK 160 #define MICROSECONDS_PER_CHUNK 20000 +#ifndef FALSE +# define FALSE false +#endif // from ITU G.191 @@ -72,7 +78,7 @@ void alaw_expand (size_t lseg, uint8_t *logbuf, int16_t *linbuf) { int done = 0; -static void phase_e_handler(t30_state_t *s, void *user_data, int result) { +static void phase_e_handler(PHASE_E_HANDLER_ARGS) { fprintf(stderr, "recv: phase E result %i\n", result); assert(result == T30_ERR_OK); done = 1; @@ -101,8 +107,8 @@ int main(int argc, char **argv) { t30_set_rx_file(t30, output_file_name, -1); t30_set_phase_e_handler(t30, phase_e_handler, NULL); t30_set_ecm_capability(t30, use_ecm); - if (use_ecm) - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); +// if (use_ecm) +// t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); t30_set_minimum_scan_line_time(t30, 40); struct timeval now, next; diff --git a/t/spandsp_recv_fax_t38.c b/t/spandsp_recv_fax_t38.c index 709117f1e..c11e04e96 100644 --- a/t/spandsp_recv_fax_t38.c +++ b/t/spandsp_recv_fax_t38.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -14,10 +15,15 @@ #include #include #include +#include "compat.h" +#include "spandsp_logging.h" #define SAMPLES_PER_CHUNK 160 +#ifndef FALSE +# define FALSE false +#endif static int packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) { @@ -38,7 +44,7 @@ static int packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *b return 0; } -static void phase_e_handler(t30_state_t *s, void *user_data, int result) { +static void phase_e_handler(PHASE_E_HANDLER_ARGS) { fprintf(stderr, "phase E result %i\n", result); assert(result == T30_ERR_OK); } diff --git a/t/spandsp_send_fax_pcm.c b/t/spandsp_send_fax_pcm.c index 434916597..42703d415 100644 --- a/t/spandsp_send_fax_pcm.c +++ b/t/spandsp_send_fax_pcm.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -11,11 +12,16 @@ #include #include #include +#include "compat.h" +#include "spandsp_logging.h" #define SAMPLES_PER_CHUNK 160 #define MICROSECONDS_PER_CHUNK 20000 +#ifndef TRUE +# define TRUE true +#endif // from ITU G.191 @@ -72,7 +78,7 @@ void alaw_expand (size_t lseg, uint8_t *logbuf, int16_t *linbuf) { int done = 0; -static void phase_e_handler(t30_state_t *s, void *user_data, int result) { +static void phase_e_handler(PHASE_E_HANDLER_ARGS) { fprintf(stderr, "send: phase E result %i\n", result); assert(result == T30_ERR_OK); done = 1; @@ -101,8 +107,8 @@ int main(int argc, char **argv) { t30_set_tx_file(t30, input_file_name, -1, -1); t30_set_phase_e_handler(t30, phase_e_handler, NULL); t30_set_ecm_capability(t30, use_ecm); - if (use_ecm) - t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); +// if (use_ecm) +// t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); t30_set_minimum_scan_line_time(t30, 40); struct timeval now, next; diff --git a/t/spandsp_send_fax_t38.c b/t/spandsp_send_fax_t38.c index dad85bdbf..cec221518 100644 --- a/t/spandsp_send_fax_t38.c +++ b/t/spandsp_send_fax_t38.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #include #include @@ -14,10 +15,15 @@ #include #include #include +#include "compat.h" +#include "spandsp_logging.h" #define SAMPLES_PER_CHUNK 160 +#ifndef TRUE +# define TRUE true +#endif static int packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) { @@ -40,7 +46,7 @@ static int packet_handler(t38_core_state_t *s, void *user_data, const uint8_t *b int g_done = 0; -static void phase_e_handler(t30_state_t *s, void *user_data, int result) { +static void phase_e_handler(PHASE_E_HANDLER_ARGS) { fprintf(stderr, "phase E result %i\n", result); assert(result == T30_ERR_OK); g_done = 1; diff --git a/t/test-dtmf-detect.c b/t/test-dtmf-detect.c index 788b99299..6aeb9f0a2 100644 --- a/t/test-dtmf-detect.c +++ b/t/test-dtmf-detect.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include