From 4734904d2d42b29fac5dee8c10a6871abd96d613 Mon Sep 17 00:00:00 2001 From: Dragos Oancea Date: Wed, 10 Mar 2021 15:43:45 +0200 Subject: [PATCH] [mod_amr] introduce new cfg setting force-oa to change between OA/BE when originating, show session in debug logs, update configs. --- conf/testing/autoload_configs/amrwb.conf.xml | 22 +++++++++++++++++ conf/vanilla/autoload_configs/amr.conf.xml | 2 ++ conf/vanilla/autoload_configs/amrwb.conf.xml | 23 ++++++++++++++---- src/mod/codecs/mod_amr/mod_amr.c | 25 +++++++++++++------- 4 files changed, 59 insertions(+), 13 deletions(-) create mode 100644 conf/testing/autoload_configs/amrwb.conf.xml diff --git a/conf/testing/autoload_configs/amrwb.conf.xml b/conf/testing/autoload_configs/amrwb.conf.xml new file mode 100644 index 0000000000..0bd8e6b733 --- /dev/null +++ b/conf/testing/autoload_configs/amrwb.conf.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + diff --git a/conf/vanilla/autoload_configs/amr.conf.xml b/conf/vanilla/autoload_configs/amr.conf.xml index e1c3e3cc1b..19b8cb8891 100644 --- a/conf/vanilla/autoload_configs/amr.conf.xml +++ b/conf/vanilla/autoload_configs/amr.conf.xml @@ -15,5 +15,7 @@ + + diff --git a/conf/vanilla/autoload_configs/amrwb.conf.xml b/conf/vanilla/autoload_configs/amrwb.conf.xml index 9dac3505a4..0bd8e6b733 100644 --- a/conf/vanilla/autoload_configs/amrwb.conf.xml +++ b/conf/vanilla/autoload_configs/amrwb.conf.xml @@ -1,7 +1,22 @@ - - - - + + + + + + + + + diff --git a/src/mod/codecs/mod_amr/mod_amr.c b/src/mod/codecs/mod_amr/mod_amr.c index 04717ca52c..e7c45c7aff 100644 --- a/src/mod/codecs/mod_amr/mod_amr.c +++ b/src/mod/codecs/mod_amr/mod_amr.c @@ -137,6 +137,7 @@ static struct { switch_byte_t volte; /* enable special fmtp for VoLTE compliance */ switch_byte_t adjust_bitrate; int debug; + switch_byte_t force_oa; /*force OA when originating*/ } globals; const int switch_amr_frame_sizes[] = {12,13,15,17,19,20,26,31,5,0,0,0,0,0,0,1}; @@ -179,7 +180,7 @@ static switch_bool_t switch_amr_pack_oa(unsigned char *shift_buf, int n) return SWITCH_TRUE; } -static switch_bool_t switch_amr_info(unsigned char *encoded_buf, int encoded_data_len, int payload_format, char *print_text) +static switch_bool_t switch_amr_info(switch_codec_t *codec, unsigned char *encoded_buf, int encoded_data_len, int payload_format, char *print_text) { uint8_t *tocs; int framesz, index, not_last_frame, q, ft; @@ -196,7 +197,7 @@ static switch_bool_t switch_amr_info(unsigned char *encoded_buf, int encoded_dat tocs = encoded_buf; index = (tocs[0] >> 3) & 0x0f; if (index > SWITCH_AMR_MODES && index != 0xf) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "AMR decoder (OA): Invalid Table Of Contents (TOC): 0x%x\n", index); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "AMR decoder (OA): Invalid Table Of Contents (TOC): 0x%x\n", index); return SWITCH_FALSE; } framesz = switch_amr_frame_sizes[index]; @@ -216,15 +217,15 @@ static switch_bool_t switch_amr_info(unsigned char *encoded_buf, int encoded_dat ft &= ~(1 << 5); /* Frame Type */ index = (shift_tocs[0] >> 3) & 0x0f; if (index > SWITCH_AMR_MODES && index != 0xf) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "AMR decoder (BE): Invalid Table Of Contents (TOC): 0x%x\n", index); + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_ERROR, "AMR decoder (BE): Invalid Table Of Contents (TOC): 0x%x\n", index); return SWITCH_FALSE; } framesz = switch_amr_frame_sizes[index]; } - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s): FT: [0x%x] Q: [0x%x] Frame flag: [%d]\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "%s (%s): FT: [0x%x] Q: [0x%x] Frame flag: [%d]\n", print_text, payload_format ? "OA":"BE", ft, q, not_last_frame); - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s): AMR encoded voice payload sz: [%d] : | encoded_data_len: [%d]\n", + switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(codec->session), SWITCH_LOG_DEBUG, "%s (%s): AMR encoded voice payload sz: [%d] : | encoded_data_len: [%d]\n", print_text, payload_format ? "OA":"BE", framesz, encoded_data_len); return SWITCH_TRUE; @@ -276,8 +277,11 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_ * bandwidth-efficient operation is employed." * */ - switch_clear_flag(context, AMR_OPT_OCTET_ALIGN); - + if (!globals.force_oa) { + switch_clear_flag(context, AMR_OPT_OCTET_ALIGN); + } else { + switch_set_flag(context, AMR_OPT_OCTET_ALIGN); + } if (codec->fmtp_in) { argc = switch_separate_string(codec->fmtp_in, ';', argv, (sizeof(argv) / sizeof(argv[0]))); for (x = 0; x < argc; x++) { @@ -452,7 +456,7 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec, } if (globals.debug) { - switch_amr_info(shift_buf, *encoded_data_len, switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, "AMR encoder"); + switch_amr_info(codec, shift_buf, *encoded_data_len, switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, "AMR encoder"); } return SWITCH_STATUS_SUCCESS; @@ -479,7 +483,7 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec, } if (globals.debug) { - switch_amr_info(buf, encoded_data_len, switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, "AMR decoder"); + switch_amr_info(codec, buf, encoded_data_len, switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, "AMR decoder"); } if (switch_test_flag(context, AMR_OPT_OCTET_ALIGN)) { @@ -643,6 +647,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load) if (!strcasecmp(var, "adjust-bitrate")) { globals.adjust_bitrate = (switch_byte_t) atoi(val); } + if (!strcasecmp(var, "force-oa")) { + globals.force_oa = (switch_byte_t) atoi(val); + } } } }