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