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:58:14 -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,43 +707,47 @@ 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 */ -int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { +/* 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 */ +/* 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_code(struct ast_rtp* rtp, int isAstFormat, int code, int usestatic) { int pt; - - if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && - code == rtp->rtp_lookup_code_cache_code) { - /* Use our cached mapping, to avoid the overhead of the loop below */ - return rtp->rtp_lookup_code_cache_result; - } + if (!usestatic) { + if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && + code == rtp->rtp_lookup_code_cache_code) { + /* Use our cached mapping, to avoid the overhead of the loop below */ + return rtp->rtp_lookup_code_cache_result; + } /* Check the dynamic list first */ - for (pt = 0; pt < MAX_RTP_PT; ++pt) { - if (rtp->current_RTP_PT[pt].code == code && - rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { - rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; - rtp->rtp_lookup_code_cache_code = code; - rtp->rtp_lookup_code_cache_result = pt; - return pt; + for (pt = 0; pt < MAX_RTP_PT; ++pt) { + if (rtp->current_RTP_PT[pt].code == code && + rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { + rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; + rtp->rtp_lookup_code_cache_code = code; + rtp->rtp_lookup_code_cache_result = pt; + return pt; + } } } - /* Then the static list */ for (pt = 0; pt < MAX_RTP_PT; ++pt) { if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) { - rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; - rtp->rtp_lookup_code_cache_code = code; - rtp->rtp_lookup_code_cache_result = pt; + /* No sense in caching this, this should not occur very often */ + if (!usestatic) { + rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; + rtp->rtp_lookup_code_cache_code = code; + rtp->rtp_lookup_code_cache_result = pt; + } return pt; } } @@ -984,7 +989,7 @@ ast_log(LOG_WARNING, "Don't know how to represent '%c'\n", digit); return -1; } - payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF); + payload = ast_rtp_lookup_code(rtp, 0, AST_RTP_DTMF, 0); /* If we have no peer, return immediately */ if (!rtp->them.sin_addr.s_addr) @@ -1145,7 +1150,7 @@ if (_f->frametype == AST_FRAME_VIDEO) subclass &= ~0x1; - codec = ast_rtp_lookup_code(rtp, 1, subclass); + codec = ast_rtp_lookup_code(rtp, 1, subclass, 0); if (codec < 0) { ast_log(LOG_WARNING, "Don't know how to send format %s packets with RTP\n", ast_getformatname(_f->subclass)); return -1; 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:58:19 -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_code(sub->rtp, 1, x, 1); 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_code(sub->rtp, 0, x, 1); 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:58:25 -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_code(p->rtp, 1, p->prefcodec, 1); 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_code(p->rtp, 1, cur->codec, 1); 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_code(p->rtp, 1, x, 1); 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_code(p->rtp, 0, x, 1); 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:58:26 -0000 @@ -88,7 +88,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_code(struct ast_rtp* rtp, int isAstFormat, int code, int usestatic); void ast_rtp_get_current_formats(struct ast_rtp* rtp, int* astFormats, int* nonAstFormats);