mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-07-24 21:22:09 +00:00
FS-9924: Removed extra space in source files
This commit is contained in:
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -42,13 +42,13 @@ extern const int switch_amr_frame_sizes[];
|
||||
/* Bandwidth Efficient AMR-NB */
|
||||
/* https://tools.ietf.org/html/rfc4867#page-17 */
|
||||
|
||||
extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n)
|
||||
extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n)
|
||||
{
|
||||
uint8_t save_toc, ft;
|
||||
|
||||
save_toc = shift_buf[1];
|
||||
|
||||
/* we must convert OA TOC -> BE TOC */
|
||||
/* we must convert OA TOC -> BE TOC */
|
||||
/* OA TOC
|
||||
0 1 2 3 4 5 6 7
|
||||
+-+-+-+-+-+-+-+-+
|
||||
@@ -68,8 +68,8 @@ extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n)
|
||||
+-+-+-+-+-+-+
|
||||
|F| FT |Q|
|
||||
+-+-+-+-+-+-+
|
||||
F = 0 , FT = XXXX , Q = 1
|
||||
eg: Frame Types (FT): ftp://www.3gpp.org/tsg_sa/TSG_SA/TSGS_04/Docs/PDF/SP-99253.pdf - table 1a
|
||||
F = 0 , FT = XXXX , Q = 1
|
||||
eg: Frame Types (FT): ftp://www.3gpp.org/tsg_sa/TSG_SA/TSGS_04/Docs/PDF/SP-99253.pdf - table 1a
|
||||
*/
|
||||
|
||||
ft = save_toc >> 3 ; /* drop Q, P1, P2 */
|
||||
@@ -86,19 +86,19 @@ extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n)
|
||||
shift_buf[1] |= 1 << 7;
|
||||
} else {
|
||||
/* reset last bit of TOC instead of P2 */
|
||||
shift_buf[1] &= ~(1 << 7);
|
||||
shift_buf[1] &= ~(1 << 7);
|
||||
}
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
|
||||
extern switch_bool_t switch_amr_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len)
|
||||
extern switch_bool_t switch_amr_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len)
|
||||
{
|
||||
int framesz, index, ft;
|
||||
uint8_t shift_tocs[2] = {0x00, 0x00};
|
||||
uint8_t *shift_buf;
|
||||
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
/* shift for BE */
|
||||
switch_amr_array_lshift(4, shift_tocs, 2);
|
||||
ft = shift_tocs[0] >> 3;
|
||||
@@ -117,7 +117,7 @@ extern switch_bool_t switch_amr_unpack_be(unsigned char *encoded_buf, uint8_t *t
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -37,10 +37,10 @@
|
||||
#define __AMR_BE_H__
|
||||
|
||||
/* Bandwidth Efficient AMR */
|
||||
extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n);
|
||||
extern switch_bool_t switch_amr_pack_be(unsigned char *shift_buf, int n);
|
||||
extern switch_bool_t switch_amr_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Paolo Missiaggia <paolo.missiaggia@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -61,7 +61,7 @@ extern int switch_amr_array_lshift(uint8_t lshift, uint8_t *buf, int a_len)
|
||||
buf[i] = ((buf[i] & first_byte) << lshift);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Paolo Missiaggia <paolo.missiaggia@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -42,7 +42,7 @@
|
||||
*/
|
||||
extern int switch_amr_array_lshift(uint8_t lshift, uint8_t *buf, int a_len);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
@@ -48,9 +48,9 @@ SWITCH_MODULE_DEFINITION(mod_amr, mod_amr_load, NULL, NULL);
|
||||
#include "amr_be.h"
|
||||
/*
|
||||
* Check section 8.1 of rfc3267 for possible sdp options.
|
||||
*
|
||||
* SDP Example
|
||||
*
|
||||
*
|
||||
* SDP Example
|
||||
*
|
||||
* a=fmtp:97 mode-set=0,2,5,7; mode-change-period=2; mode-change-neighbor=1
|
||||
*
|
||||
* Class A total speech
|
||||
@@ -176,7 +176,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(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;
|
||||
@@ -185,30 +185,30 @@ static switch_bool_t switch_amr_info(unsigned char *encoded_buf, int encoded_dat
|
||||
if (!encoded_buf) {
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* payload format can be OA (octed-aligned) or BE (bandwidth efficient)*/
|
||||
if (payload_format) {
|
||||
/* OA */
|
||||
encoded_buf++; /* CMR skip */
|
||||
tocs = encoded_buf;
|
||||
tocs = encoded_buf;
|
||||
index = (tocs[0] >> 3) & 0x0f;
|
||||
if (index > SWITCH_AMR_MODES) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "AMR decoder (OA): Invalid Table Of Contents (TOC): 0x%x\n", index);
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
framesz = switch_amr_frame_sizes[index];
|
||||
not_last_frame = (tocs[0] >> 7) & 1;
|
||||
q = (tocs[0] >> 2) & 1;
|
||||
not_last_frame = (tocs[0] >> 7) & 1;
|
||||
q = (tocs[0] >> 2) & 1;
|
||||
ft = tocs[0] >> 3 ;
|
||||
ft &= ~(1 << 5); /* Frame Type*/
|
||||
|
||||
} else {
|
||||
/* BE */
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
/* shift for BE */
|
||||
switch_amr_array_lshift(4, shift_tocs, 2);
|
||||
not_last_frame = (shift_tocs[0] >> 7) & 1;
|
||||
q = (shift_tocs[0] >> 2) & 1;
|
||||
not_last_frame = (shift_tocs[0] >> 7) & 1;
|
||||
q = (shift_tocs[0] >> 2) & 1;
|
||||
ft = shift_tocs[0] >> 3 ;
|
||||
ft &= ~(1 << 5); /* Frame Type */
|
||||
index = (shift_tocs[0] >> 3) & 0x0f;
|
||||
@@ -219,9 +219,9 @@ static switch_bool_t switch_amr_info(unsigned char *encoded_buf, int encoded_dat
|
||||
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_LOG, 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_LOG, 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;
|
||||
@@ -257,8 +257,8 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
|
||||
memset(&codec_fmtp, '\0', sizeof(struct switch_codec_fmtp));
|
||||
codec_fmtp.private_info = &amr_codec_settings;
|
||||
|
||||
/* "mode" may mean two different things:
|
||||
* "Octed Aligned" or "Bandwidth Efficient" encoding mode ,
|
||||
/* "mode" may mean two different things:
|
||||
* "Octed Aligned" or "Bandwidth Efficient" encoding mode ,
|
||||
* or the actual bitrate which is set with FMTP param "mode-set". */
|
||||
/* https://tools.ietf.org/html/rfc4867 */
|
||||
|
||||
@@ -266,7 +266,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
|
||||
/* bitrate = value read from config file or default mode 7 */
|
||||
context->enc_mode = globals.default_bitrate;
|
||||
|
||||
/* set octet-align = 0 - it must be 0 by default when there is no "octet-align" param in FMTP, per RFC :
|
||||
/* set octet-align = 0 - it must be 0 by default when there is no "octet-align" param in FMTP, per RFC :
|
||||
*
|
||||
* "octet-align: Permissible values are 0 and 1. If 1, octet-aligned
|
||||
* operation SHALL be used. If 0 or if not present,
|
||||
@@ -288,7 +288,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
|
||||
if (!strcasecmp(data, "octet-align")) {
|
||||
if (atoi(arg)) {
|
||||
switch_set_flag(context, AMR_OPT_OCTET_ALIGN);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(data, "mode-change-neighbor")) {
|
||||
if (atoi(arg)) {
|
||||
switch_set_flag(context, AMR_OPT_MODE_CHANGE_NEIGHBOR);
|
||||
@@ -346,7 +346,7 @@ static switch_status_t switch_amr_init(switch_codec_t *codec, switch_codec_flag_
|
||||
context->enc_mode);
|
||||
} else {
|
||||
/* some UEs reject the call with 488 if mode-change-capability is not 2 */
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d; max-red=0; mode-change-capability=2",
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d; max-red=0; mode-change-capability=2",
|
||||
switch_test_flag(context, AMR_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
|
||||
}
|
||||
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
|
||||
@@ -412,14 +412,14 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec,
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
/* set CMR + TOC (F + 3 bits of FT) , 1111 = CMR: No mode request */
|
||||
*(switch_byte_t *) encoded_data = 0xf0;
|
||||
/* set CMR + TOC (F + 3 bits of FT) , 1111 = CMR: No mode request */
|
||||
*(switch_byte_t *) encoded_data = 0xf0;
|
||||
*encoded_data_len = n;
|
||||
|
||||
if (switch_test_flag(context, AMR_OPT_OCTET_ALIGN)) {
|
||||
/* this function does nothing for now - the payload is already OA
|
||||
/* this function does nothing for now - the payload is already OA
|
||||
as it comes out of the encoding function */
|
||||
switch_amr_pack_oa(shift_buf, n);
|
||||
switch_amr_pack_oa(shift_buf, n);
|
||||
*encoded_data_len = n + 1;
|
||||
} else {
|
||||
switch_amr_pack_be(shift_buf, n);
|
||||
@@ -427,7 +427,7 @@ static switch_status_t switch_amr_encode(switch_codec_t *codec,
|
||||
/* mode 1 = 103 speech bits -> 104 bytes - 1 padding bit */
|
||||
/* mode 5 = 159 speech bits -> 160 bytes - 1 padding bit */
|
||||
if ((context->enc_mode == 5 ) || (context->enc_mode == 1) || (context->enc_mode == 0)) {
|
||||
/* modes 0,1 and 5 have only 1 padding bit and due to shifting
|
||||
/* modes 0,1 and 5 have only 1 padding bit and due to shifting
|
||||
* we may have an extra 0 byte at the end of the voice payload (bit stuffing) */
|
||||
if (shift_buf[n-1] != 0x0) {
|
||||
*encoded_data_len = n + 1;
|
||||
@@ -456,7 +456,7 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
|
||||
#else
|
||||
struct amr_context *context = codec->private_info;
|
||||
unsigned char *buf = encoded_data;
|
||||
uint8_t tmp[SWITCH_AMR_OUT_MAX_SIZE];
|
||||
uint8_t tmp[SWITCH_AMR_OUT_MAX_SIZE];
|
||||
|
||||
if (!context) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -466,12 +466,12 @@ static switch_status_t switch_amr_decode(switch_codec_t *codec,
|
||||
switch_amr_info(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)) {
|
||||
if (switch_test_flag(context, AMR_OPT_OCTET_ALIGN)) {
|
||||
/* Octed Aligned */
|
||||
if (!switch_amr_unpack_oa(buf, tmp, encoded_data_len)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
/* Bandwidth Efficient */
|
||||
if (!switch_amr_unpack_be(buf, tmp, encoded_data_len)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -514,32 +514,32 @@ static switch_status_t switch_amr_control(switch_codec_t *codec,
|
||||
if (!strcasecmp(cmd, "increase")) {
|
||||
if (context->enc_mode < SWITCH_AMR_MODES - 1) {
|
||||
int mode_step = 2; /*this is the mode, not the actual bitrate*/
|
||||
context->enc_mode = context->enc_mode + mode_step;
|
||||
context->enc_mode = context->enc_mode + mode_step;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMR encoder: Adjusting mode to %d (increase)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(cmd, "decrease")) {
|
||||
if (context->enc_mode > 0) {
|
||||
int mode_step = 2; /*this is the mode, not the actual bitrate*/
|
||||
context->enc_mode = context->enc_mode - mode_step;
|
||||
context->enc_mode = context->enc_mode - mode_step;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMR encoder: Adjusting mode to %d (decrease)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(cmd, "default")) {
|
||||
context->enc_mode = globals.default_bitrate;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMR encoder: Adjusting mode to %d (default)\n", context->enc_mode);
|
||||
}
|
||||
} else {
|
||||
/*minimum bitrate (AMR mode)*/
|
||||
context->enc_mode = 0;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMR encoder: Adjusting mode to %d (minimum)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
@@ -547,14 +547,14 @@ static switch_status_t switch_amr_control(switch_codec_t *codec,
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
#endif
|
||||
}
|
||||
|
||||
static char *generate_fmtp(switch_memory_pool_t *pool , int octet_align)
|
||||
{
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "octet-align=%d; ", octet_align);
|
||||
@@ -567,7 +567,7 @@ static char *generate_fmtp(switch_memory_pool_t *pool , int octet_align)
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "max-red=0; mode-change-capability=2; ");
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
if (end_of(buf) == ' ') {
|
||||
*(end_of_p(buf) - 1) = '\0';
|
||||
}
|
||||
@@ -591,11 +591,11 @@ SWITCH_STANDARD_API(mod_amr_debug)
|
||||
stream->write_function(stream, "AMR Debug: off\n");
|
||||
} else {
|
||||
stream->write_function(stream, "-USAGE: %s\n", AMRWB_DEBUG_SYNTAX);
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* Registration */
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load)
|
||||
@@ -640,7 +640,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load)
|
||||
|
||||
switch_console_set_complete("add amr_debug on");
|
||||
switch_console_set_complete("add amr_debug off");
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SWITCH_ADD_CODEC(codec_interface, "AMR / Octet Aligned");
|
||||
|
||||
@@ -657,9 +657,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load)
|
||||
320, /* number of bytes per frame decompressed */
|
||||
#ifndef AMR_PASSTHROUGH
|
||||
SWITCH_AMR_OUT_MAX_SIZE, /* number of bytes per frame compressed */
|
||||
#else
|
||||
#else
|
||||
0, /* number of bytes per frame compressed */
|
||||
#endif
|
||||
#endif
|
||||
1, /* number of channels represented */
|
||||
1, /* number of frames per network packet */
|
||||
switch_amr_init, /* function to initialize a codec handle using this implementation */
|
||||
@@ -682,9 +682,9 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amr_load)
|
||||
320, /* number of bytes per frame decompressed */
|
||||
#ifndef AMR_PASSTHROUGH
|
||||
SWITCH_AMR_OUT_MAX_SIZE, /* number of bytes per frame compressed */
|
||||
#else
|
||||
#else
|
||||
0, /* number of bytes per frame compressed */
|
||||
#endif
|
||||
#endif
|
||||
1, /* number of channels represented */
|
||||
1, /* number of frames per network packet */
|
||||
switch_amr_init, /* function to initialize a codec handle using this implementation */
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -43,13 +43,13 @@ extern const int switch_amrwb_frame_sizes[];
|
||||
/* https://tools.ietf.org/html/rfc4867#page-17 */
|
||||
|
||||
/* this works the same as in AMR NB*/
|
||||
extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n)
|
||||
extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n)
|
||||
{
|
||||
uint8_t save_toc, ft;
|
||||
|
||||
save_toc = shift_buf[1];
|
||||
|
||||
/* we must convert OA TOC -> BE TOC */
|
||||
/* we must convert OA TOC -> BE TOC */
|
||||
/* OA TOC
|
||||
0 1 2 3 4 5 6 7
|
||||
+-+-+-+-+-+-+-+-+
|
||||
@@ -69,8 +69,8 @@ extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n)
|
||||
+-+-+-+-+-+-+
|
||||
|F| FT |Q|
|
||||
+-+-+-+-+-+-+
|
||||
F = 0 , FT = XXXX , Q = 1
|
||||
eg: Frame Types (FT): ftp://www.3gpp.org/tsg_sa/TSG_SA/TSGS_04/Docs/PDF/SP-99253.pdf - table 1a
|
||||
F = 0 , FT = XXXX , Q = 1
|
||||
eg: Frame Types (FT): ftp://www.3gpp.org/tsg_sa/TSG_SA/TSGS_04/Docs/PDF/SP-99253.pdf - table 1a
|
||||
*/
|
||||
|
||||
ft = save_toc >> 3 ; /* drop Q, P1, P2 */
|
||||
@@ -87,19 +87,19 @@ extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n)
|
||||
shift_buf[1] |= 1 << 7;
|
||||
} else {
|
||||
/* reset last bit of TOC instead of P2 */
|
||||
shift_buf[1] &= ~(1 << 7);
|
||||
shift_buf[1] &= ~(1 << 7);
|
||||
}
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
|
||||
extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len)
|
||||
extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len)
|
||||
{
|
||||
int framesz, index, ft;
|
||||
uint8_t shift_tocs[2] = {0x00, 0x00};
|
||||
uint8_t *shift_buf;
|
||||
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
/* shift for BE */
|
||||
switch_amr_array_lshift(4, shift_tocs, 2);
|
||||
ft = shift_tocs[0] >> 3;
|
||||
@@ -118,7 +118,7 @@ extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -37,10 +37,10 @@
|
||||
#define __AMRWB_BE_H__
|
||||
|
||||
/* Bandwidth Efficient AMR-WB */
|
||||
extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n);
|
||||
extern switch_bool_t switch_amrwb_pack_be(unsigned char *shift_buf, int n);
|
||||
extern switch_bool_t switch_amrwb_unpack_be(unsigned char *encoded_buf, uint8_t *tmp, int encoded_len);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Paolo Missiaggia <paolo.missiaggia@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -61,7 +61,7 @@ extern int switch_amr_array_lshift(uint8_t lshift, uint8_t *buf, int a_len)
|
||||
buf[i] = ((buf[i] & first_byte) << lshift);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2016, Athonet (www.athonet.com)
|
||||
* Paolo Missiaggia <paolo.missiaggia@athonet.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -42,7 +42,7 @@
|
||||
*/
|
||||
extern int switch_amr_array_lshift(uint8_t lshift, uint8_t *buf, int a_len);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
* Dragos Oancea <dragos.oancea@athonet.com>
|
||||
@@ -117,7 +117,7 @@ static switch_bool_t switch_amrwb_unpack_oa(unsigned char *buf, uint8_t *tmp, in
|
||||
}
|
||||
tmp[0] = tocs[0];
|
||||
memcpy(&tmp[1], buf, framesz);
|
||||
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ static switch_bool_t switch_amrwb_pack_oa(unsigned char *shift_buf, int n)
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
|
||||
static switch_bool_t switch_amrwb_info(unsigned char *encoded_buf, int encoded_data_len, int payload_format, char *print_text)
|
||||
static switch_bool_t switch_amrwb_info(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;
|
||||
@@ -136,29 +136,29 @@ static switch_bool_t switch_amrwb_info(unsigned char *encoded_buf, int encoded_d
|
||||
if (!encoded_buf) {
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
|
||||
|
||||
/* payload format can be OA (octed-aligned) or BE (bandwidth efficient)*/
|
||||
if (payload_format) {
|
||||
/* OA */
|
||||
encoded_buf++; /* CMR skip */
|
||||
tocs = encoded_buf;
|
||||
tocs = encoded_buf;
|
||||
index = (tocs[0] >> 3) & 0x0f;
|
||||
if (index > SWITCH_AMRWB_MODES) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "AMRWB decoder (OA): Invalid TOC 0x%x\n", index);
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
framesz = switch_amrwb_frame_sizes[index];
|
||||
not_last_frame = (tocs[0] >> 7) & 1;
|
||||
q = (tocs[0] >> 2) & 1;
|
||||
not_last_frame = (tocs[0] >> 7) & 1;
|
||||
q = (tocs[0] >> 2) & 1;
|
||||
ft = tocs[0] >> 3;
|
||||
ft &= ~(1 << 5); /* Frame Type */
|
||||
} else {
|
||||
/* BE */
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
memcpy(shift_tocs, encoded_buf, 2);
|
||||
/* shift for BE */
|
||||
switch_amr_array_lshift(4, shift_tocs, 2);
|
||||
not_last_frame = (shift_tocs[0] >> 7) & 1;
|
||||
q = (shift_tocs[0] >> 2) & 1;
|
||||
not_last_frame = (shift_tocs[0] >> 7) & 1;
|
||||
q = (shift_tocs[0] >> 2) & 1;
|
||||
ft = shift_tocs[0] >> 3;
|
||||
ft &= ~(1 << 5); /* Frame Type */
|
||||
index = (shift_tocs[0] >> 3) & 0x0f;
|
||||
@@ -169,13 +169,13 @@ static switch_bool_t switch_amrwb_info(unsigned char *encoded_buf, int encoded_d
|
||||
framesz = switch_amrwb_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_LOG, 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): AMRWB encoded voice payload sz: [%d] : | encoded_data_len: [%d]\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s (%s): AMRWB encoded voice payload sz: [%d] : | encoded_data_len: [%d]\n",
|
||||
print_text, payload_format ? "OA":"BE", framesz, encoded_data_len);
|
||||
|
||||
return SWITCH_TRUE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
|
||||
@@ -200,8 +200,8 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
|
||||
return SWITCH_STATUS_FALSE;
|
||||
} else {
|
||||
|
||||
/* "mode" may mean two different things:
|
||||
* "Octed Aligned" or "Bandwidth Efficient" encoding mode ,
|
||||
/* "mode" may mean two different things:
|
||||
* "Octed Aligned" or "Bandwidth Efficient" encoding mode ,
|
||||
* or the actual bitrate which is set with FMTP param "mode-set". */
|
||||
/* https://tools.ietf.org/html/rfc4867 */
|
||||
|
||||
@@ -279,10 +279,10 @@ static switch_status_t switch_amrwb_init(switch_codec_t *codec, switch_codec_fla
|
||||
}
|
||||
|
||||
if (!globals.volte) {
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d",
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d",
|
||||
switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
|
||||
} else {
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d; max-red=0; mode-change-capability=2",
|
||||
switch_snprintf(fmtptmp, sizeof(fmtptmp), "octet-align=%d; mode-set=%d; max-red=0; mode-change-capability=2",
|
||||
switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0, context->enc_mode);
|
||||
}
|
||||
codec->fmtp_out = switch_core_strdup(codec->memory_pool, fmtptmp);
|
||||
@@ -346,12 +346,12 @@ static switch_status_t switch_amrwb_encode(switch_codec_t *codec,
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
/* set CMR + TOC (F + 3 bits of FT), 1111 = CMR: No mode request */
|
||||
/* set CMR + TOC (F + 3 bits of FT), 1111 = CMR: No mode request */
|
||||
*(switch_byte_t *) encoded_data = 0xf0;
|
||||
*encoded_data_len = n;
|
||||
|
||||
if (switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN)) {
|
||||
switch_amrwb_pack_oa(shift_buf, n); /* the payload is OA as it
|
||||
switch_amrwb_pack_oa(shift_buf, n); /* the payload is OA as it
|
||||
comes out of the encoding function */
|
||||
*encoded_data_len = n + 1;
|
||||
} else {
|
||||
@@ -380,7 +380,7 @@ static switch_status_t switch_amrwb_decode(switch_codec_t *codec,
|
||||
#else
|
||||
struct amrwb_context *context = codec->private_info;
|
||||
unsigned char *buf = encoded_data;
|
||||
uint8_t tmp[SWITCH_AMRWB_OUT_MAX_SIZE];
|
||||
uint8_t tmp[SWITCH_AMRWB_OUT_MAX_SIZE];
|
||||
|
||||
if (!context) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -390,12 +390,12 @@ static switch_status_t switch_amrwb_decode(switch_codec_t *codec,
|
||||
switch_amrwb_info(buf, encoded_data_len, switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN) ? 1 : 0, "AMRWB decoder");
|
||||
}
|
||||
|
||||
if (switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN)) {
|
||||
if (switch_test_flag(context, AMRWB_OPT_OCTET_ALIGN)) {
|
||||
/* Octed Aligned */
|
||||
if (!switch_amrwb_unpack_oa(buf, tmp, encoded_data_len)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
/* Bandwidth Efficient */
|
||||
if (!switch_amrwb_unpack_be(buf, tmp, encoded_data_len)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -436,32 +436,32 @@ static switch_status_t switch_amrwb_control(switch_codec_t *codec,
|
||||
if (!strcasecmp(cmd, "increase")) {
|
||||
if (context->enc_mode < SWITCH_AMRWB_MODES - 1) {
|
||||
int mode_step = 2; /*this is the mode, not the actual bitrate*/
|
||||
context->enc_mode = context->enc_mode + mode_step;
|
||||
context->enc_mode = context->enc_mode + mode_step;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMRWB encoder: Adjusting mode to %d (increase)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(cmd, "decrease")) {
|
||||
if (context->enc_mode > 0) {
|
||||
int mode_step = 2; /*this is the mode, not the actual bitrate*/
|
||||
context->enc_mode = context->enc_mode - mode_step;
|
||||
context->enc_mode = context->enc_mode - mode_step;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMRWB encoder: Adjusting mode to %d (decrease)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
} else if (!strcasecmp(cmd, "default")) {
|
||||
context->enc_mode = globals.default_bitrate;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMRWB encoder: Adjusting mode to %d (default)\n", context->enc_mode);
|
||||
}
|
||||
} else {
|
||||
/*minimum bitrate (AMRWB mode)*/
|
||||
context->enc_mode = 0;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
|
||||
"AMRWB encoder: Adjusting mode to %d (minimum)\n", context->enc_mode);
|
||||
}
|
||||
}
|
||||
@@ -469,14 +469,14 @@ static switch_status_t switch_amrwb_control(switch_codec_t *codec,
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
static char *generate_fmtp(switch_memory_pool_t *pool , int octet_align)
|
||||
{
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
|
||||
snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "octet-align=%d; ", octet_align);
|
||||
@@ -563,31 +563,31 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_amrwb_load)
|
||||
switch_console_set_complete("add amrwb_debug off");
|
||||
#else
|
||||
#define SWITCH_AMRWB_OUT_MAX_SIZE 0
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SWITCH_ADD_CODEC(codec_interface, "AMR-WB / Octet Aligned");
|
||||
|
||||
default_fmtp_oa = generate_fmtp(pool, 1);
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO, 100, "AMR-WB", default_fmtp_oa,
|
||||
SWITCH_CODEC_TYPE_AUDIO, 100, "AMR-WB", default_fmtp_oa,
|
||||
16000, 16000, 23850, 20000, 320, 640, SWITCH_AMRWB_OUT_MAX_SIZE, 1, 1,
|
||||
switch_amrwb_init, switch_amrwb_encode, switch_amrwb_decode, switch_amrwb_destroy);
|
||||
#ifndef AMRWB_PASSTHROUGH
|
||||
codec_interface->implementations->codec_control = switch_amrwb_control;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
SWITCH_ADD_CODEC(codec_interface, "AMR-WB / Bandwidth Efficient");
|
||||
|
||||
default_fmtp_be = generate_fmtp(pool, 0);
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO, 110, "AMR-WB", default_fmtp_be,
|
||||
16000, 16000, 23850, 20000, 320, 640, SWITCH_AMRWB_OUT_MAX_SIZE, 1, 1,
|
||||
SWITCH_CODEC_TYPE_AUDIO, 110, "AMR-WB", default_fmtp_be,
|
||||
16000, 16000, 23850, 20000, 320, 640, SWITCH_AMRWB_OUT_MAX_SIZE, 1, 1,
|
||||
switch_amrwb_init, switch_amrwb_encode, switch_amrwb_decode, switch_amrwb_destroy);
|
||||
#ifndef AMRWB_PASSTHROUGH
|
||||
codec_interface->implementations->codec_control = switch_amrwb_control;
|
||||
#endif
|
||||
#endif
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
*
|
||||
* mod_b64.c -- The B64 ultra-low delay audio codec (http://www.b64-codec.org/)
|
||||
@@ -53,7 +53,7 @@ static int rot(char *p, char min, char max, int i)
|
||||
{
|
||||
int r = 0;
|
||||
int c;
|
||||
|
||||
|
||||
if (*p >= min && *p <= max) {
|
||||
if ((c = *p + i) <= max) {
|
||||
*p = c;
|
||||
@@ -119,7 +119,7 @@ static switch_status_t switch_codec_b64_decode(switch_codec_t *codec,
|
||||
p += HLEN;
|
||||
encoded_data = p;
|
||||
encoded_data_len -= HLEN;
|
||||
|
||||
|
||||
rot13_buffer(encoded_data, encoded_data_len);
|
||||
switch_b64_decode(encoded_data, decoded_data, *decoded_data_len);
|
||||
*decoded_data_len = codec->implementation->decoded_bytes_per_packet;
|
||||
@@ -160,14 +160,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_b64_load)
|
||||
switch_codec_b64_encode, /* function to encode raw data into encoded data */
|
||||
switch_codec_b64_decode, /* function to decode encoded data into raw data */
|
||||
switch_codec_b64_destroy); /* deinitalize a codec handle using this implementation */
|
||||
|
||||
|
||||
bytes *= 2;
|
||||
samples *= 2;
|
||||
rate *= 2;
|
||||
bits *= 2;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
*
|
||||
* mod_bv.c -- BroadVoice16 and BroadVoice32 audio codecs (http://www.broadcom.com/support/broadvoice/)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -32,8 +32,8 @@
|
||||
#include <switch.h>
|
||||
#include <codec2.h>
|
||||
|
||||
/* Uncomment to log input/output data for debugging
|
||||
#define LOG_DATA
|
||||
/* Uncomment to log input/output data for debugging
|
||||
#define LOG_DATA
|
||||
#define CODEC2_DEBUG
|
||||
*/
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
#ifdef CODEC2_DEBUG
|
||||
#define codec2_assert(_x) switch_assert(_x)
|
||||
#else
|
||||
#define codec2_assert(_x)
|
||||
#define codec2_assert(_x)
|
||||
#endif
|
||||
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_codec2_load);
|
||||
@@ -56,7 +56,7 @@ struct codec2_context {
|
||||
int nbit; /* nr of bits per frame */
|
||||
int nbyte; /* nr of bytes per frame */
|
||||
int nsam; /* nr of samples per frame */
|
||||
#ifdef LOG_DATA
|
||||
#ifdef LOG_DATA
|
||||
FILE *encoder_in;
|
||||
FILE *encoder_out;
|
||||
FILE *encoder_out_unpacked;
|
||||
@@ -107,13 +107,13 @@ static switch_status_t switch_codec2_init(switch_codec_t *codec, switch_codec_fl
|
||||
} else {
|
||||
/* 3200 might be better for VOIP, but forcing 2400 for backwards compatibility */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "mode not supported, forcing CODEC2_MODE_2400. You can try mode 3200 too!\n");
|
||||
context->mode = CODEC2_MODE_2400;
|
||||
context->mode = CODEC2_MODE_2400;
|
||||
}
|
||||
|
||||
|
||||
if (encoding) {
|
||||
context->encoder = codec2_create(context->mode);
|
||||
}
|
||||
|
||||
|
||||
if (decoding) {
|
||||
context->decoder = codec2_create(context->mode);
|
||||
}
|
||||
@@ -126,32 +126,32 @@ static switch_status_t switch_codec2_init(switch_codec_t *codec, switch_codec_fl
|
||||
context->nbyte = (context->nbit + 7) / 8;
|
||||
|
||||
codec->private_info = context;
|
||||
|
||||
#ifdef LOG_DATA
|
||||
|
||||
#ifdef LOG_DATA
|
||||
{
|
||||
|
||||
|
||||
int c = c2_count++;
|
||||
char buf[1024];
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CONSOLE, "Logging as /tmp/c2-%d-*\n", c);
|
||||
|
||||
|
||||
if (encoding) {
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-enc-in", c);
|
||||
context->encoder_in = fopen(buf, "w");
|
||||
|
||||
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-enc-out", c);
|
||||
context->encoder_out = fopen(buf, "w");
|
||||
|
||||
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-enc-out-unpacked", c);
|
||||
context->encoder_out_unpacked = fopen(buf, "w");
|
||||
}
|
||||
if (decoding) {
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-dec-in", c);
|
||||
context->decoder_in = fopen(buf, "w");
|
||||
|
||||
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-dec-out", c);
|
||||
context->decoder_out = fopen(buf, "w");
|
||||
|
||||
|
||||
snprintf(buf, sizeof(buf), "/tmp/c2-%d-dec-out-unpacked", c);
|
||||
context->decoder_in_unpacked = fopen(buf, "w");
|
||||
}
|
||||
@@ -171,23 +171,23 @@ static switch_status_t switch_codec2_encode(switch_codec_t *codec, switch_codec_
|
||||
unsigned int *flag)
|
||||
{
|
||||
struct codec2_context *context = codec->private_info;
|
||||
|
||||
|
||||
codec2_assert(decoded_data_len == context->nsam * 2);
|
||||
|
||||
#ifdef LOG_DATA
|
||||
|
||||
#ifdef LOG_DATA
|
||||
fwrite(decoded_data, decoded_data_len, 1, context->encoder_in);
|
||||
fflush(context->encoder_in);
|
||||
#endif
|
||||
|
||||
codec2_encode(context->encoder, encoded_data, decoded_data);
|
||||
|
||||
#ifdef LOG_DATA
|
||||
|
||||
#ifdef LOG_DATA
|
||||
fwrite(encode_buf, sizeof(encode_buf), 1, context->encoder_out_unpacked);
|
||||
fflush(context->encoder_out_unpacked);
|
||||
fwrite(encoded_data, context->nbyte, 1, context->encoder_out);
|
||||
fflush(context->encoder_out);
|
||||
#endif
|
||||
|
||||
|
||||
*encoded_data_len = context->nbyte;
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
@@ -204,32 +204,32 @@ static switch_status_t switch_codec2_decode(switch_codec_t *codec,
|
||||
unsigned int *flag)
|
||||
{
|
||||
struct codec2_context *context = codec->private_info;
|
||||
|
||||
|
||||
codec2_assert(encoded_data_len == 8);
|
||||
|
||||
#ifdef LOG_DATA
|
||||
|
||||
#ifdef LOG_DATA
|
||||
fwrite(encoded_data, encoded_data_len, 1, context->decoder_in);
|
||||
fflush(context->decoder_in);
|
||||
fwrite(bits, sizeof(bits), 1, context->decoder_in_unpacked);
|
||||
fflush(context->decoder_in_unpacked);
|
||||
#endif
|
||||
|
||||
|
||||
codec2_decode(context->decoder, decoded_data, encoded_data);
|
||||
|
||||
#ifdef LOG_DATA
|
||||
#ifdef LOG_DATA
|
||||
fwrite(decoded_data, context->nsam, 2, context->decoder_out);
|
||||
fflush(context->decoder_out);
|
||||
#endif
|
||||
|
||||
*decoded_data_len = context->nsam * 2; /* eg: 160 samples for 3200,2400 */
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
static switch_status_t switch_codec2_destroy(switch_codec_t *codec)
|
||||
{
|
||||
struct codec2_context *context = codec->private_info;
|
||||
|
||||
|
||||
codec2_destroy(context->encoder);
|
||||
codec2_destroy(context->decoder);
|
||||
|
||||
@@ -266,7 +266,7 @@ static switch_status_t codec2_load_config(switch_bool_t reload) {
|
||||
switch_xml_t cfg, xml = NULL, param, settings;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
codec2_prefs.mode = 2400 ;
|
||||
codec2_prefs.mode = 2400 ;
|
||||
|
||||
if (!(xml = switch_xml_open_cfg(cf, &cfg, NULL))) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Opening of %s failed\n", cf);
|
||||
@@ -283,7 +283,7 @@ static switch_status_t codec2_load_config(switch_bool_t reload) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (xml) {
|
||||
switch_xml_free(xml);
|
||||
}
|
||||
@@ -301,14 +301,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_codec2_load)
|
||||
}
|
||||
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
|
||||
/*there is no API call to retrieve ptime per mode, so hardcoding here*/
|
||||
if ((codec2_prefs.mode == 3200) ||(codec2_prefs.mode == 2400)) {
|
||||
codec2_prefs.ptime = 20000;
|
||||
codec2_prefs.samples_per_frame = CODEC2_SAMPLES_PER_FRAME;
|
||||
codec2_prefs.samples_per_frame = CODEC2_SAMPLES_PER_FRAME;
|
||||
} else {
|
||||
codec2_prefs.ptime = 40000;
|
||||
codec2_prefs.samples_per_frame = CODEC2_SAMPLES_PER_FRAME * 2;
|
||||
codec2_prefs.samples_per_frame = CODEC2_SAMPLES_PER_FRAME * 2;
|
||||
}
|
||||
|
||||
SWITCH_ADD_CODEC(codec_interface, "CODEC2 3200/2400/1400/1200bps");
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -41,7 +41,7 @@
|
||||
|
||||
/*
|
||||
* some rules to keep in mind for G729 (the frame size may be different for G723)
|
||||
* we cannot write more than SFRAME_SIZE (320) - sizeof(struct rtp_packet) which
|
||||
* we cannot write more than SFRAME_SIZE (320) - sizeof(struct rtp_packet) which
|
||||
* seems to be 266 bytes
|
||||
* if we write less than 160 bytes (1 ulaw frame which is 20 bytes of G729 bytes, a read will block forever)
|
||||
* TODO: do buffering ourselves to provide just the fixed amount of samples that the card expects
|
||||
@@ -60,7 +60,7 @@ static uint32_t total_encoders_usage = 0;
|
||||
static uint32_t total_decoders = 0;
|
||||
static uint32_t total_decoders_usage = 0;
|
||||
|
||||
/*
|
||||
/*
|
||||
Zaptel/DAHDI definitions to not require the headers installed
|
||||
Zaptel and DAHDI are binary compatible (at least in the transcoder interface)
|
||||
*/
|
||||
@@ -122,7 +122,7 @@ static int32_t switch_dahdi_get_transcoder(struct dahdi_transcoder_formats *fmts
|
||||
if (fcntl(fd, F_SETFL, fdflags)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not set non-block mode in %s transcoder FD: %s\n",
|
||||
transcoder_name, strerror(errno));
|
||||
/* should we abort? this may cause channels to hangup when overruning the device
|
||||
/* should we abort? this may cause channels to hangup when overruning the device
|
||||
* see jira dahdi codec issue MODCODEC-8 (Hung Calls and Codec DAHDI G.729A 8.0k decoder error!)
|
||||
* */
|
||||
}
|
||||
@@ -216,7 +216,7 @@ static switch_status_t switch_dahdi_init(switch_codec_t *codec, switch_codec_fla
|
||||
context->encoding_fd = -1;
|
||||
context->decoding_fd = -1;
|
||||
|
||||
/* ulaw requires 8 times more storage than g729 and 12 times more than G723, right?
|
||||
/* ulaw requires 8 times more storage than g729 and 12 times more than G723, right?
|
||||
* this can be used to calculate the target buffer when encoding and decoding
|
||||
* */
|
||||
context->codec_r = (codec->implementation->ianacode == CODEC_G729_IANA_CODE)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Michael Jerris <mike@jerris.com>
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
*
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
*
|
||||
* mod_ilbc.c -- ilbc Codec Module
|
||||
|
||||
@@ -522,7 +522,7 @@ WebRtc_Word16 WebRtcIsac_UpdateUplinkBwImpl(
|
||||
{
|
||||
if(index > 11)
|
||||
{
|
||||
index -= 12;
|
||||
index -= 12;
|
||||
/* compute the jitter estimate as decoded on the other side */
|
||||
bwest_str->send_max_delay_avg = 0.9f * bwest_str->send_max_delay_avg +
|
||||
0.1f * (float)MAX_ISAC_MD;
|
||||
|
||||
@@ -251,7 +251,7 @@ int WebRtcSpl_ComplexFFT(WebRtc_Word16 frfi[], int stages, int mode)
|
||||
"r"(wri), "r"(frfi_r), "r"(CFFTRND));
|
||||
__asm__("smladx %0, %1, %2, %3" : "=r"(ti32) :
|
||||
"r"(wri), "r"(frfi_r), "r"(CFFTRND));
|
||||
|
||||
|
||||
#else
|
||||
tr32 = WEBRTC_SPL_MUL_16_16(wr, frfi[2 * j])
|
||||
- WEBRTC_SPL_MUL_16_16(wi, frfi[2 * j + 1]) + CFFTRND;
|
||||
|
||||
@@ -163,7 +163,7 @@ void WebRtcSpl_CrossCorrelation(WebRtc_Word32* cross_correlation, WebRtc_Word16*
|
||||
seq2Ptr = seq2 + (step_seq2 * i);
|
||||
(*CrossCorrPtr) = 0;
|
||||
|
||||
#ifndef _ARM_OPT_
|
||||
#ifndef _ARM_OPT_
|
||||
#ifdef _WIN32
|
||||
#pragma message("NOTE: default implementation is used")
|
||||
#endif
|
||||
|
||||
@@ -933,7 +933,7 @@ WebRtcIsac_EncodeUb12(
|
||||
|
||||
WebRtcIsac_GetLpcGain(s2nr, percepFilterParams, SUBFRAMES, lpcGains,
|
||||
corr, varscale);
|
||||
|
||||
|
||||
/* Store the state of arithmetic coder before coding LPC gains */
|
||||
transcodingParam.W_upper = ISACencUB_obj->bitstr_obj.W_upper;
|
||||
|
||||
|
||||
@@ -151,7 +151,7 @@ WebRtc_Word16 WebRtcIsac_CorrelateInterVec(
|
||||
* WebRtcIsac_AddLarMean()
|
||||
*
|
||||
* This is the inverse of WebRtcIsac_RemoveLarMean()
|
||||
*
|
||||
*
|
||||
* Input:
|
||||
* -data : pointer to mean-removed LAR:s.
|
||||
* -bandwidth : indicates if the given LAR vectors belong
|
||||
@@ -220,7 +220,7 @@ WebRtc_Word16 WebRtcIsac_DecorrelateLPGain(
|
||||
* WebRtcIsac_QuantizeLpcGain()
|
||||
*
|
||||
* Quantize the decorrelated log-domain gains.
|
||||
*
|
||||
*
|
||||
* Input:
|
||||
* -lpcGain : uncorrelated LPC gains.
|
||||
*
|
||||
|
||||
@@ -212,7 +212,7 @@ int WebRtcIsac_Fftns(unsigned int ndim, const int dims[],
|
||||
{
|
||||
max_factors = (int)nSpan;
|
||||
}
|
||||
if ((int)nSpan > max_perm)
|
||||
if ((int)nSpan > max_perm)
|
||||
{
|
||||
max_perm = (int)nSpan;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -59,7 +59,7 @@ static switch_status_t switch_isac_init(switch_codec_t *codec, switch_codec_flag
|
||||
codec->private_info = context;
|
||||
|
||||
err = WebRtcIsac_Create(&context->ISAC_main_inst);
|
||||
|
||||
|
||||
if (err < 0) return SWITCH_STATUS_FALSE;
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ static switch_status_t switch_isac_init(switch_codec_t *codec, switch_codec_flag
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (WebRtcIsac_SetMaxRate(context->ISAC_main_inst, codec->implementation->bits_per_second) < 0) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
@@ -126,13 +126,13 @@ static switch_status_t switch_isac_encode(switch_codec_t *codec, switch_codec_t
|
||||
len = WebRtcIsac_Encode(context->ISAC_main_inst, in, out);
|
||||
in += rise;
|
||||
}
|
||||
|
||||
|
||||
if (len < 0) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
*encoded_data_len = (uint32_t) len;
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -159,9 +159,9 @@ static switch_status_t switch_isac_decode(switch_codec_t *codec,
|
||||
*decoded_data_len = 0;
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
|
||||
*decoded_data_len = (uint32_t) len * 2;
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -170,7 +170,7 @@ static switch_status_t switch_isac_destroy(switch_codec_t *codec)
|
||||
struct isac_context *context = codec->private_info;
|
||||
|
||||
WebRtcIsac_Free(context->ISAC_main_inst);
|
||||
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -183,90 +183,90 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_isac_codec_load)
|
||||
|
||||
SWITCH_ADD_CODEC(codec_interface, "isac"); /* 8.0kbit */
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO,
|
||||
99,
|
||||
99,
|
||||
"isac",
|
||||
"ibitrate=32000;maxbitrate=53400",
|
||||
16000,
|
||||
16000,
|
||||
53400,
|
||||
30000,
|
||||
480,
|
||||
960,
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
switch_isac_init,
|
||||
"ibitrate=32000;maxbitrate=53400",
|
||||
16000,
|
||||
16000,
|
||||
53400,
|
||||
30000,
|
||||
480,
|
||||
960,
|
||||
0,
|
||||
1,
|
||||
3,
|
||||
switch_isac_init,
|
||||
switch_isac_encode,
|
||||
switch_isac_decode,
|
||||
switch_isac_destroy);
|
||||
|
||||
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO,
|
||||
99,
|
||||
99,
|
||||
"isac",
|
||||
"ibitrate=32000;maxbitrate=53400",
|
||||
16000,
|
||||
16000,
|
||||
53400,
|
||||
60000,
|
||||
960,
|
||||
1920,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
switch_isac_encode,
|
||||
switch_isac_decode,
|
||||
switch_isac_destroy);
|
||||
|
||||
|
||||
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO,
|
||||
99,
|
||||
"isac",
|
||||
"ibitrate=32000;maxbitrate=160000",
|
||||
32000,
|
||||
32000,
|
||||
160000,
|
||||
30000,
|
||||
960,
|
||||
1920,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
"ibitrate=32000;maxbitrate=53400",
|
||||
16000,
|
||||
16000,
|
||||
53400,
|
||||
60000,
|
||||
960,
|
||||
1920,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
switch_isac_encode,
|
||||
switch_isac_decode,
|
||||
switch_isac_destroy);
|
||||
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO,
|
||||
99,
|
||||
99,
|
||||
"isac",
|
||||
"ibitrate=32000;maxbitrate=160000",
|
||||
32000,
|
||||
32000,
|
||||
160000,
|
||||
60000,
|
||||
1920,
|
||||
3840,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
"ibitrate=32000;maxbitrate=160000",
|
||||
32000,
|
||||
32000,
|
||||
160000,
|
||||
30000,
|
||||
960,
|
||||
1920,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
switch_isac_encode,
|
||||
switch_isac_decode,
|
||||
switch_isac_destroy);
|
||||
|
||||
|
||||
|
||||
|
||||
switch_core_codec_add_implementation(pool, codec_interface,
|
||||
SWITCH_CODEC_TYPE_AUDIO,
|
||||
99,
|
||||
"isac",
|
||||
"ibitrate=32000;maxbitrate=160000",
|
||||
32000,
|
||||
32000,
|
||||
160000,
|
||||
60000,
|
||||
1920,
|
||||
3840,
|
||||
0,
|
||||
1,
|
||||
6,
|
||||
switch_isac_init,
|
||||
switch_isac_encode,
|
||||
switch_isac_decode,
|
||||
switch_isac_destroy);
|
||||
|
||||
|
||||
|
||||
/* indicate that the module should continue to be loaded */
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ static __inline WebRtc_Word32 MUL_ACCUM_1(WebRtc_Word32 tbl_value,
|
||||
// Return: Return: state + (((diff << 1) * tbl_value) >> 32)
|
||||
//
|
||||
// The reason to introduce this function is that, in case we can't use smlawb
|
||||
// instruction (in MUL_ACCUM_1) due to input value range, we can still use
|
||||
// instruction (in MUL_ACCUM_1) due to input value range, we can still use
|
||||
// smmla to save some cycles.
|
||||
|
||||
static __inline WebRtc_Word32 MUL_ACCUM_2(WebRtc_Word32 tbl_value,
|
||||
|
||||
@@ -1652,7 +1652,7 @@ void WebRtcSpl_SynthesisQMF(const WebRtc_Word16* low_band,
|
||||
// WebRtc_Word16 WebRtcSpl_SatW32ToW16(...)
|
||||
//
|
||||
// This function saturates a 32-bit word into a 16-bit word.
|
||||
//
|
||||
//
|
||||
// Input:
|
||||
// - value32 : The value of a 32-bit word.
|
||||
//
|
||||
@@ -1664,7 +1664,7 @@ void WebRtcSpl_SynthesisQMF(const WebRtc_Word16* low_band,
|
||||
//
|
||||
// This function multiply a 16-bit word by a 16-bit word, and accumulate this
|
||||
// value to a 32-bit integer.
|
||||
//
|
||||
//
|
||||
// Input:
|
||||
// - a : The value of the first 16-bit word.
|
||||
// - b : The value of the second 16-bit word.
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
/*
|
||||
* spectrum_ar_model_tables.h
|
||||
*
|
||||
* This file contains definitions of tables with AR coefficients,
|
||||
* This file contains definitions of tables with AR coefficients,
|
||||
* Gain coefficients and cosine tables.
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
*
|
||||
|
||||
@@ -82,7 +82,7 @@ typedef struct h264_codec_context_s {
|
||||
int FillSpecificParameters(h264_codec_context_t *context) {
|
||||
int sane = 0;
|
||||
SEncParamExt *param;
|
||||
|
||||
|
||||
param = &context->encoder_params;
|
||||
|
||||
if (!context->codec_settings.video.width) {
|
||||
@@ -216,11 +216,11 @@ static switch_size_t buffer_h264_nalu(h264_codec_context_t *context, switch_fram
|
||||
|
||||
/* hack for phones sending sps/pps with frame->m = 1 such as grandstream */
|
||||
if ((nalu_type == 7 || nalu_type == 8) && frame->m) frame->m = SWITCH_FALSE;
|
||||
|
||||
|
||||
if (nalu_type == 28) { // 0x1c FU-A
|
||||
int start = *(data + 1) & 0x80;
|
||||
int end = *(data + 1) & 0x40;
|
||||
|
||||
|
||||
nalu_type = *(data + 1) & 0x1f;
|
||||
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "WTF start:%d end:%d mark:%d\n", start, end, frame->m);
|
||||
@@ -731,8 +731,8 @@ end:
|
||||
return status;
|
||||
}
|
||||
|
||||
static switch_status_t switch_h264_control(switch_codec_t *codec,
|
||||
switch_codec_control_command_t cmd,
|
||||
static switch_status_t switch_h264_control(switch_codec_t *codec,
|
||||
switch_codec_control_command_t cmd,
|
||||
switch_codec_control_type_t ctype,
|
||||
void *cmd_data,
|
||||
switch_codec_control_type_t atype,
|
||||
@@ -746,7 +746,7 @@ static switch_status_t switch_h264_control(switch_codec_t *codec,
|
||||
|
||||
switch(cmd) {
|
||||
case SCC_VIDEO_GEN_KEYFRAME:
|
||||
context->need_key_frame = 1;
|
||||
context->need_key_frame = 1;
|
||||
break;
|
||||
case SCC_VIDEO_BANDWIDTH:
|
||||
{
|
||||
|
||||
@@ -181,7 +181,7 @@ static uint32_t switch_opus_encoder_set_audio_bandwidth(OpusEncoder *encoder_obj
|
||||
opus_encoder_ctl(encoder_object, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_SUPERWIDEBAND));
|
||||
opus_encoder_ctl(encoder_object, OPUS_SET_SIGNAL(OPUS_AUTO));
|
||||
return OPUS_BANDWIDTH_SUPERWIDEBAND;
|
||||
}
|
||||
}
|
||||
/* Audio Bandwidth: 0-20000Hz Sampling Rate: 48000Hz */
|
||||
opus_encoder_ctl(encoder_object, OPUS_SET_BANDWIDTH(OPUS_AUTO));
|
||||
opus_encoder_ctl(encoder_object, OPUS_SET_MAX_BANDWIDTH(OPUS_BANDWIDTH_FULLBAND));
|
||||
@@ -360,7 +360,7 @@ static char *gen_fmtp(opus_codec_settings_t *settings, switch_memory_pool_t *poo
|
||||
|
||||
}
|
||||
|
||||
static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_length_bytes)
|
||||
static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_length_bytes)
|
||||
{
|
||||
/* nb_silk_frames: number of silk-frames (10 or 20 ms) in an opus frame: 0, 1, 2 or 3 */
|
||||
/* computed from the 5 MSB (configuration) of the TOC byte (payload[0]) */
|
||||
@@ -370,7 +370,7 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
|
||||
/* p0p1 = 1 or 2 => nb_opus_frames = 2 */
|
||||
/* p0p1 = 3 => given by the 6 LSB of payload[1] */
|
||||
|
||||
int nb_silk_frames, nb_opus_frames, n, i;
|
||||
int nb_silk_frames, nb_opus_frames, n, i;
|
||||
opus_int16 frame_sizes[48];
|
||||
const unsigned char *frame_data[48];
|
||||
|
||||
@@ -378,12 +378,12 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "corrupted packet (invalid size)\n");
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
if (payload[0] & 0x80) {
|
||||
if (payload[0] & 0x80) {
|
||||
/* this scares users and its harmless so commenting it */
|
||||
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "FEC in CELT_ONLY mode ?!\n");
|
||||
return SWITCH_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if ((nb_opus_frames = opus_packet_parse(payload, payload_length_bytes, NULL, frame_data, frame_sizes, NULL)) <= 0) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "OPUS_INVALID_PACKET ! nb_opus_frames: %d\n", nb_opus_frames);
|
||||
return SWITCH_FALSE;
|
||||
@@ -396,7 +396,7 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
|
||||
if(nb_silk_frames == 0) {
|
||||
nb_silk_frames = 1;
|
||||
}
|
||||
if ((nb_silk_frames == 1) && (nb_opus_frames == 1)) {
|
||||
if ((nb_silk_frames == 1) && (nb_opus_frames == 1)) {
|
||||
for (n = 0; n <= (payload[0]&0x4) ; n++) { /* mono or stereo: 10,20 ms */
|
||||
if (frame_data[0][0] & (0x80 >> ((n + 1) * (nb_silk_frames + 1) - 1))) {
|
||||
return SWITCH_TRUE; /* frame has FEC */
|
||||
@@ -407,7 +407,7 @@ static switch_bool_t switch_opus_has_fec(const uint8_t* payload,int payload_leng
|
||||
for (i=0 ; i < nb_opus_frames; i++ ) { /* only mono Opus frames */
|
||||
LBRR_flag = (frame_data[i][0] >> (7 - nb_silk_frames)) & 0x1;
|
||||
if (LBRR_flag) {
|
||||
return SWITCH_TRUE; /* one of the silk frames has FEC */
|
||||
return SWITCH_TRUE; /* one of the silk frames has FEC */
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -432,17 +432,17 @@ static int switch_opus_get_fec_bitrate(int fs, int loss)
|
||||
|
||||
if (loss <= 0){
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (fs == 8000) {
|
||||
if (loss >=25) {
|
||||
if (loss >=25) {
|
||||
return threshold_bitrates[24];
|
||||
} else {
|
||||
return threshold_bitrates[loss-1];
|
||||
}
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE ;
|
||||
return SWITCH_STATUS_FALSE ;
|
||||
}
|
||||
|
||||
static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint32_t samples_per_second, char *print_text)
|
||||
@@ -476,11 +476,11 @@ static switch_status_t switch_opus_info(void * encoded_data, uint32_t len, uint3
|
||||
|
||||
nb_channels = opus_packet_get_nb_channels(payload);
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: opus_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s] channels[%d]\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s: opus_frames [%d] samples [%d] audio bandwidth [%s] bytes [%d] FEC[%s] channels[%d]\n",
|
||||
print_text, nb_opus_frames, nb_samples, audiobandwidth_str, len, has_fec ? "yes" : "no", nb_channels);
|
||||
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag_t flags, const switch_codec_settings_t *codec_settings)
|
||||
{
|
||||
@@ -576,18 +576,18 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
|
||||
}
|
||||
|
||||
/* https://tools.ietf.org/html/rfc7587 */
|
||||
if (opus_codec_settings.maxaveragebitrate) {
|
||||
if (opus_codec_settings.maxaveragebitrate) {
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(opus_codec_settings.maxaveragebitrate));
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: set bitrate based on maxaveragebitrate value found in SDP or local config [%dbps]\n", opus_codec_settings.maxaveragebitrate);
|
||||
} else {
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BANDWIDTH(OPUS_AUTO));
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(bitrate_bps)); /* OPUS_AUTO */
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(&bitrate_bps)); /* return average bps for this audio bandwidth */
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(&bitrate_bps)); /* return average bps for this audio bandwidth */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: set bitrate to local settings [%dbps]\n", bitrate_bps);
|
||||
}
|
||||
/* Another fmtp setting from https://tools.ietf.org/html/rfc7587 - "RTP Payload Format for the Opus Speech and Audio Codec" */
|
||||
if (opus_codec_settings.maxplaybackrate) {
|
||||
opus_int32 audiobandwidth;
|
||||
opus_int32 audiobandwidth;
|
||||
char audiobandwidth_str[32] = {0};
|
||||
|
||||
audiobandwidth = switch_opus_encoder_set_audio_bandwidth(context->encoder_object,opus_codec_settings.maxplaybackrate);
|
||||
@@ -617,15 +617,15 @@ static switch_status_t switch_opus_init(switch_codec_t *codec, switch_codec_flag
|
||||
if (opus_codec_settings.useinbandfec) {
|
||||
/* FEC on the encoder: start the call with a preconfigured packet loss percentage */
|
||||
int fec_bitrate = opus_codec_settings.maxaveragebitrate;
|
||||
int loss_percent = opus_prefs.plpct ;
|
||||
int loss_percent = opus_prefs.plpct ;
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_INBAND_FEC(opus_codec_settings.useinbandfec));
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_PACKET_LOSS_PERC(loss_percent));
|
||||
if (opus_prefs.keep_fec){
|
||||
fec_bitrate = switch_opus_get_fec_bitrate(enc_samplerate,loss_percent);
|
||||
if (opus_prefs.keep_fec){
|
||||
fec_bitrate = switch_opus_get_fec_bitrate(enc_samplerate,loss_percent);
|
||||
/* keep a bitrate for which the encoder will always add FEC */
|
||||
if (fec_bitrate != SWITCH_STATUS_FALSE) {
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(fec_bitrate));
|
||||
/* will override the maxaveragebitrate set in opus.conf.xml */
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(fec_bitrate));
|
||||
/* will override the maxaveragebitrate set in opus.conf.xml */
|
||||
opus_codec_settings.maxaveragebitrate = fec_bitrate;
|
||||
}
|
||||
context->control_state.keep_fec = opus_prefs.keep_fec;
|
||||
@@ -691,8 +691,8 @@ static switch_status_t switch_opus_destroy(switch_codec_t *codec)
|
||||
if (context->decoder_object) {
|
||||
switch_core_session_t *session = codec->session;
|
||||
if (session) {
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,"Opus decoder stats: Frames[%d] PLC[%d] FEC[%d]\n",
|
||||
context->decoder_stats.frame_counter, context->decoder_stats.plc_counter-context->decoder_stats.fec_counter, context->decoder_stats.fec_counter);
|
||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,"Opus decoder stats: Frames[%d] PLC[%d] FEC[%d]\n",
|
||||
context->decoder_stats.frame_counter, context->decoder_stats.plc_counter-context->decoder_stats.fec_counter, context->decoder_stats.fec_counter);
|
||||
}
|
||||
opus_decoder_destroy(context->decoder_object);
|
||||
context->decoder_object = NULL;
|
||||
@@ -817,40 +817,40 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec,
|
||||
|
||||
frame.data = buf;
|
||||
frame.buflen = sizeof(buf);
|
||||
|
||||
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Missing %s %u Checking JB\n", seq ? "SEQ" : "TS", seq ? seq : ts);
|
||||
}
|
||||
|
||||
|
||||
if (switch_jb_peek_frame(jb, ts, seq, 1, &frame) == SWITCH_STATUS_SUCCESS) {
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Lookahead frame found: %u:%u\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Lookahead frame found: %u:%u\n",
|
||||
frame.timestamp, frame.seq);
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ((fec = switch_opus_has_fec(frame.data, frame.datalen))) {
|
||||
encoded_data = frame.data;
|
||||
encoded_data_len = frame.datalen;
|
||||
}
|
||||
|
||||
|
||||
if (globals.debug || context->debug) {
|
||||
if (fec) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FEC info available in packet with SEQ: %d LEN: %d\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "FEC info available in packet with SEQ: %d LEN: %d\n",
|
||||
frame.seq, frame.datalen);
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO FEC info in this packet with SEQ: %d LEN: %d\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "NO FEC info in this packet with SEQ: %d LEN: %d\n",
|
||||
frame.seq, frame.datalen);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
opus_decoder_ctl(context->decoder_object, OPUS_GET_LAST_PACKET_DURATION(&last_frame_size));
|
||||
if (last_frame_size) frame_size = last_frame_size;
|
||||
|
||||
|
||||
if (globals.debug || context->debug) {
|
||||
if (opus_prefs.use_jb_lookahead || context->use_jb_lookahead) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "MISSING FRAME: %s\n", fec ? "Look-ahead FEC" : "PLC");
|
||||
@@ -865,7 +865,7 @@ static switch_status_t switch_opus_decode(switch_codec_t *codec,
|
||||
if (globals.debug || context->debug > 1) {
|
||||
int samplerate = context->dec_frame_size * 1000 / (codec->implementation->microseconds_per_packet / 1000);
|
||||
switch_opus_info(encoded_data, encoded_data_len,
|
||||
samplerate ? samplerate : codec->implementation->actual_samples_per_second,
|
||||
samplerate ? samplerate : codec->implementation->actual_samples_per_second,
|
||||
!encoded_data ? "PLC correction" : fec ? "FEC correction" : "decode");
|
||||
}
|
||||
|
||||
@@ -910,7 +910,7 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec,
|
||||
opus_int32 ret = 0;
|
||||
opus_int32 total_len = 0;
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
|
||||
if (!context) {
|
||||
switch_goto_status(SWITCH_STATUS_FALSE, end);
|
||||
}
|
||||
@@ -932,12 +932,12 @@ static switch_status_t switch_opus_encode_repacketize(switch_codec_t *codec,
|
||||
dec_ptr_buf = (int16_t *)decoded_data;
|
||||
for (i = 0; i < nb_frames; i++) {
|
||||
/* set inband FEC ON or OFF for the next Opus frame */
|
||||
if (i == (nb_frames - 1) && want_fec) {
|
||||
/* When FEC is enabled for Opus frame N, LBRR is stored during regular encoding of */
|
||||
if (i == (nb_frames - 1) && want_fec) {
|
||||
/* When FEC is enabled for Opus frame N, LBRR is stored during regular encoding of */
|
||||
/* this Opus frame N, and this LBRR data will be packed with the regular encoding */
|
||||
/* data of Opus frame N+1. We enable FEC on our last Opus frame which is to be packed, just */
|
||||
/* to actually have it stored in the first Opus frame, that is when switch_opus_encode_repacketize() */
|
||||
/* is called again to pack the next big 80,100 or 120 ms frame. */
|
||||
/* is called again to pack the next big 80,100 or 120 ms frame. */
|
||||
toggle_fec = 1; /* FEC ON for the last frame */
|
||||
}
|
||||
|
||||
@@ -1199,19 +1199,19 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
}
|
||||
}
|
||||
if (opus_prefs.adjust_bitrate) {
|
||||
/* make bitrate adjust the step , but keep it as a multiple of 400 (see OpusFAQ).
|
||||
/* make bitrate adjust the step , but keep it as a multiple of 400 (see OpusFAQ).
|
||||
* usual RTCP interval is 5 seconds which is long time - the step should be bigger. */
|
||||
/* step's value should depend on packet loss too, to decrease more abrubtly
|
||||
/* step's value should depend on packet loss too, to decrease more abrubtly
|
||||
* at high packet loss. */
|
||||
int base_step = 400; /*bps*/
|
||||
int range = context->codec_settings.maxaveragebitrate - SWITCH_OPUS_MIN_BITRATE;
|
||||
float steps = (float)((float)(range / 100) / base_step);
|
||||
int br_step = (int)(round(steps) * base_step) * plpct;
|
||||
int br_step = (int)(round(steps) * base_step) * plpct;
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG,
|
||||
SWITCH_LOG_DEBUG, "Opus encoder: bitrate increase/decrease step now is: %d bps, range:%d\n", br_step, range);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG,
|
||||
SWITCH_LOG_DEBUG, "Opus encoder: bitrate increase/decrease step now is: %d bps, range:%d\n", br_step, range);
|
||||
}
|
||||
context->control_state.increase_step = context->control_state.decrease_step = br_step;
|
||||
context->control_state.increase_step = context->control_state.decrease_step = br_step;
|
||||
}
|
||||
context->old_plpct = plpct;
|
||||
}
|
||||
@@ -1224,7 +1224,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
opus_int32 current_bitrate=context->control_state.current_bitrate;
|
||||
if (!strcasecmp(cmd, "increase")) {
|
||||
/* https://wiki.xiph.org/OpusFAQ
|
||||
"[...]Opus scales from about 6 to 512 kb/s, in increments of 0.4 kb/s (one byte with 20 ms frames).
|
||||
"[...]Opus scales from about 6 to 512 kb/s, in increments of 0.4 kb/s (one byte with 20 ms frames).
|
||||
Opus can have more than 1200 possible bitrates[...]" */
|
||||
int br_step = context->control_state.increase_step?context->control_state.increase_step:400;
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(¤t_bitrate));
|
||||
@@ -1232,7 +1232,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(current_bitrate+br_step));
|
||||
if ((context->control_state.keep_fec) && (current_bitrate > SWITCH_OPUS_MIN_FEC_BITRATE)) {
|
||||
opus_prefs.keep_fec = 1; /* enable back FEC if it was disabled by SCC_AUDIO_ADJUST_BITRATE, we have enough network bandwidth now */
|
||||
}
|
||||
}
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (increase)\n", current_bitrate+br_step);
|
||||
}
|
||||
@@ -1242,7 +1242,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_GET_BITRATE(¤t_bitrate));
|
||||
if (current_bitrate > SWITCH_OPUS_MIN_BITRATE) {
|
||||
if (context->control_state.keep_fec) {
|
||||
/* no point to try to keep FEC enabled anymore,
|
||||
/* no point to try to keep FEC enabled anymore,
|
||||
* we're low on network bandwidth (that's why we ended up here) */
|
||||
opus_prefs.keep_fec = 0;
|
||||
}
|
||||
@@ -1256,7 +1256,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(opus_prefs.maxaveragebitrate));
|
||||
if (context->control_state.keep_fec) {
|
||||
opus_prefs.keep_fec = 1; /* enable back FEC, we have enough network bandwidth now */
|
||||
}
|
||||
}
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (configured maxaveragebitrate)\n", opus_prefs.maxaveragebitrate);
|
||||
}
|
||||
@@ -1265,7 +1265,7 @@ static switch_status_t switch_opus_control(switch_codec_t *codec,
|
||||
opus_encoder_ctl(context->encoder_object, OPUS_SET_BITRATE(SWITCH_OPUS_MIN_BITRATE));
|
||||
if (context->control_state.keep_fec) {
|
||||
opus_prefs.keep_fec = 0; /* do not enforce FEC anymore, we're low on network bandwidth */
|
||||
}
|
||||
}
|
||||
if (globals.debug || context->debug) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Opus encoder: Adjusting bitrate to %d (minimum)\n", SWITCH_OPUS_MIN_BITRATE);
|
||||
}
|
||||
@@ -1398,7 +1398,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_opus_load)
|
||||
switch_opus_decode, /* function to decode encoded data into raw data */
|
||||
switch_opus_destroy); /* deinitalize a codec handle using this implementation */
|
||||
codec_interface->implementations->codec_control = switch_opus_control;
|
||||
|
||||
|
||||
bytes *= 2;
|
||||
samples *= 2;
|
||||
mss *= 2;
|
||||
|
||||
@@ -2,23 +2,23 @@
|
||||
* Copyright (c) 2010, Sangoma Technologies
|
||||
* Moises Silva <moy@sangoma.com>
|
||||
* All rights reserved.
|
||||
*
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
*
|
||||
* * Neither the name of the original author; nor the names of any contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
@@ -44,7 +44,7 @@ SWITCH_MODULE_DEFINITION(mod_sangoma_codec, mod_sangoma_codec_load, mod_sangoma_
|
||||
|
||||
/* it seemed we need higher PTIME than the calling parties, so we assume nobody will use higher ptime than 40 */
|
||||
#define SANGOMA_DEFAULT_SAMPLING_RATE 80
|
||||
#define SANGOMA_TRANSCODE_CONFIG "sangoma_codec.conf"
|
||||
#define SANGOMA_TRANSCODE_CONFIG "sangoma_codec.conf"
|
||||
|
||||
/* \brief vocallos configuration */
|
||||
static sngtc_init_cfg_t g_init_cfg;
|
||||
@@ -131,7 +131,7 @@ struct codec_data {
|
||||
/* packet counters */
|
||||
unsigned long tx;
|
||||
unsigned long rx;
|
||||
unsigned long ticks;
|
||||
unsigned long ticks;
|
||||
|
||||
/* Lost packets */
|
||||
long lastrxseqno;
|
||||
@@ -213,7 +213,7 @@ static int sangoma_create_rtp_port(void *usr_priv, uint32_t host_ip, uint32_t *p
|
||||
switch_port_t rtp_port;
|
||||
|
||||
local_ip_addr.s_addr = htonl(host_ip);
|
||||
|
||||
|
||||
switch_inet_ntop(AF_INET, &local_ip_addr, local_ip, sizeof(local_ip));
|
||||
|
||||
/* request a port */
|
||||
@@ -235,7 +235,7 @@ static int sangoma_release_rtp_port(void *usr_priv, uint32_t host_ip, uint32_t p
|
||||
switch_port_t rtp_port = p_rtp_port;
|
||||
|
||||
local_ip_addr.s_addr = htonl(host_ip);
|
||||
|
||||
|
||||
switch_inet_ntop(AF_INET, &local_ip_addr, local_ip, sizeof(local_ip));
|
||||
|
||||
/* release the port */
|
||||
@@ -264,8 +264,8 @@ static int sangoma_create_rtp(void *usr_priv, sngtc_codec_request_leg_t *codec_r
|
||||
|
||||
/*
|
||||
* We *MUST* use a new pool
|
||||
* Do not use the session pool since the session may go away while the RTP socket should linger around
|
||||
* until sangoma_transcode decides to kill it (possibly because the same RTP session is used for a different call)
|
||||
* Do not use the session pool since the session may go away while the RTP socket should linger around
|
||||
* until sangoma_transcode decides to kill it (possibly because the same RTP session is used for a different call)
|
||||
* also do not use the module pool otherwise memory would keep growing because switch_rtp_destroy does not
|
||||
* free the memory used (is assumed it'll be freed when the pool is destroyed)
|
||||
*/
|
||||
@@ -273,19 +273,19 @@ static int sangoma_create_rtp(void *usr_priv, sngtc_codec_request_leg_t *codec_r
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
local_ip_addr.s_addr = htonl(codec_req_leg->host_ip);
|
||||
switch_inet_ntop(AF_INET, &local_ip_addr, local_ip, sizeof(local_ip));
|
||||
sngtc_codec_ipv4_hex_to_str(codec_reply_leg->codec_ip, codec_ip);
|
||||
|
||||
iana = codec_id_to_iana(codec_req_leg->codec_id);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Creating RTP session for host (%s/%d) vocallo(%s/%d) Iana=%d CodecId=%d ms=%d idx=%lu\n",
|
||||
local_ip, rtp_port, codec_ip, codec_reply_leg->codec_udp_port, iana, codec_req_leg->codec_id,
|
||||
local_ip, rtp_port, codec_ip, codec_reply_leg->codec_udp_port, iana, codec_req_leg->codec_id,
|
||||
codec_req_leg->ms*1000, sess->sessid);
|
||||
|
||||
/* create the RTP socket */
|
||||
rtp_session = switch_rtp_new(local_ip, rtp_port,
|
||||
codec_ip, codec_reply_leg->codec_udp_port,
|
||||
rtp_session = switch_rtp_new(local_ip, rtp_port,
|
||||
codec_ip, codec_reply_leg->codec_udp_port,
|
||||
iana,
|
||||
sess->impl->samples_per_packet,
|
||||
codec_req_leg->ms * 1000, /* microseconds per packet */
|
||||
@@ -320,7 +320,7 @@ static switch_status_t switch_sangoma_init(switch_codec_t *codec, switch_codec_f
|
||||
uint32_t encoding, decoding;
|
||||
struct sangoma_transcoding_session *sess = NULL;
|
||||
vocallo_codec_t *vcodec;
|
||||
|
||||
|
||||
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
|
||||
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
|
||||
|
||||
@@ -342,11 +342,11 @@ static switch_status_t switch_sangoma_init(switch_codec_t *codec, switch_codec_f
|
||||
switch_assert(sess->impl);
|
||||
|
||||
vcodec = get_codec_from_iana(codec->implementation->ianacode, codec->implementation->bits_per_second);
|
||||
|
||||
|
||||
if (encoding) {
|
||||
sess->encoder.request.usr_priv = sess;
|
||||
sess->encoder.request.a.host_ip = g_rtpip;
|
||||
sess->encoder.request.a.codec_id = vcodec->actual_sampling_rate == 16000
|
||||
sess->encoder.request.a.codec_id = vcodec->actual_sampling_rate == 16000
|
||||
? SNGTC_CODEC_L16_2 : SNGTC_CODEC_L16_1;
|
||||
sess->encoder.request.a.ms = codec->implementation->microseconds_per_packet/1000;
|
||||
|
||||
@@ -362,7 +362,7 @@ static switch_status_t switch_sangoma_init(switch_codec_t *codec, switch_codec_f
|
||||
sess->decoder.request.a.ms = codec->implementation->microseconds_per_packet/1000;
|
||||
|
||||
sess->decoder.request.b.host_ip = g_rtpip;
|
||||
sess->decoder.request.b.codec_id = vcodec->actual_sampling_rate == 16000
|
||||
sess->decoder.request.b.codec_id = vcodec->actual_sampling_rate == 16000
|
||||
? SNGTC_CODEC_L16_2 : SNGTC_CODEC_L16_1;
|
||||
sess->decoder.request.b.ms = codec->implementation->microseconds_per_packet/1000;
|
||||
|
||||
@@ -509,7 +509,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
||||
}
|
||||
|
||||
/* do the writing */
|
||||
memset(&linear_frame, 0, sizeof(linear_frame));
|
||||
memset(&linear_frame, 0, sizeof(linear_frame));
|
||||
linear_frame.source = __SWITCH_FUNC__;
|
||||
linear_frame.data = decoded_byteswapped_data;
|
||||
linear_frame.datalen = decoded_data_len;
|
||||
@@ -528,7 +528,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
||||
}
|
||||
|
||||
if (res < i) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"Requested to write %d bytes to Sangoma encoder RTP session, but wrote %d bytes.\n", i, res);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
@@ -569,7 +569,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
||||
|
||||
if (encoded_frame.payload != codec->implementation->ianacode) {
|
||||
if (sess->encoder.request.b.codec_id == SNGTC_CODEC_ILBC_152 || sess->encoder.request.b.codec_id == SNGTC_CODEC_ILBC_133) {
|
||||
/* since we moved to SOAP based communications, the mapping between vocallo IANA and our IANA does not work,
|
||||
/* since we moved to SOAP based communications, the mapping between vocallo IANA and our IANA does not work,
|
||||
* some codecs checks cannot be completely done, like iLBC */
|
||||
if (encoded_frame.payload != IANA_ILBC_152_8000_1 && encoded_frame.payload != IANA_ILBC_133_8000_1) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Read unexpected payload %d in Sangoma encoder RTP session, expecting either %d or %d\n",
|
||||
@@ -588,7 +588,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
||||
/* if there is something where we want to write, we're dropping it */
|
||||
sess->encoder.rxdiscarded++;
|
||||
#if 0
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding encoded frame of %d bytes from RTP session %lu, windex = %d, rindex = %d\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding encoded frame of %d bytes from RTP session %lu, windex = %d, rindex = %d\n",
|
||||
sess->encoder.rtp_queue[sess->encoder.queue_rindex].datalen, sess->sessid, sess->encoder.queue_windex, sess->encoder.queue_rindex);
|
||||
#endif
|
||||
SAFE_INDEX_INC(sess->encoder.rtp_queue, sess->encoder.queue_rindex);
|
||||
@@ -603,7 +603,7 @@ static switch_status_t switch_sangoma_encode(switch_codec_t *codec, switch_codec
|
||||
/* monitor the queue size */
|
||||
sess->encoder.queue_size++;
|
||||
if (sess->encoder.queue_size > sess->encoder.queue_max_ever) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoder Rx queue for RTP session %lu is now %d, windex = %d, rindex = %d\n", sess->sessid, sess->encoder.queue_size,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoder Rx queue for RTP session %lu is now %d, windex = %d, rindex = %d\n", sess->sessid, sess->encoder.queue_size,
|
||||
sess->encoder.queue_windex, sess->encoder.queue_rindex);
|
||||
sess->encoder.queue_max_ever = sess->encoder.queue_size;
|
||||
}
|
||||
@@ -732,7 +732,7 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses
|
||||
}
|
||||
|
||||
if (res < encoded_data_len) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
|
||||
"Requested to write %d bytes to Sangoma decoder RTP session, but wrote %d bytes.\n",
|
||||
encoded_data_len, res);
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -778,7 +778,7 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses
|
||||
/* if there is something where we want to write, we're dropping it */
|
||||
sess->decoder.rxdiscarded++;
|
||||
#if 0
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding decoded frame of %d bytes from RTP session %lu, windex = %d, rindex = %d\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Discarding decoded frame of %d bytes from RTP session %lu, windex = %d, rindex = %d\n",
|
||||
sess->decoder.rtp_queue[sess->decoder.queue_rindex].datalen, sess->sessid, sess->decoder.queue_windex, sess->decoder.queue_rindex);
|
||||
#endif
|
||||
SAFE_INDEX_INC(sess->decoder.rtp_queue, sess->decoder.queue_rindex);
|
||||
@@ -799,7 +799,7 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses
|
||||
/* monitor the queue size */
|
||||
sess->decoder.queue_size++;
|
||||
if (sess->decoder.queue_size > sess->decoder.queue_max_ever) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoder Rx queue for RTP session %lu is now %d, windex = %d, rindex = %d\n", sess->sessid, sess->decoder.queue_size,
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Encoder Rx queue for RTP session %lu is now %d, windex = %d, rindex = %d\n", sess->sessid, sess->decoder.queue_size,
|
||||
sess->decoder.queue_windex, sess->decoder.queue_rindex);
|
||||
sess->decoder.queue_max_ever = sess->decoder.queue_size;
|
||||
}
|
||||
@@ -856,10 +856,10 @@ static switch_status_t switch_sangoma_decode(switch_codec_t *codec, /* codec ses
|
||||
static switch_status_t switch_sangoma_destroy(switch_codec_t *codec)
|
||||
{
|
||||
struct sangoma_transcoding_session *sess = codec->private_info;
|
||||
/* things that you may do here is closing files, sockets or other resources used during the codec session
|
||||
/* things that you may do here is closing files, sockets or other resources used during the codec session
|
||||
* no need to free memory allocated from the pool though, the owner of the pool takes care of that */
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Sangoma destroy called.\n");
|
||||
|
||||
|
||||
switch_mutex_lock(g_sessions_lock);
|
||||
|
||||
if (sess->encoder.txrtp) {
|
||||
@@ -868,7 +868,7 @@ static switch_status_t switch_sangoma_destroy(switch_codec_t *codec)
|
||||
if (sess->decoder.txrtp) {
|
||||
sngtc_free_transcoding_session(&sess->decoder.reply);
|
||||
}
|
||||
|
||||
|
||||
switch_core_hash_delete(g_sessions_hash, sess->hashkey);
|
||||
memset(sess, 0, sizeof(*sess));
|
||||
|
||||
@@ -965,9 +965,9 @@ SWITCH_STANDARD_API(sangoma_function)
|
||||
|
||||
|
||||
stream->write_function(stream, STATS_FORMAT,
|
||||
sessid_str,
|
||||
sessid_str,
|
||||
sess->impl->iananame,
|
||||
sess->encoder.txrtp ? "Yes" : "No",
|
||||
sess->encoder.txrtp ? "Yes" : "No",
|
||||
sess->decoder.txrtp ? "Yes" : "No",
|
||||
encoder_tx_str,
|
||||
encoder_rx_str,
|
||||
@@ -988,12 +988,12 @@ SWITCH_STANDARD_API(sangoma_function)
|
||||
if (argc < 2) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
ret = sscanf(argv[1], "%lu", &sessid);
|
||||
if (ret != 1) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
sess = sangoma_find_session(sessid);
|
||||
if (!sess) {
|
||||
@@ -1016,7 +1016,7 @@ SWITCH_STANDARD_API(sangoma_function)
|
||||
stream->write_function(stream, "-- Inbound Stats --\n");
|
||||
stream->write_function(stream, "Rx Discarded: %lu\n", sess->encoder.rxdiscarded);
|
||||
sangoma_print_stats(stream, &stats->inbound);
|
||||
|
||||
|
||||
|
||||
stats = switch_rtp_get_stats(sess->encoder.txrtp, NULL);
|
||||
stream->write_function(stream, "-- Outbound Stats --\n");
|
||||
@@ -1048,12 +1048,12 @@ SWITCH_STANDARD_API(sangoma_function)
|
||||
if (argc < 2) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
ret = sscanf(argv[1], "%lu", &sessid);
|
||||
if (ret != 1) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
sess = sangoma_find_session(sessid);
|
||||
if (!sess) {
|
||||
stream->write_function(stream, "Failed to find session %lu\n", sessid);
|
||||
@@ -1069,12 +1069,12 @@ SWITCH_STANDARD_API(sangoma_function)
|
||||
if (argc < 2) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
ret = sscanf(argv[1], "%lu", &sessid);
|
||||
if (ret != 1) {
|
||||
stream->write_function(stream, "%s", SANGOMA_SYNTAX);
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
sess = sangoma_find_session(sessid);
|
||||
if (!sess) {
|
||||
stream->write_function(stream, "Failed to find session %lu\n", sessid);
|
||||
@@ -1230,7 +1230,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sangoma_codec_load)
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to detect vocallo modules\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
if (sngtc_activate_modules(&g_init_cfg, &activated)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Failed to activate vocallo modules\n");
|
||||
return SWITCH_STATUS_FALSE;
|
||||
@@ -1259,14 +1259,14 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sangoma_codec_load)
|
||||
|
||||
/* check if the codec is in the load list, otherwise skip it */
|
||||
if (strcasecmp(g_codec_register_list, "all") && !strcasestr(g_codec_register_list, g_codec_map[c].iana_name)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the load list\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the load list\n",
|
||||
g_codec_map[c].iana_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* load it unless is named in the noload list */
|
||||
if (strcasestr(g_codec_noregister_list, g_codec_map[c].iana_name)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the noload list\n",
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Not loading codec %s because was not found in the noload list\n",
|
||||
g_codec_map[c].iana_name);
|
||||
continue;
|
||||
}
|
||||
@@ -1283,7 +1283,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sangoma_codec_load)
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Registering implementations for codec %s\n", g_codec_map[c].iana_name);
|
||||
|
||||
/* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface
|
||||
/* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface
|
||||
* list the core keeps, gets a codec id and set the given codec name to it.
|
||||
* At this point there is an empty shell codec interface registered, but not yet implementations */
|
||||
SWITCH_ADD_CODEC(codec_interface, g_codec_map[c].fs_name);
|
||||
@@ -1341,7 +1341,7 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_sangoma_codec_load)
|
||||
switch_sangoma_encode, /* function to encode slinear data into encoded data */
|
||||
switch_sangoma_decode, /* function to decode encoded data into slinear data */
|
||||
switch_sangoma_destroy); /* deinitalize a codec handle using this implementation */
|
||||
|
||||
|
||||
break;
|
||||
case SNGTC_CODEC_ILBC_133:
|
||||
case SNGTC_CODEC_ILBC_152:
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
*
|
||||
@@ -36,7 +36,7 @@
|
||||
SWITCH_MODULE_LOAD_FUNCTION(mod_silk_load);
|
||||
SWITCH_MODULE_DEFINITION(mod_silk, mod_silk_load, NULL, NULL);
|
||||
|
||||
#define MAX_BYTES_PER_FRAME 250
|
||||
#define MAX_BYTES_PER_FRAME 250
|
||||
#define MAX_INPUT_FRAMES 5
|
||||
#define MAX_LBRR_DELAY 2
|
||||
#define MAX_FRAME_LENGTH 480
|
||||
@@ -158,8 +158,8 @@ static switch_status_t switch_silk_fmtp_parse(const char *fmtp, switch_codec_fmt
|
||||
|
||||
|
||||
|
||||
static switch_status_t switch_silk_init(switch_codec_t *codec,
|
||||
switch_codec_flag_t freeswitch_flags,
|
||||
static switch_status_t switch_silk_init(switch_codec_t *codec,
|
||||
switch_codec_flag_t freeswitch_flags,
|
||||
const switch_codec_settings_t *codec_settings)
|
||||
{
|
||||
struct silk_context *context = NULL;
|
||||
@@ -177,7 +177,7 @@ static switch_status_t switch_silk_init(switch_codec_t *codec,
|
||||
memset(&codec_fmtp, '\0', sizeof(struct switch_codec_fmtp));
|
||||
codec_fmtp.private_info = &silk_codec_settings;
|
||||
switch_silk_fmtp_parse(codec->fmtp_in, &codec_fmtp);
|
||||
|
||||
|
||||
codec->fmtp_out = switch_core_sprintf(codec->memory_pool, "useinbandfec=%s; usedtx=%s; maxaveragebitrate=%d",
|
||||
silk_codec_settings.useinbandfec ? "1" : "0",
|
||||
silk_codec_settings.usedtx ? "1" : "0",
|
||||
@@ -187,13 +187,13 @@ static switch_status_t switch_silk_init(switch_codec_t *codec,
|
||||
if (SKP_Silk_SDK_Get_Encoder_Size(&encSizeBytes)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
context->enc_state = switch_core_alloc(codec->memory_pool, encSizeBytes);
|
||||
|
||||
if (SKP_Silk_SDK_InitEncoder(context->enc_state, &context->encoder_object)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
context->encoder_object.API_sampleRate = codec->implementation->actual_samples_per_second;
|
||||
context->encoder_object.maxInternalSampleRate = codec->implementation->actual_samples_per_second;
|
||||
@@ -208,7 +208,7 @@ static switch_status_t switch_silk_init(switch_codec_t *codec,
|
||||
if (decoding) {
|
||||
|
||||
switch_set_flag(codec, SWITCH_CODEC_FLAG_HAS_PLC);
|
||||
|
||||
|
||||
if (SKP_Silk_SDK_Get_Decoder_Size(&decSizeBytes)) {
|
||||
return SWITCH_STATUS_FALSE;
|
||||
}
|
||||
@@ -236,25 +236,25 @@ void printSilkError(SKP_int16 ret){
|
||||
switch (ret) {
|
||||
case SKP_SILK_NO_ERROR: message = "No errors";
|
||||
break;
|
||||
case SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES:
|
||||
case SKP_SILK_ENC_INPUT_INVALID_NO_OF_SAMPLES:
|
||||
message = "Input length is not multiplum of 10 ms, or length is longer than the packet length";
|
||||
break;
|
||||
case SKP_SILK_ENC_FS_NOT_SUPPORTED:
|
||||
case SKP_SILK_ENC_FS_NOT_SUPPORTED:
|
||||
message = "Sampling frequency not 8000 , 12000, 16000 or 24000 Hertz";
|
||||
break;
|
||||
case SKP_SILK_ENC_PACKET_SIZE_NOT_SUPPORTED:
|
||||
message ="Packet size not 20, 40 , 60 , 80 or 100 ms ";
|
||||
break;
|
||||
case SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT:
|
||||
break;
|
||||
case SKP_SILK_ENC_PAYLOAD_BUF_TOO_SHORT:
|
||||
message = "Allocated payload buffer too short";
|
||||
break;
|
||||
case SKP_SILK_ENC_INVALID_LOSS_RATE:
|
||||
case SKP_SILK_ENC_INVALID_LOSS_RATE:
|
||||
message = " Loss rate not between 0 and 100 % ";
|
||||
break;
|
||||
case SKP_SILK_ENC_INVALID_COMPLEXITY_SETTING:
|
||||
message = "Complexity setting not valid, use 0 ,1 or 2";
|
||||
break;
|
||||
case SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING:
|
||||
case SKP_SILK_ENC_INVALID_INBAND_FEC_SETTING:
|
||||
message = "Inband FEC setting not valid, use 0 or 1 ";
|
||||
break;
|
||||
case SKP_SILK_ENC_INVALID_DTX_SETTING:
|
||||
@@ -266,7 +266,7 @@ void printSilkError(SKP_int16 ret){
|
||||
case SKP_SILK_DEC_INVALID_SAMPLING_FREQUENCY:
|
||||
message = "Output sampling frequency lower than internal decoded sampling frequency";
|
||||
break;
|
||||
case SKP_SILK_DEC_PAYLOAD_TOO_LARGE:
|
||||
case SKP_SILK_DEC_PAYLOAD_TOO_LARGE:
|
||||
message = "Payload size exceeded the maximum allowed 1024 bytes";
|
||||
break;
|
||||
case SKP_SILK_DEC_PAYLOAD_ERROR :
|
||||
@@ -288,7 +288,7 @@ static switch_status_t switch_silk_encode(switch_codec_t *codec,
|
||||
struct silk_context *context = codec->private_info;
|
||||
SKP_int16 ret;
|
||||
SKP_int16 pktsz = (SKP_int16)context->encoder_object.packetSize;
|
||||
SKP_int16 nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
|
||||
SKP_int16 nBytes = MAX_BYTES_PER_FRAME * MAX_INPUT_FRAMES;
|
||||
SKP_int16 *lindata = (SKP_int16 *)decoded_data;
|
||||
SKP_int16 samples = (SKP_int16)(decoded_data_len /sizeof(SKP_int16));
|
||||
*encoded_data_len = 0;
|
||||
@@ -299,7 +299,7 @@ static switch_status_t switch_silk_encode(switch_codec_t *codec,
|
||||
pktsz,
|
||||
encoded_data,
|
||||
&nBytes);
|
||||
|
||||
|
||||
if (ret) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "SKP_Silk_Encode returned %d!\n", ret);
|
||||
printSilkError(ret);
|
||||
@@ -323,7 +323,7 @@ static switch_status_t switch_silk_decode(switch_codec_t *codec,
|
||||
uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
|
||||
{
|
||||
struct silk_context *context = codec->private_info;
|
||||
SKP_int16 ret, len;
|
||||
SKP_int16 ret, len;
|
||||
int16_t *target = decoded_data;
|
||||
switch_core_session_t *session = codec->session;
|
||||
switch_jb_t *jb = NULL;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,13 +22,13 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Brian K. West <brian@freeswitch.org>
|
||||
* Steve Underwood <steveu@coppice.org>
|
||||
*
|
||||
* mod_siren.c -- ITU-T G.722.1 (Siren7) and ITU-T G.722.1 Annex C (Siren14) licensed from Polycom(R)
|
||||
*
|
||||
* Using mod_siren in a commercial product will require you to acquire a patent
|
||||
* Using mod_siren in a commercial product will require you to acquire a patent
|
||||
* license directly from Polycom(R) for your company.
|
||||
*
|
||||
* http://www.polycom.com/usa/en/company/about_us/technology/siren_g7221/siren_g7221.html
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -29,7 +29,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Other source of reference for module building:
|
||||
* Other source of reference for module building:
|
||||
* src/mod/applications/mod_skel/mod_skel.c
|
||||
* http://files.freeswitch.org/cluecon_2009/presentations/Silva_FreeSWITCH_Modules_For_Asterisk_Devs.ppt
|
||||
* You can load this codec with this command:
|
||||
@@ -145,7 +145,7 @@ static switch_status_t switch_skel_decode(switch_codec_t *codec, /* codec sessio
|
||||
|
||||
static switch_status_t switch_skel_destroy(switch_codec_t *codec)
|
||||
{
|
||||
/* things that you may do here is closing files, sockets or other resources used during the codec session
|
||||
/* things that you may do here is closing files, sockets or other resources used during the codec session
|
||||
* no need to free memory allocated from the pool though, the owner of the pool takes care of that */
|
||||
struct skel_context *context = codec->private_info;
|
||||
context->encodes = 0;
|
||||
@@ -153,7 +153,7 @@ static switch_status_t switch_skel_destroy(switch_codec_t *codec)
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
/* A standard API registered by the this codec module, APIs can be executed from CLI, mod_event_socket, or many other interfaces
|
||||
/* A standard API registered by the this codec module, APIs can be executed from CLI, mod_event_socket, or many other interfaces
|
||||
* any information or actions you want to publish for users on demand is typically exposed through an API */
|
||||
SWITCH_STANDARD_API(skel_sayhi)
|
||||
/* static switch_status_t skel_sayhi(const char *cmd, switch_core_session_t *session, switch_stream_handle_t *stream) */
|
||||
@@ -168,20 +168,20 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_skel_codec_load)
|
||||
/* the codec interface that will be registered with the core */
|
||||
switch_codec_interface_t *codec_interface;
|
||||
|
||||
/* the API interface, only needed if you wish to register APIs
|
||||
/* the API interface, only needed if you wish to register APIs
|
||||
* (like commands exposed through CLI, mod_event_socket or any other FS interface capable of executing APIs) */
|
||||
switch_api_interface_t *api_interface;
|
||||
|
||||
/* The core gives us a blank module interface pointer and a pool of memory, we allocate memory from that pool to create our module interface
|
||||
/* The core gives us a blank module interface pointer and a pool of memory, we allocate memory from that pool to create our module interface
|
||||
* and set the pointer to that chunk of allocated memory */
|
||||
*module_interface = switch_loadable_module_create_module_interface(pool, modname);
|
||||
|
||||
/* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface list the core keeps,
|
||||
/* SWITCH_ADD_CODEC allocates a codec interface structure from the pool the core gave us and adds it to the internal interface list the core keeps,
|
||||
* gets a codec id and set the given codec name to it.
|
||||
* At this point there is an empty shell codec interface registered, but not yet implementations */
|
||||
SWITCH_ADD_CODEC(codec_interface, "SKEL 8.0k"); /* 8.0kbit */
|
||||
|
||||
/* Now add as many codec implementations as needed, typically this is done inside a for loop where the packetization size is
|
||||
/* Now add as many codec implementations as needed, typically this is done inside a for loop where the packetization size is
|
||||
* incremented (10ms, 20ms, 30ms etc) as needed */
|
||||
switch_core_codec_add_implementation(pool, codec_interface, /* the codec interface we allocated and we want to register with the core */
|
||||
SWITCH_CODEC_TYPE_AUDIO, /* enumeration defining the type of the codec */
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
/*
|
||||
/*
|
||||
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
||||
* Copyright (C) 2005-2014, Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
@@ -22,7 +22,7 @@
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
*
|
||||
* Anthony Minessale II <anthm@freeswitch.org>
|
||||
*
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user