[asterisk-commits] dvossel: branch dvossel/jb_ftw r312021 - /team/dvossel/jb_ftw/funcs/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 31 15:03:39 CDT 2011


Author: dvossel
Date: Thu Mar 31 15:03:35 2011
New Revision: 312021

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=312021
Log:
Added ability for interpolated frame creation and timing interval change depending on frame intervals

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=312021&r1=312020&r2=312021
==============================================================================
--- team/dvossel/jb_ftw/funcs/func_jitterbuffer.c (original)
+++ team/dvossel/jb_ftw/funcs/func_jitterbuffer.c Thu Mar 31 15:03:35 2011
@@ -36,15 +36,18 @@
 #include "asterisk/abstract_jb.h"
 #include "asterisk/timing.h"
 
+#define DEFAULT_TIMER_INTERVAL 20
+
 struct jb_framedata {
 	const struct ast_jb_impl *jb_impl;
 	struct ast_jb_conf jb_conf;
-	void *jb_obj;
+	struct timeval start_tv;
+	struct ast_format last_format;
 	struct ast_timer *timer;
-	int timer_rate;
+	int timer_interval; /* ms between deliveries */
 	int timer_fd;
 	int first;
-	struct timeval start_tv;
+	void *jb_obj;
 };
 
 static void jb_framedata_destroy(struct jb_framedata *framedata)
@@ -75,7 +78,8 @@
 		return -1;
 	}
 	framedata->timer_fd = ast_timer_fd(framedata->timer);
-	ast_timer_set_rate(framedata->timer, 1000 / 20); //todohere move this to cb and check based on frame samples 
+	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
@@ -133,16 +137,22 @@
 
 	if (frame->frametype == AST_FRAME_VOICE) {
 		int res;
-		long next;
 		struct ast_frame *jbframe = ast_frisolate(frame);
+		ast_format_copy(&framedata->last_format, &frame->subclass.format);
+
+		if (frame->len && (frame->len != framedata->timer_interval)) {
+			framedata->timer_interval = frame->len;
+			ast_timer_set_rate(framedata->timer, 1000 / framedata->timer_interval);
+		}
 		if (!framedata->first) {
 			framedata->first = 1;
 			res = framedata->jb_impl->put_first(framedata->jb_obj, jbframe, now);
 		} else {
 			res = framedata->jb_impl->put(framedata->jb_obj, jbframe, now);
 		}
-		next = framedata->jb_impl->next(framedata->jb_obj);
-		frame = &ast_null_frame;
+		if (res == AST_JB_IMPL_OK) {
+			frame = &ast_null_frame;
+		}
 	}
 
 	if (frame->frametype == AST_FRAME_NULL) {
@@ -152,17 +162,28 @@
 		if (now < next) {
 			return frame;
 		}
-		res = framedata->jb_impl->get(framedata->jb_obj, &frame, now, 20);
+		res = framedata->jb_impl->get(framedata->jb_obj, &frame, now, framedata->timer_interval);
 		switch (res) {
 		case AST_JB_IMPL_OK:
+			/* got it, and pass it through */
 			break;
 		case AST_JB_IMPL_DROP:
 			ast_frfree(frame);
 			frame = &ast_null_frame;
 			break;
 		case AST_JB_IMPL_INTERP:
-			//todohere learn to handle dropped frames.
-			/* fall through */
+			if (framedata->last_format.id) {
+				struct ast_frame tmp = { 0, };
+				tmp.frametype = AST_FRAME_VOICE;
+				ast_format_copy(&tmp.subclass.format, &framedata->last_format);
+				/* example: 8000hz / (1000 / 20ms) = 160 samples */
+				tmp.samples = ast_format_rate(&framedata->last_format) / (1000 / framedata->timer_interval);
+				tmp.delivery = ast_tvadd(framedata->start_tv, ast_samp2tv(next, 1000));
+				tmp.offset = AST_FRIENDLY_OFFSET;
+				tmp.src  = "func_jitterbuffer interpolation";
+				frame = ast_frdup(&tmp);
+				break;
+		}
 		case AST_JB_IMPL_NOFRAME:
 			frame = &ast_null_frame;
 			break;




More information about the asterisk-commits mailing list