Index: channels/chan_iax2.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v retrieving revision 1.237 diff -u -r1.237 chan_iax2.c --- channels/chan_iax2.c 14 Jan 2005 21:10:16 -0000 1.237 +++ channels/chan_iax2.c 15 Jan 2005 00:26:40 -0000 @@ -2367,6 +2367,38 @@ return tmp; } +/* Sub-function of iax2_call. Determines preferred format, and appends it to the iax_ie_data. */ +static void iax2_call_set_preferred_codec(struct iax_ie_data *ie_data, struct ast_channel *channel, struct chan_iax2_pvt* pvt) +{ + /* Shares code with chan_sip.c::sip_call */ + /* PREFERRED_CODEC can override the selection for preferred codec. + Be sure to set the var _PREFERRED_CODEC in the dialplan (note leading underscore), + so that the variable is passed onto the new channel. */ + char *preferred_codec; + int format = channel->nativeformats; /* Default to using the current native format */ + + preferred_codec = pbx_builtin_getvar_helper(channel, "PREFERRED_CODEC"); + if (preferred_codec && !ast_strlen_zero(preferred_codec)) { + int override_format = ast_getformatbyname(preferred_codec); + if (override_format) { + if (override_format & pvt->capability) { + format = override_format; + if (option_verbose > 2) { + ast_verbose(VERBOSE_PREFIX_3 "PREFERRED_CODEC variable overriding preferred format for this call to %s\n", preferred_codec); + } + } else { + ast_log(LOG_NOTICE, + "Ignoring PREFERRED_CODEC variable: Cannot use because current capabilites (0x%x) do not include %s (0x%x).\n", + pvt->capability, preferred_codec, override_format); + } + } else { + ast_log(LOG_NOTICE, "Ignoring PREFERRED_CODEC variable: Unknown codec '%s'.\n", preferred_codec); + } + } + + iax_ie_append_int(ie_data, IAX_IE_FORMAT, format); +} + static int iax2_call(struct ast_channel *c, char *dest, int timeout) { struct sockaddr_in sin; @@ -2499,7 +2531,7 @@ } else strncpy(iaxs[callno]->secret, secret, sizeof(iaxs[callno]->secret)-1); } - iax_ie_append_int(&ied, IAX_IE_FORMAT, c->nativeformats); + iax2_call_set_preferred_codec(&ied, c, iaxs[callno]); iax_ie_append_int(&ied, IAX_IE_CAPABILITY, iaxs[callno]->capability); iax_ie_append_short(&ied, IAX_IE_ADSICPE, c->adsicpe); iax_ie_append_int(&ied, IAX_IE_DATETIME, iax2_datetime(tz)); Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.631 diff -u -r1.631 chan_sip.c --- channels/chan_sip.c 13 Jan 2005 20:26:33 -0000 1.631 +++ channels/chan_sip.c 15 Jan 2005 00:26:49 -0000 @@ -1393,7 +1393,6 @@ return -1; } /* Check whether there is vxml_url, distinctive ring variables */ - headp=&ast->varshead; AST_LIST_TRAVERSE(headp,current,entries) { /* Check whether there is a VXML_URL variable */ @@ -1433,6 +1432,28 @@ if ( res != -1 ) { p->callingpres = ast->cid.cid_pres; p->jointcapability = p->capability; + + /* Handle PREFERRED_CODEC override. Ensure dialplan sets var with leading underscore so it gets passed. */ + /* Shares code with chan_iax2.c::iax2_call_set_preferred_codec */ + char *preferred_codec = pbx_builtin_getvar_helper(ast, "PREFERRED_CODEC"); + if (preferred_codec && !ast_strlen_zero(preferred_codec)) { + int override_format = ast_getformatbyname(preferred_codec); + if (override_format) { + if (override_format & p->capability) { + p->prefcodec = override_format; + if (option_verbose > 2) { + ast_verbose(VERBOSE_PREFIX_3 "PREFERRED_CODEC variable overriding preferred format for this call to %s\n", preferred_codec); + } + } else { + ast_log(LOG_NOTICE, + "Ignoring PREFERRED_CODEC variable: Cannot use because current capabilites (0x%x) do not include %s (0x%x).\n", + p->capability, preferred_codec, override_format); + } + } else { + ast_log(LOG_NOTICE, "Ignoring PREFERRED_CODEC variable: Unknown codec '%s'.\n", preferred_codec); + } + } + transmit_invite(p, "INVITE", 1, NULL, NULL, vxml_url,distinctive_ring, osptoken, addsipheaders, 1); if (p->maxtime) { /* Initialize auto-congest time */ @@ -3343,6 +3364,7 @@ add_line(req, tmp); return 0; } + /*--- add_sdp: Add Session Description Protocol message ---*/ static int add_sdp(struct sip_request *resp, struct sip_pvt *p)