Index: channels/chan_sip.c =================================================================== --- channels/chan_sip.c (revision 393919) +++ channels/chan_sip.c (working copy) @@ -7357,36 +7357,59 @@ return 0; } -/*! \brief Try setting codec suggested by the SIP_CODEC channel variable */ static void try_suggested_sip_codec(struct sip_pvt *p) { struct ast_format fmt; - const char *codec; + const char *codec_list; + char *codec_list_copy; + struct ast_format_cap *jointcaps_copy; + char *codec; + int first_codec = 1; + char *strtok_ptr; + ast_format_clear(&fmt); - + if (p->outgoing_call) { - codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND"); - } else if (!(codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) { - codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"); + codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND"); + } else if (!(codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) { + codec_list = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"); } - - if (!codec) + + if (!codec_list) return; - ast_getformatbyname(codec, &fmt); - if (fmt.id) { - ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); - if (ast_format_cap_iscompatible(p->jointcaps, &fmt)) { - ast_format_cap_set(p->jointcaps, &fmt); - ast_format_cap_set(p->caps, &fmt); - } else - ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n"); - } else - ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec); - return; -} + codec_list_copy = ast_strdupa(codec_list); + jointcaps_copy = ast_format_cap_dup(p->jointcaps); + for (codec = strtok_r(codec_list_copy, ",", &strtok_ptr); codec; codec = strtok_r(NULL, ",", &strtok_ptr)) { + codec = ast_strip(codec); + + ast_getformatbyname(codec, &fmt); + if (!fmt.id) { + ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec); + continue; + } + if (ast_format_cap_iscompatible(jointcaps_copy, &fmt)) { + if (first_codec) { + ast_log(LOG_NOTICE, "Set codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); + ast_format_cap_set(p->jointcaps, &fmt); + ast_format_cap_set(p->caps, &fmt); + first_codec = 0; + } else { + ast_log(LOG_NOTICE, "Add codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); + ast_format_cap_add(p->jointcaps, &fmt); + ast_format_cap_add(p->caps, &fmt); + } + } else { + ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends: %s\n", codec); + } + } + ast_format_cap_destroy(jointcaps_copy); + return; + } + + /*! \brief sip_answer: Answer SIP call , send 200 OK on Invite * Part of PBX interface */ static int sip_answer(struct ast_channel *ast)