From 9e05fb4f39c1f8f694baf4431d70ace2fc7bedbd Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Fri, 24 Jun 2005 21:53:02 +0000 Subject: [PATCH] print non-codec capabilities correctly (bug #3960) git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/v1-0@6003 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- channels/chan_sip.c | 6 +++--- include/asterisk/rtp.h | 3 +++ rtp.c | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 43 insertions(+), 5 deletions(-) diff --git a/channels/chan_sip.c b/channels/chan_sip.c index b746d63095..291e4ad950 100755 --- a/channels/chan_sip.c +++ b/channels/chan_sip.c @@ -2784,9 +2784,9 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req) ast_getformatname_multiple(s4, slen, p->jointcapability)); ast_verbose("Non-codec capabilities: us - %s, peer - %s, combined - %s\n", - ast_getformatname_multiple(s1, slen, noncodeccapability), - ast_getformatname_multiple(s2, slen, peernoncodeccapability), - ast_getformatname_multiple(s3, slen, p->noncodeccapability)); + ast_rtp_lookup_mime_multiple(s1, slen, noncodeccapability, 0), + ast_rtp_lookup_mime_multiple(s2, slen, peernoncodeccapability, 0), + ast_rtp_lookup_mime_multiple(s3, slen, p->noncodeccapability, 0)); } if (!p->jointcapability) { ast_log(LOG_NOTICE, "No compatible codecs!\n"); diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h index b8436578cb..2aee0d42a7 100755 --- a/include/asterisk/rtp.h +++ b/include/asterisk/rtp.h @@ -97,6 +97,9 @@ void ast_rtp_get_current_formats(struct ast_rtp* rtp, // Mapping an Asterisk code into a MIME subtype (string): char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code); +/* Build a string of MIME subtype names from a capability list */ +char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat); + void ast_rtp_setnat(struct ast_rtp *rtp, int nat); int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc); diff --git a/rtp.c b/rtp.c index c41faa7bb8..5a58a80c02 100755 --- a/rtp.c +++ b/rtp.c @@ -753,7 +753,7 @@ struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) } /* Looks up an RTP code out of our *static* outbound list */ -int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { +int ast_rtp_lookup_code(struct ast_rtp* rtp, const int isAstFormat, const int code) { int pt; @@ -787,7 +787,7 @@ int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code) { return -1; } -char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) { +char* ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code) { int i; for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) { @@ -799,6 +799,41 @@ char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) { return ""; } +char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat) +{ + int format; + unsigned len; + char *end = buf; + char *start = buf; + + if (!buf || !size) + return NULL; + + snprintf(end, size, "0x%x (", capability); + + len = strlen(end); + end += len; + size -= len; + start = end; + + for (format = 1; format < AST_RTP_MAX; format <<= 1) { + if (capability & format) { + const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format); + snprintf(end, size, "%s|", name); + len = strlen(end); + end += len; + size -= len; + } + } + + if (start == end) + snprintf(start, size, "nothing)"); + else if (size > 1) + *(end -1) = ')'; + + return buf; + } + static int rtp_socket(void) { int s; -- 2.47.2