summaryrefslogtreecommitdiff
path: root/main/jitterbuf.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2012-03-22 19:51:16 +0000
committerKinsey Moore <kmoore@digium.com>2012-03-22 19:51:16 +0000
commitc5b3db1956a3db2446b0310b3a7d59961fe3e089 (patch)
tree530b55034f5adfb0c7106ae1194679a031afc888 /main/jitterbuf.c
parent1d1c28ac4b09df2b663123e55239e411b8f5ad26 (diff)
Kill off red blobs in most of main/*
Everything still compiled after making these changes, so I assume these whitespace-only changes didn't break anything (and shouldn't have). git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@360190 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/jitterbuf.c')
-rw-r--r--main/jitterbuf.c164
1 files changed, 82 insertions, 82 deletions
diff --git a/main/jitterbuf.c b/main/jitterbuf.c
index a49d04e64..1ff261f47 100644
--- a/main/jitterbuf.c
+++ b/main/jitterbuf.c
@@ -50,24 +50,24 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
static jb_output_function_t warnf, errf, dbgf;
-void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
+void jb_setoutput(jb_output_function_t err, jb_output_function_t warn, jb_output_function_t dbg)
{
errf = err;
warnf = warn;
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;
@@ -76,14 +76,14 @@ void jb_reset(jitterbuf *jb)
/* initialize length, using the default value */
jb->info.current = jb->info.target = jb->info.conf.target_extra = JB_TARGET_EXTRA;
- jb->info.silence_begin_ts = -1;
+ jb->info.silence_begin_ts = -1;
}
-jitterbuf * jb_new()
+jitterbuf * jb_new()
{
jitterbuf *jb;
- if (!(jb = ast_malloc(sizeof(*jb))))
+ if (!(jb = ast_malloc(sizeof(*jb))))
return NULL;
jb_reset(jb);
@@ -92,9 +92,9 @@ jitterbuf * jb_new()
return jb;
}
-void jb_destroy(jitterbuf *jb)
+void jb_destroy(jitterbuf *jb)
{
- jb_frame *frame;
+ jb_frame *frame;
jb_dbg2("jb_destroy(%x)\n", jb);
/* free all the frames on the "free list" */
@@ -105,7 +105,7 @@ void jb_destroy(jitterbuf *jb)
frame = next;
}
- /* free ourselves! */
+ /* free ourselves! */
ast_free(jb);
}
@@ -170,13 +170,13 @@ static int history_put(jitterbuf *jb, long ts, long now, long ms, long delay)
/* optimization; the max/min buffers don't need to be recalculated, if this packet's
* entry doesn't change them. This happens if this packet is not involved, _and_ any packet
- * that got kicked out of the history is also not involved
+ * that got kicked out of the history is also not involved
* We do a number of comparisons, but it's probably still worthwhile, because it will usually
* succeed, and should be a lot faster than going through all 500 packets in history */
if (!jb->hist_maxbuf_valid)
return 0;
- /* don't do this until we've filled history
+ /* don't do this until we've filled history
* (reduces some edge cases below) */
if (jb->hist_ptr < JB_HISTORY_SZ)
goto invalidate;
@@ -190,13 +190,13 @@ static int history_put(jitterbuf *jb, long ts, long now, long ms, long delay)
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
+ /* if we got here, we don't need to invalidate, 'cause this delay didn't
* affect things */
return 0;
/* end optimization */
@@ -207,11 +207,11 @@ invalidate:
return 0;
}
-static void history_calc_maxbuf(jitterbuf *jb)
+static void history_calc_maxbuf(jitterbuf *jb)
{
int i,j;
- if (jb->hist_ptr == 0)
+ if (jb->hist_ptr == 0)
return;
@@ -229,7 +229,7 @@ static void history_calc_maxbuf(jitterbuf *jb)
/* we want it to be the top "n" values, in order */
/* start at the beginning, or JB_HISTORY_SZ frames ago */
- i = (jb->hist_ptr > JB_HISTORY_SZ) ? (jb->hist_ptr - JB_HISTORY_SZ) : 0;
+ 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];
@@ -268,14 +268,14 @@ static void history_calc_maxbuf(jitterbuf *jb)
}
}
- if (0) {
+ 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");
}
@@ -284,13 +284,13 @@ static void history_calc_maxbuf(jitterbuf *jb)
jb->hist_maxbuf_valid = 1;
}
-static void history_get(jitterbuf *jb)
+static void history_get(jitterbuf *jb)
{
long max, min, jitter;
int idx;
int count;
- if (!jb->hist_maxbuf_valid)
+ if (!jb->hist_maxbuf_valid)
history_calc_maxbuf(jb);
/* count is how many items in history we're examining */
@@ -300,7 +300,7 @@ static void history_get(jitterbuf *jb)
idx = count * JB_HISTORY_DROPPCT / 100;
/* sanity checks for idx */
- if (idx > (JB_HISTORY_MAXBUF_SZ - 1))
+ if (idx > (JB_HISTORY_MAXBUF_SZ - 1))
idx = JB_HISTORY_MAXBUF_SZ - 1;
if (idx < 0) {
@@ -326,7 +326,7 @@ 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, const enum jb_frame_type type, long ms, long ts)
+static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts)
{
jb_frame *frame;
jb_frame *p;
@@ -347,8 +347,8 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
frame->ms = ms;
frame->type = type;
- /*
- * frames are a circular list, jb-frames points to to the lowest ts,
+ /*
+ * frames are a circular list, jb-frames points to to the lowest ts,
* jb->frames->prev points to the highest ts
*/
@@ -369,13 +369,13 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
jb->frames = frame;
head = 1;
- } else {
+ } else {
p = jb->frames;
/* frame is out of order */
if (resync_ts < p->prev->ts) jb->info.frames_ooo++;
- while (resync_ts < p->prev->ts && p->prev != jb->frames)
+ while (resync_ts < p->prev->ts && p->prev != jb->frames)
p = p->prev;
frame->next = p;
@@ -387,23 +387,23 @@ static int queue_put(jitterbuf *jb, void *data, const enum jb_frame_type type, l
return head;
}
-static long queue_next(jitterbuf *jb)
+static long queue_next(jitterbuf *jb)
{
- if (jb->frames)
+ if (jb->frames)
return jb->frames->ts;
- else
+ else
return -1;
}
-static long queue_last(jitterbuf *jb)
+static long queue_last(jitterbuf *jb)
{
- if (jb->frames)
+ if (jb->frames)
return jb->frames->prev->ts;
- else
+ else
return -1;
}
-static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
+static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
{
jb_frame *frame;
frame = jb->frames;
@@ -430,52 +430,52 @@ static jb_frame *_queue_get(jitterbuf *jb, long ts, int all)
jb->info.frames_cur--;
- /* we return the frame pointer, even though it's on free list,
+ /* we return the frame pointer, even though it's on free list,
* but caller must copy data */
return frame;
- }
+ }
return NULL;
}
-static jb_frame *queue_get(jitterbuf *jb, long ts)
+static jb_frame *queue_get(jitterbuf *jb, long ts)
{
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);
}
#if 0
/* some diagnostics */
-static void jb_dbginfo(jitterbuf *jb)
+static void jb_dbginfo(jitterbuf *jb)
{
- if (dbgf == NULL)
+ 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_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.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)
+ 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_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_next(jb),
queue_last(jb),
- jb->info.next_voice_ts,
+ 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;
jb_frame *p = jb->frames;
@@ -486,14 +486,14 @@ static void jb_chkqueue(jitterbuf *jb)
do {
if (p->next == NULL) {
- jb_err("Queue is BROKEN at item [%d]", i);
+ jb_err("Queue is BROKEN at item [%d]", i);
}
i++;
p=p->next;
} while (p->next != jb->frames);
}
-static void jb_dbgqueue(jitterbuf *jb)
+static void jb_dbgqueue(jitterbuf *jb)
{
int i=0;
jb_frame *p = jb->frames;
@@ -514,7 +514,7 @@ static void jb_dbgqueue(jitterbuf *jb)
}
#endif
-enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now)
+enum jb_return_code jb_put(jitterbuf *jb, void *data, const enum jb_frame_type type, long ms, long ts, long now)
{
long delay = now - (ts - jb->info.resync_offset);
jb_dbg2("jb_put(%x,%x,%ld,%ld,%ld)\n", jb, data, ms, ts, now);
@@ -539,7 +539,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, long now, long interpl)
+static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
{
jb_frame *frame;
long diff;
@@ -554,7 +554,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
dbg_cnt++;
/* target */
- jb->info.target = jb->info.jitter + jb->info.min + jb->info.conf.target_extra;
+ jb->info.target = jb->info.jitter + jb->info.min + jb->info.conf.target_extra;
/* if a hard clamp was requested, use it */
if ((jb->info.conf.max_jitterbuf) && ((jb->info.target - jb->info.min) > jb->info.conf.max_jitterbuf)) {
@@ -568,11 +568,11 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long 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) {
+ if (!jb->info.silence_begin_ts) {
/* we want to grow */
- if ((diff > 0) &&
+ if ((diff > 0) &&
/* we haven't grown in the delay length */
- (((jb->info.last_adjustment + JB_ADJUST_DELAY) < now) ||
+ (((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)) ) ) {
/* grow by interp frame length */
@@ -608,7 +608,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
if (frame && frame->ts + jb->info.current < jb->info.next_voice_ts) {
if (frame->ts + jb->info.current > jb->info.next_voice_ts - jb->info.last_voice_ms) {
/* either we interpolated past this frame in the last jb_get */
- /* or the frame is still in order, but came a little too quick */
+ /* or the frame is still in order, but came a little too quick */
*frameout = *frame;
/* reset expectation for next frame */
jb->info.next_voice_ts = frame->ts + jb->info.current + frame->ms;
@@ -638,8 +638,8 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
/* 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) ||
+ 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;
@@ -672,16 +672,16 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
* otherwise, we presently get into a pattern where we return
* INTERP for the lost frame, then it shows up next, and we
* throw it away because it's late */
- /* I've recently only been able to replicate this using
+ /* I've recently only been able to replicate this using
* iaxclient talking to app_echo on asterisk. In this case,
* my outgoing packets go through asterisk's (old)
- * jitterbuffer, and then might get an unusual increasing delay
+ * jitterbuffer, and then might get an unusual increasing delay
* there if it decides to grow?? */
/* Update: that might have been a different bug, that has been fixed..
* But, this still seemed like a good idea, except that it ended up making a single actual
* 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) {
+ /*if (diff > -1 * jb->info.last_voice_ms) {
jb->info.current += jb->info.last_voice_ms;
jb->info.last_adjustment = now;
jb_warn("g");
@@ -707,7 +707,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
decrement_losspct(jb);
jb_dbg("v");
return JB_OK;
- } else {
+ } else {
/* TODO: after we get the non-silent case down, we'll make the
* silent case -- basically, we'll just grow and shrink faster
* here, plus handle next_voice_ts a bit differently */
@@ -715,12 +715,12 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
/* to disable silent special case altogether, just uncomment this: */
/* 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) {
- jb->info.current -= interpl;
- jb->info.last_adjustment = now;
- }
+ /* shrink interpl len every 10ms during silence */
+ if (diff < -jb->info.conf.target_extra &&
+ jb->info.last_adjustment + 10 <= now) {
+ jb->info.current -= interpl;
+ jb->info.last_adjustment = now;
+ }
frame = queue_get(jb, now - jb->info.current);
if (!frame) {
@@ -756,7 +756,7 @@ static enum jb_return_code _jb_get(jitterbuf *jb, jb_frame *frameout, long now,
}
}
-long jb_next(jitterbuf *jb)
+long jb_next(jitterbuf *jb)
{
if (jb->info.silence_begin_ts) {
if (jb->frames) {
@@ -767,14 +767,14 @@ long jb_next(jitterbuf *jb)
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, long now, long interpl)
+enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, long now, long interpl)
{
enum jb_return_code ret = _jb_get(jb, frameout, now, interpl);
#if 0
@@ -784,13 +784,13 @@ enum jb_return_code jb_get(jitterbuf *jb, jb_frame *frameout, long now, long int
if (thists && thists < lastts) jb_warn("XXXX timestamp roll-back!!!\n");
lastts = thists;
#endif
- if (ret == JB_INTERP)
+ if (ret == JB_INTERP)
frameout->ms = jb->info.last_voice_ms;
-
+
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);
@@ -804,7 +804,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);
@@ -814,12 +814,12 @@ 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 */
jb->info.conf.max_jitterbuf = conf->max_jitterbuf;
- jb->info.conf.resync_threshold = conf->resync_threshold;
+ jb->info.conf.resync_threshold = conf->resync_threshold;
jb->info.conf.max_contig_interp = conf->max_contig_interp;
/* -1 indicates use of the default JB_TARGET_EXTRA value */
@@ -827,7 +827,7 @@ enum jb_return_code jb_setconf(jitterbuf *jb, jb_conf *conf)
? JB_TARGET_EXTRA
: conf->target_extra
;
-
+
/* update these to match new target_extra setting */
jb->info.current = jb->info.conf.target_extra;
jb->info.target = jb->info.conf.target_extra;