Various and assundary formatting fixes (bug #3174)

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@4569 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-12-28 16:43:20 +00:00
parent d331358a3b
commit 46ffd20c48

329
rtp.c
View File

@@ -186,12 +186,14 @@ static struct ast_frame *send_dtmf(struct ast_rtp *rtp)
gettimeofday(&tv, NULL); gettimeofday(&tv, NULL);
if ((tv.tv_sec < rtp->dtmfmute.tv_sec) || if ((tv.tv_sec < rtp->dtmfmute.tv_sec) ||
((tv.tv_sec == rtp->dtmfmute.tv_sec) && (tv.tv_usec < rtp->dtmfmute.tv_usec))) { ((tv.tv_sec == rtp->dtmfmute.tv_sec) && (tv.tv_usec < rtp->dtmfmute.tv_usec))) {
ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr)); if (option_debug)
ast_log(LOG_DEBUG, "Ignore potential DTMF echo from '%s'\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
rtp->resp = 0; rtp->resp = 0;
rtp->dtmfduration = 0; rtp->dtmfduration = 0;
return &null_frame; return &null_frame;
} }
ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr)); if (option_debug)
ast_log(LOG_DEBUG, "Sending dtmf: %d (%c), at %s\n", rtp->resp, rtp->resp, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr));
if (rtp->resp == 'X') { if (rtp->resp == 'X') {
rtp->f.frametype = AST_FRAME_CONTROL; rtp->f.frametype = AST_FRAME_CONTROL;
rtp->f.subclass = AST_CONTROL_FLASH; rtp->f.subclass = AST_CONTROL_FLASH;
@@ -388,7 +390,8 @@ struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp)
(rtp->rtcp->them.sin_port != sin.sin_port)) { (rtp->rtcp->them.sin_port != sin.sin_port)) {
memcpy(&rtp->them, &sin, sizeof(rtp->them)); memcpy(&rtp->them, &sin, sizeof(rtp->them));
rtp->rxseqno = 0; rtp->rxseqno = 0;
ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port)); if (option_debug)
ast_log(LOG_DEBUG, "RTP NAT: Using address %s:%d\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->rtcp->them.sin_addr), ntohs(rtp->rtcp->them.sin_port));
} }
} }
if (option_debug) if (option_debug)
@@ -491,34 +494,45 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
} }
if(rtp_debug_test_addr(&sin)) if(rtp_debug_test_addr(&sin))
ast_verbose("Got RTP packet from %s:%d (type %d, seq %d, ts %d, len %d)\n" ast_verbose("Got RTP packet from %s:%d (type %d, seq %d, ts %d, len %d)\n"
, ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen); , ast_inet_ntoa(iabuf, sizeof(iabuf), sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen);
rtpPT = ast_rtp_lookup_pt(rtp, payloadtype); rtpPT = ast_rtp_lookup_pt(rtp, payloadtype);
if (!rtpPT.isAstFormat) { if (!rtpPT.isAstFormat) {
/* This is special in-band data that's not one of our codecs */ /* This is special in-band data that's not one of our codecs */
if (rtpPT.code == AST_RTP_DTMF) { if (rtpPT.code == AST_RTP_DTMF) {
/* It's special -- rfc2833 process it */ /* It's special -- rfc2833 process it */
if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) { if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); f = process_rfc2833(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
rtp->lasteventseqn = seqno; rtp->lasteventseqn = seqno;
} else f = NULL; } else
if (f) return f; else return &null_frame; f = NULL;
} else if (rtpPT.code == AST_RTP_CISCO_DTMF) { if (f)
/* It's really special -- process it the Cisco way */ return f;
if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) { else
f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); return &null_frame;
rtp->lasteventseqn = seqno; } else if (rtpPT.code == AST_RTP_CISCO_DTMF) {
} else f = NULL; /* It's really special -- process it the Cisco way */
if (f) return f; else return &null_frame; if (rtp->lasteventseqn <= seqno || rtp->resp == 0 || (rtp->lasteventseqn >= 65530 && seqno <= 6)) {
} else if (rtpPT.code == AST_RTP_CN) { f = process_cisco_dtmf(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
/* Comfort Noise */ rtp->lasteventseqn = seqno;
f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen); } else
if (f) return f; else return &null_frame; f = NULL;
} else { if (f)
ast_log(LOG_NOTICE, "Unknown RTP codec %d received\n", payloadtype); return f;
return &null_frame; else
} return &null_frame;
} else if (rtpPT.code == AST_RTP_CN) {
/* Comfort Noise */
f = process_rfc3389(rtp, rtp->rawdata + AST_FRIENDLY_OFFSET + hdrlen, res - hdrlen);
if (f)
return f;
else
return &null_frame;
} else {
ast_log(LOG_NOTICE, "Unknown RTP codec %d received\n", payloadtype);
return &null_frame;
}
} }
rtp->f.subclass = rtpPT.code; rtp->f.subclass = rtpPT.code;
if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO) if (rtp->f.subclass < AST_FORMAT_MAX_AUDIO)
@@ -559,7 +573,8 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
/* Send any pending DTMF */ /* Send any pending DTMF */
if (rtp->resp && !rtp->dtmfcount) { if (rtp->resp && !rtp->dtmfcount) {
ast_log(LOG_DEBUG, "Sending pending DTMF\n"); if (option_debug)
ast_log(LOG_DEBUG, "Sending pending DTMF\n");
return send_dtmf(rtp); return send_dtmf(rtp);
} }
rtp->f.mallocd = 0; rtp->f.mallocd = 0;
@@ -593,10 +608,10 @@ struct ast_frame *ast_rtp_read(struct ast_rtp *rtp)
break; break;
case AST_FORMAT_SPEEX: case AST_FORMAT_SPEEX:
/* assumes that the RTP packet contained one Speex frame */ /* assumes that the RTP packet contained one Speex frame */
rtp->f.samples = 160; rtp->f.samples = 160;
break; break;
case AST_FORMAT_LPC10: case AST_FORMAT_LPC10:
rtp->f.samples = 22 * 8; rtp->f.samples = 22 * 8;
rtp->f.samples += (((char *)(rtp->f.data))[7] & 0x1) * 8; rtp->f.samples += (((char *)(rtp->f.data))[7] & 0x1) * 8;
break; break;
default: default:
@@ -677,145 +692,148 @@ static struct rtpPayloadType static_RTP_PT[MAX_RTP_PT] = {
void ast_rtp_pt_clear(struct ast_rtp* rtp) void ast_rtp_pt_clear(struct ast_rtp* rtp)
{ {
int i; int i;
for (i = 0; i < MAX_RTP_PT; ++i) { for (i = 0; i < MAX_RTP_PT; ++i) {
rtp->current_RTP_PT[i].isAstFormat = 0; rtp->current_RTP_PT[i].isAstFormat = 0;
rtp->current_RTP_PT[i].code = 0; rtp->current_RTP_PT[i].code = 0;
} }
rtp->rtp_lookup_code_cache_isAstFormat = 0; rtp->rtp_lookup_code_cache_isAstFormat = 0;
rtp->rtp_lookup_code_cache_code = 0; rtp->rtp_lookup_code_cache_code = 0;
rtp->rtp_lookup_code_cache_result = 0; rtp->rtp_lookup_code_cache_result = 0;
} }
void ast_rtp_pt_default(struct ast_rtp* rtp) void ast_rtp_pt_default(struct ast_rtp* rtp)
{ {
int i; int i;
/* Initialize to default payload types */
for (i = 0; i < MAX_RTP_PT; ++i) {
rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat;
rtp->current_RTP_PT[i].code = static_RTP_PT[i].code;
}
rtp->rtp_lookup_code_cache_isAstFormat = 0; /* Initialize to default payload types */
rtp->rtp_lookup_code_cache_code = 0; for (i = 0; i < MAX_RTP_PT; ++i) {
rtp->rtp_lookup_code_cache_result = 0; rtp->current_RTP_PT[i].isAstFormat = static_RTP_PT[i].isAstFormat;
rtp->current_RTP_PT[i].code = static_RTP_PT[i].code;
}
rtp->rtp_lookup_code_cache_isAstFormat = 0;
rtp->rtp_lookup_code_cache_code = 0;
rtp->rtp_lookup_code_cache_result = 0;
} }
/* Make a note of a RTP payload type that was seen in a SDP "m=" line. */ /* Make a note of a RTP payload type that was seen in a SDP "m=" line. */
/* By default, use the well-known value for this type (although it may */ /* By default, use the well-known value for this type (although it may */
/* still be set to a different value by a subsequent "a=rtpmap:" line): */ /* still be set to a different value by a subsequent "a=rtpmap:" line): */
void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) { void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt) {
if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */ if (pt < 0 || pt > MAX_RTP_PT)
return; /* bogus payload type */
if (static_RTP_PT[pt].code != 0) { if (static_RTP_PT[pt].code != 0) {
rtp->current_RTP_PT[pt] = static_RTP_PT[pt]; rtp->current_RTP_PT[pt] = static_RTP_PT[pt];
} }
} }
/* Make a note of a RTP payload type (with MIME type) that was seen in */ /* Make a note of a RTP payload type (with MIME type) that was seen in */
/* a SDP "a=rtpmap:" line. */ /* a SDP "a=rtpmap:" line. */
void ast_rtp_set_rtpmap_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) {
int i; int i;
if (pt < 0 || pt > MAX_RTP_PT) return; /* bogus payload type */ 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 && 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; rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
return; return;
} }
} }
} }
/* Return the union of all of the codecs that were set by rtp_set...() calls */ /* Return the union of all of the codecs that were set by rtp_set...() calls */
/* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */ /* They're returned as two distinct sets: AST_FORMATs, and AST_RTPs */
void ast_rtp_get_current_formats(struct ast_rtp* rtp, void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats) { int* astFormats, int* nonAstFormats) {
int pt; int pt;
*astFormats = *nonAstFormats = 0; *astFormats = *nonAstFormats = 0;
for (pt = 0; pt < MAX_RTP_PT; ++pt) { for (pt = 0; pt < MAX_RTP_PT; ++pt) {
if (rtp->current_RTP_PT[pt].isAstFormat) { if (rtp->current_RTP_PT[pt].isAstFormat) {
*astFormats |= rtp->current_RTP_PT[pt].code; *astFormats |= rtp->current_RTP_PT[pt].code;
} else { } else {
*nonAstFormats |= rtp->current_RTP_PT[pt].code; *nonAstFormats |= rtp->current_RTP_PT[pt].code;
} }
} }
} }
void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local) { void ast_rtp_offered_from_local(struct ast_rtp* rtp, int local) {
if (rtp) if (rtp)
rtp->rtp_offered_from_local = local; rtp->rtp_offered_from_local = local;
else else
ast_log(LOG_WARNING, "rtp structure is null\n"); ast_log(LOG_WARNING, "rtp structure is null\n");
} }
struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt)
{ {
struct rtpPayloadType result; struct rtpPayloadType result;
result.isAstFormat = result.code = 0; result.isAstFormat = result.code = 0;
if (pt < 0 || pt > MAX_RTP_PT) { if (pt < 0 || pt > MAX_RTP_PT)
return result; /* bogus payload type */ return result; /* bogus payload type */
}
/* Start with the negotiated codecs */ /* Start with the negotiated codecs */
if (!rtp->rtp_offered_from_local) if (!rtp->rtp_offered_from_local)
result = rtp->current_RTP_PT[pt]; result = rtp->current_RTP_PT[pt];
/* If it doesn't exist, check our static RTP type list, just in case */
if (!result.code) /* If it doesn't exist, check our static RTP type list, just in case */
result = static_RTP_PT[pt]; if (!result.code)
return result; 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 *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, int isAstFormat, int code) {
int pt;
int pt;
if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat && if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
code == rtp->rtp_lookup_code_cache_code) { 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; /* Use our cached mapping, to avoid the overhead of the loop below */
} return rtp->rtp_lookup_code_cache_result;
}
/* Check the dynamic list first */ /* Check the dynamic list first */
for (pt = 0; pt < MAX_RTP_PT; ++pt) { for (pt = 0; pt < MAX_RTP_PT; ++pt) {
if (rtp->current_RTP_PT[pt].code == code && if (rtp->current_RTP_PT[pt].code == code && rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) {
rtp->current_RTP_PT[pt].isAstFormat == isAstFormat) { rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; rtp->rtp_lookup_code_cache_code = code;
rtp->rtp_lookup_code_cache_code = code; rtp->rtp_lookup_code_cache_result = pt;
rtp->rtp_lookup_code_cache_result = pt; return pt;
return pt; }
} }
}
/* Then the static list */ /* Then the static list */
for (pt = 0; pt < MAX_RTP_PT; ++pt) { for (pt = 0; pt < MAX_RTP_PT; ++pt) {
if (static_RTP_PT[pt].code == code && if (static_RTP_PT[pt].code == code && static_RTP_PT[pt].isAstFormat == isAstFormat) {
static_RTP_PT[pt].isAstFormat == isAstFormat) { rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat;
rtp->rtp_lookup_code_cache_isAstFormat = isAstFormat; rtp->rtp_lookup_code_cache_code = code;
rtp->rtp_lookup_code_cache_code = code; rtp->rtp_lookup_code_cache_result = pt;
rtp->rtp_lookup_code_cache_result = pt; return pt;
return pt; }
} }
} return -1;
return -1;
} }
char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) { char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code) {
int i;
for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) { int i;
if (mimeTypes[i].payloadType.code == code &&
mimeTypes[i].payloadType.isAstFormat == isAstFormat) { for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
return mimeTypes[i].subtype; if (mimeTypes[i].payloadType.code == code && mimeTypes[i].payloadType.isAstFormat == isAstFormat) {
} return mimeTypes[i].subtype;
} }
return ""; }
return "";
} }
static int rtp_socket(void) static int rtp_socket(void)
@@ -869,7 +887,7 @@ struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io
rtp->seqno = rand() & 0xffff; rtp->seqno = rand() & 0xffff;
if (rtp->s < 0) { if (rtp->s < 0) {
free(rtp); free(rtp);
ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno)); ast_log(LOG_ERROR, "Unable to allocate socket: %s\n", strerror(errno));
return NULL; return NULL;
} }
if (sched && rtcpenable) { if (sched && rtcpenable) {
@@ -895,7 +913,7 @@ struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io
rtp->s = rtp_socket(); rtp->s = rtp_socket();
} }
if (errno != EADDRINUSE) { if (errno != EADDRINUSE) {
ast_log(LOG_WARNING, "Unexpected bind error: %s\n", strerror(errno)); ast_log(LOG_ERROR, "Unexpected bind error: %s\n", strerror(errno));
close(rtp->s); close(rtp->s);
if (rtp->rtcp) { if (rtp->rtcp) {
close(rtp->rtcp->s); close(rtp->rtcp->s);
@@ -908,7 +926,7 @@ struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io
if (x > rtpend) if (x > rtpend)
x = (rtpstart + 1) & ~1; x = (rtpstart + 1) & ~1;
if (x == startplace) { if (x == startplace) {
ast_log(LOG_WARNING, "No RTP ports remaining\n"); ast_log(LOG_ERROR, "No RTP ports remaining\n");
close(rtp->s); close(rtp->s);
if (rtp->rtcp) { if (rtp->rtcp) {
close(rtp->rtcp->s); close(rtp->rtcp->s);
@@ -931,6 +949,7 @@ struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io
struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode) struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode)
{ {
struct in_addr ia; struct in_addr ia;
memset(&ia, 0, sizeof(ia)); memset(&ia, 0, sizeof(ia));
return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia); return ast_rtp_new_with_bindaddr(sched, io, rtcpenable, callbackmode, ia);
} }
@@ -938,6 +957,7 @@ struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io,
int ast_rtp_settos(struct ast_rtp *rtp, int tos) int ast_rtp_settos(struct ast_rtp *rtp, int tos)
{ {
int res; int res;
if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)))) if ((res = setsockopt(rtp->s, IPPROTO_IP, IP_TOS, &tos, sizeof(tos))))
ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos); ast_log(LOG_WARNING, "Unable to set TOS to %d\n", tos);
return res; return res;
@@ -1082,7 +1102,7 @@ int ast_rtp_senddigit(struct ast_rtp *rtp, char digit)
if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) { if (rtp->them.sin_port && rtp->them.sin_addr.s_addr) {
res = sendto(rtp->s, (void *)rtpheader, hdrlen + 4, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them)); res = sendto(rtp->s, (void *)rtpheader, hdrlen + 4, 0, (struct sockaddr *)&rtp->them, sizeof(rtp->them));
if (res <0) if (res <0)
ast_log(LOG_NOTICE, "RTP Transmission error to %s:%d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno)); ast_log(LOG_ERROR, "RTP Transmission error to %s:%d: %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), strerror(errno));
if(rtp_debug_test_addr(&rtp->them)) if(rtp_debug_test_addr(&rtp->them))
ast_verbose("Sent RTP packet to %s:%d (type %d, seq %d, ts %d, len %d)\n" ast_verbose("Sent RTP packet to %s:%d (type %d, seq %d, ts %d, len %d)\n"
, ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen); , ast_inet_ntoa(iabuf, sizeof(iabuf), rtp->them.sin_addr), ntohs(rtp->them.sin_port), payload, rtp->seqno, rtp->lastts,res - hdrlen);
@@ -1105,12 +1125,12 @@ int ast_rtp_senddigit(struct ast_rtp *rtp, char digit)
#ifdef SOLARIS #ifdef SOLARIS
static void put_uint32(unsigned char *buf, int i) static void put_uint32(unsigned char *buf, int i)
{ {
unsigned char *c = (unsigned char *)&i; unsigned char *c = (unsigned char *)&i;
buf[0] = (i>>24) & 0xff; buf[0] = (i>>24) & 0xff;
buf[1] = (i>>16) & 0xff; buf[1] = (i>>16) & 0xff;
buf[2] = (i>>8) & 0xff; buf[2] = (i>>8) & 0xff;
buf[3] = i & 0xff; buf[3] = i & 0xff;
} }
#else #else
#define put_uint32(p,v) ((*((unsigned int *)(p))) = (v)) #define put_uint32(p,v) ((*((unsigned int *)(p))) = (v))
@@ -1162,7 +1182,7 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
break; break;
case AST_FORMAT_LPC10: case AST_FORMAT_LPC10:
/* assumes that the RTP packet contains one LPC10 frame */ /* assumes that the RTP packet contains one LPC10 frame */
pred = rtp->lastts + 22 * 8; pred = rtp->lastts + 22 * 8;
pred += (((char *)(f->data))[7] & 0x1) * 8; pred += (((char *)(f->data))[7] & 0x1) * 8;
break; break;
default: default:
@@ -1176,7 +1196,8 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
if (abs(rtp->lastts - pred) < MAX_TIMESTAMP_SKEW) if (abs(rtp->lastts - pred) < MAX_TIMESTAMP_SKEW)
rtp->lastts = pred; rtp->lastts = pred;
else { else {
ast_log(LOG_DEBUG, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms); if (option_debug > 2)
ast_log(LOG_DEBUG, "Difference is %d, ms is %d\n", abs(rtp->lastts - pred), ms);
mark = 1; mark = 1;
} }
} }
@@ -1191,7 +1212,8 @@ static int ast_rtp_raw_write(struct ast_rtp *rtp, struct ast_frame *f, int codec
rtp->lastts = pred; rtp->lastts = pred;
rtp->lastovidtimestamp += f->samples; rtp->lastovidtimestamp += f->samples;
} else { } else {
ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples); if (option_debug > 2)
ast_log(LOG_DEBUG, "Difference is %d, ms is %d (%d), pred/ts/samples %d/%d/%d\n", abs(rtp->lastts - pred), ms, ms * 90, rtp->lastts, pred, f->samples);
rtp->lastovidtimestamp = rtp->lastts; rtp->lastovidtimestamp = rtp->lastts;
} }
} }
@@ -1250,7 +1272,8 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
if (rtp->lasttxformat != subclass) { if (rtp->lasttxformat != subclass) {
/* New format, reset the smoother */ /* New format, reset the smoother */
ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass)); if (option_debug)
ast_log(LOG_DEBUG, "Ooh, format changed from %s to %s\n", ast_getformatname(rtp->lasttxformat), ast_getformatname(subclass));
rtp->lasttxformat = subclass; rtp->lasttxformat = subclass;
if (rtp->smoother) if (rtp->smoother)
ast_smoother_free(rtp->smoother); ast_smoother_free(rtp->smoother);
@@ -1349,6 +1372,7 @@ int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *_f)
void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto) void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto)
{ {
struct ast_rtp_protocol *cur, *prev; struct ast_rtp_protocol *cur, *prev;
cur = protos; cur = protos;
prev = NULL; prev = NULL;
while(cur) { while(cur) {
@@ -1500,7 +1524,7 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
if ((c0->pvt->pvt != pvt0) || if ((c0->pvt->pvt != pvt0) ||
(c1->pvt->pvt != pvt1) || (c1->pvt->pvt != pvt1) ||
(c0->masq || c0->masqr || c1->masq || c1->masqr)) { (c0->masq || c0->masqr || c1->masq || c1->masqr)) {
ast_log(LOG_DEBUG, "Oooh, something is weird, backing out\n"); ast_log(LOG_WARNING, "Oooh, something is weird, backing out\n");
if (c0->pvt->pvt == pvt0) { if (c0->pvt->pvt == pvt0) {
if (pr0->set_rtp_peer(c0, NULL, NULL, 0)) if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name); ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
@@ -1524,14 +1548,16 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
if (vp0) if (vp0)
ast_rtp_get_peer(vp0, &vt0); ast_rtp_get_peer(vp0, &vt0);
if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1)) || (codec1 != oldcodec1)) { if (inaddrcmp(&t1, &ac1) || (vp1 && inaddrcmp(&vt1, &vac1)) || (codec1 != oldcodec1)) {
ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n", if (option_debug) {
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t1.sin_addr), ntohs(t1.sin_port), codec1); ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n", c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t1.sin_addr), ntohs(t1.sin_port), codec1);
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vt1.sin_addr), ntohs(vt1.sin_port), codec1); ast_log(LOG_DEBUG, "Oooh, '%s' changed end vaddress to %s:%d (format %d)\n",
ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n", c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vt1.sin_addr), ntohs(vt1.sin_port), codec1);
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1); ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
ast_log(LOG_DEBUG, "Oooh, '%s' wasv %s:%d/(format %d)\n", c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac1.sin_addr), ntohs(ac1.sin_port), oldcodec1);
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1); ast_log(LOG_DEBUG, "Oooh, '%s' wasv %s:%d/(format %d)\n",
c1->name, ast_inet_ntoa(iabuf, sizeof(iabuf), vac1.sin_addr), ntohs(vac1.sin_port), oldcodec1);
}
if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, codec1)) if (pr0->set_rtp_peer(c0, t1.sin_addr.s_addr ? p1 : NULL, vt1.sin_addr.s_addr ? vp1 : NULL, codec1))
ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name); ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
memcpy(&ac1, &t1, sizeof(ac1)); memcpy(&ac1, &t1, sizeof(ac1));
@@ -1539,10 +1565,12 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
oldcodec1 = codec1; oldcodec1 = codec1;
} }
if (inaddrcmp(&t0, &ac0) || (vp0 && inaddrcmp(&vt0, &vac0))) { if (inaddrcmp(&t0, &ac0) || (vp0 && inaddrcmp(&vt0, &vac0))) {
ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n", if (option_debug) {
c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t0.sin_addr), ntohs(t0.sin_port), codec0); ast_log(LOG_DEBUG, "Oooh, '%s' changed end address to %s:%d (format %d)\n",
ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n", c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), t0.sin_addr), ntohs(t0.sin_port), codec0);
c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0); ast_log(LOG_DEBUG, "Oooh, '%s' was %s:%d/(format %d)\n",
c0->name, ast_inet_ntoa(iabuf, sizeof(iabuf), ac0.sin_addr), ntohs(ac0.sin_port), oldcodec0);
}
if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, codec0)) if (pr1->set_rtp_peer(c1, t0.sin_addr.s_addr ? p0 : NULL, vt0.sin_addr.s_addr ? vp0 : NULL, codec0))
ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name); ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
memcpy(&ac0, &t0, sizeof(ac0)); memcpy(&ac0, &t0, sizeof(ac0));
@@ -1551,7 +1579,8 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
} }
who = ast_waitfor_n(cs, 2, &to); who = ast_waitfor_n(cs, 2, &to);
if (!who) { if (!who) {
ast_log(LOG_DEBUG, "Ooh, empty read...\n"); if (option_debug)
ast_log(LOG_DEBUG, "Ooh, empty read...\n");
/* check for hagnup / whentohangup */ /* check for hagnup / whentohangup */
if (ast_check_hangup(c0) || ast_check_hangup(c1)) if (ast_check_hangup(c0) || ast_check_hangup(c1))
break; break;
@@ -1563,7 +1592,8 @@ int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, st
((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) { ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
*fo = f; *fo = f;
*rc = who; *rc = who;
ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup"); if (option_debug)
ast_log(LOG_DEBUG, "Oooh, got a %s\n", f ? "digit" : "hangup");
if ((c0->pvt->pvt == pvt0) && (!c0->_softhangup)) { if ((c0->pvt->pvt == pvt0) && (!c0->_softhangup)) {
if (pr0->set_rtp_peer(c0, NULL, NULL, 0)) if (pr0->set_rtp_peer(c0, NULL, NULL, 0))
ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name); ast_log(LOG_WARNING, "Channel '%s' failed to revert\n", c0->name);
@@ -1603,11 +1633,12 @@ static int rtp_do_debug_ip(int fd, int argc, char *argv[])
char iabuf[INET_ADDRSTRLEN]; char iabuf[INET_ADDRSTRLEN];
int port = 0; int port = 0;
char *p, *arg; char *p, *arg;
if (argc != 4) if (argc != 4)
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
arg = argv[3]; arg = argv[3];
p = strstr(arg, ":"); p = strstr(arg, ":");
if (p){ if (p) {
*p = '\0'; *p = '\0';
p++; p++;
port = atoi(p); port = atoi(p);
@@ -1651,6 +1682,7 @@ static int rtp_no_debug(int fd, int argc, char *argv[])
static char debug_usage[] = static char debug_usage[] =
"Usage: rtp debug [ip host[:port]]\n" "Usage: rtp debug [ip host[:port]]\n"
" Enable dumping of all RTP packets to and from host.\n"; " Enable dumping of all RTP packets to and from host.\n";
static char no_debug_usage[] = static char no_debug_usage[] =
"Usage: rtp no debug\n" "Usage: rtp no debug\n"
" Disable all RTP debugging\n"; " Disable all RTP debugging\n";
@@ -1668,6 +1700,7 @@ void ast_rtp_reload(void)
{ {
struct ast_config *cfg; struct ast_config *cfg;
char *s; char *s;
rtpstart = 5000; rtpstart = 5000;
rtpend = 31000; rtpend = 31000;
#ifdef SO_NO_CHECK #ifdef SO_NO_CHECK
@@ -1703,7 +1736,7 @@ void ast_rtp_reload(void)
ast_destroy(cfg); ast_destroy(cfg);
} }
if (rtpstart >= rtpend) { if (rtpstart >= rtpend) {
ast_log(LOG_WARNING, "Unreasonable values for RTP start/end\n"); ast_log(LOG_WARNING, "Unreasonable values for RTP start in rtp.conf/end\n");
rtpstart = 5000; rtpstart = 5000;
rtpend = 31000; rtpend = 31000;
} }