Sat Aug 6 00:39:34 2011

Asterisk developer's documentation


app_controlplayback.c File Reference

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

#include "asterisk.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#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"
#include "asterisk/options.h"

Go to the source code of this file.

Functions

static void __reg_module (void)
static void __unreg_module (void)
static int controlplayback_exec (struct ast_channel *chan, void *data)
static int is_on_phonepad (char key)
static int load_module (void)
static int unload_module (void)

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Control Playback Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, }
static const char * app = "ControlPlayback"
static const struct ast_module_infoast_module_info = &__mod_info
static const char * descrip
static const char * synopsis = "Play a file with fast forward and rewind"


Detailed Description

Trivial application to control playback of a sound file.

Author:
Mark Spencer <markster@digium.com>

Definition in file app_controlplayback.c.


Function Documentation

static void __reg_module ( void   )  [static]

Definition at line 168 of file app_controlplayback.c.

static void __unreg_module ( void   )  [static]

Definition at line 168 of file app_controlplayback.c.

static int controlplayback_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 75 of file app_controlplayback.c.

References ast_app_separate_args(), ast_control_streamfile(), ast_goto_if_exists(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, ast_strdupa, ast_strlen_zero(), ast_module_user::chan, ast_channel::context, is_on_phonepad(), LOG_WARNING, pbx_builtin_setvar_helper(), and skipms.

Referenced by load_module().

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    /* If we stopped on one of our stop keys, return 0  */
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 }

static int is_on_phonepad ( char  key  )  [static]

Definition at line 70 of file app_controlplayback.c.

Referenced by controlplayback_exec().

00071 {
00072    return key == 35 || key == 42 || (key >= 48 && key <= 57);
00073 }

static int load_module ( void   )  [static]

Definition at line 163 of file app_controlplayback.c.

References ast_register_application(), and controlplayback_exec().

static int unload_module ( void   )  [static]

Definition at line 156 of file app_controlplayback.c.

References ast_unregister_application().

00157 {
00158    int res;
00159    res = ast_unregister_application(app);
00160    return res;
00161 }


Variable Documentation

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT | AST_MODFLAG_BUILDSUM, .description = "Control Playback Application" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = "361d7bb937402d51e4658efb5b4d76e4" , .load = load_module, .unload = unload_module, } [static]

Definition at line 168 of file app_controlplayback.c.

const char* app = "ControlPlayback" [static]

Definition at line 47 of file app_controlplayback.c.

const struct ast_module_info* ast_module_info = &__mod_info [static]

Definition at line 168 of file app_controlplayback.c.

const char* descrip [static]

Definition at line 51 of file app_controlplayback.c.

const char* synopsis = "Play a file with fast forward and rewind" [static]

Definition at line 49 of file app_controlplayback.c.


Generated on Sat Aug 6 00:39:34 2011 for Asterisk - the Open Source PBX by  doxygen 1.4.7