indent pass 2

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8689 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2008-05-27 04:54:52 +00:00
1 parent 9bbcabbbdd
commit f930eaeec7
101 files changed
+31644 -31458

No files matched your search

+6 -6
View File
@@ -47,7 +47,7 @@ mutex_status_t iax_mutex_create(mutex_t **mutex)
#endif
mutex_t *check = NULL;
check = (mutex_t *)malloc(sizeof(**mutex));
check = (mutex_t *) malloc(sizeof(**mutex));
if (!check)
goto done;
#ifdef WIN32
@@ -64,16 +64,16 @@ mutex_status_t iax_mutex_create(mutex_t **mutex)
goto success;
fail:
pthread_mutexattr_destroy(&attr);
goto done;
fail:
pthread_mutexattr_destroy(&attr);
goto done;
success:
success:
#endif
*mutex = check;
status = MUTEX_SUCCESS;
done:
done:
return status;
}
File diff suppressed because it is too large. Load diff
+193 -181
View File
@@ -40,12 +40,12 @@ static int oframes = 0;
#ifdef ALIGN32
static unsigned int get_uint32(unsigned char *p)
{
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
}
static unsigned short get_uint16(unsigned char *p)
{
return (p[0] << 8) | p[1] ;
return (p[0] << 8) | p[1];
}
#else
@@ -64,8 +64,8 @@ static void internalerror(const char *str)
fprintf(stderr, "WARNING: %s", str);
}
static void (*outputf)(const char *str) = internaloutput;
static void (*errorf)(const char *str) = internalerror;
static void (*outputf) (const char *str) = internaloutput;
static void (*errorf) (const char *str) = internalerror;
static void dump_addr(char *output, int maxlen, void *value, int len)
{
@@ -83,21 +83,21 @@ static void dump_string(char *output, int maxlen, void *value, int len)
maxlen--;
if (maxlen > len)
maxlen = len;
strncpy(output,value, maxlen);
strncpy(output, value, maxlen);
output[maxlen] = '\0';
}
static void dump_int(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned int))
snprintf(output, maxlen, "%lu", (unsigned long)ntohl(get_uint32(value)));
if (len == (int) sizeof(unsigned int))
snprintf(output, maxlen, "%lu", (unsigned long) ntohl(get_uint32(value)));
else
snprintf(output, maxlen, "Invalid INT");
}
static void dump_short(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned short))
if (len == (int) sizeof(unsigned short))
snprintf(output, maxlen, "%d", ntohs(get_uint16(value)));
else
snprintf(output, maxlen, "Invalid SHORT");
@@ -105,8 +105,8 @@ static void dump_short(char *output, int maxlen, void *value, int len)
static void dump_byte(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned char))
snprintf(output, maxlen, "%d", *((unsigned char *)value));
if (len == (int) sizeof(unsigned char))
snprintf(output, maxlen, "%d", *((unsigned char *) value));
else
snprintf(output, maxlen, "Invalid BYTE");
}
@@ -115,7 +115,7 @@ static void dump_byte(char *output, int maxlen, void *value, int len)
static void dump_ipaddr(char *output, int maxlen, void *value, int len)
{
struct sockaddr_in sin;
if (len == (int)sizeof(unsigned int)) {
if (len == (int) sizeof(unsigned int)) {
memcpy(&sin.sin_addr, value, len);
snprintf(output, maxlen, "%s", inet_ntoa(sin.sin_addr));
} else
@@ -124,9 +124,8 @@ static void dump_ipaddr(char *output, int maxlen, void *value, int len)
static void dump_prov_flags(char *output, int maxlen, void *value, int len)
{
if (len == (int)sizeof(unsigned int))
snprintf(output, maxlen, "%lu (%s)", (unsigned long)ntohl(get_uint32(value)),
"PROVISION_PARSING_NOT_IMPLEMENTED");
if (len == (int) sizeof(unsigned int))
snprintf(output, maxlen, "%lu (%s)", (unsigned long) ntohl(get_uint32(value)), "PROVISION_PARSING_NOT_IMPLEMENTED");
else
snprintf(output, maxlen, "Invalid INT");
}
@@ -134,10 +133,10 @@ static void dump_prov_flags(char *output, int maxlen, void *value, int len)
static void dump_samprate(char *output, int maxlen, void *value, int len)
{
char tmp[256]="";
char tmp[256] = "";
int sr;
if (len == (int)sizeof(unsigned short)) {
sr = ntohs(*((unsigned short *)value));
if (len == (int) sizeof(unsigned short)) {
sr = ntohs(*((unsigned short *) value));
if (sr & IAX_RATE_8KHZ)
strcat(tmp, ",8khz");
if (sr & IAX_RATE_11KHZ)
@@ -170,61 +169,61 @@ static void dump_prov(char *output, int maxlen, void *value, int len)
static struct iax2_ie {
int ie;
char *name;
void (*dump)(char *output, int maxlen, void *value, int len);
void (*dump) (char *output, int maxlen, void *value, int len);
} ies[] = {
{ IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string },
{ IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string },
{ IAX_IE_CALLING_ANI, "ANI", dump_string },
{ IAX_IE_CALLING_NAME, "CALLING NAME", dump_string },
{ IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string },
{ IAX_IE_USERNAME, "USERNAME", dump_string },
{ IAX_IE_PASSWORD, "PASSWORD", dump_string },
{ IAX_IE_CAPABILITY, "CAPABILITY", dump_int },
{ IAX_IE_FORMAT, "FORMAT", dump_int },
{ IAX_IE_LANGUAGE, "LANGUAGE", dump_string },
{ IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string },
{ IAX_IE_VERSION, "VERSION", dump_short },
{ IAX_IE_ADSICPE, "ADSICPE", dump_short },
{ IAX_IE_DNID, "DNID", dump_string },
{ IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short },
{ IAX_IE_CHALLENGE, "CHALLENGE", dump_string },
{ IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string },
{ IAX_IE_RSA_RESULT, "RSA RESULT", dump_string },
{ IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr },
{ IAX_IE_REFRESH, "REFRESH", dump_short },
{ IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short },
{ IAX_IE_CALLNO, "CALL NUMBER", dump_short },
{ IAX_IE_CAUSE, "CAUSE", dump_string },
{ IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte },
{ IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short },
{ IAX_IE_AUTOANSWER, "AUTO ANSWER REQ" },
{ IAX_IE_TRANSFERID, "TRANSFER ID", dump_int },
{ IAX_IE_RDNIS, "REFERRING DNIS", dump_string },
{ IAX_IE_PROVISIONING, "PROVISIONING", dump_prov },
{ IAX_IE_AESPROVISIONING, "AES PROVISIONG" },
{ IAX_IE_DATETIME, "DATE TIME", dump_int },
{ IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string },
{ IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string },
{ IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short },
{ IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int },
{ IAX_IE_FWBLOCKDATA, "FW BLOCK DATA" },
{ IAX_IE_PROVVER, "PROVISIONG VER", dump_int },
{ IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte },
{ IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte },
{ IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short },
{ IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate },
{ IAX_IE_RR_JITTER, "RR_JITTER", dump_int },
{ IAX_IE_RR_LOSS, "RR_LOSS", dump_int },
{ IAX_IE_RR_PKTS, "RR_PKTS", dump_int },
{ IAX_IE_RR_DELAY, "RR_DELAY", dump_short },
{ IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int },
{ IAX_IE_RR_OOO, "RR_OOO", dump_int },
};
{
IAX_IE_CALLED_NUMBER, "CALLED NUMBER", dump_string}, {
IAX_IE_CALLING_NUMBER, "CALLING NUMBER", dump_string}, {
IAX_IE_CALLING_ANI, "ANI", dump_string}, {
IAX_IE_CALLING_NAME, "CALLING NAME", dump_string}, {
IAX_IE_CALLED_CONTEXT, "CALLED CONTEXT", dump_string}, {
IAX_IE_USERNAME, "USERNAME", dump_string}, {
IAX_IE_PASSWORD, "PASSWORD", dump_string}, {
IAX_IE_CAPABILITY, "CAPABILITY", dump_int}, {
IAX_IE_FORMAT, "FORMAT", dump_int}, {
IAX_IE_LANGUAGE, "LANGUAGE", dump_string}, {
IAX_IE_CODEC_PREFS, "CODEC_PREFS", dump_string}, {
IAX_IE_VERSION, "VERSION", dump_short}, {
IAX_IE_ADSICPE, "ADSICPE", dump_short}, {
IAX_IE_DNID, "DNID", dump_string}, {
IAX_IE_AUTHMETHODS, "AUTHMETHODS", dump_short}, {
IAX_IE_CHALLENGE, "CHALLENGE", dump_string}, {
IAX_IE_MD5_RESULT, "MD5 RESULT", dump_string}, {
IAX_IE_RSA_RESULT, "RSA RESULT", dump_string}, {
IAX_IE_APPARENT_ADDR, "APPARENT ADDRESS", dump_addr}, {
IAX_IE_REFRESH, "REFRESH", dump_short}, {
IAX_IE_DPSTATUS, "DIALPLAN STATUS", dump_short}, {
IAX_IE_CALLNO, "CALL NUMBER", dump_short}, {
IAX_IE_CAUSE, "CAUSE", dump_string}, {
IAX_IE_IAX_UNKNOWN, "UNKNOWN IAX CMD", dump_byte}, {
IAX_IE_MSGCOUNT, "MESSAGE COUNT", dump_short}, {
IAX_IE_AUTOANSWER, "AUTO ANSWER REQ"}, {
IAX_IE_TRANSFERID, "TRANSFER ID", dump_int}, {
IAX_IE_RDNIS, "REFERRING DNIS", dump_string}, {
IAX_IE_PROVISIONING, "PROVISIONING", dump_prov}, {
IAX_IE_AESPROVISIONING, "AES PROVISIONG"}, {
IAX_IE_DATETIME, "DATE TIME", dump_int}, {
IAX_IE_DEVICETYPE, "DEVICE TYPE", dump_string}, {
IAX_IE_SERVICEIDENT, "SERVICE IDENT", dump_string}, {
IAX_IE_FIRMWAREVER, "FIRMWARE VER", dump_short}, {
IAX_IE_FWBLOCKDESC, "FW BLOCK DESC", dump_int}, {
IAX_IE_FWBLOCKDATA, "FW BLOCK DATA"}, {
IAX_IE_PROVVER, "PROVISIONG VER", dump_int}, {
IAX_IE_CALLINGPRES, "CALLING PRESNTN", dump_byte}, {
IAX_IE_CALLINGTON, "CALLING TYPEOFNUM", dump_byte}, {
IAX_IE_CALLINGTNS, "CALLING TRANSITNET", dump_short}, {
IAX_IE_SAMPLINGRATE, "SAMPLINGRATE", dump_samprate}, {
IAX_IE_RR_JITTER, "RR_JITTER", dump_int}, {
IAX_IE_RR_LOSS, "RR_LOSS", dump_int}, {
IAX_IE_RR_PKTS, "RR_PKTS", dump_int}, {
IAX_IE_RR_DELAY, "RR_DELAY", dump_short}, {
IAX_IE_RR_DROPPED, "RR_DROPPED", dump_int}, {
IAX_IE_RR_OOO, "RR_OOO", dump_int},};
const char *iax_ie2str(int ie)
{
int x;
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
if (ies[x].ie == ie)
return ies[x].name;
}
@@ -240,22 +239,25 @@ static void dump_prov_ies(char *output, int maxlen, unsigned char *iedata, int l
char tmp[256];
if (len < 2)
return;
strcpy(output, "\n");
maxlen -= (int)strlen(output); output += strlen(output);
while(len > 2) {
strcpy(output, "\n");
maxlen -= (int) strlen(output);
output += strlen(output);
while (len > 2) {
ie = iedata[0];
ielen = iedata[1];
if (ielen + 2> len) {
snprintf(tmp, (int)sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
if (ielen + 2 > len) {
snprintf(tmp, (int) sizeof(tmp), "Total Prov IE length of %d bytes exceeds remaining prov frame length of %d bytes\n", ielen + 2, len);
strncpy(output, tmp, maxlen - 1);
maxlen -= (int)strlen(output); output += strlen(output);
maxlen -= (int) strlen(output);
output += strlen(output);
return;
}
found = 0;
if (!found) {
snprintf(tmp, (int)sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
snprintf(tmp, (int) sizeof(tmp), " Unknown Prov IE %03d : Present\n", ie);
strncpy(output, tmp, maxlen - 1);
maxlen -= (int)strlen(output); output += strlen(output);
maxlen -= (int) strlen(output);
output += strlen(output);
}
iedata += (2 + ielen);
len -= (2 + ielen);
@@ -272,34 +274,34 @@ static void dump_ies(unsigned char *iedata, int len)
char tmp[1024];
if (len < 2)
return;
while(len > 2) {
while (len > 2) {
ie = iedata[0];
ielen = iedata[1];
if (ielen + 2> len) {
snprintf(tmp, (int)sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
if (ielen + 2 > len) {
snprintf(tmp, (int) sizeof(tmp), "Total IE length of %d bytes exceeds remaining frame length of %d bytes\n", ielen + 2, len);
outputf(tmp);
return;
}
found = 0;
for (x=0;x<(int)sizeof(ies) / (int)sizeof(ies[0]); x++) {
for (x = 0; x < (int) sizeof(ies) / (int) sizeof(ies[0]); x++) {
if (ies[x].ie == ie) {
if (ies[x].dump) {
ies[x].dump(interp, (int)sizeof(interp), iedata + 2, ielen);
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
ies[x].dump(interp, (int) sizeof(interp), iedata + 2, ielen);
snprintf(tmp, (int) sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
outputf(tmp);
} else {
if (ielen)
snprintf(interp, (int)sizeof(interp), "%d bytes", ielen);
snprintf(interp, (int) sizeof(interp), "%d bytes", ielen);
else
strcpy(interp, "Present");
snprintf(tmp, (int)sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
snprintf(tmp, (int) sizeof(tmp), " %-15.15s : %s\n", ies[x].name, interp);
outputf(tmp);
}
found++;
}
}
if (!found) {
snprintf(tmp, (int)sizeof(tmp), " Unknown IE %03d : Present\n", ie);
snprintf(tmp, (int) sizeof(tmp), " Unknown IE %03d : Present\n", ie);
outputf(tmp);
}
iedata += (2 + ielen);
@@ -319,7 +321,8 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
"NULL ",
"IAX ",
"TEXT ",
"IMAGE " };
"IMAGE "
};
const char *iaxs[] = {
"(0?)",
"NEW ",
@@ -368,7 +371,8 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
"ANSWER ",
"BUSY ",
"TKOFFHK ",
"OFFHOOK" };
"OFFHOOK"
};
struct ast_iax2_full_hdr *fh;
char retries[20];
char class2[20];
@@ -379,7 +383,7 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
if (f) {
fh = f->data;
snprintf(retries, (int)sizeof(retries), "%03d", f->retries);
snprintf(retries, (int) sizeof(retries), "%03d", f->retries);
} else {
fh = fhi;
if (ntohs(fh->dcallno) & IAX_FLAG_RETRANS)
@@ -391,43 +395,41 @@ void iax_showframe(struct iax_frame *f, struct ast_iax2_full_hdr *fhi, int rx, s
/* Don't mess with mini-frames */
return;
}
if (fh->type > ((int)sizeof(frames)/(int)sizeof(char *)) - 1) {
snprintf(class2, (int)sizeof(class2), "(%d?)", fh->type);
if (fh->type > ((int) sizeof(frames) / (int) sizeof(char *)) - 1) {
snprintf(class2, (int) sizeof(class2), "(%d?)", fh->type);
class = class2;
} else {
class = frames[(int)fh->type];
class = frames[(int) fh->type];
}
if (fh->type == AST_FRAME_DTMF) {
sprintf(subclass2, "%c", fh->csub);
subclass = subclass2;
} else if (fh->type == AST_FRAME_IAX) {
if (fh->csub >= (int)sizeof(iaxs)/(int)sizeof(iaxs[0])) {
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
if (fh->csub >= (int) sizeof(iaxs) / (int) sizeof(iaxs[0])) {
snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
subclass = subclass2;
} else {
subclass = iaxs[(int)fh->csub];
subclass = iaxs[(int) fh->csub];
}
} else if (fh->type == AST_FRAME_CONTROL) {
if (fh->csub > (int)sizeof(cmds)/(int)sizeof(char *)) {
snprintf(subclass2, (int)sizeof(subclass2), "(%d?)", fh->csub);
if (fh->csub > (int) sizeof(cmds) / (int) sizeof(char *)) {
snprintf(subclass2, (int) sizeof(subclass2), "(%d?)", fh->csub);
subclass = subclass2;
} else {
subclass = cmds[(int)fh->csub];
subclass = cmds[(int) fh->csub];
}
} else {
snprintf(subclass2, (int)sizeof(subclass2), "%d", fh->csub);
snprintf(subclass2, (int) sizeof(subclass2), "%d", fh->csub);
subclass = subclass2;
}
snprintf(tmp, (int)sizeof(tmp),
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
(rx ? "Rx" : "Tx"),
retries, fh->oseqno, fh->iseqno, class, subclass);
snprintf(tmp, (int) sizeof(tmp),
"%s-Frame Retry[%s] -- OSeqno: %3.3d ISeqno: %3.3d Type: %s Subclass: %s\n",
(rx ? "Rx" : "Tx"), retries, fh->oseqno, fh->iseqno, class, subclass);
outputf(tmp);
snprintf(tmp, (int)sizeof(tmp),
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
(unsigned long)ntohl(fh->ts),
ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS,
inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
snprintf(tmp, (int) sizeof(tmp),
" Timestamp: %05lums SCall: %5.5d DCall: %5.5d [%s:%d]\n",
(unsigned long) ntohl(fh->ts),
ntohs(fh->scallno) & ~IAX_FLAG_FULL, ntohs(fh->dcallno) & ~IAX_FLAG_RETRANS, inet_ntoa(sin->sin_addr), ntohs(sin->sin_port));
outputf(tmp);
if (fh->type == AST_FRAME_IAX)
dump_ies(fh->iedata, datalen);
@@ -436,13 +438,14 @@ snprintf(tmp, (int)sizeof(tmp),
int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *data, int datalen)
{
char tmp[256];
if (datalen > ((int)sizeof(ied->buf) - ied->pos)) {
snprintf(tmp, (int)sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen, (int)sizeof(ied->buf) - ied->pos);
if (datalen > ((int) sizeof(ied->buf) - ied->pos)) {
snprintf(tmp, (int) sizeof(tmp), "Out of space for ie '%s' (%d), need %d have %d\n", iax_ie2str(ie), ie, datalen,
(int) sizeof(ied->buf) - ied->pos);
errorf(tmp);
return -1;
}
ied->buf[ied->pos++] = ie;
ied->buf[ied->pos++] = (unsigned char)datalen;
ied->buf[ied->pos++] = (unsigned char) datalen;
memcpy(ied->buf + ied->pos, data, datalen);
ied->pos += datalen;
return 0;
@@ -450,26 +453,26 @@ int iax_ie_append_raw(struct iax_ie_data *ied, unsigned char ie, const void *dat
int iax_ie_append_addr(struct iax_ie_data *ied, unsigned char ie, struct sockaddr_in *sin)
{
return iax_ie_append_raw(ied, ie, sin, (int)sizeof(struct sockaddr_in));
return iax_ie_append_raw(ied, ie, sin, (int) sizeof(struct sockaddr_in));
}
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
int iax_ie_append_int(struct iax_ie_data *ied, unsigned char ie, unsigned int value)
{
unsigned int newval;
newval = htonl(value);
return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
}
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
int iax_ie_append_short(struct iax_ie_data *ied, unsigned char ie, unsigned short value)
{
unsigned short newval;
newval = htons(value);
return iax_ie_append_raw(ied, ie, &newval, (int)sizeof(newval));
return iax_ie_append_raw(ied, ie, &newval, (int) sizeof(newval));
}
int iax_ie_append_str(struct iax_ie_data *ied, unsigned char ie, const unsigned char *str)
{
return iax_ie_append_raw(ied, ie, str, (int)strlen((char *) str));
return iax_ie_append_raw(ied, ie, str, (int) strlen((char *) str));
}
int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char dat)
@@ -477,17 +480,17 @@ int iax_ie_append_byte(struct iax_ie_data *ied, unsigned char ie, unsigned char
return iax_ie_append_raw(ied, ie, &dat, 1);
}
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
int iax_ie_append(struct iax_ie_data *ied, unsigned char ie)
{
return iax_ie_append_raw(ied, ie, NULL, 0);
}
void iax_set_output(void (*func)(const char *))
void iax_set_output(void (*func) (const char *))
{
outputf = func;
}
void iax_set_error(void (*func)(const char *))
void iax_set_error(void (*func) (const char *))
{
errorf = func;
}
@@ -498,21 +501,21 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
int len;
int ie;
char tmp[256];
memset(my_ies, 0, (int)sizeof(struct iax_ies));
memset(my_ies, 0, (int) sizeof(struct iax_ies));
my_ies->msgcount = -1;
my_ies->firmwarever = -1;
my_ies->calling_ton = -1;
my_ies->calling_tns = -1;
my_ies->calling_pres = -1;
my_ies->samprate = IAX_RATE_8KHZ;
while(datalen >= 2) {
while (datalen >= 2) {
ie = data[0];
len = data[1];
if (len > datalen - 2) {
errorf("Information element length exceeds message size\n");
return -1;
}
switch(ie) {
switch (ie) {
case IAX_IE_CALLED_NUMBER:
my_ies->called_number = (char *) data + 2;
break;
@@ -535,15 +538,15 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->password = (char *) data + 2;
break;
case IAX_IE_CAPABILITY:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting capability to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->capability = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FORMAT:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting format to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->format = ntohl(get_uint32(data + 2));
@@ -555,22 +558,22 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->codec_prefs = (char *) data + 2;
break;
case IAX_IE_VERSION:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting version to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->version = ntohs(get_uint16(data + 2));
break;
case IAX_IE_ADSICPE:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting adsicpe to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->adsicpe = ntohs(get_uint16(data + 2));
break;
case IAX_IE_SAMPLINGRATE:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting samplingrate to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->samprate = ntohs(get_uint16(data + 2));
@@ -582,8 +585,8 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->rdnis = (char *) data + 2;
break;
case IAX_IE_AUTHMETHODS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting authmethods to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->authmethods = ntohs(get_uint16(data + 2));
@@ -598,25 +601,25 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->rsa_result = (char *) data + 2;
break;
case IAX_IE_APPARENT_ADDR:
my_ies->apparent_addr = ((struct sockaddr_in *)(data + 2));
my_ies->apparent_addr = ((struct sockaddr_in *) (data + 2));
break;
case IAX_IE_REFRESH:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting refresh to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->refresh = ntohs(get_uint16(data + 2));
break;
case IAX_IE_DPSTATUS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting dpstatus to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->dpstatus = ntohs(get_uint16(data + 2));
break;
case IAX_IE_CALLNO:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting callno to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->callno = ntohs(get_uint16(data + 2));
@@ -626,7 +629,7 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
break;
case IAX_IE_CAUSECODE:
if (len != 1) {
snprintf(tmp, (int)sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expecting causecode to be single byte but was %d\n", len);
errorf(tmp);
} else {
my_ies->causecode = data[2];
@@ -636,16 +639,16 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->iax_unknown = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte Unknown command, but was %d long\n", len);
errorf(tmp);
}
break;
case IAX_IE_MSGCOUNT:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting msgcount to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->msgcount = ntohs(get_uint16(data + 2));
my_ies->msgcount = ntohs(get_uint16(data + 2));
break;
case IAX_IE_AUTOANSWER:
my_ies->autoanswer = 1;
@@ -654,25 +657,25 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->musiconhold = 1;
break;
case IAX_IE_TRANSFERID:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting transferid to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->transferid = ntohl(get_uint32(data + 2));
break;
case IAX_IE_DATETIME:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting date/time to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->datetime = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FIRMWAREVER:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting firmwarever to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->firmwarever = ntohs(get_uint16(data + 2));
my_ies->firmwarever = ntohs(get_uint16(data + 2));
break;
case IAX_IE_DEVICETYPE:
my_ies->devicetype = (char *) data + 2;
@@ -681,19 +684,19 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
my_ies->serviceident = (char *) data + 2;
break;
case IAX_IE_FWBLOCKDESC:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected block desc to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else
my_ies->fwdesc = ntohl(get_uint32(data + 2));
break;
case IAX_IE_FWBLOCKDATA:
my_ies->fwdata = data + 2;
my_ies->fwdatalen = (unsigned char)len;
my_ies->fwdatalen = (unsigned char) len;
break;
case IAX_IE_PROVVER:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected provisioning version to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->provverpres = 1;
@@ -704,7 +707,7 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->calling_pres = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte callingpres, but was %d long\n", len);
errorf(tmp);
}
break;
@@ -712,67 +715,67 @@ int iax_parse_ies(struct iax_ies *my_ies, unsigned char *data, int datalen)
if (len == 1)
my_ies->calling_ton = data[2];
else {
snprintf(tmp, (int)sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
snprintf(tmp, (int) sizeof(tmp), "Expected single byte callington, but was %d long\n", len);
errorf(tmp);
}
break;
case IAX_IE_CALLINGTNS:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expecting callingtns to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else
my_ies->calling_tns = ntohs(get_uint16(data + 2));
my_ies->calling_tns = ntohs(get_uint16(data + 2));
break;
case IAX_IE_RR_JITTER:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected jitter rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_jitter = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_LOSS:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_loss = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_PKTS:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_pkts = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_DELAY:
if (len != (int)sizeof(unsigned short)) {
snprintf(tmp, (int)sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int)sizeof(unsigned short), len);
if (len != (int) sizeof(unsigned short)) {
snprintf(tmp, (int) sizeof(tmp), "Expected loss rr to be %d bytes long but was %d\n", (int) sizeof(unsigned short), len);
errorf(tmp);
} else {
my_ies->rr_delay = ntohs(get_uint16(data + 2));
}
break;
case IAX_IE_RR_DROPPED:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_dropped = ntohl(get_uint32(data + 2));
}
break;
case IAX_IE_RR_OOO:
if (len != (int)sizeof(unsigned int)) {
snprintf(tmp, (int)sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int)sizeof(unsigned int), len);
if (len != (int) sizeof(unsigned int)) {
snprintf(tmp, (int) sizeof(tmp), "Expected packets rr to be %d bytes long but was %d\n", (int) sizeof(unsigned int), len);
errorf(tmp);
} else {
my_ies->rr_ooo = ntohl(get_uint32(data + 2));
}
break;
default:
snprintf(tmp, (int)sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
snprintf(tmp, (int) sizeof(tmp), "Ignoring unknown information element '%s' (%d) of length %d\n", iax_ie2str(ie), ie, len);
outputf(tmp);
}
/* Overwrite information element with 0, to null terminate previous portion */
@@ -793,20 +796,20 @@ void iax_frame_wrap(struct iax_frame *fr, struct ast_frame *f)
{
fr->af.frametype = f->frametype;
fr->af.subclass = f->subclass;
fr->af.mallocd = 0; /* Our frame is static relative to the container */
fr->af.mallocd = 0; /* Our frame is static relative to the container */
fr->af.datalen = f->datalen;
fr->af.samples = f->samples;
fr->af.offset = AST_FRIENDLY_OFFSET;
fr->af.src = f->src;
fr->af.data = fr->afdata;
if (fr->af.datalen)
if (fr->af.datalen)
memcpy(fr->af.data, f->data, fr->af.datalen);
}
struct iax_frame *iax_frame_new(int direction, int datalen)
{
struct iax_frame *fr;
fr = malloc((int)sizeof(struct iax_frame) + datalen);
fr = malloc((int) sizeof(struct iax_frame) + datalen);
if (fr) {
fr->direction = direction;
fr->retrans = -1;
@@ -835,6 +838,15 @@ void iax_frame_free(struct iax_frame *fr)
frame_count--;
}
int iax_get_frames(void) { return frame_count; }
int iax_get_iframes(void) { return iframes; }
int iax_get_oframes(void) { return oframes; }
int iax_get_frames(void)
{
return frame_count;
}
int iax_get_iframes(void)
{
return iframes;
}
int iax_get_oframes(void)
{
return oframes;
}
+90 -100
View File
@@ -32,9 +32,9 @@
#define jb_dbg if (dbgf) dbgf
#ifdef DEEP_DEBUG
#define jb_dbg2 if (dbgf) dbgf
#define jb_dbg2 if (dbgf) dbgf
#else
#define jb_dbg2 if (0) dbgf
#define jb_dbg2 if (0) dbgf
#endif
#else
@@ -60,17 +60,17 @@ void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output
dbgf = dbg;
}
static void increment_losspct(jitterbuf *jb)
static void increment_losspct(jitterbuf * jb)
{
jb->info.losspct = (100000 + 499 * jb->info.losspct)/500;
jb->info.losspct = (100000 + 499 * jb->info.losspct) / 500;
}
static void decrement_losspct(jitterbuf *jb)
static void decrement_losspct(jitterbuf * jb)
{
jb->info.losspct = (499 * jb->info.losspct)/500;
jb->info.losspct = (499 * jb->info.losspct) / 500;
}
void jb_reset(jitterbuf *jb)
void jb_reset(jitterbuf * jb)
{
/* only save settings */
jb_conf s = jb->info.conf;
@@ -82,11 +82,12 @@ void jb_reset(jitterbuf *jb)
jb->info.silence_begin_ts = -1;
}
jitterbuf * jb_new()
jitterbuf *jb_new()
{
jitterbuf *jb = (jitterbuf *)malloc(sizeof(*jb));
jitterbuf *jb = (jitterbuf *) malloc(sizeof(*jb));
if (!jb) return NULL;
if (!jb)
return NULL;
jb->info.conf.target_extra = JB_TARGET_EXTRA;
@@ -95,7 +96,7 @@ jitterbuf * jb_new()
return jb;
}
void jb_destroy(jitterbuf *jb)
void jb_destroy(jitterbuf * jb)
{
jb_frame *frame;
@@ -116,7 +117,7 @@ void jb_destroy(jitterbuf *jb)
#if 0
static int longcmp(const void *a, const void *b)
{
return *(long *)a - *(long *)b;
return *(long *) a - *(long *) b;
}
#endif
@@ -124,7 +125,7 @@ static int longcmp(const void *a, const void *b)
/* maybe later we can make the history buckets variable size, or something? */
/* drop parameter determines whether we will drop outliers to minimize
* delay */
static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
static int history_put(jitterbuf * jb, time_in_ms_t ts, time_in_ms_t now)
{
time_in_ms_t delay = now - (ts - jb->info.resync_offset);
time_in_ms_t threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
@@ -144,9 +145,10 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
jb->hist_ptr = 0;
jb->hist_maxbuf_valid = 0;
jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold, ts - now);
jb_warn("Resyncing the jb. last_delay %ld, this delay %ld, threshold %ld, new offset %ld\n", jb->info.last_delay, delay, threshold,
ts - now);
jb->info.resync_offset = ts - now;
jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
jb->info.last_delay = delay = 0; /* after resync, frame is right on time */
} else {
return -1;
}
@@ -176,18 +178,18 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
goto invalidate;
/* if the new delay would go into min */
if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
if (delay < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* or max.. */
if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
if (delay > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* or the kicked delay would be in min */
if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1])
if (kicked <= jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1])
if (kicked >= jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1])
goto invalidate;
/* if we got here, we don't need to invalidate, 'cause this delay didn't
@@ -196,21 +198,21 @@ static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now)
/* end optimization */
invalidate:
invalidate:
jb->hist_maxbuf_valid = 0;
return 0;
}
static void history_calc_maxbuf(jitterbuf *jb)
static void history_calc_maxbuf(jitterbuf * jb)
{
int i,j;
int i, j;
if (jb->hist_ptr == 0)
return;
/* initialize maxbuf/minbuf to the latest value */
for (i=0;i<JB_HISTORY_MAXBUF_SZ;i++) {
for (i = 0; i < JB_HISTORY_MAXBUF_SZ; i++) {
/*
* jb->hist_maxbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
* jb->hist_minbuf[i] = jb->history[(jb->hist_ptr-1) % JB_HISTORY_SZ];
@@ -225,14 +227,14 @@ static void history_calc_maxbuf(jitterbuf *jb)
/* start at the beginning, or JB_HISTORY_SZ frames ago */
i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
for (;i<jb->hist_ptr;i++) {
time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
for (; i < jb->hist_ptr; i++) {
time_in_ms_t toins = jb->history[i % JB_HISTORY_SZ];
/* if the maxbuf should get this */
if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ-1]) {
if (toins > jb->hist_maxbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
/* insertion-sort it into the maxbuf */
for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
/* found where it fits */
if (toins > jb->hist_maxbuf[j]) {
/* move over */
@@ -246,10 +248,10 @@ static void history_calc_maxbuf(jitterbuf *jb)
}
/* if the minbuf should get this */
if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ-1]) {
if (toins < jb->hist_minbuf[JB_HISTORY_MAXBUF_SZ - 1]) {
/* insertion-sort it into the maxbuf */
for (j=0;j<JB_HISTORY_MAXBUF_SZ;j++) {
for (j = 0; j < JB_HISTORY_MAXBUF_SZ; j++) {
/* found where it fits */
if (toins < jb->hist_minbuf[j]) {
/* move over */
@@ -261,15 +263,14 @@ static void history_calc_maxbuf(jitterbuf *jb)
}
}
}
#if 0
int k;
fprintf(stderr, "toins = %ld\n", toins);
fprintf(stderr, "maxbuf =");
for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
fprintf(stderr, "%ld ", jb->hist_maxbuf[k]);
fprintf(stderr, "\nminbuf =");
for (k=0;k<JB_HISTORY_MAXBUF_SZ;k++)
for (k = 0; k < JB_HISTORY_MAXBUF_SZ; k++)
fprintf(stderr, "%ld ", jb->hist_minbuf[k]);
fprintf(stderr, "\n");
#endif
@@ -278,9 +279,9 @@ static void history_calc_maxbuf(jitterbuf *jb)
jb->hist_maxbuf_valid = 1;
}
static void history_get(jitterbuf *jb)
static void history_get(jitterbuf * jb)
{
time_in_ms_t max, min, jitter;
time_in_ms_t max, min, jitter;
int index;
int count;
@@ -312,16 +313,16 @@ static void history_get(jitterbuf *jb)
/* these debug stmts compare the difference between looking at the absolute jitter, and the
* values we get by throwing away the outliers */
/*
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
*/
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", index, min, max, jitter);
fprintf(stderr, "[%d] min=%d, max=%d, jitter=%d\n", 0, jb->hist_minbuf[0], jb->hist_maxbuf[0], jb->hist_maxbuf[0]-jb->hist_minbuf[0]);
*/
jb->info.min = min;
jb->info.jitter = jitter;
}
/* returns 1 if frame was inserted into head of queue, 0 otherwise */
static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
static int queue_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts)
{
jb_frame *frame = jb->free;
jb_frame *p;
@@ -331,7 +332,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
if (frame) {
jb->free = frame->next;
} else {
frame = (jb_frame *)malloc(sizeof(*frame));
frame = (jb_frame *) malloc(sizeof(*frame));
if (!frame) {
jb_err("cannot allocate frame\n");
return 0;
@@ -350,7 +351,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
* jb->frames->prev points to the highest ts
*/
if (!jb->frames) { /* queue is empty */
if (!jb->frames) { /* queue is empty */
jb->frames = frame;
frame->next = frame;
frame->prev = frame;
@@ -371,7 +372,8 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
p = jb->frames;
/* frame is out of order */
if (resync_ts < p->prev->ts) jb->info.frames_ooo++;
if (resync_ts < p->prev->ts)
jb->info.frames_ooo++;
while (resync_ts < p->prev->ts && p->prev != jb->frames)
p = p->prev;
@@ -385,7 +387,7 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
return head;
}
static time_in_ms_t queue_next(jitterbuf *jb)
static time_in_ms_t queue_next(jitterbuf * jb)
{
if (jb->frames)
return jb->frames->ts;
@@ -393,7 +395,7 @@ static time_in_ms_t queue_next(jitterbuf *jb)
return -1;
}
static time_in_ms_t queue_last(jitterbuf *jb)
static time_in_ms_t queue_last(jitterbuf * jb)
{
if (jb->frames)
return jb->frames->prev->ts;
@@ -401,7 +403,7 @@ static time_in_ms_t queue_last(jitterbuf *jb)
return -1;
}
static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all)
static jb_frame *_queue_get(jitterbuf * jb, time_in_ms_t ts, int all)
{
jb_frame *frame;
frame = jb->frames;
@@ -436,46 +438,41 @@ static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all)
return NULL;
}
static jb_frame *queue_get(jitterbuf *jb, time_in_ms_t ts)
static jb_frame *queue_get(jitterbuf * jb, time_in_ms_t ts)
{
return _queue_get(jb,ts,0);
return _queue_get(jb, ts, 0);
}
static jb_frame *queue_getall(jitterbuf *jb)
static jb_frame *queue_getall(jitterbuf * jb)
{
return _queue_get(jb,0,1);
return _queue_get(jb, 0, 1);
}
#if 0
/* some diagnostics */
static void jb_dbginfo(jitterbuf *jb)
static void jb_dbginfo(jitterbuf * jb)
{
if (dbgf == NULL)
return;
jb_dbg("\njb info: fin=%ld fout=%ld flate=%ld flost=%ld fdrop=%ld fcur=%ld\n",
jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
jb->info.frames_in, jb->info.frames_out, jb->info.frames_late, jb->info.frames_lost, jb->info.frames_dropped, jb->info.frames_cur);
jb_dbg("jitter=%ld current=%ld target=%ld min=%ld sil=%d len=%d len/fcur=%ld\n",
jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
jb->info.frames_cur ? (jb->info.current - jb->info.min)/jb->info.frames_cur : -8);
jb->info.jitter, jb->info.current, jb->info.target, jb->info.min, jb->info.silence_begin_ts, jb->info.current - jb->info.min,
jb->info.frames_cur ? (jb->info.current - jb->info.min) / jb->info.frames_cur : -8);
if (jb->info.frames_in > 0)
jb_dbg("jb info: Loss PCT = %ld%%, Late PCT = %ld%%\n",
jb->info.frames_lost * 100/(jb->info.frames_in + jb->info.frames_lost),
jb->info.frames_late * 100/jb->info.frames_in);
jb->info.frames_lost * 100 / (jb->info.frames_in + jb->info.frames_lost), jb->info.frames_late * 100 / jb->info.frames_in);
jb_dbg("jb info: queue %d -> %d. last_ts %d (queue len: %d) last_ms %d\n",
queue_next(jb),
queue_last(jb),
jb->info.next_voice_ts,
queue_last(jb) - queue_next(jb),
jb->info.last_voice_ms);
queue_next(jb), queue_last(jb), jb->info.next_voice_ts, queue_last(jb) - queue_next(jb), jb->info.last_voice_ms);
}
#endif
#ifdef DEEP_DEBUG
static void jb_chkqueue(jitterbuf *jb)
static void jb_chkqueue(jitterbuf * jb)
{
int i=0;
int i = 0;
jb_frame *p = jb->frames;
if (!p) {
@@ -483,17 +480,17 @@ static void jb_chkqueue(jitterbuf *jb)
}
do {
if (p->next == NULL) {
if (p->next == NULL) {
jb_err("Queue is BROKEN at item [%d]", i);
}
i++;
p=p->next;
p = p->next;
} while (p->next != jb->frames);
}
static void jb_dbgqueue(jitterbuf *jb)
static void jb_dbgqueue(jitterbuf * jb)
{
int i=0;
int i = 0;
jb_frame *p = jb->frames;
jb_dbg("queue: ");
@@ -505,14 +502,14 @@ static void jb_dbgqueue(jitterbuf *jb)
do {
jb_dbg("[%d]=%ld ", i++, p->ts);
p=p->next;
p = p->next;
} while (p->next != jb->frames);
jb_dbg("\n");
}
#endif
enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
enum jb_return_code jb_put(jitterbuf * jb, void *data, const enum jb_frame_type type, long ms, time_in_ms_t ts, time_in_ms_t now)
{
jb->info.frames_in++;
@@ -522,12 +519,12 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
* sending retransmitted control frames with their awkward
* timestamps through
*/
if (history_put(jb,ts,now))
if (history_put(jb, ts, now))
return JB_DROP;
}
/* if put into head of queue, caller needs to reschedule */
if (queue_put(jb,data,type,ms,ts)) {
if (queue_put(jb, data, type, ms, ts)) {
return JB_SCHED;
}
@@ -535,7 +532,7 @@ enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type t
}
static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
static enum jb_return_code _jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
{
jb_frame *frame;
time_in_ms_t diff;
@@ -557,7 +554,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
diff = jb->info.target - jb->info.current;
/* jb_warn("diff = %d lms=%d last = %d now = %d\n", diff, */
/* jb->info.last_voice_ms, jb->info.last_adjustment, now); */
/* jb->info.last_voice_ms, jb->info.last_adjustment, now); */
/* let's work on non-silent case first */
if (!jb->info.silence_begin_ts) {
@@ -565,8 +562,8 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
if ((diff > 0) &&
/* we haven't grown in the delay length */
(((jb->info.last_adjustment + JB_ADJUST_DELAY) < now) ||
/* we need to grow more than the "length" we have left */
(diff > queue_last(jb) - queue_next(jb)) ) ) {
/* we need to grow more than the "length" we have left */
(diff > queue_last(jb) - queue_next(jb)))) {
/* grow by interp frame length */
jb->info.current += interpl;
jb->info.next_voice_ts += interpl;
@@ -619,7 +616,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
jb->info.frames_lost--;
jb_dbg("l");
/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
jb_warninfo(jb); */
jb_warninfo(jb); */
return JB_DROP;
}
}
@@ -633,9 +630,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
/* unless we don't have a frame, then shrink 1 frame */
/* every 80ms (though perhaps we can shrink even faster */
/* in this case) */
if (diff < -jb->info.conf.target_extra &&
((!frame && jb->info.last_adjustment + 80 < now) ||
(jb->info.last_adjustment + 500 < now))) {
if (diff < -jb->info.conf.target_extra && ((!frame && jb->info.last_adjustment + 80 < now) || (jb->info.last_adjustment + 500 < now))) {
jb->info.last_adjustment = now;
jb->info.cnt_contig_interp = 0;
@@ -677,11 +672,11 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
* lost frame get interpolated two or more times, when there was "room" to grow, so it might
* be a bit of a bad idea overall */
/*if (diff > -1 * jb->info.last_voice_ms) {
jb->info.current += jb->info.last_voice_ms;
jb->info.last_adjustment = now;
jb_warn("g");
return JB_INTERP;
} */
jb->info.current += jb->info.last_voice_ms;
jb->info.last_adjustment = now;
jb_warn("g");
return JB_INTERP;
} */
jb->info.frames_lost++;
increment_losspct(jb);
jb->info.next_voice_ts += interpl;
@@ -712,8 +707,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
/* jb->info.silence_begin_ts = 0; */
/* shrink interpl len every 10ms during silence */
if (diff < -jb->info.conf.target_extra &&
jb->info.last_adjustment + 10 <= now) {
if (diff < -jb->info.conf.target_extra && jb->info.last_adjustment + 10 <= now) {
jb->info.current -= interpl;
jb->info.last_adjustment = now;
}
@@ -736,7 +730,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
jb->info.frames_lost--;
jb_dbg("l");
/*jb_warn("\nlate: wanted=%ld, this=%ld, next=%ld\n", jb->info.next_voice_ts - jb->info.current, frame->ts, queue_next(jb));
jb_warninfo(jb); */
jb_warninfo(jb); */
return JB_DROP;
} else {
/* voice frame */
@@ -754,7 +748,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms
}
}
time_in_ms_t jb_next(jitterbuf *jb)
time_in_ms_t jb_next(jitterbuf * jb)
{
if (jb->info.silence_begin_ts) {
if (jb->frames) {
@@ -764,28 +758,28 @@ time_in_ms_t jb_next(jitterbuf *jb)
if (jb->info.target - jb->info.current < -jb->info.conf.target_extra)
return jb->info.last_adjustment + 10;
return next + jb->info.target;
}
else
} else
return JB_LONGMAX;
} else {
return jb->info.next_voice_ts;
}
}
enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
enum jb_return_code jb_get(jitterbuf * jb, jb_frame * frameout, time_in_ms_t now, long interpl)
{
enum jb_return_code ret = _jb_get(jb, frameout, now, interpl);
#if 0
static int lastts=0;
static int lastts = 0;
int thists = ((ret == JB_OK) || (ret == JB_DROP)) ? frameout->ts : 0;
jb_warn("jb_get(%x,%x,%ld) = %d (%d)\n", jb, frameout, now, ret, thists);
if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
if (thists && thists < lastts)
jb_warn("XXXX timestamp roll-back!!!\n");
lastts = thists;
#endif
return ret;
}
enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
enum jb_return_code jb_getall(jitterbuf * jb, jb_frame * frameout)
{
jb_frame *frame;
frame = queue_getall(jb);
@@ -799,7 +793,7 @@ enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout)
}
enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
enum jb_return_code jb_getinfo(jitterbuf * jb, jb_info * stats)
{
history_get(jb);
@@ -808,7 +802,7 @@ enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats)
return JB_OK;
}
enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
enum jb_return_code jb_setconf(jitterbuf * jb, jb_conf * conf)
{
/* take selected settings from the struct */
@@ -817,10 +811,8 @@ enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
jb->info.conf.max_contig_interp = conf->max_contig_interp;
/* -1 indicates use of the default JB_TARGET_EXTRA value */
jb->info.conf.target_extra = ( conf->target_extra == -1 )
? JB_TARGET_EXTRA
: conf->target_extra
;
jb->info.conf.target_extra = (conf->target_extra == -1)
? JB_TARGET_EXTRA : conf->target_extra;
/* update these to match new target_extra setting */
jb->info.current = jb->info.conf.target_extra;
@@ -828,5 +820,3 @@ enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
return JB_OK;
}
+150 -151
View File
@@ -3,13 +3,13 @@
#ifdef FREEBSD
# include <machine/endian.h>
#elif defined(LINUX)
#elif defined(LINUX)
# include <endian.h>
# include <features.h>
# include <sys/types.h>
#elif defined(SOLARIS)
/* each solaris is different -- this won't work on 2.6 or 2.7 */
# include <sys/isa_defs.h> /* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
# include <sys/isa_defs.h> /* Defines either _LITTLE_ENDIAN or _BIG_ENDIAN */
# define __BIG_ENDIAN 4321
# define __LITTLE_ENDIAN 1234
# define BIG_ENDIAN 4321
@@ -59,7 +59,7 @@
* needed on buffers full of bytes, and then call MD5Final, which
* will fill a supplied 16-byte array with the digest.
*/
#include <string.h> /* for memcpy() */
#include <string.h> /* for memcpy() */
#include "md5.h"
#ifndef HIGHFIRST
@@ -73,13 +73,12 @@ void byteReverse(unsigned char *buf, unsigned longs);
*/
void byteReverse(unsigned char *buf, unsigned longs)
{
uint32 t;
do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 |
((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
} while (--longs);
uint32 t;
do {
t = (uint32) ((unsigned) buf[3] << 8 | buf[2]) << 16 | ((unsigned) buf[1] << 8 | buf[0]);
*(uint32 *) buf = t;
buf += 4;
} while (--longs);
}
#endif
#endif
@@ -90,13 +89,13 @@ void byteReverse(unsigned char *buf, unsigned longs)
*/
void MD5Init(struct MD5Context *ctx)
{
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->buf[0] = 0x67452301;
ctx->buf[1] = 0xefcdab89;
ctx->buf[2] = 0x98badcfe;
ctx->buf[3] = 0x10325476;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
ctx->bits[0] = 0;
ctx->bits[1] = 0;
}
/*
@@ -105,46 +104,46 @@ void MD5Init(struct MD5Context *ctx)
*/
void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
{
uint32 t;
uint32 t;
/* Update bitcount */
/* Update bitcount */
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = ctx->bits[0];
if ((ctx->bits[0] = t + ((uint32) len << 3)) < t)
ctx->bits[1]++; /* Carry from low to high */
ctx->bits[1] += len >> 29;
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */
/* Handle any leading odd-sized chunks */
/* Handle any leading odd-sized chunks */
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
if (t) {
unsigned char *p = (unsigned char *) ctx->in + t;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
t = 64 - t;
if (len < t) {
memcpy(p, buf, len);
return;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
memcpy(p, buf, t);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += t;
len -= t;
}
/* Process data in 64-byte chunks */
/* Process data in 64-byte chunks */
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
}
while (len >= 64) {
memcpy(ctx->in, buf, 64);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
buf += 64;
len -= 64;
}
/* Handle any remaining bytes of data. */
/* Handle any remaining bytes of data. */
memcpy(ctx->in, buf, len);
memcpy(ctx->in, buf, len);
}
/*
@@ -153,43 +152,43 @@ void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len)
*/
void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
{
unsigned count;
unsigned char *p;
unsigned count;
unsigned char *p;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Compute number of bytes mod 64 */
count = (ctx->bits[0] >> 3) & 0x3F;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Set the first char of padding to 0x80. This is safe since there is
always at least one byte free */
p = ctx->in + count;
*p++ = 0x80;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Bytes of padding needed to make 64 bytes */
count = 64 - 1 - count;
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1];
/* Pad out to 56 mod 64 */
if (count < 8) {
/* Two lots of padding: Pad the first block to 64 bytes */
memset(p, 0, count);
byteReverse(ctx->in, 16);
MD5Transform(ctx->buf, (uint32 *) ctx->in);
/* Now fill the next block with 56 bytes */
memset(ctx->in, 0, 56);
} else {
/* Pad block to 56 bytes */
memset(p, 0, count - 8);
}
byteReverse(ctx->in, 14);
/* Append length in bits and transform */
((uint32 *) ctx->in)[14] = ctx->bits[0];
((uint32 *) ctx->in)[15] = ctx->bits[1];
MD5Transform(ctx->buf, (uint32 *) ctx->in);
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
byteReverse((unsigned char *) ctx->buf, 4);
memcpy(digest, ctx->buf, 16);
memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
}
#ifndef ASM_MD5
@@ -213,85 +212,85 @@ void MD5Final(unsigned char digest[16], struct MD5Context *ctx)
*/
void MD5Transform(uint32 buf[4], uint32 const in[16])
{
register uint32 a, b, c, d;
register uint32 a, b, c, d;
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
a = buf[0];
b = buf[1];
c = buf[2];
d = buf[3];
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
buf[0] += a;
buf[1] += b;
buf[2] += c;
buf[3] += d;
}
#endif
+37 -38
View File
@@ -110,14 +110,14 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip);
static char *IAXNAMES[] = { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
"IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
"IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
"IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
"IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
"IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
"IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
"IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
};
@@ -129,24 +129,24 @@ struct ast_iana {
//999 means it's wrong nad i dont know the real one
static struct ast_iana AST_IANA[] = { {AST_FORMAT_G723_1, 4, "g723.1"},
{AST_FORMAT_GSM, 3, "gsm"},
{AST_FORMAT_ULAW, 0, "ulaw"},
{AST_FORMAT_ALAW, 8, "alaw"},
{AST_FORMAT_G726, 999, "g726"},
{AST_FORMAT_ADPCM, 999, "adpcm"},
{AST_FORMAT_SLINEAR, 10, "slinear"},
{AST_FORMAT_LPC10, 7, "lpc10"},
{AST_FORMAT_G729A, 18, "g729"},
{AST_FORMAT_SPEEX, 97, "speex"},
{AST_FORMAT_SPEEX, 98, "speex"},
{AST_FORMAT_ILBC, 102, "ilbc"},
{AST_FORMAT_MAX_AUDIO, 999, ""},
{AST_FORMAT_JPEG, 999, ""},
{AST_FORMAT_PNG, 999, ""},
{AST_FORMAT_H261, 999, ""},
{AST_FORMAT_H263, 999, ""},
{AST_FORMAT_MAX_VIDEO, 999, ""},
{0, 0}
{AST_FORMAT_GSM, 3, "gsm"},
{AST_FORMAT_ULAW, 0, "ulaw"},
{AST_FORMAT_ALAW, 8, "alaw"},
{AST_FORMAT_G726, 999, "g726"},
{AST_FORMAT_ADPCM, 999, "adpcm"},
{AST_FORMAT_SLINEAR, 10, "slinear"},
{AST_FORMAT_LPC10, 7, "lpc10"},
{AST_FORMAT_G729A, 18, "g729"},
{AST_FORMAT_SPEEX, 97, "speex"},
{AST_FORMAT_SPEEX, 98, "speex"},
{AST_FORMAT_ILBC, 102, "ilbc"},
{AST_FORMAT_MAX_AUDIO, 999, ""},
{AST_FORMAT_JPEG, 999, ""},
{AST_FORMAT_PNG, 999, ""},
{AST_FORMAT_H261, 999, ""},
{AST_FORMAT_H263, 999, ""},
{AST_FORMAT_MAX_VIDEO, 999, ""},
{0, 0}
};
static char *ast2str(int ast)
@@ -214,7 +214,7 @@ typedef enum {
IAX_QUERY = 2
} iax_io_t;
static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *iax_session,
static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io)
{
char *dname = NULL;
@@ -281,8 +281,8 @@ static switch_status_t iax_set_codec(private_t * tech_pvt, struct iax_session *i
char pref_str[256] = "(";
for (x = 0; x < len; x++) {
strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str)-1);
strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str)-1);
strncat(pref_str, ast2str(prefs[x]), sizeof(pref_str) - 1);
strncat(pref_str, x == len - 1 ? ")" : ",", sizeof(pref_str) - 1);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Codec Prefs Detected: %s\n", pref_str);
@@ -439,7 +439,7 @@ static void iax_out_cb(const char *s)
}
}
static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
{
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
@@ -619,7 +619,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_FALSE;
cng:
cng:
data = (switch_byte_t *) tech_pvt->read_frame.data;
data[0] = 65;
data[1] = 0;
@@ -791,7 +791,7 @@ switch_io_routines_t iax_io_routines = {
/*.write_frame */ channel_write_frame,
/*.kill_channel */ channel_kill_channel,
/*.send_dtmf */ channel_send_dtmf,
/*.receive_message*/ channel_receive_message,
/*.receive_message */ channel_receive_message,
/*.receive_event */ channel_receive_event
};
@@ -867,7 +867,7 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
{
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
@@ -1025,8 +1025,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
NULL,
NULL,
modname,
iaxevent->ies.called_context,
iaxevent->ies.called_number)) != 0) {
iaxevent->ies.called_context, iaxevent->ies.called_number)) != 0) {
char name[128];
switch_snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
@@ -1062,7 +1061,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_mutex_unlock(tech_pvt->flag_mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
@@ -1102,7 +1101,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
break;
case IAX_EVENT_DTMF:
if (channel) {
switch_dtmf_t dtmf = { (char) iaxevent->subclass , switch_core_default_dtmf_duration(0) };
switch_dtmf_t dtmf = { (char) iaxevent->subclass, switch_core_default_dtmf_duration(0) };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%c DTMF %s\n", dtmf.digit, switch_channel_get_name(channel));
}
@@ -1118,7 +1117,7 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
break;
}
iax_event_free(iaxevent);
switch_mutex_unlock(globals.mutex);
switch_mutex_unlock(globals.mutex);
if (tech_pvt && tech_pvt->session) {
switch_core_session_signal_unlock(tech_pvt->session);
}