提交 c5e31447 authored 作者: Michael Jerris's avatar Michael Jerris

eliminate some int overflows in iax.

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@856 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 125a2b2d
......@@ -107,7 +107,7 @@ typedef int (*recvfrom_t)(int s, void *buf, size_t len, int flags, struct sockad
struct iax_event {
int etype; /* Type of event */
int subclass; /* Subclass data (event specific) */
unsigned int ts; /* Timestamp */
time_in_ms_t ts; /* Timestamp */
struct iax_session *session; /* Applicable session */
int datalen; /* Length of raw data */
struct iax_ies ies; /* IE's for IAX2 frames */
......@@ -133,7 +133,7 @@ extern int iax_shutdown(void);
extern int iax_get_fd(void);
/* Find out how many milliseconds until the next scheduled event */
extern int iax_time_to_next_event(void);
extern time_in_ms_t iax_time_to_next_event(void);
/* Generate a new IAX session */
extern struct iax_session *iax_session_new(void);
......@@ -196,16 +196,16 @@ extern void iax_disable_debug(void);
extern int iax_setup_transfer(struct iax_session *s0, struct iax_session *s1);
struct iax_netstat {
int jitter;
time_in_ms_t jitter;
int losspct;
int losscnt;
int packets;
int delay;
time_in_ms_t delay;
int dropped;
int ooo;
};
/* fills in rtt, and an iax_netstat structure for each of local/remote directions of call */
extern int iax_get_netstats(struct iax_session *s, int *rtt, struct iax_netstat *local, struct iax_netstat *remote);
extern int iax_get_netstats(struct iax_session *s, time_in_ms_t *rtt, struct iax_netstat *local, struct iax_netstat *remote);
extern void iax_set_private(struct iax_session *s, void *pvt);
......
差异被折叠。
......@@ -86,9 +86,9 @@ struct iax_frame {
/* How many retries so far? */
int retries;
/* Outgoing relative timestamp (ms) */
unsigned int ts;
time_in_ms_t ts;
/* How long to wait before retrying */
int retrytime;
time_in_ms_t retrytime;
/* Are we received out of order? */
int outoforder;
/* Have we been sent at all yet? */
......
......@@ -14,6 +14,9 @@
#ifndef _IAX2_H
#define _IAX2_H
typedef long long time_in_ms_t;
#define iax_abs(x) ((x) >= 0 ? (x) : -(x))
/* Max version of IAX protocol we support */
#define IAX_PROTO_VERSION 2
......
......@@ -13,6 +13,7 @@
* Copyright on this file is disclaimed to Digium for inclusion in Asterisk
*/
#include "iax2.h"
#include "jitterbuf.h"
#include <stdio.h>
#include <stdlib.h>
......@@ -123,11 +124,11 @@ static int longcmp(const void *a, const void *b)
}
#endif
static int history_put(jitterbuf *jb, long ts, long now, long ms)
static int history_put(jitterbuf *jb, time_in_ms_t ts, time_in_ms_t now, long ms)
{
long delay = now - (ts - jb->info.resync_offset);
long threshold = 2 * jb->info.jitter + jb->info.conf.resync_threshold;
long kicked;
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;
time_in_ms_t kicked;
/* don't add special/negative times to history */
if (ts <= 0)
......@@ -135,7 +136,7 @@ static int history_put(jitterbuf *jb, long ts, long now, long ms)
/* check for drastic change in delay */
if (jb->info.conf.resync_threshold != -1) {
if (abs(delay - jb->info.last_delay) > threshold) {
if (iax_abs(delay - jb->info.last_delay) > threshold) {
jb->info.cnt_delay_discont++;
if (jb->info.cnt_delay_discont > 3) {
/* resync the jitterbuffer */
......@@ -222,7 +223,7 @@ static void history_calc_maxbuf(jitterbuf *jb)
i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
for(;i<jb->hist_ptr;i++) {
long toins = jb->history[i % JB_HISTORY_SZ];
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]) {
......@@ -276,7 +277,7 @@ static void history_calc_maxbuf(jitterbuf *jb)
static void history_get(jitterbuf *jb)
{
long max, min, jitter;
time_in_ms_t max, min, jitter;
int index;
int count;
......@@ -316,12 +317,12 @@ static void history_get(jitterbuf *jb)
}
/* returns 1 if frame was inserted into head of queue, 0 otherwise */
static int queue_put(jitterbuf *jb, void *data, int type, long ms, long ts)
static int queue_put(jitterbuf *jb, void *data, int type, long ms, time_in_ms_t ts)
{
jb_frame *frame;
jb_frame *p;
int head = 0;
long resync_ts = ts - jb->info.resync_offset;
time_in_ms_t resync_ts = ts - jb->info.resync_offset;
frame = jb->free;
if(frame) {
......@@ -382,19 +383,19 @@ static int queue_put(jitterbuf *jb, void *data, int type, long ms, long ts)
return head;
}
static long queue_next(jitterbuf *jb)
static time_in_ms_t queue_next(jitterbuf *jb)
{
if(jb->frames) return jb->frames->ts;
else return -1;
}
static long queue_last(jitterbuf *jb)
static time_in_ms_t queue_last(jitterbuf *jb)
{
if(jb->frames) return jb->frames->prev->ts;
else return -1;
}
static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
static jb_frame *_queue_get(jitterbuf *jb, time_in_ms_t ts, int all)
{
jb_frame *frame;
frame = jb->frames;
......@@ -429,7 +430,7 @@ static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
return NULL;
}
static jb_frame *queue_get(jitterbuf *jb, long ts)
static jb_frame *queue_get(jitterbuf *jb, time_in_ms_t ts)
{
return _queue_get(jb,ts,0);
}
......@@ -504,7 +505,7 @@ static void jb_dbgqueue(jitterbuf *jb)
}
#endif
int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now)
int jb_put(jitterbuf *jb, void *data, int type, long ms, time_in_ms_t ts, time_in_ms_t now)
{
jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
......@@ -526,10 +527,10 @@ int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now)
}
static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
static int _jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
{
jb_frame *frame;
long diff;
time_in_ms_t diff;
/*if((now - jb_next(jb)) > 2 * jb->info.last_voice_ms) jb_warn("SCHED: %ld", (now - jb_next(jb))); */
/* get jitter info */
......@@ -742,10 +743,10 @@ static int _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
}
}
long jb_next(jitterbuf *jb)
time_in_ms_t jb_next(jitterbuf *jb)
{
if(jb->info.silence_begin_ts) {
long next = queue_next(jb);
time_in_ms_t next = queue_next(jb);
if(next > 0) {
/* shrink during silence */
if (jb->info.target - jb->info.current < -JB_TARGET_EXTRA)
......@@ -758,7 +759,7 @@ long jb_next(jitterbuf *jb)
}
}
int jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
int jb_get(jitterbuf *jb, jb_frame *frameout, time_in_ms_t now, long interpl)
{
int ret = _jb_get(jb,frameout,now,interpl);
#if 0
......
......@@ -69,24 +69,24 @@ typedef struct jb_info {
long frames_dropped; /* number of frames dropped (shrinkage) */
long frames_ooo; /* number of frames received out-of-order */
long frames_cur; /* number of frames presently in jb, awaiting delivery.*/
long jitter; /* jitter measured within current history interval*/
long min; /* minimum lateness within current history interval */
long current; /* the present jitterbuffer adjustment */
long target; /* the target jitterbuffer adjustment */
time_in_ms_t jitter; /* jitter measured within current history interval*/
time_in_ms_t min; /* minimum lateness within current history interval */
time_in_ms_t current; /* the present jitterbuffer adjustment */
time_in_ms_t target; /* the target jitterbuffer adjustment */
long losspct; /* recent lost frame percentage (* 1000) */
long next_voice_ts; /* the ts of the next frame to be read from the jb - in receiver's time */
time_in_ms_t next_voice_ts; /* the ts of the next frame to be read from the jb - in receiver's time */
long last_voice_ms; /* the duration of the last voice frame */
long silence_begin_ts; /* the time of the last CNG frame, when in silence */
long last_adjustment; /* the time of the last adjustment */
long last_delay; /* the last now added to history */
time_in_ms_t silence_begin_ts; /* the time of the last CNG frame, when in silence */
time_in_ms_t last_adjustment; /* the time of the last adjustment */
time_in_ms_t last_delay; /* the last now added to history */
long cnt_delay_discont; /* the count of discontinuous delays */
long resync_offset; /* the amount to offset ts to support resyncs */
time_in_ms_t resync_offset; /* the amount to offset ts to support resyncs */
long cnt_contig_interp; /* the number of contiguous interp frames returned */
} jb_info;
typedef struct jb_frame {
void *data; /* the frame data */
long ts; /* the relative delivery time expected */
time_in_ms_t ts; /* the relative delivery time expected */
long ms; /* the time covered by this frame, in sec/8000 */
int type; /* the type of frame */
struct jb_frame *next, *prev;
......@@ -96,10 +96,10 @@ typedef struct jitterbuf {
jb_info info;
/* history */
long history[JB_HISTORY_SZ]; /* history */
time_in_ms_t history[JB_HISTORY_SZ]; /* history */
int hist_ptr; /* points to index in history for next entry */
long hist_maxbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the max delays (highest first) */
long hist_minbuf[JB_HISTORY_MAXBUF_SZ]; /* a sorted buffer of the min delays (lowest first) */
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) */
int hist_maxbuf_valid; /* are the "maxbuf"/minbuf valid? */
......@@ -125,7 +125,7 @@ extern void jb_reset(jitterbuf *jb);
* JB_DROP: Drop this frame immediately
* JB_SCHED: Frame added. Call jb_next() to get a new time for the next frame
*/
extern int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long now);
extern int jb_put(jitterbuf *jb, void *data, int type, long ms, time_in_ms_t ts, time_in_ms_t now);
/* get a frame for time now (receiver's time) return value is one of
* JB_OK: You've got frame!
......@@ -134,14 +134,14 @@ extern int jb_put(jitterbuf *jb, void *data, int type, long ms, long ts, long
* JB_INTERP: Please interpolate an interpl-length frame for this time (either we need to grow, or there was a lost frame)
* JB_EMPTY: The jb is empty.
*/
extern int jb_get(jitterbuf *jb, jb_frame *frame, long now, long interpl);
extern int jb_get(jitterbuf *jb, jb_frame *frame, time_in_ms_t now, long interpl);
/* unconditionally get frames from jitterbuf until empty */
extern int jb_getall(jitterbuf *jb, jb_frame *frameout);
/* 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) */
extern long jb_next(jitterbuf *jb);
extern time_in_ms_t jb_next(jitterbuf *jb);
/* get jitterbuf info: only "statistics" may be valid */
extern int jb_getinfo(jitterbuf *jb, jb_info *stats);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论