Thu Apr 28 2011 17:13:36

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

static void __reg_module (void)
static void __unreg_module (void)
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 struct ast_module_info
__MODULE_INFO_SECTION 
__mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Control Playback Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, }
static const char * app = "ControlPlayback"
static struct ast_module_infoast_module_info = &__mod_info
static struct ast_app_option cpb_opts [128] = { [ 'o' ] = { .flag = OPT_OFFSET , .arg_index = OPT_ARG_OFFSET + 1 }, }

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.

     {
   OPT_OFFSET = (1 << 1),
};
anonymous enum
Enumerator:
OPT_ARG_OFFSET 
OPT_ARG_ARRAY_LEN 

Definition at line 101 of file app_controlplayback.c.

     {
   OPT_ARG_OFFSET = 0,
   /* must stay as the last entry ... */
   OPT_ARG_ARRAY_LEN,
};

Function Documentation

static void __reg_module ( void  ) [static]

Definition at line 226 of file app_controlplayback.c.

static void __unreg_module ( void  ) [static]

Definition at line 226 of file app_controlplayback.c.

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, cpb_opts, 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().

{
   int res = 0;
   int skipms = 0;
   long offsetms = 0;
   char offsetbuf[20];
   char stopkeybuf[2];
   char *tmp;
   struct ast_flags opts = { 0, };
   char *opt_args[OPT_ARG_ARRAY_LEN];
   AST_DECLARE_APP_ARGS(args,
      AST_APP_ARG(filename);
      AST_APP_ARG(skip);
      AST_APP_ARG(fwd);
      AST_APP_ARG(rev);
      AST_APP_ARG(stop);
      AST_APP_ARG(pause);
      AST_APP_ARG(restart);
      AST_APP_ARG(options);
   );

   if (ast_strlen_zero(data)) {
      ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
      return -1;
   }
   
   tmp = ast_strdupa(data);
   AST_STANDARD_APP_ARGS(args, tmp);

   if (args.argc < 1) {
      ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
      return -1;
   }

   skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;

   if (!args.fwd || !is_on_phonepad(*args.fwd)) {
      char *digit = "#";
      if (!is_argument(args.rev, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
         args.fwd = digit;
      else
         args.fwd = NULL;
   }
   if (!args.rev || !is_on_phonepad(*args.rev)) {
      char *digit = "*";
      if (!is_argument(args.fwd, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
         args.rev = digit;
      else
         args.rev = NULL;
   }
   ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
   if (args.stop && !is_on_phonepad(*args.stop))
      args.stop = NULL;
   if (args.pause && !is_on_phonepad(*args.pause))
      args.pause = NULL;
   if (args.restart && !is_on_phonepad(*args.restart))
      args.restart = NULL;

   if (args.options) {
      ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);
      if (ast_test_flag(&opts, OPT_OFFSET))
         offsetms = atol(opt_args[OPT_ARG_OFFSET]);
   }

   res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);

   /* If we stopped on one of our stop keys, return 0  */
   if (res > 0 && args.stop && strchr(args.stop, res)) {
      pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
      snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
      pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
      res = 0;
   } else {
      if (res < 0) {
         res = 0;
         pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
      } else
         pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
   }

   snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
   pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);

   return res;
}
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().

{
   if (ast_strlen_zero(haystack))
      return 0;

   if (strchr(haystack, needle))
      return -1;

   return 0;
}
static int is_on_phonepad ( char  key) [static]

Definition at line 112 of file app_controlplayback.c.

Referenced by controlplayback_exec().

{
   return key == 35 || key == 42 || (key >= 48 && key <= 57);
}
static int load_module ( void  ) [static]
static int unload_module ( void  ) [static]

Definition at line 214 of file app_controlplayback.c.

References ast_unregister_application().

{
   int res;
   res = ast_unregister_application(app);
   return res;
}

Variable Documentation

struct ast_module_info __MODULE_INFO_SECTION __mod_info = { __MODULE_INFO_GLOBALS .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Control Playback Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, } [static]

Definition at line 226 of file app_controlplayback.c.

const char* app = "ControlPlayback" [static]

Definition at line 95 of file app_controlplayback.c.

Definition at line 226 of file app_controlplayback.c.

struct ast_app_option cpb_opts[128] = { [ 'o' ] = { .flag = OPT_OFFSET , .arg_index = OPT_ARG_OFFSET + 1 }, } [static]

Definition at line 110 of file app_controlplayback.c.

Referenced by controlplayback_exec().