From: <do...@us...> - 2007-12-19 19:51:35
|
Revision: 1318 http://iaxclient.svn.sourceforge.net/iaxclient/?rev=1318&view=rev Author: dohpaz Date: 2007-12-19 11:51:40 -0800 (Wed, 19 Dec 2007) Log Message: ----------- Merge up to trunk of r1317. Modified Paths: -------------- branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c branches/team/elbunce/iaxclient/lib/libiax2/src/iax2-parser.c Modified: branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c =================================================================== --- branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c 2007-12-19 15:55:20 UTC (rev 1317) +++ branches/team/elbunce/iaxclient/lib/libiax2/src/iax.c 2007-12-19 19:51:40 UTC (rev 1318) @@ -30,7 +30,6 @@ #include <winsock.h> #include <time.h> #include <stdlib.h> -#include <malloc.h> #include <stdarg.h> #include <stdio.h> #include <limits.h> @@ -76,9 +75,9 @@ #include <arpa/inet.h> #include <time.h> -#ifndef MACOSX +#if !defined(MACOSX) && !defined(__OpenBSD__) #include <malloc.h> -#ifndef SOLARIS +#if !defined(SOLARIS) #include <error.h> #endif #endif @@ -97,7 +96,7 @@ #ifdef MACOSX #define IAX_SOCKOPTS MSG_DONTWAIT #else -#ifdef SOLARIS +#if defined(SOLARIS) || defined(__OpenBSD__) #define IAX_SOCKOPTS MSG_DONTWAIT #else /* Linux and others */ #define IAX_SOCKOPTS MSG_DONTWAIT | MSG_NOSIGNAL @@ -128,6 +127,9 @@ /* Video frames bypass jitterbuffer */ static int video_bypass_jitterbuffer = 0; +/* To use or not to use the jitterbuffer */ +static int iax_use_jitterbuffer = 1; + /* UDP Socket (file descriptor) */ static int netfd = -1; @@ -249,7 +251,55 @@ debug = 0; } +void iax_enable_jitterbuffer(void) +{ + iax_use_jitterbuffer = 1; +} +void iax_disable_jitterbuffer(void) +{ + iax_use_jitterbuffer = 0; +} + +void iax_set_private(struct iax_session *s, void *ptr) +{ + s->pvt = ptr; +} + +void *iax_get_private(struct iax_session *s) +{ + return s->pvt; +} + +void iax_set_sendto(struct iax_session *s, iax_sendto_t ptr) +{ + s->sendto = ptr; +} + +void iax_seed_random() +{ +#if defined(HAVE_SRANDOMDEV) + srandomdev(); +#elif defined(HAVE_SRANDOM) + srandom((unsigned int)time(0)); +#elif define(HAVE_SRAND48) + srand48((long int)time(0)); +#else + srand((unsigned int)time(0)); +#endif +} + +int iax_random() +{ +#if defined(HAVE_RANDOM) + return (int)random(); +#elif defined(HAVE_LRAND48) + return (int)lrand48(); +#else + return rand(); +#endif +} + /* This is a little strange, but to debug you call DEBU(G "Hello World!\n"); */ #if defined(WIN32) || defined(_WIN32_WCE) #define G __FILE__, __LINE__, @@ -315,52 +365,11 @@ static struct iax_session *sessions = NULL; static int callnums = 1; -void iax_seed_random() -{ -#if defined(HAVE_SRANDOMDEV) - srandomdev(); -#elif defined(HAVE_SRANDOM) - srandom((unsigned int)time(0)); -#elif define(HAVE_SRAND48) - srand48((long int)time(0)); -#else - srand((unsigned int)time(0)); -#endif -} - -int iax_random() -{ -#if defined(HAVE_RANDOM) - return (int)random(); -#elif defined(HAVE_LRAND48) - return (int)lrand48(); -#else - return rand(); -#endif -} - -void iax_set_private(struct iax_session *s, void *ptr) -{ - s->pvt = ptr; -} - -void *iax_get_private(struct iax_session *s) -{ - return s->pvt; -} - -void iax_set_sendto(struct iax_session *s, iax_sendto_t ptr) -{ - s->sendto = ptr; -} - - unsigned int iax_session_get_capability(struct iax_session *s) { return s->capability; } - static int inaddrcmp(struct sockaddr_in *sin1, struct sockaddr_in *sin2) { return (sin1->sin_addr.s_addr != sin2->sin_addr.s_addr) || (sin1->sin_port != sin2->sin_port); @@ -848,8 +857,9 @@ } #endif /* Send the frame raw */ - res = f->session->sendto(netfd, (const char *) f->data, f->datalen, IAX_SOCKOPTS, - f->transfer ? (struct sockaddr *)&(f->session->transfer) : + res = f->session->sendto(netfd, (const char *) f->data, f->datalen, + IAX_SOCKOPTS, f->transfer ? + (struct sockaddr *)&(f->session->transfer) : (struct sockaddr *)&(f->session->peeraddr), sizeof(f->session->peeraddr)); return res; @@ -1026,7 +1036,7 @@ { int x; for (x=0;x<16;x++) - out += sprintf(out, "%2.2x", (int)in[x]); + sprintf(out + (x << 1), "%2.2x", (int)in[x]); } static unsigned char compress_subclass(int subclass) @@ -1063,7 +1073,7 @@ struct iax_frame *fr; int res; int sendmini=0; - unsigned int lastsent; + unsigned int nextpred; unsigned int fts; if (!pvt) @@ -1072,14 +1082,15 @@ return -1; } - /* this must come before the next call to calc_timestamp() since - calc_timestamp() will change lastsent to the returned value */ - lastsent = pvt->lastsent; - /* Calculate actual timestamp */ fts = calc_timestamp(pvt, ts, f); - if (((fts & 0xFFFF0000L) == (lastsent & 0xFFFF0000L)) + /* If the next predicted VOICE timestamp will overflow the 16-bit + portion of the timestamp then we send a full VOICE frame to + keep the 32-bit portion of the timestamp synchronized. */ + nextpred = pvt->nextpred; + + if (((fts & 0xFFFF0000L) == (nextpred & 0xFFFF0000L)) /* High two bits are the same on timestamp, or sending on a trunk */ && (f->frametype == AST_FRAME_VOICE) /* is a voice frame */ && @@ -1095,7 +1106,7 @@ /* Bitmask taken from chan_iax2.c... I must ask Mark Spencer for this? I think not... */ if ( f->frametype == AST_FRAME_VIDEO ) { - if (((fts & 0xFFFF8000L) == (lastsent & 0xFFFF8000L)) + if (((fts & 0xFFFF8000L) == (nextpred & 0xFFFF8000L)) /* High two bits are the same on timestamp, or sending on a trunk */ && ((f->subclass & ~0x01) == pvt->svideoformat) /* is the same type */ ) @@ -1613,6 +1624,7 @@ */ case IAX_EVENT_REJECT: case IAX_EVENT_HANGUP: + case IAX_EVENT_REGACK: /* Destroy this session -- it's no longer valid */ destroy_session(event->session); return event; @@ -1942,7 +1954,7 @@ convert_reply(realreply, (unsigned char *) reply); iax_ie_append_str(&ied, IAX_IE_MD5_RESULT, realreply); } else { - iax_ie_append_str(&ied, IAX_IE_MD5_RESULT, password); + iax_ie_append_str(&ied, IAX_IE_PASSWORD, password); } return send_command(session, AST_FRAME_IAX, IAX_COMMAND_AUTHREP, 0, ied.buf, ied.pos, -1); } @@ -1967,7 +1979,7 @@ convert_reply(realreply, (unsigned char *) reply); iax_ie_append_str(&ied, IAX_IE_MD5_RESULT, realreply); } else { - iax_ie_append_str(&ied, IAX_IE_MD5_RESULT, password); + iax_ie_append_str(&ied, IAX_IE_PASSWORD, password); } return send_command(session, AST_FRAME_IAX, IAX_COMMAND_REGREQ, 0, ied.buf, ied.pos, -1); } @@ -2368,7 +2380,9 @@ /* insert into jitterbuffer */ /* TODO: Perhaps we could act immediately if it's not droppable and late */ - if ( e->etype == IAX_EVENT_VIDEO && video_bypass_jitterbuffer ) + if ( !iax_use_jitterbuffer || + (e->etype == IAX_EVENT_VIDEO && + video_bypass_jitterbuffer) ) { iax_sched_add(e, NULL, NULL, NULL, 0); return NULL; @@ -2508,7 +2522,7 @@ /* don't run last_ts backwards; i.e. for retransmits and the like */ if (ts > session->last_ts && - (fh->type == AST_FRAME_IAX && + ((fh->type == AST_FRAME_IAX || fh->type == AST_FRAME_VOICE) && subclass != IAX_COMMAND_ACK && subclass != IAX_COMMAND_PONG && subclass != IAX_COMMAND_LAGRP)) @@ -2633,6 +2647,7 @@ */ e->etype = -1; e->session = session; + e->ts = ts; switch(fh->type) { case AST_FRAME_DTMF: e->etype = IAX_EVENT_DTMF; @@ -2645,7 +2660,6 @@ case AST_FRAME_VOICE: e->etype = IAX_EVENT_VOICE; e->subclass = subclass; - e->ts = ts; session->voiceformat = subclass; if (datalen) { memcpy(e->data, fh->iedata, datalen); @@ -2726,17 +2740,14 @@ case IAX_COMMAND_LAGRQ: /* Pass this along for later handling */ e->etype = IAX_EVENT_LAGRQ; - e->ts = ts; e = schedule_delivery(e, ts, updatehistory); break; case IAX_COMMAND_POKE: e->etype = IAX_EVENT_POKE; - e->ts = ts; break; case IAX_COMMAND_PING: /* PINGS and PONGS don't get scheduled; */ e->etype = IAX_EVENT_PING; - e->ts = ts; break; case IAX_COMMAND_PONG: e->etype = IAX_EVENT_PONG; @@ -2905,7 +2916,6 @@ case AST_FRAME_VIDEO: e->etype = IAX_EVENT_VIDEO; e->subclass = subclass; - e->ts = ts; session->videoformat = e->subclass; memcpy(e->data, fh->iedata, datalen); e->datalen = datalen; @@ -3023,7 +3033,8 @@ e->subclass = session->voiceformat; e->datalen = datalen; memcpy(e->data, mh->data, datalen); - e->ts = (session->last_ts & 0xFFFF0000) | ntohs(mh->ts); + e->ts = (session->last_ts & 0xFFFF0000L) | (ntohs(mh->ts) & 0xFFFF); + e->ts = unwrap_timestamp(e->ts, session->last_ts); return schedule_delivery(e, e->ts, 1); } Modified: branches/team/elbunce/iaxclient/lib/libiax2/src/iax2-parser.c =================================================================== --- branches/team/elbunce/iaxclient/lib/libiax2/src/iax2-parser.c 2007-12-19 15:55:20 UTC (rev 1317) +++ branches/team/elbunce/iaxclient/lib/libiax2/src/iax2-parser.c 2007-12-19 19:51:40 UTC (rev 1318) @@ -159,7 +159,6 @@ { 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 }, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |