[asterisk-commits] branch group/rtpjitterbuffer r29691 - in
/team/group/rtpjitterbuffer: ./ incl...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue May 23 06:05:41 MST 2006
Author: russell
Date: Tue May 23 08:05:40 2006
New Revision: 29691
URL: http://svn.digium.com/view/asterisk?rev=29691&view=rev
Log:
little coding guidelines type changes - use enums instead of a list of defines,
make use of some more of the asterisk API, little formatting changes
Modified:
team/group/rtpjitterbuffer/abstract_jb.c
team/group/rtpjitterbuffer/include/asterisk/abstract_jb.h
Modified: team/group/rtpjitterbuffer/abstract_jb.c
URL: http://svn.digium.com/view/asterisk/team/group/rtpjitterbuffer/abstract_jb.c?rev=29691&r1=29690&r2=29691&view=diff
==============================================================================
--- team/group/rtpjitterbuffer/abstract_jb.c (original)
+++ team/group/rtpjitterbuffer/abstract_jb.c Tue May 23 08:05:40 2006
@@ -47,12 +47,12 @@
#include "scx_jitterbuf.h"
#include "jitterbuf.h"
-
-/* Internal jb flags */
-#define JB_USE (1 << 0)
-#define JB_TIMEBASE_INITIALIZED (1 << 1)
-#define JB_CREATED (1 << 2)
-
+/*! Internal jb flags */
+enum {
+ JB_USE = (1 << 0),
+ JB_TIMEBASE_INITIALIZED = (1 << 1),
+ JB_CREATED = (1 << 2)
+};
/* Hooks for the abstract jb implementation */
@@ -140,11 +140,13 @@
static int default_impl = 0;
-/* Abstract return codes */
-#define JB_IMPL_OK 0
-#define JB_IMPL_DROP 1
-#define JB_IMPL_INTERP 2
-#define JB_IMPL_NOFRAME 3
+/*! Abstract return codes */
+enum {
+ JB_IMPL_OK,
+ JB_IMPL_DROP,
+ JB_IMPL_INTERP,
+ JB_IMPL_NOFRAME
+};
/* Translations between impl and abstract return codes */
static int scx_to_abstract_code[] =
@@ -157,19 +159,20 @@
/*! \brief Macros for JB logs */
/*#define jb_verbose(...) ast_verbose(VERBOSE_PREFIX_3 " ***[JB LOG]*** " __VA_ARGS__)*/
-#define jb_verbose(...) if (1){\
+#define jb_verbose(...) do {\
char tmp[192];\
char msg[128];\
snprintf(msg, sizeof(msg), VERBOSE_PREFIX_3 "***[JB LOG]*** " __VA_ARGS__);\
- ast_verbose("%s\n", term_color(tmp, msg, COLOR_BRGREEN, 0, sizeof(tmp)));}
+ ast_verbose("%s\n", term_color(tmp, msg, COLOR_BRGREEN, 0, sizeof(tmp))); \
+} while (0);
/*! \brief Macros for the frame log files */
-#define jb_framelog(...) \
-if (jb->logfile) \
-{ \
- fprintf(jb->logfile, __VA_ARGS__); \
- fflush(jb->logfile); \
-} \
+#define jb_framelog(...) do { \
+ if (jb->logfile) { \
+ fprintf(jb->logfile, __VA_ARGS__); \
+ fflush(jb->logfile); \
+ } \
+} while (0)
/* Internal utility functions */
@@ -191,18 +194,17 @@
jb->impl = &avail_impl[default_impl];
- if (*jbconf->impl == '\0')
+ if (ast_strlen_zero(jbconf->impl))
return;
- for(i=0; i<avail_impl_count; i++) {
+ for (i = 0; i < avail_impl_count; i++) {
test_impl = &avail_impl[i];
- if (strcmp(jbconf->impl, test_impl->name) == 0) {
+ if (!strcmp(jbconf->impl, test_impl->name)) {
jb->impl = test_impl;
return;
}
}
}
-
void ast_jb_do_usecheck(struct ast_channel *c0, struct ast_channel *c1)
{
@@ -331,7 +333,7 @@
} else {
frr = ast_frisolate(f);
}
- if (frr == NULL) {
+ if (!frr) {
ast_log(LOG_ERROR, "Failed to isolate frame for the jitterbuffer on channel '%s'\n", chan->name);
return -1;
}
@@ -375,13 +377,11 @@
int c1_use_jb = ast_test_flag(jb1, JB_USE);
int c1_jb_is_created = ast_test_flag(jb1, JB_CREATED);
- if (c0_use_jb && c0_jb_is_created) {
+ if (c0_use_jb && c0_jb_is_created)
jb_get_and_deliver(c0);
- }
-
- if (c1_use_jb && c1_jb_is_created) {
+
+ if (c1_use_jb && c1_jb_is_created)
jb_get_and_deliver(c1);
- }
}
@@ -401,7 +401,7 @@
return;
}
- while(now >= jb->next) {
+ while (now >= jb->next) {
interpolation_len = ast_codec_interp_len(jb->last_format);
res = jbimpl->get(jbobj, &f, now, interpolation_len);
@@ -427,7 +427,7 @@
f->src = "JB interpolation";
f->data = NULL;
f->delivery = ast_tvadd(jb->timebase, ast_samp2tv(jb->next, 1000));
- f->offset=AST_FRIENDLY_OFFSET;
+ f->offset = AST_FRIENDLY_OFFSET;
/* deliver the interpolated frame */
ast_write(chan, f);
jb_framelog("\tJB_GET {now=%ld}: Interpolated frame with len=%d\n", now, interpolation_len);
@@ -462,7 +462,7 @@
int res;
jbobj = jb->jbobj = jbimpl->create(jbconf, jbconf->resync_threshold);
- if (jbobj == NULL) {
+ if (!jbobj) {
ast_log(LOG_WARNING, "Failed to create jitterbuffer on channel '%s'\n", chan->name);
return -1;
}
@@ -490,42 +490,39 @@
if (ast_test_flag(jbconf, AST_JB_LOG)) {
snprintf(name2, sizeof(name2), "%s", chan->name);
tmp = strchr(name2, '/');
- if (tmp != NULL) {
+ if (tmp)
*tmp = '#';
- }
+
bridged = ast_bridged_channel(chan);
- if (bridged == NULL) {
+ if (!bridged) {
/* We should always have bridged chan if a jitterbuffer is in use */
CRASH;
}
snprintf(name1, sizeof(name1), "%s", bridged->name);
tmp = strchr(name1, '/');
- if (tmp != NULL) {
+ if (tmp)
*tmp = '#';
- }
+
snprintf(logfile_pathname, sizeof(logfile_pathname),
"/tmp/ast_%s_jb_%s--%s.log", jbimpl->name, name1, name2);
jb->logfile = fopen(logfile_pathname, "w+b");
- if (jb->logfile == NULL) {
+ if (!jb->logfile)
ast_log(LOG_WARNING, "Failed to create frame log file with pathname '%s'\n", logfile_pathname);
- }
-
- if (res == JB_IMPL_OK) {
+
+ if (res == JB_IMPL_OK)
jb_framelog("JB_PUT_FIRST {now=%ld}: Queued frame with ts=%ld and len=%ld\n",
now, frr->ts, frr->len);
- } else {
+ else
jb_framelog("JB_PUT_FIRST {now=%ld}: Dropped frame with ts=%ld and len=%ld\n",
now, frr->ts, frr->len);
- }
}
jb_verbose("%s jitterbuffer created on channel %s", jbimpl->name, chan->name);
/* Free the frame if it has not been queued in the jb */
- if (res != JB_IMPL_OK) {
+ if (res != JB_IMPL_OK)
ast_frfree(frr);
- }
return 0;
}
@@ -538,14 +535,14 @@
void *jbobj = jb->jbobj;
struct ast_frame *f;
- if (jb->logfile != NULL) {
+ if (jb->logfile) {
fclose(jb->logfile);
jb->logfile = NULL;
}
if (ast_test_flag(jb, JB_CREATED)) {
/* Remove and free all frames still queued in jb */
- while(jbimpl->remove(jbobj, &f) == JB_IMPL_OK) {
+ while (jbimpl->remove(jbobj, &f) == JB_IMPL_OK) {
ast_frfree(f);
}
@@ -562,17 +559,13 @@
static long get_now(struct ast_jb *jb, struct timeval *tv)
{
struct timeval now;
-
- if (tv == NULL) {
+
+ if (tv) {
tv = &now;
gettimeofday(tv, NULL);
}
-
- return (long) ((tv->tv_sec - jb->timebase.tv_sec) * 1000) +
- (long) ((double) (tv->tv_usec - jb->timebase.tv_usec) / 1000.0);
-
- /* TODO: For asterisk complience, we should use: */
- /* return ast_tvdiff_ms(*tv, jb->timebase); */
+
+ return ast_tvdiff_ms(*tv, jb->timebase);
}
@@ -582,41 +575,26 @@
char *name;
int tmp;
- if (memcmp(AST_JB_CONF_PREFIX, varname, prefixlen) != 0) {
+ if (memcmp(AST_JB_CONF_PREFIX, varname, prefixlen))
return -1;
- }
name = varname + prefixlen;
- if (strcmp(name, AST_JB_CONF_ENABLE) == 0) {
- if (ast_true(value)) {
- conf->flags |= AST_JB_ENABLED;
- }
- }
- else if (strcmp(name, AST_JB_CONF_FORCE) == 0) {
- if (ast_true(value)) {
- conf->flags |= AST_JB_FORCED;
- }
- }
- else if (strcmp(name, AST_JB_CONF_MAX_SIZE) == 0) {
- if ((tmp = atoi(value)) > 0) {
+ if (!strcmp(name, AST_JB_CONF_ENABLE)) {
+ ast_set2_flag(conf, ast_true(value), AST_JB_ENABLED);
+ } else if (!strcmp(name, AST_JB_CONF_FORCE)) {
+ ast_set2_flag(conf, ast_true(value), AST_JB_FORCED);
+ } else if (!strcmp(name, AST_JB_CONF_MAX_SIZE)) {
+ if ((tmp = atoi(value)) > 0)
conf->max_size = tmp;
- }
- }
- else if (strcmp(name, AST_JB_CONF_RESYNCH_THRESHOLD) == 0) {
- if ((tmp = atoi(value)) > 0) {
+ } else if (!strcmp(name, AST_JB_CONF_RESYNCH_THRESHOLD)) {
+ if ((tmp = atoi(value)) > 0)
conf->resync_threshold = tmp;
- }
- }
- else if (strcmp(name, AST_JB_CONF_IMPL) == 0) {
- if (*value) {
+ } else if (!strcmp(name, AST_JB_CONF_IMPL)) {
+ if (!ast_strlen_zero(value))
snprintf(conf->impl, sizeof(conf->impl), "%s", value);
- }
- }
- else if (strcmp(name, AST_JB_CONF_LOG) == 0) {
- if (ast_true(value)) {
- conf->flags |= AST_JB_LOG;
- }
+ } else if (!strcmp(name, AST_JB_CONF_LOG)) {
+ ast_set2_flag(conf, ast_true(value), AST_JB_LOG);
} else {
return -1;
}
@@ -625,21 +603,15 @@
}
-void ast_jb_configure(struct ast_channel *chan, struct ast_jb_conf *conf)
-{
- struct ast_jb *jb = &chan->jb;
- struct ast_jb_conf *jbconf = &jb->conf;
-
- memcpy(jbconf, conf, sizeof(struct ast_jb_conf));
-}
-
-
-void ast_jb_get_config(struct ast_channel *chan, struct ast_jb_conf *conf)
-{
- struct ast_jb *jb = &chan->jb;
- struct ast_jb_conf *jbconf = &jb->conf;
-
- memcpy(conf, jbconf, sizeof(struct ast_jb_conf));
+void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf)
+{
+ memcpy(&chan->jb.conf, conf, sizeof(*conf));
+}
+
+
+void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf)
+{
+ memcpy(conf, &chan->jb.conf, sizeof(*conf));
}
@@ -739,7 +711,7 @@
jitterbuf *stevekjb;
stevekjb = jb_new();
- if (stevekjb != NULL) {
+ if (stevekjb) {
jbconf.max_jitterbuf = general_config->max_size;
jbconf.resync_threshold = general_config->resync_threshold;
jbconf.max_contig_interp = 10;
Modified: team/group/rtpjitterbuffer/include/asterisk/abstract_jb.h
URL: http://svn.digium.com/view/asterisk/team/group/rtpjitterbuffer/include/asterisk/abstract_jb.h?rev=29691&r1=29690&r2=29691&view=diff
==============================================================================
--- team/group/rtpjitterbuffer/include/asterisk/abstract_jb.h (original)
+++ team/group/rtpjitterbuffer/include/asterisk/abstract_jb.h Tue May 23 08:05:40 2006
@@ -198,7 +198,7 @@
* Called from a channel driver when a channel is created and its jitterbuffer needs
* to be configured.
*/
-void ast_jb_configure(struct ast_channel *chan, struct ast_jb_conf *conf);
+void ast_jb_configure(struct ast_channel *chan, const struct ast_jb_conf *conf);
/*!
@@ -206,7 +206,7 @@
* \param chan channel.
* \param conf destination.
*/
-void ast_jb_get_config(struct ast_channel *chan, struct ast_jb_conf *conf);
+void ast_jb_get_config(const struct ast_channel *chan, struct ast_jb_conf *conf);
#if defined(__cplusplus) || defined(c_plusplus)
More information about the asterisk-commits
mailing list