Index: rtp.c =================================================================== RCS file: /usr/cvsroot/asterisk/rtp.c,v retrieving revision 1.84 diff -u -r1.84 rtp.c --- rtp.c 7 Aug 2004 14:22:09 -0000 1.84 +++ rtp.c 25 Aug 2004 20:34:49 -0000 @@ -587,7 +587,7 @@ {{1, AST_FORMAT_SLINEAR}, "audio", "L16"}, {{1, AST_FORMAT_LPC10}, "audio", "LPC"}, {{1, AST_FORMAT_G729A}, "audio", "G729"}, - {{1, AST_FORMAT_SPEEX}, "audio", "SPEEX"}, + {{1, AST_FORMAT_SPEEX}, "audio", "speex"}, {{1, AST_FORMAT_ILBC}, "audio", "iLBC"}, {{0, AST_RTP_DTMF}, "audio", "telephone-event"}, {{0, AST_RTP_CISCO_DTMF}, "audio", "cisco-telephone-event"}, @@ -698,6 +698,7 @@ } } +/* We must ALWAYS look up from our own RTP PT table when receiving RTP */ struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) { struct rtpPayloadType result; @@ -706,15 +707,14 @@ result.isAstFormat = result.code = 0; return result; /* bogus payload type */ } - /* Start with the negotiated codecs */ - result = rtp->current_RTP_PT[pt]; - /* If it doesn't exist, check our static RTP type list, just in case */ - if (!result.code) - result = static_RTP_PT[pt]; + result = static_RTP_PT[pt]; return result; } -/* Looks up an RTP code out of our *static* outbound list */ +/* Looks up an RTP code out of our *dynamic* outbound list falling back + onto our static outbound list, this function will be run primarily + by ast_rtp_write and ast_rtp_senddigit -- in those cases, we must match + the remote's payload type */ int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { int pt; @@ -743,6 +743,21 @@ rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; rtp->rtp_lookup_code_cache_code = code; rtp->rtp_lookup_code_cache_result = pt; + return pt; + } + } + return -1; +} + +/* Looks up an RTP code out of our *static* outbound list, here, we must + advertise our version of the payload type numbers */ +int ast_rtp_lookup_static_code(struct ast_rtp* rtp, int isAstFormat, int code) { + int pt; + + /* No sense in caching this, this should not occur very often */ + for (pt = 0; pt < MAX_RTP_PT; ++pt) { + if (static_RTP_PT[pt].code == code && + static_RTP_PT[pt].isAstFormat == isAstFormat) { return pt; } } Index: channels/chan_mgcp.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_mgcp.c,v retrieving revision 1.75 diff -u -r1.75 chan_mgcp.c --- channels/chan_mgcp.c 13 Aug 2004 13:19:29 -0000 1.75 +++ channels/chan_mgcp.c 25 Aug 2004 20:34:53 -0000 @@ -1872,7 +1872,7 @@ if (mgcpdebug) { ast_verbose("Answering with capability %d\n", x); } - codec = ast_rtp_lookup_code(sub->rtp, 1, x); + codec = ast_rtp_lookup_static_code(sub->rtp, 1, x); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); strncat(m, costr, sizeof(m) - strlen(m) - 1); @@ -1886,7 +1886,7 @@ if (mgcpdebug) { ast_verbose("Answering with non-codec capability %d\n", x); } - codec = ast_rtp_lookup_code(sub->rtp, 0, x); + codec = ast_rtp_lookup_static_code(sub->rtp, 0, x); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); strncat(m, costr, sizeof(m) - strlen(m) - 1); Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.477 diff -u -r1.477 chan_sip.c --- channels/chan_sip.c 23 Aug 2004 14:31:20 -0000 1.477 +++ channels/chan_sip.c 25 Aug 2004 20:35:01 -0000 @@ -3380,7 +3381,7 @@ if (capability & p->prefcodec) { if (debug) ast_verbose("Answering/Requesting with root capability %d\n", p->prefcodec); - codec = ast_rtp_lookup_code(p->rtp, 1, p->prefcodec); + codec = ast_rtp_lookup_static_code(p->rtp, 1, p->prefcodec); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); if (p->prefcodec <= AST_FORMAT_MAX_AUDIO) { @@ -3401,7 +3402,7 @@ if ((capability & cur->codec) && !(alreadysent & cur->codec)) { if (debug) ast_verbose("Answering with preferred capability 0x%x(%s)\n", cur->codec, ast_getformatname(cur->codec)); - codec = ast_rtp_lookup_code(p->rtp, 1, cur->codec); + codec = ast_rtp_lookup_static_code(p->rtp, 1, cur->codec); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); if (cur->codec <= AST_FORMAT_MAX_AUDIO) { @@ -3423,7 +3424,7 @@ if ((capability & x) && !(alreadysent & x)) { if (debug) ast_verbose("Answering with capability 0x%x(%s)\n", x, ast_getformatname(x)); - codec = ast_rtp_lookup_code(p->rtp, 1, x); + codec = ast_rtp_lookup_static_code(p->rtp, 1, x); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); if (x <= AST_FORMAT_MAX_AUDIO) { @@ -3442,7 +3443,7 @@ if (p->noncodeccapability & x) { if (debug) ast_verbose("Answering with non-codec capability 0x%x(%s)\n", x, ast_getformatname(x)); - codec = ast_rtp_lookup_code(p->rtp, 0, x); + codec = ast_rtp_lookup_static_code(p->rtp, 0, x); if (codec > -1) { snprintf(costr, sizeof(costr), " %d", codec); strncat(m, costr, sizeof(m) - strlen(m) - 1); Index: include/asterisk/rtp.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/rtp.h,v retrieving revision 1.15 diff -u -r1.15 rtp.h --- include/asterisk/rtp.h 8 Jul 2004 11:46:15 -0000 1.15 +++ include/asterisk/rtp.h 25 Aug 2004 20:35:02 -0000 @@ -89,6 +89,7 @@ // Mapping between RTP payload format codes and Asterisk codes: struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt); int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code); +int ast_rtp_lookup_static_code(struct ast_rtp* rtp, int isAstFormat, int code); void ast_rtp_get_current_formats(struct ast_rtp* rtp, int* astFormats, int* nonAstFormats);