提交 dfa78985 authored 作者: Anthony Minessale's avatar Anthony Minessale

Change codec behaviour

channel_variable: sdp_m_per_ptime
Adds a new m= line for each distinct ptime in codec list.

When this variable is not set:
	When mixing codecs with various ptime in a codec list, they will now be allowed to co-exist in the sdp but it will send no ptime attr.
		This means the ptime preferences on the offer will be ignored when mixing codecs with various ptimes.
	When receiving a codec list with no ptime attr, the ptime will be chosen from local preference instead of assuming 20ms
		This means if offer contains PCMU with not ptime and FS has PCMU@40i

Dynamic payloads will now start at 98 and increment per additional dynamic codec per call.
	So now you can add CELT@32000h,CELT@48000h and each one will be auto-assigned a dynamic paylaod type.
上级 3cd8766b
......@@ -1031,13 +1031,10 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
if (codec_ms != tech_pvt->codec_ms) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_WARNING,
"We were told to use ptime %d but what they meant to say was %d\n"
"This issue has so far been identified to happen on the following broken platforms/devices:\n"
"Linksys/Sipura aka Cisco\n"
"ShoreTel\n"
"Sonus/L3\n"
"We will try to fix it but some of the devices on this list are so broken,\n"
"who knows what will happen..\n", (int) tech_pvt->codec_ms, (int) codec_ms);
"Asynchronous PTIME not supported, changing our end from %d to %d\n",
(int) tech_pvt->codec_ms,
(int) codec_ms
);
switch_channel_set_variable_printf(channel, "sip_h_X-Broken-PTIME", "Adv=%d;Sent=%d",
(int) tech_pvt->codec_ms, (int) codec_ms);
......
......@@ -705,6 +705,8 @@ struct private_object {
char *user_via;
char *redirected;
sofia_cid_type_t cid_type;
switch_payload_t payload_space;
switch_payload_t ianacodes[SWITCH_MAX_CODECS];
};
struct callback_t {
......
......@@ -1423,7 +1423,7 @@ static void switch_load_core_config(const char *file)
{
switch_xml_t xml = NULL, cfg = NULL;
switch_core_hash_insert(runtime.ptimes, "ilbc", &d_30);
//switch_core_hash_insert(runtime.ptimes, "ilbc", &d_30);
switch_core_hash_insert(runtime.ptimes, "G723", &d_30);
if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) {
......
......@@ -1547,12 +1547,91 @@ SWITCH_DECLARE(switch_management_interface_t *) switch_loadable_module_get_manag
return switch_core_hash_find_locked(loadable_modules.management_hash, relative_oid, loadable_modules.mutex);
}
#ifdef DEBUG_CODEC_SORTING
static void do_print(const switch_codec_implementation_t **array, int arraylen)
{
int i;
for(i = 0; i < arraylen; i++) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
"DEBUG %d %s:%d %d\n", i, array[i]->iananame, array[i]->ianacode, array[i]->microseconds_per_packet / 1000);
}
}
#endif
/* helper only -- bounds checking enforced by caller */
static void do_swap(const switch_codec_implementation_t **array, int a, int b)
{
const switch_codec_implementation_t *tmp = array[b];
array[b] = array[a];
array[a] = tmp;
}
static void switch_loadable_module_sort_codecs(const switch_codec_implementation_t **array, int arraylen)
{
int i = 0, sorted_ptime = 0;
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "--BEFORE\n");
do_print(array, arraylen);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "--BEFORE\n");
#endif
for (i = 0; i < arraylen; i++) {
int this_ptime = array[i]->microseconds_per_packet / 1000;
if (!sorted_ptime) {
sorted_ptime = this_ptime;
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sorted1 = %d\n", sorted_ptime);
#endif
}
if (this_ptime != sorted_ptime) {
int j;
int swapped = 0;
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%d != %d\n", this_ptime, sorted_ptime);
#endif
for(j = i; j < arraylen; j++) {
int check_ptime = array[j]->microseconds_per_packet / 1000;
if (check_ptime == sorted_ptime) {
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "swap %d %d ptime %d\n", i, j, check_ptime);
#endif
do_swap(array, i, j);
swapped = 1;
break;
}
}
if (!swapped) {
sorted_ptime = this_ptime;
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "sorted2 = %d\n", sorted_ptime);
#endif
}
}
}
#ifdef DEBUG_CODEC_SORTING
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "--AFTER\n");
do_print(array, arraylen);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "--AFTER\n");
#endif
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_implementation_t **array, int arraylen)
{
switch_hash_index_t *hi;
void *val;
switch_codec_interface_t *codec_interface;
int i = 0, lock = 0;
int i = 0;
const switch_codec_implementation_t *imp;
switch_mutex_lock(loadable_modules.mutex);
......@@ -1564,10 +1643,6 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
for (imp = codec_interface->implementations; imp; imp = imp->next) {
uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
if (lock && imp->microseconds_per_packet != lock) {
continue;
}
if (imp->microseconds_per_packet / 1000 == (int)default_ptime) {
array[i++] = imp;
goto found;
......@@ -1578,9 +1653,6 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
found:
if (!lock && i > 0)
lock = array[i - 1]->microseconds_per_packet;
if (i > arraylen) {
break;
}
......@@ -1588,13 +1660,15 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs(const switch_codec_impleme
switch_mutex_unlock(loadable_modules.mutex);
switch_loadable_module_sort_codecs(array, i);
return i;
}
SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_implementation_t **array, int arraylen, char **prefs, int preflen)
{
int x, i = 0, lock = 0;
int x, i = 0;
switch_codec_interface_t *codec_interface;
const switch_codec_implementation_t *imp;
......@@ -1635,9 +1709,6 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
uint32_t default_ptime = switch_default_ptime(imp->iananame, imp->ianacode);
if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
if (lock && imp->microseconds_per_packet != lock) {
continue;
}
if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != default_ptime) ||
(interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) {
......@@ -1664,10 +1735,6 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
for (imp = codec_interface->implementations; imp; imp = imp->next) {
if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) {
if (lock && imp->microseconds_per_packet != lock) {
continue;
}
if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) {
continue;
}
......@@ -1689,10 +1756,6 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
found:
if (!lock && i > 0) {
lock = array[i - 1]->microseconds_per_packet;
}
UNPROTECT_INTERFACE(codec_interface);
if (i > arraylen) {
......@@ -1704,6 +1767,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_
switch_mutex_unlock(loadable_modules.mutex);
switch_loadable_module_sort_codecs(array, i);
return i;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论