/* 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 */
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),
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;
}
}
#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];
/* 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 */
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");
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;
{
struct sockaddr_in sin;
int res;
+ int updatehistory=1;
int new = NEW_PREVENT;
char buf[4096];
int len = sizeof(sin);
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) &&
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;
/* 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 */
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
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]);
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;
}
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) {
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);
}
}
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... */
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);
}
}
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);
}
}
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;
}
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;
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);
}
}
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);
}
}
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... */
}
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;
}
} 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));
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 {
/* Frametype implicitly VOICE_FRAME */
/* subclass implicit from last ast_iax2_full_hdr */
unsigned char iedata[0];
-};
+} __attribute__ ((__packed__));
#endif
int ast_rtp_settos(struct ast_rtp *rtp, int tos);
// Setting RTP payload types from lines in a SDP description:
-void rtp_pt_init(struct ast_rtp* rtp);
-void rtp_set_m_type(struct ast_rtp* rtp, int pt);
-void rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
+void ast_rtp_pt_clear(struct ast_rtp* rtp);
+/* Set payload types to defaults */
+void ast_rtp_pt_default(struct ast_rtp* rtp);
+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);
// Mapping between RTP payload format codes and Asterisk codes:
-struct rtpPayloadType rtp_lookup_pt(struct ast_rtp* rtp, int pt);
-int rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
+struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
+int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
-void rtp_get_current_formats(struct ast_rtp* rtp,
+void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats);
// Mapping an Asterisk code into a MIME subtype (string):
-char* rtp_lookup_mime_subtype(int isAstFormat, int code);
+char* ast_rtp_lookup_mime_subtype(int isAstFormat, int code);
void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
static int dtmftimeout = 300; /* 300 samples */
-// The value of each RTP payload format mapping:
+// The value of each payload format mapping:
struct rtpPayloadType {
int isAstFormat; // whether the following code is an AST_FORMAT
int code;
printf("Got RTP packet from %s:%d (type %d, seq %d, ts %d, len = %d)\n", inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), payloadtype, seqno, timestamp,res - hdrlen);
#endif
rtp->f.frametype = AST_FRAME_VOICE;
- rtpPT = rtp_lookup_pt(rtp, payloadtype);
+ rtpPT = ast_rtp_lookup_pt(rtp, payloadtype);
if (!rtpPT.isAstFormat) {
// This is special in-band data that's not one of our codecs
if (rtpPT.code == AST_RTP_DTMF) {
{{1, AST_FORMAT_LPC10}, "audio", "LPC"},
{{1, AST_FORMAT_G729A}, "audio", "G729"},
{{1, AST_FORMAT_SPEEX}, "audio", "SPEEX"},
- {{0, AST_RTP_DTMF}, "audio", "TELEPHONE-EVENT"},
+ {{0, AST_RTP_DTMF}, "audio", "telephone-event"},
{{0, AST_RTP_CN}, "audio", "CN"},
{{1, AST_FORMAT_JPEG}, "video", "JPEG"},
{{1, AST_FORMAT_PNG}, "video", "PNG"},
[26] = {1, AST_FORMAT_JPEG},
[31] = {1, AST_FORMAT_H261},
[34] = {1, AST_FORMAT_H263},
+ [101] = {0, AST_RTP_DTMF},
};
-void rtp_pt_init(struct ast_rtp* rtp) {
+void ast_rtp_pt_clear(struct ast_rtp* rtp)
+{
int i;
for (i = 0; i < MAX_RTP_PT; ++i) {
rtp->rtp_lookup_code_cache_result = 0;
}
+void ast_rtp_pt_default(struct ast_rtp* rtp)
+{
+ 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;
+ 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.
// 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):
-void 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 (static_RTP_PT[pt].code != 0) {
// Make a note of a RTP payload type (with MIME type) that was seen in
// a SDP "a=rtpmap:" line.
-void 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) {
int i;
if (pt < 0 || pt > MAX_RTP_PT) return; // bogus payload type
for (i = 0; i < sizeof mimeTypes/sizeof mimeTypes[0]; ++i) {
- if (strcmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
- strcmp(mimeType, mimeTypes[i].type) == 0) {
+ if (strcasecmp(mimeSubtype, mimeTypes[i].subtype) == 0 &&
+ strcasecmp(mimeType, mimeTypes[i].type) == 0) {
rtp->current_RTP_PT[pt] = mimeTypes[i].payloadType;
return;
}
// 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
-void rtp_get_current_formats(struct ast_rtp* rtp,
+void ast_rtp_get_current_formats(struct ast_rtp* rtp,
int* astFormats, int* nonAstFormats) {
int pt;
}
}
-struct rtpPayloadType rtp_lookup_pt(struct ast_rtp* rtp, int pt) {
+struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt) {
if (pt < 0 || pt > MAX_RTP_PT) {
struct rtpPayloadType result;
result.isAstFormat = result.code = 0;
return rtp->current_RTP_PT[pt];
}
-int 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;
if (isAstFormat == rtp->rtp_lookup_code_cache_isAstFormat &&
return -1;
}
-char* 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) {
rtp->io = io;
rtp->ioid = ast_io_add(rtp->io, rtp->s, rtpread, AST_IO_IN, rtp);
}
+ ast_rtp_pt_default(rtp);
return rtp;
}
return -1;
}
- codec = rtp_lookup_code(rtp, 1, _f->subclass);
+ codec = ast_rtp_lookup_code(rtp, 1, _f->subclass);
if (codec < 0) {
ast_log(LOG_WARNING, "Don't know how to send format %d packets with RTP\n", _f->subclass);
return -1;