2004-05-26 18:38:10 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
2004-05-26 18:38:10 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Mark Spencer <markster@digium.com>
|
2004-05-26 18:38:10 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
2004-05-26 18:38:10 +00:00
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Trivial application to control playback of a sound file
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
2004-05-26 18:38:10 +00:00
|
|
|
*/
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <stdlib.h>
|
2005-11-08 04:48:00 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2005-06-06 22:39:32 +00:00
|
|
|
|
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/app.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/translate.h"
|
|
|
|
#include "asterisk/utils.h"
|
2005-11-06 05:03:14 +00:00
|
|
|
#include "asterisk/options.h"
|
2004-05-26 18:38:10 +00:00
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
static const char *tdesc = "Control Playback Application";
|
2004-05-26 18:38:10 +00:00
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
static const char *app = "ControlPlayback";
|
2004-05-26 18:38:10 +00:00
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
static const char *synopsis = "Play a file with fast forward and rewind";
|
2004-05-26 18:38:10 +00:00
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
static const char *descrip =
|
2005-11-11 13:34:38 +00:00
|
|
|
" ControlPlayback(file[|skipms[|ff[|rew[|stop[|pause[|restart|options]]]]]]]):\n"
|
|
|
|
"This application will play back the given filename. By default, the '*' key\n"
|
|
|
|
"can be used to rewind, and the '#' key can be used to fast-forward.\n"
|
|
|
|
"Parameters:\n"
|
|
|
|
" skipms - This is number of milliseconds to skip when rewinding or\n"
|
|
|
|
" fast-forwarding.\n"
|
|
|
|
" ff - Fast-forward when this DTMF digit is received.\n"
|
|
|
|
" rew - Rewind when this DTMF digit is received.\n"
|
|
|
|
" stop - Stop playback when this DTMF digit is received.\n"
|
|
|
|
" pause - Pause playback when this DTMF digit is received.\n"
|
|
|
|
" restart - Restart playback when this DTMF digit is received.\n"
|
|
|
|
"Options:\n"
|
|
|
|
" j - Jump to priority n+101 if the requested file is not found.\n"
|
|
|
|
"This application sets the following channel variable upon completion:\n"
|
|
|
|
" CPLAYBACKSTATUS - This variable contains the status of the attempt as a text\n"
|
|
|
|
" string, one of: SUCCESS | USERSTOPPED | ERROR\n";
|
2004-05-26 18:38:10 +00:00
|
|
|
|
|
|
|
LOCAL_USER_DECL;
|
|
|
|
|
2004-05-26 22:18:59 +00:00
|
|
|
static int is_on_phonepad(char key)
|
|
|
|
{
|
2005-08-22 19:06:42 +00:00
|
|
|
return key == 35 || key == 42 || (key >= 48 && key <= 57);
|
2004-05-26 22:18:59 +00:00
|
|
|
}
|
|
|
|
|
2004-05-26 18:38:10 +00:00
|
|
|
static int controlplayback_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
2005-11-06 05:03:14 +00:00
|
|
|
int res = 0, priority_jump = 0;
|
2004-05-26 18:38:10 +00:00
|
|
|
int skipms = 0;
|
|
|
|
struct localuser *u;
|
2005-08-22 19:06:42 +00:00
|
|
|
char *tmp;
|
|
|
|
int argc;
|
2005-11-06 05:03:14 +00:00
|
|
|
char *argv[8];
|
2005-08-22 19:06:42 +00:00
|
|
|
enum arg_ids {
|
|
|
|
arg_file = 0,
|
|
|
|
arg_skip = 1,
|
|
|
|
arg_fwd = 2,
|
|
|
|
arg_rev = 3,
|
|
|
|
arg_stop = 4,
|
|
|
|
arg_pause = 5,
|
|
|
|
arg_restart = 6,
|
2005-11-06 05:03:14 +00:00
|
|
|
options = 7,
|
2005-08-22 19:06:42 +00:00
|
|
|
};
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2004-05-26 18:38:10 +00:00
|
|
|
ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2004-05-26 23:56:41 +00:00
|
|
|
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_ADD(u);
|
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
tmp = ast_strdupa(data);
|
|
|
|
memset(argv, 0, sizeof(argv));
|
|
|
|
|
2005-11-03 21:19:11 +00:00
|
|
|
argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
|
2005-08-22 19:06:42 +00:00
|
|
|
|
|
|
|
if (argc < 1) {
|
|
|
|
ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
2005-08-22 19:06:42 +00:00
|
|
|
return -1;
|
2004-05-26 18:38:10 +00:00
|
|
|
}
|
2004-05-26 22:18:59 +00:00
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
skipms = argv[arg_skip] ? atoi(argv[arg_skip]) : 3000;
|
2004-05-27 00:07:18 +00:00
|
|
|
if (!skipms)
|
2004-05-26 22:18:59 +00:00
|
|
|
skipms = 3000;
|
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
if (!argv[arg_fwd] || !is_on_phonepad(*argv[arg_fwd]))
|
|
|
|
argv[arg_fwd] = "#";
|
|
|
|
if (!argv[arg_rev] || !is_on_phonepad(*argv[arg_rev]))
|
|
|
|
argv[arg_rev] = "*";
|
|
|
|
if (argv[arg_stop] && !is_on_phonepad(*argv[arg_stop]))
|
|
|
|
argv[arg_stop] = NULL;
|
|
|
|
if (argv[arg_pause] && !is_on_phonepad(*argv[arg_pause]))
|
|
|
|
argv[arg_pause] = NULL;
|
|
|
|
if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart]))
|
|
|
|
argv[arg_restart] = NULL;
|
2004-05-26 23:56:41 +00:00
|
|
|
|
2005-11-06 05:03:14 +00:00
|
|
|
if (argv[options]) {
|
|
|
|
if (strchr(argv[options], 'j'))
|
|
|
|
priority_jump = 1;
|
|
|
|
}
|
|
|
|
|
2005-08-22 19:06:42 +00:00
|
|
|
res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms);
|
2004-05-26 23:56:41 +00:00
|
|
|
|
2004-06-15 20:33:26 +00:00
|
|
|
/* If we stopped on one of our stop keys, return 0 */
|
2005-11-06 05:03:14 +00:00
|
|
|
if (argv[arg_stop] && strchr(argv[arg_stop], res)) {
|
2004-06-15 20:33:26 +00:00
|
|
|
res = 0;
|
2005-11-06 05:03:14 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
|
|
|
|
} else {
|
|
|
|
if (res < 0) {
|
2005-12-04 20:40:46 +00:00
|
|
|
if (priority_jump || ast_opt_priority_jumping) {
|
2005-11-20 05:39:47 +00:00
|
|
|
if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
|
2005-11-06 05:03:14 +00:00
|
|
|
ast_log(LOG_WARNING, "ControlPlayback tried to jump to priority n+101 as requested, but priority didn't exist\n");
|
|
|
|
}
|
|
|
|
}
|
2005-08-22 19:06:42 +00:00
|
|
|
res = 0;
|
2005-11-06 05:03:14 +00:00
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
|
|
|
|
} else
|
|
|
|
pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
|
2004-10-26 02:25:50 +00:00
|
|
|
}
|
2005-08-22 19:06:42 +00:00
|
|
|
|
2005-10-19 18:19:02 +00:00
|
|
|
LOCAL_USER_REMOVE(u);
|
|
|
|
|
2004-05-26 18:38:10 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
int unload_module(void)
|
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
|
2004-05-26 18:38:10 +00:00
|
|
|
STANDARD_HANGUP_LOCALUSERS;
|
2005-08-22 19:06:42 +00:00
|
|
|
|
2005-10-18 22:52:21 +00:00
|
|
|
return res;
|
2004-05-26 18:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int load_module(void)
|
|
|
|
{
|
|
|
|
return ast_register_application(app, controlplayback_exec, synopsis, descrip);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *description(void)
|
|
|
|
{
|
2005-08-22 19:06:42 +00:00
|
|
|
return (char *) tdesc;
|
2004-05-26 18:38:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int usecount(void)
|
|
|
|
{
|
|
|
|
int res;
|
2005-08-22 19:06:42 +00:00
|
|
|
|
2004-05-26 18:38:10 +00:00
|
|
|
STANDARD_USECOUNT(res);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *key()
|
|
|
|
{
|
|
|
|
return ASTERISK_GPL_KEY;
|
|
|
|
}
|