[svn-commits] dvossel: branch dvossel/jb_ftw r312068 - /team/dvossel/jb_ftw/funcs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Mar 31 16:48:14 CDT 2011


Author: dvossel
Date: Thu Mar 31 16:48:09 2011
New Revision: 312068

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=312068
Log:
Documentation and argument parsing

Modified:
    team/dvossel/jb_ftw/funcs/func_jitterbuffer.c

Modified: team/dvossel/jb_ftw/funcs/func_jitterbuffer.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/jb_ftw/funcs/func_jitterbuffer.c?view=diff&rev=312068&r1=312067&r2=312068
==============================================================================
--- team/dvossel/jb_ftw/funcs/func_jitterbuffer.c (original)
+++ team/dvossel/jb_ftw/funcs/func_jitterbuffer.c Thu Mar 31 16:48:09 2011
@@ -35,8 +35,46 @@
 #include "asterisk/pbx.h"
 #include "asterisk/abstract_jb.h"
 #include "asterisk/timing.h"
+#include "asterisk/app.h"
+
+/*** DOCUMENTATION
+	<function name="JITTERBUFFER" language="en_US">
+		<synopsis>
+			Add a Jitterbuffer to the Read side of the channel.  This dejitters the audio stream before it reaches the Asterisk core. This is a write only function.
+		</synopsis>
+		<syntax>
+			<parameter name="jitterbuffer type" required="true">
+				<para>Jitterbuffer type can be either <literal>fixed</literal> or <literal>adaptive</literal>.</para>
+				<para>Used as follows. </para>
+				<para>Set(JITTERBUFFER(type)=max_size[,resync_threshold[,target_extra]])</para>
+				<para>Set(JITTERBUFFER(type)=default) </para>
+			</parameter>
+		</syntax>
+		<description>
+			<para>max_size: Defaults to 200 ms</para>
+			<para>Length in milliseconds of buffer.</para>
+			<para> </para>
+			<para>resync_threshold: Defaults to 1000ms </para>
+			<para>The length in milliseconds over which a timestamp difference will result in resyncing the jitterbuffer. </para>
+			<para> </para>
+			<para>target_extra: Defaults to 40ms</para>
+			<para>This option only affects the adaptive jitterbuffer. It represents the amount time in milliseconds by which the new jitter buffer will pad its size.</para>
+			<para> </para>
+			<para>Examples:</para>
+			<para>exten => 1,1,Set(JITTERBUFFER(fixed)=default);Fixed with defaults. </para>
+			<para>exten => 1,1,Set(JITTERBUFFER(fixed)=200);Fixed with max size 200ms, default resync threshold and target extra. </para>
+			<para>exten => 1,1,Set(JITTERBUFFER(fixed)=200,1500);Fixed with max size 200ms resync threshold 1500. </para>
+			<para>exten => 1,1,Set(JITTERBUFFER(adaptive)=default);Adaptive with defaults. </para>
+			<para>exten => 1,1,Set(JITTERBUFFER(adaptive)=200,,60);Adaptive with max size 200ms, default resync threshold and 40ms target extra. </para>
+		</description>
+	</function>
+ ***/
 
 #define DEFAULT_TIMER_INTERVAL 20
+#define DEFAULT_SIZE  200
+#define DEFAULT_TARGET_EXTRA  40
+#define DEFAULT_RESYNC  1000
+#define DEFAULT_TYPE AST_JB_FIXED
 
 struct jb_framedata {
 	const struct ast_jb_impl *jb_impl;
@@ -66,30 +104,81 @@
 	}
 	ast_free(framedata);
 }
-static int jb_framedata_init(struct jb_framedata *framedata)
-{
-//todohere eventually this should take a custom jb config, for testing this is all hardcoded at the moment.
+
+static void jb_conf_default(struct ast_jb_conf *conf)
+{
+	conf->max_size = DEFAULT_SIZE;
+	conf->resync_threshold = DEFAULT_RESYNC;
+	ast_copy_string(conf->impl, "fixed", sizeof(conf->impl));
+	conf->target_extra = DEFAULT_TARGET_EXTRA;
+}
+
+/* set defaults */
+static int jb_framedata_init(struct jb_framedata *framedata, const char *data, const char *value)
+{
+	int jb_impl_type = DEFAULT_TYPE;
+
+	/* Initialize defaults */
 	framedata->timer_fd = -1;
-	if (!(framedata->jb_impl = ast_jb_get_impl(AST_JB_ADAPTIVE))) {
+	jb_conf_default(&framedata->jb_conf);
+	if (!(framedata->jb_impl = ast_jb_get_impl(jb_impl_type))) {
 		return -1;
 	}
-
 	if (!(framedata->timer = ast_timer_open())) {
 		return -1;
 	}
 	framedata->timer_fd = ast_timer_fd(framedata->timer);
 	framedata->timer_interval = DEFAULT_TIMER_INTERVAL;
 	ast_timer_set_rate(framedata->timer, 1000 / framedata->timer_interval);
-
 	framedata->start_tv = ast_tvnow();
-//todohere setup fake conf
-	framedata->jb_conf.max_size = 1000;
-	framedata->jb_conf.resync_threshold = 4000;
-	ast_copy_string(framedata->jb_conf.impl, "adaptive", sizeof(framedata->jb_conf.impl));
-	framedata->jb_conf.target_extra = 2000;
-
-	framedata->jb_obj = framedata->jb_impl->create(&framedata->jb_conf, 4000);
-
+
+
+
+	/* Now check user options to see if any of the defaults need to change. */
+	if (!ast_strlen_zero(data)) {
+		if (!strcasecmp(data, "fixed")) {
+			jb_impl_type = AST_JB_FIXED;
+		} else if (!strcasecmp(data, "adaptive")) {
+			jb_impl_type = AST_JB_ADAPTIVE;
+		} else {
+			ast_log(LOG_WARNING, "Unknown Jitterbuffer type %s. Failed to create jitterbuffer.\n", data);
+			return -1;
+		}
+		ast_copy_string(framedata->jb_conf.impl, data, sizeof(framedata->jb_conf.impl));
+	}
+
+	if (!ast_strlen_zero(value) && strcasecmp(value, "default")) {
+		char *parse = ast_strdupa(value);
+		int res = 0;
+		AST_DECLARE_APP_ARGS(args,
+			AST_APP_ARG(max_size);
+			AST_APP_ARG(resync_threshold);
+			AST_APP_ARG(target_extra);
+		);
+
+		AST_STANDARD_APP_ARGS(args, parse);
+		if (!ast_strlen_zero(args.max_size)) {
+			res |= ast_jb_read_conf(&framedata->jb_conf,
+				"jbmaxsize",
+				args.max_size);
+		}
+		if (!ast_strlen_zero(args.resync_threshold)) {
+			res |= ast_jb_read_conf(&framedata->jb_conf,
+				"jbresyncthreshold",
+				args.resync_threshold);
+		}
+		if (!ast_strlen_zero(args.target_extra)) {
+			res |= ast_jb_read_conf(&framedata->jb_conf,
+				"jbtargetextra",
+				args.target_extra);
+		}
+		if (res) {
+			ast_log(LOG_WARNING, "Invalid jitterbuffer parameters %s\n", value);
+		}
+	}
+
+	/* now that all the user parsing is done and nothing will change, create the jb obj */
+	framedata->jb_obj = framedata->jb_impl->create(&framedata->jb_conf, framedata->jb_conf.resync_threshold);
 	return 0;
 }
 
@@ -208,7 +297,7 @@
 		return 0;
 	}
 
-	if (jb_framedata_init(framedata)) {
+	if (jb_framedata_init(framedata, data, value)) {
 		jb_framedata_destroy(framedata);
 		return 0;
 	}




More information about the svn-commits mailing list