Tue Aug 24 20:34:10 2010

Asterisk developer's documentation


app_controlplayback.c File Reference

Trivial application to control playback of a sound file. More...

#include "asterisk.h"
#include "asterisk/pbx.h"
#include "asterisk/app.h"
#include "asterisk/module.h"
Include dependency graph for app_controlplayback.c:

Go to the source code of this file.

Enumerations

enum  { OPT_OFFSET = (1 << 1) }
enum  { OPT_ARG_OFFSET = 0, OPT_ARG_ARRAY_LEN }

Functions

 AST_APP_OPTIONS (cpb_opts, BEGIN_OPTIONS AST_APP_OPTION_ARG('o', OPT_OFFSET, OPT_ARG_OFFSET), END_OPTIONS)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Control Playback Application")
static int controlplayback_exec (struct ast_channel *chan, void *data)
static int is_argument (const char *haystack, int needle)
static int is_on_phonepad (char key)
static int load_module (void)
static int unload_module (void)

Variables

static const char * app = "ControlPlayback"

Detailed Description

Trivial application to control playback of a sound file.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_controlplayback.c.


Enumeration Type Documentation

anonymous enum
Enumerator:
OPT_OFFSET 

Definition at line 97 of file app_controlplayback.c.

00097      {
00098    OPT_OFFSET = (1 << 1),
00099 };

anonymous enum
Enumerator:
OPT_ARG_OFFSET 
OPT_ARG_ARRAY_LEN 

Definition at line 101 of file app_controlplayback.c.

00101      {
00102    OPT_ARG_OFFSET = 0,
00103    /* must stay as the last entry ... */
00104    OPT_ARG_ARRAY_LEN,
00105 };


Function Documentation

AST_APP_OPTIONS ( cpb_opts  ,
BEGIN_OPTIONS   AST_APP_OPTION_ARG'o', OPT_OFFSET, OPT_ARG_OFFSET,
END_OPTIONS   
)
AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Control Playback Application"   
)
static int controlplayback_exec ( struct ast_channel *  chan,
void *  data 
) [static]

Definition at line 128 of file app_controlplayback.c.

References AST_APP_ARG, ast_app_parse_options(), ast_control_streamfile(), ast_debug, AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_test_flag, is_argument(), is_on_phonepad(), LOG_WARNING, OPT_ARG_ARRAY_LEN, OPT_ARG_OFFSET, OPT_OFFSET, pbx_builtin_setvar_helper(), skipms, and stop.

Referenced by load_module().

00129 {
00130    int res = 0;
00131    int skipms = 0;
00132    long offsetms = 0;
00133    char offsetbuf[20];
00134    char stopkeybuf[2];
00135    char *tmp;
00136    struct ast_flags opts = { 0, };
00137    char *opt_args[OPT_ARG_ARRAY_LEN];
00138    AST_DECLARE_APP_ARGS(args,
00139       AST_APP_ARG(filename);
00140       AST_APP_ARG(skip);
00141       AST_APP_ARG(fwd);
00142       AST_APP_ARG(rev);
00143       AST_APP_ARG(stop);
00144       AST_APP_ARG(pause);
00145       AST_APP_ARG(restart);
00146       AST_APP_ARG(options);
00147    );
00148 
00149    if (ast_strlen_zero(data)) {
00150       ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00151       return -1;
00152    }
00153    
00154    tmp = ast_strdupa(data);
00155    AST_STANDARD_APP_ARGS(args, tmp);
00156 
00157    if (args.argc < 1) {
00158       ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
00159       return -1;
00160    }
00161 
00162    skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;
00163 
00164    if (!args.fwd || !is_on_phonepad(*args.fwd)) {
00165       char *digit = "#";
00166       if (!is_argument(args.rev, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
00167          args.fwd = digit;
00168       else
00169          args.fwd = NULL;
00170    }
00171    if (!args.rev || !is_on_phonepad(*args.rev)) {
00172       char *digit = "*";
00173       if (!is_argument(args.fwd, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
00174          args.rev = digit;
00175       else
00176          args.rev = NULL;
00177    }
00178    ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
00179    if (args.stop && !is_on_phonepad(*args.stop))
00180       args.stop = NULL;
00181    if (args.pause && !is_on_phonepad(*args.pause))
00182       args.pause = NULL;
00183    if (args.restart && !is_on_phonepad(*args.restart))
00184       args.restart = NULL;
00185 
00186    if (args.options) {
00187       ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);
00188       if (ast_test_flag(&opts, OPT_OFFSET))
00189          offsetms = atol(opt_args[OPT_ARG_OFFSET]);
00190    }
00191 
00192    res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);
00193 
00194    /* If we stopped on one of our stop keys, return 0  */
00195    if (res > 0 && args.stop && strchr(args.stop, res)) {
00196       pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
00197       snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
00198       pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
00199       res = 0;
00200    } else {
00201       if (res < 0) {
00202          res = 0;
00203          pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
00204       } else
00205          pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
00206    }
00207 
00208    snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
00209    pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
00210 
00211    return res;
00212 }

static int is_argument ( const char *  haystack,
int  needle 
) [static]

Definition at line 117 of file app_controlplayback.c.

References ast_strlen_zero().

Referenced by controlplayback_exec().

00118 {
00119    if (ast_strlen_zero(haystack))
00120       return 0;
00121 
00122    if (strchr(haystack, needle))
00123       return -1;
00124 
00125    return 0;
00126 }

static int is_on_phonepad ( char  key  )  [static]

Definition at line 112 of file app_controlplayback.c.

Referenced by controlplayback_exec().

00113 {
00114    return key == 35 || key == 42 || (key >= 48 && key <= 57);
00115 }

static int load_module ( void   )  [static]

Definition at line 221 of file app_controlplayback.c.

References ast_register_application_xml, and controlplayback_exec().

00222 {
00223    return ast_register_application_xml(app, controlplayback_exec);
00224 }

static int unload_module ( void   )  [static]

Definition at line 214 of file app_controlplayback.c.

References ast_unregister_application().

00215 {
00216    int res;
00217    res = ast_unregister_application(app);
00218    return res;
00219 }


Variable Documentation

const char* app = "ControlPlayback" [static]

Definition at line 95 of file app_controlplayback.c.


Generated on 24 Aug 2010 for Asterisk - the Open Source PBX by  doxygen 1.6.1