[asterisk-commits] russell: branch russell/jack r93149 - /team/russell/jack/apps/app_jack.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Dec 14 23:29:00 CST 2007


Author: russell
Date: Fri Dec 14 23:28:59 2007
New Revision: 93149

URL: http://svn.digium.com/view/asterisk?view=rev&rev=93149
Log:
Let the channel thread go to sleep while the jack client is running.  Wake
the channel thread back up after the jack client stops running.

Modified:
    team/russell/jack/apps/app_jack.c

Modified: team/russell/jack/apps/app_jack.c
URL: http://svn.digium.com/view/asterisk/team/russell/jack/apps/app_jack.c?view=diff&rev=93149&r1=93148&r2=93149
==============================================================================
--- team/russell/jack/apps/app_jack.c (original)
+++ team/russell/jack/apps/app_jack.c Fri Dec 14 23:28:59 2007
@@ -44,6 +44,7 @@
 #include "asterisk/module.h"
 #include "asterisk/channel.h"
 #include "asterisk/strings.h"
+#include "asterisk/lock.h"
 
 #include "libresample.h"
 
@@ -58,6 +59,9 @@
 	jack_client_t *client;
 	jack_port_t *input_port;
 	jack_port_t *output_port;
+	ast_mutex_t lock;
+	ast_cond_t cond;
+	unsigned int stop:1;
 };
 
 static const struct {
@@ -73,7 +77,7 @@
 	{ JackNoSuchClient,   "No Such Client" },
 	{ JackLoadFailure,    "Load Failure" },
 	{ JackInitFailure,    "Init Failure" },
-	{ JackShmFailure, "Shared Memory Access Failure" },
+	{ JackShmFailure,     "Shared Memory Access Failure" },
 	{ JackVersionError,   "Version Mismatch" },
 };
 
@@ -122,8 +126,10 @@
 {
 	struct jack_data *jack_data = arg;
 
-	(void)(jack_data);
-	/* XXX */
+	ast_mutex_lock(&jack_data->lock);
+	jack_data->stop = 1;
+	ast_cond_signal(&jack_data->cond);
+	ast_mutex_unlock(&jack_data->lock);
 }
 
 static int init_jack_data(struct ast_channel *chan, struct jack_data *jack_data)
@@ -134,6 +140,9 @@
 	ast_channel_lock(chan);
 	chan_name = ast_strdupa(chan->name);
 	ast_channel_unlock(chan);
+
+	ast_mutex_init(&jack_data->lock);
+	ast_cond_init(&jack_data->cond, NULL);
 
 	jack_data->client = jack_client_open(chan_name, 0, &status);
 
@@ -163,11 +172,6 @@
 		return -1;
 	}
 
-	if (jack_activate(jack_data->client)) {
-		ast_log(LOG_ERROR, "Failed to start the jack client\n");
-		return -1;
-	}
-
 	/* XXX */
 
 	return 0;
@@ -181,6 +185,9 @@
 		jack_client_close(jack_data->client);
 		jack_data->client = NULL;
 	}
+
+	ast_mutex_destroy(&jack_data->lock);
+	ast_cond_destroy(&jack_data->cond);
 }
 
 static int jack_exec(struct ast_channel *chan, void *data)
@@ -193,7 +200,17 @@
 		return -1;
 	}
 
-	/* XXX */
+	ast_mutex_lock(&jack_data.lock);
+
+	if (jack_activate(jack_data.client)) {
+		ast_log(LOG_ERROR, "Failed to start the jack client\n");
+		return -1;
+	}
+
+	while (!jack_data.stop)
+		ast_cond_wait(&jack_data.cond, &jack_data.lock);
+
+	ast_mutex_unlock(&jack_data.lock);
 
 	destroy_jack_data(&jack_data);
 




More information about the asterisk-commits mailing list