[svn-commits] russell: branch russell/res_monkeys r81325 - /team/russell/res_monkeys/funcs/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Aug 28 18:38:08 CDT 2007


Author: russell
Date: Tue Aug 28 18:38:08 2007
New Revision: 81325

URL: http://svn.digium.com/view/asterisk?view=rev&rev=81325
Log:
Check in progress toward moving this over to using a whisper callback instead
of a dedicated thread to feed in the announcement

Modified:
    team/russell/res_monkeys/funcs/func_announce.c

Modified: team/russell/res_monkeys/funcs/func_announce.c
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/funcs/func_announce.c?view=diff&rev=81325&r1=81324&r2=81325
==============================================================================
--- team/russell/res_monkeys/funcs/func_announce.c (original)
+++ team/russell/res_monkeys/funcs/func_announce.c Tue Aug 28 18:38:08 2007
@@ -39,12 +39,15 @@
 #include "asterisk/audiohook.h"
 #include "asterisk/app.h"
 
+static int unique_id;
+
 struct announce_data {
 	const char *file;
 	struct timeval begin;
 	unsigned int begin_offset;
 	unsigned int repeat_interval;
 	int id;
+	struct ast_audiohook audiohook;
 };
 
 static void announce_data_destroy(void *data)
@@ -55,48 +58,23 @@
 	ast_free(announce);
 }
 
-static void play_announcement(struct ast_chan_thread_args *thread_args)
-{
-	struct announce_data *announce = thread_args->data;
-
-	ast_log(LOG_DEBUG, "Should be playing '%s' to channel '%s'\n",
-		announce->file, thread_args->chan->name);
-}
-
-static void *announce_thread(void *data)
-{
-	struct ast_chan_thread_args *thread_args = data;
-	struct announce_data *announce = thread_args->data;
-	struct timeval next_playback;
-
-	next_playback = ast_tvadd(ast_tvnow(), ast_tv(announce->begin_offset, 0));
-
-	while (!thread_args->stop_thread) {
-		struct timespec ts = { 0, };
-
-		if (ast_tvdiff_ms(next_playback, ast_tvnow()) <= 0) {
-			next_playback = ast_tvadd(ast_tvnow(), ast_tv(announce->repeat_interval, 0));
-			play_announcement(thread_args);
-		}
-
-		ast_mutex_lock(&thread_args->lock);
-		if (thread_args->stop_thread) {
-			ast_mutex_unlock(&thread_args->lock);
-			break;
-		}
-		ts.tv_sec = next_playback.tv_sec;
-		ts.tv_nsec = next_playback.tv_usec * 1000;
-		ast_cond_timedwait(&thread_args->cond, &thread_args->lock, &ts);
-		ast_mutex_unlock(&thread_args->lock);
-	}
-
-	return announce;
+static const struct ast_datastore_info announce_datastore_info = {
+	.type = AST_MODULE,
+	.destroy = announce_data_destroy,
+};
+
+static int announce_whisper_callback(struct ast_audiohook *audiohook,
+	struct ast_channel *chan, unsigned int samples)
+{
+
+	return 0;
 }
 
 static int start_announce_read(struct ast_channel *chan, const char *cmd, 
 	char *data, char *buf, size_t len)
 {
 	struct announce_data *announce = NULL;
+	struct ast_datastore *datastore;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(file);
 		AST_APP_ARG(begin_offset);
@@ -132,10 +110,20 @@
 		}
 	}
 
-	ast_chan_thread_create(chan, &announce->id, announce_thread, 
-		announce, announce_data_destroy);
-
+	announce->id = ast_atomic_fetchadd_int(&unique_id, +1);
 	snprintf(buf, len, "%d", announce->id);
+
+	ast_audiohook_init(&announce->audiohook, AST_AUDIOHOOK_TYPE_WHISPER, AST_MODULE);
+	announce->audiohook.whisper_callback = announce_whisper_callback;
+	announce->audiohook.user_data = announce;
+
+	if (!(datastore = ast_channel_datastore_alloc(&announce_datastore_info, buf)))
+		goto return_error;
+
+	datastore->data = announce;
+	ast_channel_lock(chan);
+	ast_channel_datastore_add(chan, datastore);
+	ast_channel_unlock(chan);
 
 	return 0;
 
@@ -151,20 +139,25 @@
 static int stop_announce_read(struct ast_channel *chan, const char *cmd, 
 	char *data, char *buf, size_t len)
 {
+	struct ast_datastore *datastore;
 	struct announce_data *announce;
-	int id;
-
-	if (sscanf(data, "%d", &id) != 1) {
+	int id_sanity_check;
+
+	if (ast_strlen_zero(data) || sscanf(data, "%d", &id_sanity_check) != 1) {
 		ast_log(LOG_WARNING, "STOP_ANNOUNCE given invalid argument: '%s'\n", data);
 		return -1;
 	}
 
-	announce = ast_chan_thread_stop(chan, id);
-
-	if (!announce) {
-		ast_log(LOG_ERROR, "No Periodic announcement found for ID '%d'\n", id);
+	ast_channel_lock(chan);
+	if (!(datastore = ast_channel_datastore_find(chan, &announce_datastore_info, data))) {
+		ast_channel_unlock(chan);
+		ast_log(LOG_ERROR, "No Periodic announcement found for ID '%s'\n", data);
 		return -1;
 	}
+	announce = datastore->data;
+	ast_channel_datastore_remove(chan, datastore);
+	ast_channel_unlock(chan);
+	ast_channel_datastore_free(datastore);
 
 	snprintf(buf, len, "%d", ast_tvdiff_ms(ast_tvnow(), announce->begin));
 




More information about the svn-commits mailing list