[asterisk-commits] branch group/rtpjitterbuffer r26491 -
/team/group/rtpjitterbuffer/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed May 10 07:31:57 MST 2006
Author: russell
Date: Wed May 10 09:31:56 2006
New Revision: 26491
URL: http://svn.digium.com/view/asterisk?rev=26491&view=rev
Log:
clean up some coding guidelines issues, inline a couple of functions,
and make the assert statements only present of SCX_JB_DEBUG is defined,
since we do not use them in Asterisk
Modified:
team/group/rtpjitterbuffer/scx_jitterbuf.c
Modified: team/group/rtpjitterbuffer/scx_jitterbuf.c
URL: http://svn.digium.com/view/asterisk/team/group/rtpjitterbuffer/scx_jitterbuf.c?rev=26491&r1=26490&r2=26491&view=diff
==============================================================================
--- team/group/rtpjitterbuffer/scx_jitterbuf.c (original)
+++ team/group/rtpjitterbuffer/scx_jitterbuf.c Wed May 10 09:31:56 2006
@@ -38,6 +38,13 @@
#include "asterisk/utils.h"
#include "scx_jitterbuf.h"
+#undef SCX_JB_DEBUG
+
+#ifdef SCX_JB_DEBUG
+#define ASSERT(a)
+#else
+#define ASSERT(a) assert(a)
+#endif
/*! \brief private scx_jb structure */
struct scx_jb
@@ -57,17 +64,15 @@
static void get_jb_head(struct scx_jb *jb, struct scx_jb_frame *frame);
static int resynch_jb(struct scx_jb *jb, void *data, long ms, long ts, long now);
-static struct scx_jb_frame *alloc_jb_frame(struct scx_jb *jb)
-{
- return (struct scx_jb_frame *) ast_calloc(1, sizeof(struct scx_jb_frame));
-}
-
-
-static void release_jb_frame(struct scx_jb *jb, struct scx_jb_frame *frame)
+static inline struct scx_jb_frame *alloc_jb_frame(struct scx_jb *jb)
+{
+ return ast_calloc(1, sizeof(struct scx_jb_frame));
+}
+
+static inline void release_jb_frame(struct scx_jb *jb, struct scx_jb_frame *frame)
{
free(frame);
}
-
static void get_jb_head(struct scx_jb *jb, struct scx_jb_frame *frame)
{
@@ -76,7 +81,7 @@
/* unlink the frame */
fr = jb->frames;
jb->frames = fr->next;
- if(jb->frames != NULL) {
+ if (jb->frames) {
jb->frames->prev = NULL;
} else {
/* the jb is empty - update tail */
@@ -98,10 +103,8 @@
{
struct scx_jb *jb;
- jb = ast_calloc(1, sizeof(struct scx_jb));
- if(jb == NULL) {
+ if (!(jb = ast_calloc(1, sizeof(*jb))))
return NULL;
- }
/* First copy our config */
memcpy(&jb->conf, conf, sizeof(struct scx_jb_conf));
@@ -110,10 +113,10 @@
conf = &jb->conf;
/* validate the configuration */
- if(conf->jbsize < 1)
+ if (conf->jbsize < 1)
conf->jbsize = SCX_JB_SIZE_DEFAULT;
- if(conf->resync_threshold < 1)
+ if (conf->resync_threshold < 1)
conf->resync_threshold = SCX_JB_RESYNCH_THRESHOLD_DEFAULT;
/* Set the constant delay to the jitterbuf */
@@ -126,7 +129,7 @@
void scx_jb_destroy(struct scx_jb *jb)
{
/* jitterbuf MUST be empty before it can be destroyed */
- assert(jb->frames == NULL);
+ ASSERT(jb->frames == NULL);
free(jb);
}
@@ -138,9 +141,9 @@
struct scx_jb_frame *frame;
/* If jb is empty, just reinitialize the jb */
- if(jb->frames == NULL) {
+ if (!jb->frames) {
/* debug check: tail should also be NULL */
- assert(jb->tail == NULL);
+ ASSERT(jb->tail == NULL);
return scx_jb_put_first(jb, data, ms, ts, now);
}
@@ -156,7 +159,7 @@
offset = diff - jb->tail->ms;
/* Do we really need to resynch, or this is just a frame for dropping? */
- if(!jb->force_resynch && (offset < jb->conf.resync_threshold && offset > -jb->conf.resync_threshold))
+ if (!jb->force_resynch && (offset < jb->conf.resync_threshold && offset > -jb->conf.resync_threshold))
return SCX_JB_DROP;
/* Reset the force resynch flag */
@@ -165,7 +168,7 @@
/* apply the offset to the jb state */
jb->rxcore -= offset;
frame = jb->frames;
- while(frame) {
+ while (frame) {
frame->ts += offset;
frame = frame->next;
}
@@ -200,16 +203,16 @@
long delivery;
/* debug check the validity of the input params */
- assert(data != NULL);
+ ASSERT(data != NULL);
/* do not allow frames shorter than 2 ms */
- assert(ms >= 2);
- assert(ts >= 0);
- assert(now >= 0);
+ ASSERT(ms >= 2);
+ ASSERT(ts >= 0);
+ ASSERT(now >= 0);
delivery = jb->rxcore + jb->delay + ts;
/* check if the new frame is not too late */
- if(delivery < jb->next_delivery) {
+ if (delivery < jb->next_delivery) {
/* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
the force resynch flag was not set. */
return resynch_jb(jb, data, ms, ts, now);
@@ -217,7 +220,7 @@
/* what if the delivery time is bigger than next + delay? Seems like a frame for the future.
However, allow more resync_threshold ms in advance */
- if(delivery > jb->next_delivery + jb->delay + jb->conf.resync_threshold) {
+ if (delivery > jb->next_delivery + jb->delay + jb->conf.resync_threshold) {
/* should drop the frame, but let first resynch_jb() check if this is not a jump in ts, or
the force resynch flag was not set. */
return resynch_jb(jb, data, ms, ts, now);
@@ -225,12 +228,12 @@
/* find the right place in the frames list, sorted by delivery time */
frame = jb->tail;
- while(frame != NULL && frame->delivery > delivery) {
+ while (frame && frame->delivery > delivery) {
frame = frame->prev;
}
/* Check if the new delivery time is not covered already by the chosen frame */
- if(frame && (frame->delivery == delivery ||
+ if (frame && (frame->delivery == delivery ||
delivery < frame->delivery + frame->ms ||
(frame->next && delivery + ms > frame->next->delivery)))
{
@@ -253,10 +256,10 @@
newframe->delivery = delivery;
/* and insert it right on place */
- if(frame != NULL) {
+ if (frame) {
next = frame->next;
frame->next = newframe;
- if(next != NULL) {
+ if (next) {
newframe->next = next;
next->prev = newframe;
} else {
@@ -267,10 +270,10 @@
newframe->prev = frame;
return SCX_JB_OK;
- } else if(jb->frames == NULL) {
+ } else if (!jb->frames) {
/* the frame list is empty or thats just the first frame ever */
/* tail should also be NULL is that case */
- assert(jb->tail == NULL);
+ ASSERT(jb->tail == NULL);
jb->frames = jb->tail = newframe;
newframe->next = NULL;
newframe->prev = NULL;
@@ -290,16 +293,16 @@
int scx_jb_get(struct scx_jb *jb, struct scx_jb_frame *frame, long now, long interpl)
{
- assert(now >= 0);
- assert(interpl >= 2);
-
- if(now < jb->next_delivery) {
+ ASSERT(now >= 0);
+ ASSERT(interpl >= 2);
+
+ if (now < jb->next_delivery) {
/* too early for the next frame */
return SCX_JB_NOFRAME;
}
/* Is the jb empty? */
- if(jb->frames == NULL) {
+ if (!jb->frames) {
/* should interpolate a frame */
/* update next */
jb->next_delivery += interpl;
@@ -308,7 +311,7 @@
}
/* Isn't it too late for the first frame available in the jb? */
- if(now > jb->frames->delivery + jb->frames->ms) {
+ if (now > jb->frames->delivery + jb->frames->ms) {
/* yes - should drop this frame and update next to point the next frame (get_jb_head() does it) */
get_jb_head(jb, frame);
@@ -316,7 +319,7 @@
}
/* isn't it too early to play the first frame available? */
- if(now < jb->frames->delivery) {
+ if (now < jb->frames->delivery) {
/* yes - should interpolate one frame */
/* update next */
jb->next_delivery += interpl;
@@ -339,13 +342,10 @@
int scx_jb_remove(struct scx_jb *jb, struct scx_jb_frame *frameout)
{
- if(jb->frames == NULL)
+ if (!jb->frames)
return SCX_JB_NOFRAME;
get_jb_head(jb, frameout);
return SCX_JB_OK;
}
-
-
-
More information about the asterisk-commits
mailing list