backport change from the iaxclient sf repository rev 648, 649, 650, 656.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@5158 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-05-11 21:20:13 +00:00
parent 343d77a408
commit 9c475bb692
4 changed files with 1010 additions and 970 deletions

View File

@ -226,6 +226,10 @@ extern unsigned int iax_session_get_capability(struct iax_session *s);
extern char iax_pref_codec_add(struct iax_session *session, unsigned int format); extern char iax_pref_codec_add(struct iax_session *session, unsigned int format);
extern void iax_pref_codec_del(struct iax_session *session, unsigned int format); extern void iax_pref_codec_del(struct iax_session *session, unsigned int format);
extern int iax_pref_codec_get(struct iax_session *session, unsigned int *array, int len); extern int iax_pref_codec_get(struct iax_session *session, unsigned int *array, int len);
/* Fine tune jitterbuffer */
extern void iax_set_jb_target_extra( long value );
extern char *iax_get_peer_ip(struct iax_session *session); extern char *iax_get_peer_ip(struct iax_session *session);
extern char *iax_event_get_apparent_ip(struct iax_event *event); extern char *iax_event_get_apparent_ip(struct iax_event *event);
extern void iax_set_samplerate(struct iax_session *session, unsigned short samplemask); extern void iax_set_samplerate(struct iax_session *session, unsigned short samplemask);

View File

@ -140,6 +140,9 @@ static int netfd = -1;
/* Max timeouts */ /* Max timeouts */
static int maxretries = 10; static int maxretries = 10;
/* configurable jitterbuffer options */
static long jb_target_extra = -1;
static int do_shutdown = 0; static int do_shutdown = 0;
/* external global networking replacements */ /* external global networking replacements */
@ -521,6 +524,7 @@ struct iax_session *iax_session_new(void)
jbconf.max_jitterbuf = 0; jbconf.max_jitterbuf = 0;
jbconf.resync_threshold = 1000; jbconf.resync_threshold = 1000;
jbconf.max_contig_interp = 0; jbconf.max_contig_interp = 0;
jbconf.target_extra = jb_target_extra;
jb_setconf(s->jb, &jbconf); jb_setconf(s->jb, &jbconf);
} }
#endif #endif
@ -944,6 +948,12 @@ int iax_shutdown(void)
return do_shutdown++; return do_shutdown++;
} }
void iax_set_jb_target_extra( long value )
{
/* store in jb_target_extra, a static global */
jb_target_extra = value ;
}
int iax_init(char *ip, int preferredportno) int iax_init(char *ip, int preferredportno)
{ {
int portno = preferredportno; int portno = preferredportno;

File diff suppressed because it is too large Load Diff

View File

@ -1,160 +1,162 @@
/* /*
* jitterbuf: an application-independent jitterbuffer * jitterbuf: an application-independent jitterbuffer
* *
* Copyrights: * Copyrights:
* Copyright (C) 2004-2005, Horizon Wimba, Inc. * Copyright (C) 2004-2005, Horizon Wimba, Inc.
* *
* Contributors: * Contributors:
* Steve Kann <stevek@stevek.com> * Steve Kann <stevek@stevek.com>
* *
* This program is free software, distributed under the terms of * This program is free software, distributed under the terms of
* the GNU Lesser (Library) General Public License * the GNU Lesser (Library) General Public License
* *
* Copyright on this file is disclaimed to Digium for inclusion in Asterisk * Copyright on this file is disclaimed to Digium for inclusion in Asterisk
*/ */
#ifndef _JITTERBUF_H_ #ifndef _JITTERBUF_H_
#define _JITTERBUF_H_ #define _JITTERBUF_H_
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
/* configuration constants */ /* configuration constants */
/* Number of historical timestamps to use in calculating jitter and drift */ /* Number of historical timestamps to use in calculating jitter and drift */
#define JB_HISTORY_SZ 500 #define JB_HISTORY_SZ 500
/* what percentage of timestamps should we drop from the history when we examine it; /* what percentage of timestamps should we drop from the history when we examine it;
* this might eventually be something made configurable */ * this might eventually be something made configurable */
#define JB_HISTORY_DROPPCT 3 #define JB_HISTORY_DROPPCT 3
/* the maximum droppct we can handle (say it was configurable). */ /* the maximum droppct we can handle (say it was configurable). */
#define JB_HISTORY_DROPPCT_MAX 4 #define JB_HISTORY_DROPPCT_MAX 4
/* the size of the buffer we use to keep the top and botton timestamps for dropping */ /* the size of the buffer we use to keep the top and botton timestamps for dropping */
#define JB_HISTORY_MAXBUF_SZ JB_HISTORY_SZ * JB_HISTORY_DROPPCT_MAX / 100 #define JB_HISTORY_MAXBUF_SZ JB_HISTORY_SZ * JB_HISTORY_DROPPCT_MAX / 100
/* amount of additional jitterbuffer adjustment */ /* amount of additional jitterbuffer adjustment */
#define JB_TARGET_EXTRA 40 #define JB_TARGET_EXTRA 40
/* ms between growing and shrinking; may not be honored if jitterbuffer runs out of space */ /* ms between growing and shrinking; may not be honored if jitterbuffer runs out of space */
#define JB_ADJUST_DELAY 40 #define JB_ADJUST_DELAY 40
enum jb_return_code {
/* return codes */ /* return codes */
#define JB_OK 0 JB_OK, /* 0 */
#define JB_EMPTY 1 JB_EMPTY, /* 1 */
#define JB_NOFRAME 2 JB_NOFRAME, /* 2 */
#define JB_INTERP 3 JB_INTERP, /* 3 */
#define JB_DROP 4 JB_DROP, /* 4 */
#define JB_SCHED 5 JB_SCHED /* 5 */
};
/* frame types */
#define JB_TYPE_CONTROL 0 enum jb_frame_type {
#define JB_TYPE_VOICE 1 /* frame types */
#define JB_TYPE_VIDEO 2 /* reserved */ JB_TYPE_CONTROL, /* 0 */
#define JB_TYPE_SILENCE 3 JB_TYPE_VOICE, /* 1 */
JB_TYPE_VIDEO, /* 2 - reserved */
JB_TYPE_SILENCE /* 3 */
typedef struct jb_conf { };
/* settings */
long max_jitterbuf; /* defines a hard clamp to use in setting the jitter buffer delay */ typedef struct jb_conf {
long resync_threshold; /* the jb will resync when delay increases to (2 * jitter) + this param */ /* settings */
long max_contig_interp; /* the max interp frames to return in a row */ long max_jitterbuf; /* defines a hard clamp to use in setting the jitter buffer delay */
} jb_conf; long resync_threshold; /* the jb will resync when delay increases to (2 * jitter) + this param */
long max_contig_interp; /* the max interp frames to return in a row */
typedef struct jb_info { long target_extra; /* amount of additional jitterbuffer adjustment, overrides JB_TARGET_EXTRA */
jb_conf conf; } jb_conf;
/* statistics */ typedef struct jb_info {
long frames_in; /* number of frames input to the jitterbuffer.*/ jb_conf conf;
long frames_out; /* number of frames output from the jitterbuffer.*/
long frames_late; /* number of frames which were too late, and dropped.*/ /* statistics */
long frames_lost; /* number of missing frames.*/ long frames_in; /* number of frames input to the jitterbuffer.*/
long frames_dropped; /* number of frames dropped (shrinkage) */ long frames_out; /* number of frames output from the jitterbuffer.*/
long frames_ooo; /* number of frames received out-of-order */ long frames_late; /* number of frames which were too late, and dropped.*/
long frames_cur; /* number of frames presently in jb, awaiting delivery.*/ long frames_lost; /* number of missing frames.*/
time_in_ms_t jitter; /* jitter measured within current history interval*/ long frames_dropped; /* number of frames dropped (shrinkage) */
time_in_ms_t min; /* minimum lateness within current history interval */ long frames_ooo; /* number of frames received out-of-order */
time_in_ms_t current; /* the present jitterbuffer adjustment */ long frames_cur; /* number of frames presently in jb, awaiting delivery.*/
time_in_ms_t target; /* the target jitterbuffer adjustment */ time_in_ms_t jitter; /* jitter measured within current history interval*/
long losspct; /* recent lost frame percentage (* 1000) */ time_in_ms_t min; /* minimum lateness within current history interval */
time_in_ms_t next_voice_ts; /* the ts of the next frame to be read from the jb - in receiver's time */ time_in_ms_t current; /* the present jitterbuffer adjustment */
long last_voice_ms; /* the duration of the last voice frame */ time_in_ms_t target; /* the target jitterbuffer adjustment */
time_in_ms_t silence_begin_ts; /* the time of the last CNG frame, when in silence */ long losspct; /* recent lost frame percentage (* 1000) */
time_in_ms_t last_adjustment; /* the time of the last adjustment */ time_in_ms_t next_voice_ts; /* the ts of the next frame to be read from the jb - in receiver's time */
time_in_ms_t last_delay; /* the last now added to history */ long last_voice_ms; /* the duration of the last voice frame */
long cnt_delay_discont; /* the count of discontinuous delays */ time_in_ms_t silence_begin_ts; /* the time of the last CNG frame, when in silence */
time_in_ms_t resync_offset; /* the amount to offset ts to support resyncs */ time_in_ms_t last_adjustment; /* the time of the last adjustment */
long cnt_contig_interp; /* the number of contiguous interp frames returned */ time_in_ms_t last_delay; /* the last now added to history */
} jb_info; long cnt_delay_discont; /* the count of discontinuous delays */
time_in_ms_t resync_offset; /* the amount to offset ts to support resyncs */
typedef struct jb_frame { long cnt_contig_interp; /* the number of contiguous interp frames returned */
void *data; /* the frame data */ } jb_info;
time_in_ms_t ts; /* the relative delivery time expected */
long ms; /* the time covered by this frame, in sec/8000 */ typedef struct jb_frame {
int type; /* the type of frame */ void *data; /* the frame data */
struct jb_frame *next, *prev; time_in_ms_t ts; /* the relative delivery time expected */
} jb_frame; long ms; /* the time covered by this frame, in sec/8000 */
enum jb_frame_type type; /* the type of frame */
typedef struct jitterbuf { struct jb_frame *next, *prev;
jb_info info; } jb_frame;
/* history */ typedef struct jitterbuf {
time_in_ms_t history[JB_HISTORY_SZ]; /* history */ jb_info info;
int hist_ptr; /* points to index in history for next entry */
time_in_ms_t hist_maxbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the max delays (highest first) */ /* history */
time_in_ms_t hist_minbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the min delays (lowest first) */ time_in_ms_t history[JB_HISTORY_SZ]; /* history */
int hist_maxbuf_valid; /* are the "maxbuf"/minbuf valid? */ int hist_ptr; /* points to index in history for next entry */
time_in_ms_t hist_maxbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the max delays (highest first) */
time_in_ms_t hist_minbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the min delays (lowest first) */
jb_frame *frames; /* queued frames */ int hist_maxbuf_valid; /* are the "maxbuf"/minbuf valid? */
jb_frame *free; /* free frames (avoid malloc?) */
} jitterbuf; jb_frame *frames; /* queued frames */
jb_frame *free; /* free frames (avoid malloc?) */
} jitterbuf;
/* new jitterbuf */
extern jitterbuf * jb_new(void);
/* new jitterbuf */
/* destroy jitterbuf */ jitterbuf * jb_new(void);
extern void jb_destroy(jitterbuf *jb);
/* destroy jitterbuf */
/* reset jitterbuf */ void jb_destroy(jitterbuf *jb);
/* NOTE: The jitterbuffer should be empty before you call this, otherwise
* you will leak queued frames, and some internal structures */ /* reset jitterbuf */
extern void jb_reset(jitterbuf *jb); /* NOTE: The jitterbuffer should be empty before you call this, otherwise
* you will leak queued frames, and some internal structures */
/* queue a frame data=frame data, timings (in ms): ms=length of frame (for voice), ts=ts (sender's time) void jb_reset(jitterbuf *jb);
* now=now (in receiver's time) return value is one of
* JB_OK: Frame added. Last call to jb_next() still valid /* queue a frame data=frame data, timings (in ms): ms=length of frame (for voice), ts=ts (sender's time)
* JB_DROP: Drop this frame immediately * now=now (in receiver's time) return value is one of
* JB_SCHED: Frame added. Call jb_next() to get a new time for the next frame * JB_OK: Frame added. Last call to jb_next() still valid
*/ * JB_DROP: Drop this frame immediately
extern int jb_put(jitterbuf *jb, void *data, int type, long ms, time_in_ms_t ts, time_in_ms_t now); * JB_SCHED: Frame added. Call jb_next() to get a new time for the next frame
*/
/* get a frame for time now (receiver's time) return value is one of 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_OK: You've got frame!
* JB_DROP: Here's an audio frame you should just drop. Ask me again for this time.. /* get a frame for time now (receiver's time) return value is one of
* JB_NOFRAME: There's no frame scheduled for this time. * JB_OK: You've got frame!
* JB_INTERP: Please interpolate an interpl-length frame for this time (either we need to grow, or there was a lost frame) * JB_DROP: Here's an audio frame you should just drop. Ask me again for this time..
* JB_EMPTY: The jb is empty. * JB_NOFRAME: There's no frame scheduled for this time.
*/ * JB_INTERP: Please interpolate an interpl-length frame for this time (either we need to grow, or there was a lost frame)
extern int jb_get(jitterbuf *jb, jb_frame *frame, time_in_ms_t now, long interpl); * JB_EMPTY: The jb is empty.
*/
/* unconditionally get frames from jitterbuf until empty */ enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frame, time_in_ms_t now, long interpl);
extern int jb_getall(jitterbuf *jb, jb_frame *frameout);
/* unconditionally get frames from jitterbuf until empty */
/* when is the next frame due out, in receiver's time (0=EMPTY) enum jb_return_code jb_getall(jitterbuf *jb, jb_frame *frameout);
* This value may change as frames are added (esp non-audio frames) */
extern time_in_ms_t jb_next(jitterbuf *jb); /* when is the next frame due out, in receiver's time (0=EMPTY)
* This value may change as frames are added (esp non-audio frames) */
/* get jitterbuf info: only "statistics" may be valid */ time_in_ms_t jb_next(jitterbuf *jb);
extern int jb_getinfo(jitterbuf *jb, jb_info *stats);
/* get jitterbuf info: only "statistics" may be valid */
/* set jitterbuf conf */ enum jb_return_code jb_getinfo(jitterbuf *jb, jb_info *stats);
extern int jb_setconf(jitterbuf *jb, jb_conf *conf);
/* set jitterbuf conf */
typedef void (*jb_output_function_t)(const char *fmt, ...); enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf);
extern void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg);
typedef void (*jb_output_function_t)(const char *fmt, ...);
#ifdef __cplusplus extern void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg);
}
#endif #ifdef __cplusplus
}
#endif
#endif
#endif