aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-13 01:38:47 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-07-13 01:38:47 +0000
commit471ba9658e1e88044c419e9740961620f3ef1545 (patch)
treead7ef4ac83582f6e9e8b0e02e7746a6fbb49f569
parentb2b23b395d856d8c40461ce058f870a02fd4305b (diff)
allow users of RTP to use G726-32 AAL2 packing even when RFC3551 packing has been requested (Sipura/Grandstream ATAs and others will need this)
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@37501 f38db490-d61c-443f-a65b-d21fe96a405b
-rw-r--r--channels/chan_jingle.c2
-rw-r--r--channels/chan_mgcp.c10
-rw-r--r--channels/chan_sip.c24
-rw-r--r--include/asterisk/rtp.h13
-rw-r--r--rtp.c43
5 files changed, 57 insertions, 35 deletions
diff --git a/channels/chan_jingle.c b/channels/chan_jingle.c
index c5957e399..cefecc783 100644
--- a/channels/chan_jingle.c
+++ b/channels/chan_jingle.c
@@ -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);
}
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index df7db1b8a..5ad6cb733 100644
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -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);
}
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 91aaef100..35ac561a6 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -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... */
diff --git a/include/asterisk/rtp.h b/include/asterisk/rtp.h
index 5334b351c..bc539cb29 100644
--- a/include/asterisk/rtp.h
+++ b/include/asterisk/rtp.h
@@ -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 3ac4928d2..f5ac07fef 100644
--- 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;