[asterisk-commits] dvossel: branch dvossel/awesomehooks r287305 - in /team/dvossel/awesomehooks:...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 17 08:07:39 CDT 2010


Author: dvossel
Date: Fri Sep 17 08:07:35 2010
New Revision: 287305

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=287305
Log:
awesome update.  includes more updates to func_awesome_trace

Modified:
    team/dvossel/awesomehooks/funcs/func_awesome_trace.c
    team/dvossel/awesomehooks/main/awesomehook.c

Modified: team/dvossel/awesomehooks/funcs/func_awesome_trace.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/funcs/func_awesome_trace.c?view=diff&rev=287305&r1=287304&r2=287305
==============================================================================
--- team/dvossel/awesomehooks/funcs/func_awesome_trace.c (original)
+++ team/dvossel/awesomehooks/funcs/func_awesome_trace.c Fri Sep 17 08:07:35 2010
@@ -34,6 +34,8 @@
 #include "asterisk/pbx.h"
 #include "asterisk/awesomehook.h"
 
+static void print_frame(struct ast_frame *frame);
+
 static struct ast_frame *awesome_trace_event_cb(struct ast_channel *chan, struct ast_frame *frame, enum ast_awesomehook_event event, void *datastore)
 {
 	if (!frame) {
@@ -45,7 +47,20 @@
 	}
 
 	ast_verbose("%s on Channel %s\n", event == AST_AWESOMEHOOK_EVENT_READ ? "<--Read" : "--> Write", chan->name);
-
+	print_frame(frame);
+	return frame;
+}
+
+static int awesome_trace_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)
+{
+	ast_channel_lock(chan);
+	ast_awesomehook_attach(chan, awesome_trace_event_cb, NULL, NULL);
+	ast_channel_unlock(chan);
+
+	return 0;
+}
+
+static void print_frame(struct ast_frame *frame) {
 	switch (frame->frametype) {
 	case AST_FRAME_DTMF_END:
 		ast_verbose("FrameType: DTMF END\n");
@@ -59,6 +74,10 @@
 		break;
 	case AST_FRAME_VIDEO:
 		ast_verbose("FrameType: VIDEO\n");
+		ast_verbose("Codec: %s\n", ast_getformatname(frame->subclass.codec));
+		ast_verbose("MS: %ld\n", frame->len);
+		ast_verbose("Samples: %d\n", frame->samples);
+		ast_verbose("Bytes: %d\n", frame->datalen);
 		break;
 	case AST_FRAME_CONTROL:
 		ast_verbose("FrameType: CONTROL\n");
@@ -180,19 +199,9 @@
 	}
 
 	ast_verbose("Src: %s\n", ast_strlen_zero(frame->src) ? "NOT PRESENT" : frame->src);
-
 	ast_verbose("\n");
-	return frame;
-}
-
-static int awesome_trace_helper(struct ast_channel *chan, const char *cmd, char *data, const char *value)
-{
-	ast_channel_lock(chan);
-	ast_awesomehook_attach(chan, awesome_trace_event_cb, NULL, NULL);
-	ast_channel_unlock(chan);
-
-	return 0;
-}
+}
+
 
 static struct ast_custom_function awesome_trace_function = {
 	.name = "AWESOME_TRACE",

Modified: team/dvossel/awesomehooks/main/awesomehook.c
URL: http://svnview.digium.com/svn/asterisk/team/dvossel/awesomehooks/main/awesomehook.c?view=diff&rev=287305&r1=287304&r2=287305
==============================================================================
--- team/dvossel/awesomehooks/main/awesomehook.c (original)
+++ team/dvossel/awesomehooks/main/awesomehook.c Fri Sep 17 08:07:35 2010
@@ -39,6 +39,8 @@
 	struct ast_channel *chan;
 	/*! the id representing this awesomehook on a channel */
 	unsigned int id;
+	/* when set, this signals the read and write function to detach the hook */
+	int detach_and_destroy_me;
 	/*! Pointer to the registered event callback function. */
 	ast_awesomehook_event_callback event_cb;
 	/*! Pointer to the registered destruction callback function. */
@@ -67,9 +69,16 @@
 static struct ast_frame *awesomehook_list_push_event(struct ast_awesomehook_list *awesomehooks, struct ast_frame *frame, enum ast_awesomehook_event event)
 {
 	struct ast_awesomehook *awesomehook;
-	AST_LIST_TRAVERSE(&awesomehooks->list, awesomehook, list) {
-		frame = awesomehook->event_cb(awesomehook->chan, frame, event, awesomehook->datastore);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&awesomehooks->list, awesomehook, list) {
+		if (awesomehook->detach_and_destroy_me) {
+			/* this guy is signaled for destruction */
+			AST_LIST_REMOVE_CURRENT(list);
+			awesomehook_detach_and_destroy(awesomehook);
+		} else {
+			frame = awesomehook->event_cb(awesomehook->chan, frame, event, awesomehook->datastore);
+		}
 	}
+	AST_LIST_TRAVERSE_SAFE_END;
 	return frame;
 }
 
@@ -107,8 +116,11 @@
 
 	AST_LIST_TRAVERSE_SAFE_BEGIN(&chan->awesomehooks.list, awesomehook, list) {
 		if (awesomehook->id == id) {
-			AST_LIST_REMOVE_CURRENT(list);
-			awesomehook_detach_and_destroy(awesomehook);
+			/* we mark for detachment rather than doing explicitly here because
+			 * it needs to be safe for this function to be called within the
+			 * event callback.  If we allowed the hook to actually be destroyed
+			 * immediately here, the event callback would crash on exit. */
+			awesomehook->detach_and_destroy_me = 1;
 			res = 0;
 			break;
 		}




More information about the asterisk-commits mailing list