diff --git a/daemon/main.c b/daemon/main.c index 20b5be5f0..60d4156db 100644 --- a/daemon/main.c +++ b/daemon/main.c @@ -681,6 +681,7 @@ static void init_everything(void) { media_player_init(); dtmf_init(); jitter_buffer_init(); + t38_init(); } diff --git a/daemon/t38.c b/daemon/t38.c index 689775310..9a1a12cce 100644 --- a/daemon/t38.c +++ b/daemon/t38.c @@ -7,11 +7,13 @@ #include #include +#include #include "codec.h" #include "call.h" #include "log.h" #include "str.h" #include "media_player.h" +#include "log_funcs.h" @@ -74,6 +76,17 @@ 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) { + if (level <= SPAN_LOG_PROTOCOL_ERROR) + level = LOG_ERR; + else if (level <= SPAN_LOG_PROTOCOL_WARNING) + level = LOG_WARN; + else + level = LOG_DEBUG; + ilog(level, "SpanDSP: %s", text); +} + + // call is locked in R or W static int t38_gateway_handler(t38_core_state_t *stat, void *user_data, const uint8_t *b, int len, int count) { struct t38_gateway *tg = user_data; @@ -250,6 +263,10 @@ static void t38_pcm_player(struct media_player *mp) { if (!tg) return; + if (tg->pcm_media && tg->pcm_media->streams.head + && ((struct packet_stream *) tg->pcm_media->streams.head->data)->selected_sfd) + log_info_stream_fd(((struct packet_stream *) tg->pcm_media->streams.head->data)->selected_sfd); + ilog(LOG_DEBUG, "Generating T.38 PCM samples"); mutex_lock(&tg->lock); @@ -301,6 +318,16 @@ static void __t38_options_normalise(struct t38_options *opts) { opts->max_datagram = 0x3fff; } +static int span_log_level_map(int level) { + if (level <= LOG_ERR) + level = SPAN_LOG_PROTOCOL_ERROR; + else if (level < LOG_DEBUG) + level = SPAN_LOG_PROTOCOL_WARNING; + else + level = SPAN_LOG_DEBUG_3; + return level; +} + // call is locked in W int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, const struct t38_options *options) @@ -375,6 +402,10 @@ int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, t38_set_jbig_transcoding(t38, opts.transcoding_jbig); 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); + span_log_set_level(ls, span_log_level_map(get_log_level())); + packet_sequencer_init(&tg->sequencer, (GDestroyNotify) __udptl_packet_free); tg->sequencer.seq = 0; @@ -722,5 +753,10 @@ void t38_gateway_stop(struct t38_gateway *tg) { } +void t38_init(void) { + span_set_message_handler(NULL); +} + + #endif diff --git a/include/t38.h b/include/t38.h index 857eb8378..19d8b73cc 100644 --- a/include/t38.h +++ b/include/t38.h @@ -67,6 +67,8 @@ struct t38_gateway { +void t38_init(void); + int t38_gateway_pair(struct call_media *t38_media, struct call_media *pcm_media, const struct t38_options *); void t38_gateway_start(struct t38_gateway *); int t38_gateway_input_samples(struct t38_gateway *, int16_t amp[], int len); @@ -87,6 +89,7 @@ INLINE void t38_gateway_put(struct t38_gateway **tp) { #include "compat.h" // stubs +INLINE void t38_init(void) { } INLINE void t38_gateway_start(struct t38_gateway *tg) { } INLINE void t38_gateway_stop(struct t38_gateway *tg) { } INLINE void t38_gateway_put(struct t38_gateway **tp) { }