00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "asterisk.h"
00029
00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 86754 $")
00031
00032 #include <stdlib.h>
00033 #include <stdio.h>
00034 #include <string.h>
00035
00036 #include "asterisk/lock.h"
00037 #include "asterisk/file.h"
00038 #include "asterisk/logger.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/app.h"
00042 #include "asterisk/module.h"
00043 #include "asterisk/translate.h"
00044 #include "asterisk/utils.h"
00045 #include "asterisk/options.h"
00046
00047 static const char *app = "ControlPlayback";
00048
00049 static const char *synopsis = "Play a file with fast forward and rewind";
00050
00051 static const char *descrip =
00052 " ControlPlayback(file[|skipms[|ff[|rew[|stop[|pause[|restart|options]]]]]]]):\n"
00053 "This application will play back the given filename. By default, the '*' key\n"
00054 "can be used to rewind, and the '#' key can be used to fast-forward.\n"
00055 "Parameters:\n"
00056 " skipms - This is number of milliseconds to skip when rewinding or\n"
00057 " fast-forwarding.\n"
00058 " ff - Fast-forward when this DTMF digit is received.\n"
00059 " rew - Rewind when this DTMF digit is received.\n"
00060 " stop - Stop playback when this DTMF digit is received.\n"
00061 " pause - Pause playback when this DTMF digit is received.\n"
00062 " restart - Restart playback when this DTMF digit is received.\n"
00063 "Options:\n"
00064 " j - Jump to priority n+101 if the requested file is not found.\n"
00065 "This application sets the following channel variable upon completion:\n"
00066 " CPLAYBACKSTATUS - This variable contains the status of the attempt as a text\n"
00067 " string, one of: SUCCESS | USERSTOPPED | ERROR\n";
00068
00069
00070 static int is_on_phonepad(char key)
00071 {
00072 return key == 35 || key == 42 || (key >= 48 && key <= 57);
00073 }
00074
00075 static int controlplayback_exec(struct ast_channel *chan, void *data)
00076 {
00077 int res = 0, priority_jump = 0;
00078 int skipms = 0;
00079 struct ast_module_user *u;
00080 char *tmp;
00081 int argc;
00082 char *argv[8];
00083 enum arg_ids {
00084 arg_file = 0,
00085 arg_skip = 1,
00086 arg_fwd = 2,
00087 arg_rev = 3,
00088 arg_stop = 4,
00089 arg_pause = 5,
00090 arg_restart = 6,
00091 options = 7,
00092 };
00093
00094 if (ast_strlen_zero(data)) {
00095 ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00096 return -1;
00097 }
00098
00099 u = ast_module_user_add(chan);
00100
00101 tmp = ast_strdupa(data);
00102 memset(argv, 0, sizeof(argv));
00103
00104 argc = ast_app_separate_args(tmp, '|', argv, sizeof(argv) / sizeof(argv[0]));
00105
00106 if (argc < 1) {
00107 ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00108 ast_module_user_remove(u);
00109 return -1;
00110 }
00111
00112 skipms = argv[arg_skip] ? atoi(argv[arg_skip]) : 3000;
00113 if (!skipms)
00114 skipms = 3000;
00115
00116 if (!argv[arg_fwd] || !is_on_phonepad(*argv[arg_fwd]))
00117 argv[arg_fwd] = "#";
00118 if (!argv[arg_rev] || !is_on_phonepad(*argv[arg_rev]))
00119 argv[arg_rev] = "*";
00120 if (argv[arg_stop] && !is_on_phonepad(*argv[arg_stop]))
00121 argv[arg_stop] = NULL;
00122 if (argv[arg_pause] && !is_on_phonepad(*argv[arg_pause]))
00123 argv[arg_pause] = NULL;
00124 if (argv[arg_restart] && !is_on_phonepad(*argv[arg_restart]))
00125 argv[arg_restart] = NULL;
00126
00127 if (argv[options]) {
00128 if (strchr(argv[options], 'j'))
00129 priority_jump = 1;
00130 }
00131
00132 res = ast_control_streamfile(chan, argv[arg_file], argv[arg_fwd], argv[arg_rev], argv[arg_stop], argv[arg_pause], argv[arg_restart], skipms);
00133
00134
00135 if (res > 0 && argv[arg_stop] && strchr(argv[arg_stop], res)) {
00136 res = 0;
00137 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
00138 } else {
00139 if (res < 0) {
00140 if (priority_jump || ast_opt_priority_jumping) {
00141 if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) {
00142 ast_log(LOG_WARNING, "ControlPlayback tried to jump to priority n+101 as requested, but priority didn't exist\n");
00143 }
00144 }
00145 res = 0;
00146 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
00147 } else
00148 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
00149 }
00150
00151 ast_module_user_remove(u);
00152
00153 return res;
00154 }
00155
00156 static int unload_module(void)
00157 {
00158 int res;
00159 res = ast_unregister_application(app);
00160 return res;
00161 }
00162
00163 static int load_module(void)
00164 {
00165 return ast_register_application(app, controlplayback_exec, synopsis, descrip);
00166 }
00167
00168 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Control Playback Application");