diff -Nru a/apps/app_chanisavail.c b/apps/app_chanisavail.c --- a/apps/app_chanisavail.c 2005-03-11 09:12:43 -07:00 +++ b/apps/app_chanisavail.c 2005-03-11 09:12:43 -07:00 @@ -98,7 +98,7 @@ snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); status = inuse = ast_device_state(trychan); } - if ((inuse < 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { + if ((inuse < 1) && (tempchan = ast_request(tech, chan->preferredformat, number, &status))) { pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); /* Store the originally used channel too */ snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); diff -Nru a/apps/app_dial.c b/apps/app_dial.c --- a/apps/app_dial.c 2005-03-11 09:12:43 -07:00 +++ b/apps/app_dial.c 2005-03-11 09:12:43 -07:00 @@ -352,7 +352,7 @@ if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name); /* Setup parameters */ - o->chan = ast_request(tech, in->nativeformats, stuff, &cause); + o->chan = ast_request(tech, in->preferredformat, stuff, &cause); if (!o->chan) ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause); } else { @@ -930,7 +930,7 @@ ast_log(LOG_DEBUG, "Dialing by extension %s\n", numsubst); } /* Request the peer */ - tmp->chan = ast_request(tech, chan->nativeformats, numsubst, &cause); + tmp->chan = ast_request(tech, chan->preferredformat, numsubst, &cause); if (!tmp->chan) { /* If we can't, just go on to the next call */ ast_log(LOG_NOTICE, "Unable to create channel of type '%s' (cause %d)\n", tech, cause); @@ -959,7 +959,7 @@ ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", chan->name, tech, stuff, tmp->chan->name); ast_hangup(tmp->chan); /* Setup parameters */ - tmp->chan = ast_request(tech, chan->nativeformats, stuff, &cause); + tmp->chan = ast_request(tech, chan->preferredformat, stuff, &cause); if (!tmp->chan) ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s' (cause = %d)\n", tech, stuff, cause); } else { diff -Nru a/apps/app_dumpchan.c b/apps/app_dumpchan.c --- a/apps/app_dumpchan.c 2005-03-11 09:12:43 -07:00 +++ b/apps/app_dumpchan.c 2005-03-11 09:12:43 -07:00 @@ -68,6 +68,7 @@ "State= %s (%d)\n" "Rings= %d\n" "NativeFormat= %d\n" + "PreferredFormat= %d\n" "WriteFormat= %d\n" "ReadFormat= %d\n" "1stFileDescriptor= %d\n" @@ -93,6 +94,7 @@ c->_state, c->rings, c->nativeformats, + c->preferredformat, c->writeformat, c->readformat, c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "", diff -Nru a/apps/app_queue.c b/apps/app_queue.c --- a/apps/app_queue.c 2005-03-11 09:12:43 -07:00 +++ b/apps/app_queue.c 2005-03-11 09:12:43 -07:00 @@ -833,7 +833,7 @@ location = ""; /* Request the peer */ - tmp->chan = ast_request(tech, qe->chan->nativeformats, location, &status); + tmp->chan = ast_request(tech, qe->chan->preferredformat, location, &status); if (!tmp->chan) { /* If we can't, just go on to the next call */ #if 0 ast_log(LOG_NOTICE, "Unable to create channel of type '%s' for Queue\n", cur->tech); @@ -1089,7 +1089,7 @@ if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name); /* Setup parameters */ - o->chan = ast_request(tech, in->nativeformats, stuff, &status); + o->chan = ast_request(tech, in->preferredformat, stuff, &status); if (status != o->oldstatus) update_dial_status(qe->parent, o->member, status); if (!o->chan) { diff -Nru a/channels/chan_features.c b/channels/chan_features.c --- a/channels/chan_features.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_features.c 2005-03-11 09:12:43 -07:00 @@ -169,6 +169,7 @@ p->subs[index].owner->alertpipe[1] = p->subchan->alertpipe[1]; if (p->subs[index].owner->nativeformats != p->subchan->readformat) { p->subs[index].owner->nativeformats = p->subchan->readformat; + p->subs[index].owner->preferredformat = p->subchan->readformat; if (p->subs[index].owner->readformat) ast_set_read_format(p->subs[index].owner, p->subs[index].owner->readformat); if (p->subs[index].owner->writeformat) @@ -467,6 +468,7 @@ tmp->readformat = p->subchan->readformat; tmp->rawreadformat = p->subchan->rawreadformat; tmp->nativeformats = p->subchan->readformat; + tmp->preferredformat = p->subchan->readformat; tmp->tech_pvt = p; p->subs[index].owner = tmp; if (!p->owner) diff -Nru a/channels/chan_h323.c b/channels/chan_h323.c --- a/channels/chan_h323.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_h323.c 2005-03-11 09:12:43 -07:00 @@ -23,7 +23,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * - * Version Info: $Id: chan_h323.c,v 1.105 2005/03/08 23:11:23 twisted Exp $ + * Version Info: $Id: chan_h323.c,v 1.103 2005/02/13 07:45:40 markster Exp $ */ #include @@ -657,6 +657,7 @@ if (f->subclass != pvt->owner->nativeformats) { ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); pvt->owner->nativeformats = f->subclass; + pvt->owner->preferredformat = f->subclass; ast_set_read_format(pvt->owner, pvt->owner->readformat); ast_set_write_format(pvt->owner, pvt->owner->writeformat); } @@ -788,7 +789,7 @@ ast_update_use_count(); ast_mutex_lock(&pvt->lock); if (ch) { - ch->tech = &oh323_tech; + tmp->tech = &oh323_tech; snprintf(ch->name, sizeof(ch->name), "H323/%s", host); ch->nativeformats = pvt->capability; if (!ch->nativeformats) { @@ -800,6 +801,7 @@ if (state == AST_STATE_RING) { ch->rings = 1; } + ch->preferredformat = fmt; ch->writeformat = fmt; ch->rawwriteformat = fmt; ch->readformat = fmt; @@ -1216,6 +1218,7 @@ ast_mutex_lock(&pvt->lock); pvt->owner->nativeformats = rtptype.code; + pvt->owner->preferredformat = fmt; pvt->owner->readformat = fmt; pvt->owner->writeformat = fmt; ast_set_read_format(pvt->owner, pvt->owner->readformat); @@ -2221,7 +2224,7 @@ char *description() { - return (char *) desc; + return desc; } char *key() diff -Nru a/channels/chan_iax2.c b/channels/chan_iax2.c --- a/channels/chan_iax2.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_iax2.c 2005-03-11 09:12:43 -07:00 @@ -2998,6 +2998,7 @@ tmp->type = channeltype; /* We can support any format by default, until we get restricted */ tmp->nativeformats = capability; + tmp->preferredformat = capability; tmp->readformat = ast_best_codec(capability); tmp->writeformat = ast_best_codec(capability); tmp->tech_pvt = CALLNO_TO_PTR(i->callno); @@ -6368,6 +6369,7 @@ if (iaxs[fr.callno]->owner) { /* Switch us to use a compatible format */ iaxs[fr.callno]->owner->nativeformats = iaxs[fr.callno]->peerformat; + iaxs[fr.callno]->owner->preferredformat = iaxs[fr.callno]->peerformat; if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "Format for call is %s\n", ast_getformatname(iaxs[fr.callno]->owner->nativeformats)); retryowner2: @@ -7224,6 +7226,7 @@ return NULL; } c->nativeformats = native; + c->preferredformat = native; } c->readformat = ast_best_codec(c->nativeformats); c->writeformat = c->readformat; diff -Nru a/channels/chan_local.c b/channels/chan_local.c --- a/channels/chan_local.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_local.c 2005-03-11 09:12:43 -07:00 @@ -465,7 +465,9 @@ if (tmp) { tmp2->tech = tmp->tech = &local_tech; tmp->nativeformats = p->reqformat; + tmp->preferredformat = p->reqformat; tmp2->nativeformats = p->reqformat; + tmp2->preferredformat = p->reqformat; snprintf(tmp->name, sizeof(tmp->name), "Local/%s@%s-%04x,1", p->exten, p->context, randnum); snprintf(tmp2->name, sizeof(tmp2->name), "Local/%s@%s-%04x,2", p->exten, p->context, randnum); tmp->type = type; diff -Nru a/channels/chan_mgcp.c b/channels/chan_mgcp.c --- a/channels/chan_mgcp.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_mgcp.c 2005-03-11 09:12:43 -07:00 @@ -1204,6 +1204,7 @@ if (f->subclass != sub->owner->nativeformats) { ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); sub->owner->nativeformats = f->subclass; + sub->owner->preferredformat = f->subclass; ast_set_read_format(sub->owner, sub->owner->readformat); ast_set_write_format(sub->owner, sub->owner->writeformat); } @@ -1387,6 +1388,7 @@ ast_setstate(tmp, state); if (state == AST_STATE_RING) tmp->rings = 1; + tmp->preferredformat = fmt; tmp->writeformat = fmt; tmp->rawwriteformat = fmt; tmp->readformat = fmt; diff -Nru a/channels/chan_modem.c b/channels/chan_modem.c --- a/channels/chan_modem.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_modem.c 2005-03-11 09:12:43 -07:00 @@ -552,6 +552,7 @@ tmp->type = type; tmp->fds[0] = i->fd; tmp->nativeformats = i->mc->formats; + tmp->preferredformat = i->mc->formats; ast_setstate(tmp, state); if (state == AST_STATE_RING) tmp->rings = 1; diff -Nru a/channels/chan_nbs.c b/channels/chan_nbs.c --- a/channels/chan_nbs.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_nbs.c 2005-03-11 09:12:43 -07:00 @@ -217,6 +217,7 @@ tmp->type = type; tmp->fds[0] = nbs_fd(i->nbs); tmp->nativeformats = prefformat; + tmp->preferredformat = prefformat; tmp->rawreadformat = prefformat; tmp->rawwriteformat = prefformat; tmp->writeformat = prefformat; diff -Nru a/channels/chan_oss.c b/channels/chan_oss.c --- a/channels/chan_oss.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_oss.c 2005-03-11 09:12:43 -07:00 @@ -743,6 +743,7 @@ tmp->type = type; tmp->fds[0] = sounddev; tmp->nativeformats = AST_FORMAT_SLINEAR; + tmp->preferredformat = AST_FORMAT_SLINEAR; tmp->readformat = AST_FORMAT_SLINEAR; tmp->writeformat = AST_FORMAT_SLINEAR; tmp->tech_pvt = p; diff -Nru a/channels/chan_phone.c b/channels/chan_phone.c --- a/channels/chan_phone.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_phone.c 2005-03-11 09:12:43 -07:00 @@ -762,11 +762,13 @@ ioctl(i->fd, PHONE_QUERY_CODEC, &codec) == 0) { if (codec.type == LINEAR16) tmp->nativeformats = + tmp->preferredformat = tmp->rawreadformat = tmp->rawwriteformat = AST_FORMAT_SLINEAR; else { tmp->nativeformats = + tmp->preferredformat = tmp->rawreadformat = tmp->rawwriteformat = prefformat & ~AST_FORMAT_SLINEAR; @@ -774,6 +776,7 @@ } else { tmp->nativeformats = prefformat; + tmp->preferredformat = prefformat; tmp->rawreadformat = prefformat; tmp->rawwriteformat = prefformat; } diff -Nru a/channels/chan_sip.c b/channels/chan_sip.c --- a/channels/chan_sip.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_sip.c 2005-03-11 09:12:43 -07:00 @@ -1881,7 +1881,6 @@ static int sip_answer(struct ast_channel *ast) { int res = 0,fmt; - char *codec; struct sip_pvt *p = ast->tech_pvt; ast_mutex_lock(&p->lock); @@ -1890,17 +1889,10 @@ time(&p->ospstart); #endif - codec=pbx_builtin_getvar_helper(p->owner,"SIP_CODEC"); - if (codec) { - fmt=ast_getformatbyname(codec); - if (fmt) { - ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC) variable\n",codec); - if (p->jointcapability & fmt) { - p->jointcapability &= fmt; - p->capability &= 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); + fmt = ast->preferredformat; + if (p->jointcapability & fmt) { + p->jointcapability &= fmt; + p->capability &= fmt; } ast_setstate(ast, AST_STATE_UP); @@ -2132,6 +2124,7 @@ if (state == AST_STATE_RING) tmp->rings = 1; tmp->adsicpe = AST_ADSI_UNAVAILABLE; + tmp->preferredformat = fmt; tmp->writeformat = fmt; tmp->rawwriteformat = fmt; tmp->readformat = fmt; @@ -2340,6 +2333,7 @@ if (f->subclass != p->owner->nativeformats) { ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); p->owner->nativeformats = f->subclass; + p->owner->preferredformat = f->subclass; ast_set_read_format(p->owner, p->owner->readformat); ast_set_write_format(p->owner, p->owner->writeformat); } @@ -2925,6 +2919,7 @@ ast_getformatname_multiple(s1, slen, p->jointcapability), ast_getformatname_multiple(s2, slen, p->owner->nativeformats)); p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1); + p->owner->preferredformat = p->owner->nativeformats; ast_set_read_format(p->owner, p->owner->readformat); ast_set_write_format(p->owner, p->owner->writeformat); } diff -Nru a/channels/chan_skinny.c b/channels/chan_skinny.c --- a/channels/chan_skinny.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_skinny.c 2005-03-11 09:12:43 -07:00 @@ -1829,6 +1829,7 @@ if (f->subclass != sub->owner->nativeformats) { ast_log(LOG_DEBUG, "Oooh, format changed to %d\n", f->subclass); sub->owner->nativeformats = f->subclass; + sub->owner->preferredformat = f->subclass; ast_set_read_format(sub->owner, sub->owner->readformat); ast_set_write_format(sub->owner, sub->owner->writeformat); } @@ -2011,6 +2012,7 @@ ast_setstate(tmp, state); if (state == AST_STATE_RING) tmp->rings = 1; + tmp->preferredformat = fmt; tmp->writeformat = fmt; tmp->rawwriteformat = fmt; tmp->readformat = fmt; diff -Nru a/channels/chan_zap.c b/channels/chan_zap.c --- a/channels/chan_zap.c 2005-03-11 09:12:43 -07:00 +++ b/channels/chan_zap.c 2005-03-11 09:12:43 -07:00 @@ -4678,7 +4678,7 @@ tmp->type = type; tmp->fds[0] = i->subs[index].zfd; tmp->nativeformats = AST_FORMAT_SLINEAR | deflaw; - /* Start out assuming ulaw since it's smaller :) */ + tmp->preferredformat = deflaw; tmp->rawreadformat = deflaw; tmp->readformat = deflaw; tmp->rawwriteformat = deflaw; diff -Nru a/cli.c b/cli.c --- a/cli.c 2005-03-11 09:12:43 -07:00 +++ b/cli.c 2005-03-11 09:12:43 -07:00 @@ -704,6 +704,7 @@ " State: %s (%d)\n" " Rings: %d\n" " NativeFormat: %d\n" + "PreferredFormat: %d\n" " WriteFormat: %d\n" " ReadFormat: %d\n" "1st File Descriptor: %d\n" @@ -725,7 +726,8 @@ c->name, c->type, c->uniqueid, (c->cid.cid_num ? c->cid.cid_num : "(N/A)"), (c->cid.cid_name ? c->cid.cid_name : "(N/A)"), - (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, c->writeformat, c->readformat, + (c->cid.cid_dnid ? c->cid.cid_dnid : "(N/A)" ), ast_state2str(c->_state), c->_state, c->rings, c->nativeformats, + c->preferredformat, c->writeformat, c->readformat, c->fds[0], c->fin & 0x7fffffff, (c->fin & 0x80000000) ? " (DEBUGGED)" : "", c->fout & 0x7fffffff, (c->fout & 0x80000000) ? " (DEBUGGED)" : "", (long)c->whentohangup, cdrtime, c->_bridge ? c->_bridge->name : "", ast_bridged_channel(c) ? ast_bridged_channel(c)->name : "", diff -Nru a/doc/README.variables b/doc/README.variables --- a/doc/README.variables 2005-03-11 09:12:43 -07:00 +++ b/doc/README.variables 2005-03-11 09:12:43 -07:00 @@ -321,6 +321,7 @@ ${INVALID_EXTEN} The invalid called extension (used in the "i" extension) ${LANGUAGE} * Current language ${LEN(VAR)} * String length of VAR (integer) +${PREFERRED_CODEC} * Codec (format) to be requested when outgoing channels are created ${PRIORITY} * Current priority in the dialplan ${PRIREDIRECTREASON} Reason for redirect on PRI, if a call was directed ${RDNIS} * Redirected Dial Number ID Service @@ -398,9 +399,6 @@ ${SIPDOMAIN} SIP destination domain of an inbound call (if appropriate) ${SIPUSERAGENT} SIP user agent ${SIPURI} SIP uri - -The SIP channel reads the following variable: -${SIP_CODEC} Set the SIP codec for a call The Agent channel uses the following variables: --------------------------------------------------------- diff -Nru a/include/asterisk/channel.h b/include/asterisk/channel.h --- a/include/asterisk/channel.h 2005-03-11 09:12:43 -07:00 +++ b/include/asterisk/channel.h 2005-03-11 09:12:43 -07:00 @@ -227,6 +227,8 @@ /*! Kinds of data this channel can natively handle */ int nativeformats; + /*! Preferred format for channels created by this one */ + int preferredformat; /*! Requested read format */ int readformat; /*! Requested write format */ diff -Nru a/pbx.c b/pbx.c --- a/pbx.c 2005-03-11 09:12:43 -07:00 +++ b/pbx.c 2005-03-11 09:12:43 -07:00 @@ -192,6 +192,7 @@ static int pbx_builtin_importvar(struct ast_channel *, void *); void pbx_builtin_setvar_helper(struct ast_channel *chan, char *name, char *value); char *pbx_builtin_getvar_helper(struct ast_channel *chan, char *name); +static int pbx_builtin_setpreferredcodec(struct ast_channel *, void *); static struct varshead globals; @@ -406,6 +407,13 @@ "Always returns 0.\n" }, + { "SetPreferredCodec", pbx_builtin_setpreferredcodec, + "Set preferred codec (format)", + " SetPreferredCodec(codec): Set preferred codec (format) to codec.\n" + "Preferred codec will be passed to peer when outbound channels are\n" + "channels are created.\n" + }, + { "SetVar", pbx_builtin_setvar, "Set variable to value", " SetVar(#n1=value|#n2=value|..[|options]) Set a variables to a CDR.\n" @@ -1039,6 +1047,9 @@ } else if (c && !strcmp(var, "LANGUAGE")) { strncpy(workspace, c->language, workspacelen - 1); *ret = workspace; + } else if (c && !strcmp(var, "PREFERRED_CODEC")) { + strncpy(workspace, ast_getformatname(c->preferredformat), workspacelen - 1); + *ret = workspace; } else { icky: if (headp) { @@ -5146,6 +5157,21 @@ /* Copy the language as specified */ if (data) strncpy(chan->language, (char *)data, sizeof(chan->language)-1); + return 0; +} + +static int pbx_builtin_setpreferredcodec(struct ast_channel *chan, void *data) +{ + if (data) { + int fmt = ast_getformatbyname(data); + + if (fmt) + chan->preferredformat = fmt; + else + chan->preferredformat = 0; + } + else + chan->preferredformat = 0; return 0; }