[asterisk-commits] russell: branch russell/res_monkeys r81293 - /team/russell/res_monkeys/funcs/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 28 16:55:21 CDT 2007
Author: russell
Date: Tue Aug 28 16:55:21 2007
New Revision: 81293
URL: http://svn.digium.com/view/asterisk?view=rev&rev=81293
Log:
Parse the args to START_ANNOUNCE, and work out the timing logic in the
channel attached thread for when the file should be played to the channel
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=81293&r1=81292&r2=81293
==============================================================================
--- team/russell/res_monkeys/funcs/func_announce.c (original)
+++ team/russell/res_monkeys/funcs/func_announce.c Tue Aug 28 16:55:21 2007
@@ -37,9 +37,13 @@
#include "asterisk/utils.h"
#include "asterisk/linkedlists.h"
#include "asterisk/audiohook.h"
+#include "asterisk/app.h"
struct announce_data {
+ const char *file;
struct timeval begin;
+ unsigned int begin_offset;
+ unsigned int repeat_interval;
int id;
};
@@ -47,21 +51,42 @@
{
struct announce_data *announce = data;
+ ast_free((void *) announce->file);
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;
}
- ast_cond_wait(&thread_args->cond, &thread_args->lock);
+ 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);
}
@@ -71,12 +96,41 @@
static int start_announce_read(struct ast_channel *chan, const char *cmd,
char *data, char *buf, size_t len)
{
- struct announce_data *announce;
+ struct announce_data *announce = NULL;
+ AST_DECLARE_APP_ARGS(args,
+ AST_APP_ARG(file);
+ AST_APP_ARG(begin_offset);
+ AST_APP_ARG(repeat_interval);
+ );
+
+ AST_STANDARD_APP_ARGS(args, data);
+
+ if (ast_strlen_zero(args.file)) {
+ ast_log(LOG_ERROR, "START_ANNOUNCE requires a filename.\n");
+ goto return_error;
+ }
if (!(announce = ast_calloc(1, sizeof(*announce))))
- return -1;
+ goto return_error;
+
+ if (!(announce->file = ast_strdup(args.file)))
+ goto return_error;
announce->begin = ast_tvnow();
+ if (!ast_strlen_zero(args.begin_offset)) {
+ if (sscanf(args.begin_offset, "%u", &announce->begin_offset) != 1) {
+ ast_log(LOG_ERROR, "'%s' is not a valid value for the begin offset\n",
+ args.begin_offset);
+ goto return_error;
+ }
+ }
+ if (!ast_strlen_zero(args.repeat_interval)) {
+ if (sscanf(args.repeat_interval, "%u", &announce->repeat_interval) != 1) {
+ ast_log(LOG_ERROR, "'%s' is not a valid value for the repeat interval\n",
+ args.begin_offset);
+ goto return_error;
+ }
+ }
ast_chan_thread_create(chan, &announce->id, announce_thread,
announce, announce_data_destroy);
@@ -84,6 +138,14 @@
snprintf(buf, len, "%d", announce->id);
return 0;
+
+return_error:
+ if (announce) {
+ if (announce->file)
+ ast_free((void *) announce->file);
+ ast_free(announce);
+ }
+ return -1;
}
static int stop_announce_read(struct ast_channel *chan, const char *cmd,
@@ -114,7 +176,7 @@
static struct ast_custom_function start_announce_function = {
.name = "START_ANNOUNCE",
.synopsis = "Start a periodic announcement",
- .syntax = "START_ANNOUNCE(<file>,<begin_time>[,<repeat_interval>])",
+ .syntax = "START_ANNOUNCE(<file>[,begin_time[,repeat_interval]])",
.desc =
"Start playing a periodic announcement to the channel. The function\n"
"will return a unique identifier which can later be used to stop the\n"
More information about the asterisk-commits
mailing list