Merge pull request #1103 from dragos-oancea/amr_sync_changes_from_amrwb

[mod_amr] introduce new cfg setting force-oa to change between OA/BE when originating, show session in debug logs, update configs
This commit is contained in:
Andrey Volk
2021-03-10 23:34:36 +03:00
committed by GitHub
4 changed files with 59 additions and 13 deletions

View File

@@ -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);
}
}
}
}