allow users of RTP to use G726-32 AAL2 packing even when RFC3551 packing has been...
authorKevin P. Fleming <kpfleming@digium.com>
Thu, 13 Jul 2006 01:38:47 +0000 (01:38 +0000)
committerKevin P. Fleming <kpfleming@digium.com>
Thu, 13 Jul 2006 01:38:47 +0000 (01:38 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@37501 65c4cc65-6c06-0410-ace0-fbb531ad65f3

channels/chan_jingle.c
channels/chan_mgcp.c
channels/chan_sip.c
include/asterisk/rtp.h
rtp.c

index c5957e3..cefecc7 100644 (file)
@@ -882,7 +882,7 @@ static int jingle_newcall(struct jingle *client, ikspak *pak)
                while (codec) {
                        ast_rtp_set_m_type(p->rtp, atoi(iks_find_attrib(codec, "id")));
                        ast_rtp_set_rtpmap_type(p->rtp, atoi(iks_find_attrib(codec, "id")), "audio",
-                                                                       iks_find_attrib(codec, "name"));
+                                               iks_find_attrib(codec, "name"), 0);
                        codec = iks_next(codec);
                }
                
index df7db1b..5ad6cb7 100644 (file)
@@ -1882,7 +1882,7 @@ static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
                if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2)
                        continue;
                /* Note: should really look at the 'freq' and '#chans' params too */
-               ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype);
+               ast_rtp_set_rtpmap_type(sub->rtp, codec, "audio", mimeSubtype, 0);
        }
 
        /* Now gather all of the codecs that were asked for: */
@@ -2081,7 +2081,7 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
                        if (codec > -1) {
                                snprintf(costr, sizeof(costr), " %d", codec);
                                strncat(m, costr, sizeof(m) - strlen(m) - 1);
-                               snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, x));
+                               snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, x, 0));
                                strncat(a, costr, sizeof(a) - strlen(a) - 1);
                        }
                }
@@ -2095,7 +2095,7 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_subchannel *sub, struc
                        if (codec > -1) {
                                snprintf(costr, sizeof(costr), " %d", codec);
                                strncat(m, costr, sizeof(m) - strlen(m) - 1);
-                               snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(0, x));
+                               snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(0, x, 0));
                                strncat(a, costr, sizeof(a) - strlen(a) - 1);
                                if (x == AST_RTP_DTMF) {
                                        /* Indicate we support DTMF...  Not sure about 16,
@@ -2140,7 +2140,7 @@ static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
        snprintf(local, sizeof(local), "p:20");
        for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) {
                if (p->capability & x) {
-                       snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
+                       snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0));
                        strncat(local, tmp, sizeof(local) - strlen(local) - 1);
                }
        }
@@ -2170,7 +2170,7 @@ static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp
        snprintf(local, sizeof(local), "p:20");
        for (x=1;x<= AST_FORMAT_MAX_AUDIO; x <<= 1) {
                if (p->capability & x) {
-                       snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
+                       snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x, 0));
                        strncat(local, tmp, sizeof(local) - strlen(local) - 1);
                }
        }
index 91aaef1..35ac561 100644 (file)
@@ -4719,9 +4719,9 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
                        ast_verbose("Found description format %s for ID %d\n", mimeSubtype, codec);
 
                /* Note: should really look at the 'freq' and '#chans' params too */
-               ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype);
+               ast_rtp_set_rtpmap_type(newaudiortp, codec, "audio", mimeSubtype, 0);
                if (p->vrtp)
-                       ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype);
+                       ast_rtp_set_rtpmap_type(newvideortp, codec, "video", mimeSubtype, 0);
        }
        
        if (udptlportno != -1) {
@@ -4855,15 +4855,15 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
                char s1[BUFSIZ], s2[BUFSIZ], s3[BUFSIZ], s4[BUFSIZ];
 
                ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s, combined - %s\n",
-                       ast_getformatname_multiple(s1, BUFSIZ, p->capability),
-                       ast_getformatname_multiple(s2, BUFSIZ, newpeercapability),
-                       ast_getformatname_multiple(s3, BUFSIZ, vpeercapability),
-                       ast_getformatname_multiple(s4, BUFSIZ, newjointcapability));
+                           ast_getformatname_multiple(s1, BUFSIZ, p->capability),
+                           ast_getformatname_multiple(s2, BUFSIZ, newpeercapability),
+                           ast_getformatname_multiple(s3, BUFSIZ, vpeercapability),
+                           ast_getformatname_multiple(s4, BUFSIZ, newjointcapability));
 
                ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n",
-                       ast_rtp_lookup_mime_multiple(s1, BUFSIZ, noncodeccapability, 0),
-                       ast_rtp_lookup_mime_multiple(s2, BUFSIZ, peernoncodeccapability, 0),
-                       ast_rtp_lookup_mime_multiple(s3, BUFSIZ, newnoncodeccapability, 0));
+                           ast_rtp_lookup_mime_multiple(s1, BUFSIZ, noncodeccapability, 0, 0),
+                           ast_rtp_lookup_mime_multiple(s2, BUFSIZ, peernoncodeccapability, 0, 0),
+                           ast_rtp_lookup_mime_multiple(s3, BUFSIZ, newnoncodeccapability, 0, 0));
        }
        if (!newjointcapability) {
                ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n");
@@ -5571,7 +5571,7 @@ static void add_codec_to_sdp(const struct sip_pvt *p, int codec, int sample_rate
 
        ast_build_string(m_buf, m_size, " %d", rtp_code);
        ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-                        ast_rtp_lookup_mime_subtype(1, codec),
+                        ast_rtp_lookup_mime_subtype(1, codec, 0),
                         sample_rate);
        if (codec == AST_FORMAT_G729A) {
                /* Indicate that we don't support VAD (G.729 annex B) */
@@ -5727,13 +5727,13 @@ static void add_noncodec_to_sdp(const struct sip_pvt *p, int format, int sample_
        int rtp_code;
 
        if (debug)
-               ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format));
+               ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format, 0));
        if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1)
                return;
 
        ast_build_string(m_buf, m_size, " %d", rtp_code);
        ast_build_string(a_buf, a_size, "a=rtpmap:%d %s/%d\r\n", rtp_code,
-                        ast_rtp_lookup_mime_subtype(0, format),
+                        ast_rtp_lookup_mime_subtype(0, format, 0),
                         sample_rate);
        if (format == AST_RTP_DTMF)
                /* Indicate we support DTMF and FLASH... */
index 5334b35..bc539cb 100644 (file)
@@ -50,6 +50,10 @@ extern "C" {
 
 #define MAX_RTP_PT                     256
 
+enum ast_rtp_options {
+       AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
+};
+
 struct ast_rtp_protocol {
        /*! Get RTP struct, or NULL if unwilling to transfer */
        struct ast_rtp *(* const get_rtp_info)(struct ast_channel *chan);
@@ -141,7 +145,8 @@ void ast_rtp_pt_copy(struct ast_rtp *dest, const struct ast_rtp *src);
 
 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
 void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
-                        char* mimeType, char* mimeSubtype);
+                            char *mimeType, char *mimeSubtype,
+                            enum ast_rtp_options options);
 
 /*! \brief  Mapping between RTP payload format codes and Asterisk codes: */
 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
@@ -151,10 +156,12 @@ void ast_rtp_get_current_formats(struct ast_rtp* rtp,
                             int* astFormats, int* nonAstFormats);
 
 /*! \brief  Mapping an Asterisk code into a MIME subtype (string): */
-char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
+const char *ast_rtp_lookup_mime_subtype(int isAstFormat, int code,
+                                       enum ast_rtp_options options);
 
 /*! \brief 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);
+char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability,
+                                  const int isAstFormat, enum ast_rtp_options options);
 
 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
 
diff --git a/rtp.c b/rtp.c
index 3ac4928..f5ac07f 100644 (file)
--- a/rtp.c
+++ b/rtp.c
@@ -1439,19 +1439,25 @@ void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt)
 } 
 
 /*! \brief Make a note of a RTP payload type (with MIME type) that was seen in
-       a SDP "a=rtpmap:" line. */
-void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
-                        char* mimeType, char* mimeSubtype) 
+ * an SDP "a=rtpmap:" line.
+ */
+void ast_rtp_set_rtpmap_type(struct ast_rtp *rtp, int pt,
+                            char *mimeType, char *mimeSubtype,
+                            enum ast_rtp_options options)
 {
-       int i;
+       unsigned int i;
 
        if (pt < 0 || pt > MAX_RTP_PT) 
                return; /* bogus payload type */
 
-       for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
+       for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) {
                if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
-                    strcasecmp(mimeType, mimeTypes[i].type) == 0) {
+                   strcasecmp(mimeType, mimeTypes[i].type) == 0) {
                        rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
+                       if ((mimeTypes[i].payloadType.code == AST_FORMAT_G726) &&
+                           mimeTypes[i].payloadType.isAstFormat &&
+                           (options & AST_RTP_OPT_G726_NONSTANDARD))
+                               rtp->current_RTP_PT[pt].code = AST_FORMAT_G726_AAL2;
                        return;
                }
        }
@@ -1524,19 +1530,27 @@ int ast_rtp_lookup_code(struct ast_rtp* rtp, const int isAstFormat, const int co
        return -1;
 }
 
-char* ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code) 
+const char *ast_rtp_lookup_mime_subtype(const int isAstFormat, const int code,
+                                 enum ast_rtp_options options)
 {
+       unsigned int i;
 
-       int i;
-
-       for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
-               if (mimeTypes[i].payloadType.code == code && mimeTypes[i].payloadType.isAstFormat == isAstFormat)
-                       return mimeTypes[i].subtype;
+       for (i = 0; i < sizeof(mimeTypes)/sizeof(mimeTypes[0]); ++i) {
+               if ((mimeTypes[i].payloadType.code == code) && (mimeTypes[i].payloadType.isAstFormat == isAstFormat)) {
+                       if (isAstFormat &&
+                           (code == AST_FORMAT_G726_AAL2) &&
+                           (options & AST_RTP_OPT_G726_NONSTANDARD))
+                               return "AAL2-G726-32";
+                       else
+                               return mimeTypes[i].subtype;
+               }
        }
+
        return "";
 }
 
-char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, const int isAstFormat)
+char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability,
+                                  const int isAstFormat, enum ast_rtp_options options)
 {
        int format;
        unsigned len;
@@ -1555,7 +1569,8 @@ char *ast_rtp_lookup_mime_multiple(char *buf, int size, const int capability, co
 
        for (format = 1; format < AST_RTP_MAX; format <<= 1) {
                if (capability & format) {
-                       const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format);
+                       const char *name = ast_rtp_lookup_mime_subtype(isAstFormat, format, options);
+
                        snprintf(end, size, "%s|", name);
                        len = strlen(end);
                        end += len;