summaryrefslogtreecommitdiff
path: root/channels
diff options
context:
space:
mode:
authorMatteo Brancaleoni <mbrancaleoni@espia.it>2003-03-13 06:00:20 +0000
committerMatteo Brancaleoni <mbrancaleoni@espia.it>2003-03-13 06:00:20 +0000
commit4ebaef0e1cf0718219b5a31ec182582e4f31b47e (patch)
treef000e1e3d7222acbc97fd66eed3436cc5dde90e3 /channels
parent66a57e51e328a0c0b855184c15096758401c0dac (diff)
Thu Mar 13 07:00:01 CET 2003
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@642 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'channels')
-rwxr-xr-xchannels/chan_iax2.c53
-rwxr-xr-xchannels/chan_mgcp.c26
-rwxr-xr-xchannels/chan_sip.c30
-rwxr-xr-xchannels/iax2.h8
4 files changed, 55 insertions, 62 deletions
diff --git a/channels/chan_iax2.c b/channels/chan_iax2.c
index 7ddcf01d2..23f936efb 100755
--- a/channels/chan_iax2.c
+++ b/channels/chan_iax2.c
@@ -277,13 +277,13 @@ struct chan_iax2_pvt {
/* Expirey (optional) */
int expirey;
/* Next outgoing sequence number */
- unsigned short oseqno;
+ unsigned char oseqno;
/* Next sequence number they have not yet acknowledged */
- unsigned short rseqno;
+ unsigned char rseqno;
/* Next incoming sequence number */
- unsigned short iseqno;
+ unsigned char iseqno;
/* Last incoming sequence number we have acknowledged */
- unsigned short aseqno;
+ unsigned char aseqno;
/* Peer name */
char peer[80];
/* Default Context */
@@ -606,9 +606,9 @@ void showframe(struct ast_iax2_frame *f, struct ast_iax2_full_hdr *fhi, int rx,
subclass = subclass2;
}
ast_verbose(
-"%s-Frame Retry[%s] -- OSeqno: %4.4d ISeqno: %4.4d Type: %s Subclass: %s\n",
+"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
(rx ? "Rx" : "Tx"),
- retries, ntohs(fh->oseqno), ntohs(fh->iseqno), class, subclass);
+ retries, fh->oseqno, fh->iseqno, class, subclass);
fprintf(stderr,
" Timestamp: %05dms SCall: %5.5d DCall: %5.5d [%s:%d]\n",
ntohl(fh->ts),
@@ -1163,7 +1163,7 @@ static int update_packet(struct ast_iax2_frame *f)
fh->dcallno = ntohs(AST_FLAG_RETRANS | f->dcallno);
/* Update iseqno */
f->iseqno = iaxs[f->callno]->iseqno;
- fh->iseqno = ntohs(f->iseqno);
+ fh->iseqno = f->iseqno;
return 0;
}
@@ -1398,7 +1398,7 @@ static int forward_delivery(struct ast_iax2_frame *fr)
}
#endif
-static int schedule_delivery(struct ast_iax2_frame *fr, int reallydeliver)
+static int schedule_delivery(struct ast_iax2_frame *fr, int reallydeliver, int updatehistory)
{
int ms,x;
int drops[MEMORY_SIZE];
@@ -1423,10 +1423,12 @@ static int schedule_delivery(struct ast_iax2_frame *fr, int reallydeliver)
/* Rotate our history queue of "lateness". Don't worry about those initial
zeros because the first entry will always be zero */
- for (x=0;x<MEMORY_SIZE - 1;x++)
- iaxs[fr->callno]->history[x] = iaxs[fr->callno]->history[x+1];
- /* Add a history entry for this one */
- iaxs[fr->callno]->history[x] = ms;
+ if (updatehistory) {
+ for (x=0;x<MEMORY_SIZE - 1;x++)
+ iaxs[fr->callno]->history[x] = iaxs[fr->callno]->history[x+1];
+ /* Add a history entry for this one */
+ iaxs[fr->callno]->history[x] = ms;
+ }
/* Initialize the minimum to reasonable values. It's too much
work to do the same for the maximum, repeatedly */
@@ -2177,9 +2179,9 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
int res;
unsigned int lastsent;
/* Allocate an ast_iax2_frame */
- if (now)
+ if (now) {
fr = &fr2;
- else
+ } else
fr = ast_iax2_frame_new(DIRECTION_OUTGRESS, f->datalen);
if (!fr) {
ast_log(LOG_WARNING, "Out of memory\n");
@@ -2220,8 +2222,8 @@ static int iax2_send(struct chan_iax2_pvt *pvt, struct ast_frame *f, unsigned in
fh = (struct ast_iax2_full_hdr *)(fr->af.data - sizeof(struct ast_iax2_full_hdr));
fh->scallno = htons(fr->callno | AST_FLAG_FULL);
fh->ts = htonl(fr->ts);
- fh->oseqno = htons(fr->oseqno);
- fh->iseqno = htons(fr->iseqno);
+ fh->oseqno = fr->oseqno;
+ fh->iseqno = fr->iseqno;
/* Keep track of the last thing we've acknowledged */
pvt->aseqno = fr->iseqno;
fh->type = fr->af.frametype & 0xFF;
@@ -3491,6 +3493,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
{
struct sockaddr_in sin;
int res;
+ int updatehistory=1;
int new = NEW_PREVENT;
char buf[4096];
int len = sizeof(sin);
@@ -3568,10 +3571,13 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
iaxs[fr.callno]->peercallno = (short)(ntohs(mh->callno) & ~AST_FLAG_FULL);
if (ntohs(mh->callno) & AST_FLAG_FULL) {
if (option_debug)
- ast_log(LOG_DEBUG, "Received packet %d, (%d, %d)\n", ntohs(fh->oseqno), f.frametype, f.subclass);
+ ast_log(LOG_DEBUG, "Received packet %d, (%d, %d)\n", fh->oseqno, f.frametype, f.subclass);
/* Check if it's out of order (and not an ACK or INVAL) */
- fr.oseqno = ntohs(fh->oseqno);
- fr.iseqno = ntohs(fh->iseqno);
+ fr.oseqno = fh->oseqno;
+ fr.iseqno = fh->iseqno;
+ fr.ts = ntohl(fh->ts);
+ if (ntohs(fh->dcallno) & AST_FLAG_RETRANS)
+ updatehistory = 0;
if ((iaxs[fr.callno]->iseqno != fr.oseqno) &&
(iaxs[fr.callno]->iseqno ||
((f.subclass != AST_IAX2_COMMAND_TXCNT) &&
@@ -3684,7 +3690,6 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
f.data = empty;
memset(&ies, 0, sizeof(ies));
}
- fr.ts = ntohl(fh->ts);
if (f.frametype == AST_FRAME_VOICE) {
if (f.subclass != iaxs[fr.callno]->voiceformat) {
iaxs[fr.callno]->voiceformat = f.subclass;
@@ -3713,7 +3718,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
/* Go through the motions of delivering the packet without actually doing so,
unless this is a lag request since it will be done for real */
if (f.subclass != AST_IAX2_COMMAND_LAGRQ)
- schedule_delivery(&fr, 0);
+ schedule_delivery(&fr, 0, updatehistory);
switch(f.subclass) {
case AST_IAX2_COMMAND_ACK:
/* Do nothing */
@@ -3963,7 +3968,7 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
f.offset = 0;
f.samples = 0;
ast_iax2_frame_wrap(&fr, &f);
- schedule_delivery(iaxfrdup2(&fr), 1);
+ schedule_delivery(iaxfrdup2(&fr), 1, updatehistory);
#ifdef BRIDGE_OPTIMIZATION
}
#endif
@@ -4239,10 +4244,10 @@ static int socket_read(int *id, int fd, short events, void *cbdata)
if (iaxs[fr.callno]->bridgecallno) {
forward_delivery(&fr);
} else {
- schedule_delivery(iaxfrdup2(&fr), 1);
+ schedule_delivery(iaxfrdup2(&fr), 1, updatehistory);
}
#else
- schedule_delivery(iaxfrdup2(&fr), 1);
+ schedule_delivery(iaxfrdup2(&fr), 1, updatehistory);
#endif
/* Always run again */
ast_pthread_mutex_unlock(&iaxsl[fr.callno]);
diff --git a/channels/chan_mgcp.c b/channels/chan_mgcp.c
index e2a779577..0b7627d90 100755
--- a/channels/chan_mgcp.c
+++ b/channels/chan_mgcp.c
@@ -867,14 +867,14 @@ static int process_sdp(struct mgcp_endpoint *p, struct mgcp_request *req)
printf("Peer RTP is at port %s:%d\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
#endif
// Scan through the RTP payload types specified in a "m=" line:
- rtp_pt_init(p->rtp);
+ ast_rtp_pt_clear(p->rtp);
codecs = m + len;
while(strlen(codecs)) {
if (sscanf(codecs, "%d %n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
return -1;
}
- rtp_set_m_type(p->rtp, codec);
+ ast_rtp_set_m_type(p->rtp, codec);
codecs += len;
}
@@ -883,20 +883,14 @@ static int process_sdp(struct mgcp_endpoint *p, struct mgcp_request *req)
sdpLineNum_iterator_init(&iterator);
while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
char* mimeSubtype = strdup(a); // ensures we have enough space
- int subtypeLen, i;
if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) continue;
// Note: should really look at the 'freq' and '#chans' params too
- subtypeLen = strlen(mimeSubtype);
- // Convert the MIME subtype to upper case, for ease of searching:
- for (i = 0; i < subtypeLen; ++i) {
- mimeSubtype[i] = toupper(mimeSubtype[i]);
- }
- rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype);
+ ast_rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype);
free(mimeSubtype);
}
// Now gather all of the codecs that were asked for:
- rtp_get_current_formats(p->rtp,
+ ast_rtp_get_current_formats(p->rtp,
&peercapability, &peerNonCodecCapability);
p->capability = capability & peercapability;
if (mgcpdebug) {
@@ -1065,11 +1059,11 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_endpoint *p, struct as
if (p->capability & x) {
if (mgcpdebug)
ast_verbose("Answering with capability %d\n", x);
- codec = rtp_lookup_code(p->rtp, 1, x);
+ codec = ast_rtp_lookup_code(p->rtp, 1, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strcat(m, costr);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, 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));
strcat(a, costr);
}
}
@@ -1078,11 +1072,11 @@ static int add_sdp(struct mgcp_request *resp, struct mgcp_endpoint *p, struct as
if (p->nonCodecCapability & x) {
if (mgcpdebug)
ast_verbose("Answering with non-codec capability %d\n", x);
- codec = rtp_lookup_code(p->rtp, 0, x);
+ codec = ast_rtp_lookup_code(p->rtp, 0, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strcat(m, costr);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, 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));
strcat(a, costr);
if (x == AST_RTP_DTMF) {
/* Indicate we support DTMF... Not sure about 16, but MSN supports it so dang it, we will too... */
@@ -1121,7 +1115,7 @@ static int transmit_modify_with_sdp(struct mgcp_endpoint *p, struct ast_rtp *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", rtp_lookup_mime_subtype(1, x));
+ snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
strcat(local, tmp);
}
}
@@ -1146,7 +1140,7 @@ static int transmit_connect_with_sdp(struct mgcp_endpoint *p, struct ast_rtp *rt
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", rtp_lookup_mime_subtype(1, x));
+ snprintf(tmp, sizeof(tmp), ", a:%s", ast_rtp_lookup_mime_subtype(1, x));
strcat(local, tmp);
}
}
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index d665d64e5..729bb816e 100755
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1422,14 +1422,14 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
printf("Peer RTP is at port %s:%d\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
#endif
// Scan through the RTP payload types specified in a "m=" line:
- rtp_pt_init(p->rtp);
+ ast_rtp_pt_clear(p->rtp);
codecs = m + len;
while(strlen(codecs)) {
if (sscanf(codecs, "%d %n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
return -1;
}
- rtp_set_m_type(p->rtp, codec);
+ ast_rtp_set_m_type(p->rtp, codec);
codecs += len;
}
@@ -1438,20 +1438,14 @@ static int process_sdp(struct sip_pvt *p, struct sip_request *req)
sdpLineNum_iterator_init(&iterator);
while ((a = get_sdp_iterate(&iterator, req, "a"))[0] != '\0') {
char* mimeSubtype = strdup(a); // ensures we have enough space
- int subtypeLen, i;
if (sscanf(a, "rtpmap: %u %[^/]/", &codec, mimeSubtype) != 2) continue;
// Note: should really look at the 'freq' and '#chans' params too
- subtypeLen = strlen(mimeSubtype);
- // Convert the MIME subtype to upper case, for ease of searching:
- for (i = 0; i < subtypeLen; ++i) {
- mimeSubtype[i] = toupper(mimeSubtype[i]);
- }
- rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype);
+ ast_rtp_set_rtpmap_type(p->rtp, codec, "audio", mimeSubtype);
free(mimeSubtype);
}
// Now gather all of the codecs that were asked for:
- rtp_get_current_formats(p->rtp,
+ ast_rtp_get_current_formats(p->rtp,
&peercapability, &peerNonCodecCapability);
p->capability = capability & peercapability;
p->nonCodecCapability = nonCodecCapability & peerNonCodecCapability;
@@ -1861,11 +1855,11 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
if (p->capability & cur->codec) {
if (sipdebug)
ast_verbose("Answering with preferred capability %d\n", cur->codec);
- codec = rtp_lookup_code(p->rtp, 1, cur->codec);
+ codec = ast_rtp_lookup_code(p->rtp, 1, cur->codec);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strcat(m, costr);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, rtp_lookup_mime_subtype(1, cur->codec));
+ snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, ast_rtp_lookup_mime_subtype(1, cur->codec));
strcat(a, costr);
}
}
@@ -1877,11 +1871,11 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
if ((p->capability & x) && !(alreadysent & x)) {
if (sipdebug)
ast_verbose("Answering with capability %d\n", x);
- codec = rtp_lookup_code(p->rtp, 1, x);
+ codec = ast_rtp_lookup_code(p->rtp, 1, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strcat(m, costr);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, 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));
strcat(a, costr);
}
}
@@ -1890,11 +1884,11 @@ static int add_sdp(struct sip_request *resp, struct sip_pvt *p, struct ast_rtp *
if (p->nonCodecCapability & x) {
if (sipdebug)
ast_verbose("Answering with non-codec capability %d\n", x);
- codec = rtp_lookup_code(p->rtp, 0, x);
+ codec = ast_rtp_lookup_code(p->rtp, 0, x);
if (codec > -1) {
snprintf(costr, sizeof(costr), " %d", codec);
strcat(m, costr);
- snprintf(costr, sizeof(costr), "a=rtpmap:%d %s/8000\r\n", codec, 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));
strcat(a, costr);
if (x == AST_RTP_DTMF) {
/* Indicate we support DTMF... Not sure about 16, but MSN supports it so dang it, we will too... */
@@ -2894,7 +2888,7 @@ static int sip_show_channel(int fd, int argc, char *argv[])
}
ast_pthread_mutex_unlock(&iflock);
if (!cur)
- ast_cli(fd, "No such SIP Call ID '%s'\n", cur->callid);
+ ast_cli(fd, "No such SIP Call ID '%s'\n", argv[3]);
return RESULT_SUCCESS;
}
@@ -4281,7 +4275,7 @@ static int reload_config(void)
} else {
hp = gethostbyname(ourhost);
if (!hp) {
- ast_log(LOG_WARNING, "Unable to get our IP address, SIP disabled\n");
+ ast_log(LOG_WARNING, "Unable to get IP address for %s, SIP disabled\n", ourhost);
return 0;
}
memcpy(&__ourip, hp->h_addr, sizeof(__ourip));
diff --git a/channels/iax2.h b/channels/iax2.h
index c3727ac81..da8acadff 100755
--- a/channels/iax2.h
+++ b/channels/iax2.h
@@ -107,12 +107,12 @@ struct ast_iax2_full_hdr {
unsigned short scallno; /* Source call number -- high bit must be 1 */
unsigned short dcallno; /* Destination call number -- high bit is 1 if retransmission */
unsigned int ts; /* 32-bit timestamp in milliseconds (from 1st transmission) */
- unsigned short oseqno; /* Packet number (outgoing) */
- unsigned short iseqno; /* Packet number (next incoming expected) */
+ unsigned char oseqno; /* Packet number (outgoing) */
+ unsigned char iseqno; /* Packet number (next incoming expected) */
char type; /* Frame type */
unsigned char csub; /* Compressed subclass */
unsigned char iedata[0];
-};
+} __attribute__ ((__packed__));
/* Mini header is used only for voice frames -- delivered unreliably */
struct ast_iax2_mini_hdr {
@@ -121,6 +121,6 @@ struct ast_iax2_mini_hdr {
/* Frametype implicitly VOICE_FRAME */
/* subclass implicit from last ast_iax2_full_hdr */
unsigned char iedata[0];
-};
+} __attribute__ ((__packed__));
#endif