Asterisk - The Open Source Telephony Project GIT-master-27fb039
Loading...
Searching...
No Matches
Enumerations | Functions | Variables
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 "asterisk/manager.h"
#include "asterisk/utils.h"
#include "asterisk/astobj2.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)
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static int controlplayback_exec (struct ast_channel *chan, const char *data)
 
static int controlplayback_manager (struct mansession *s, const struct message *m)
 
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 __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Control Playback Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
 
static const char app [] = "ControlPlayback"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static const 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 marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

Definition in file app_controlplayback.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
OPT_OFFSET 

Definition at line 172 of file app_controlplayback.c.

172 {
173 OPT_OFFSET = (1 << 1),
174};

◆ anonymous enum

anonymous enum
Enumerator
OPT_ARG_OFFSET 
OPT_ARG_ARRAY_LEN 

Definition at line 176 of file app_controlplayback.c.

176 {
177 OPT_ARG_OFFSET = 0,
178 /* must stay as the last entry ... */
180};
@ OPT_ARG_OFFSET
@ OPT_ARG_ARRAY_LEN

Function Documentation

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 355 of file app_controlplayback.c.

◆ __unreg_module()

static void __unreg_module ( void  )
static

Definition at line 355 of file app_controlplayback.c.

◆ AST_MODULE_SELF_SYM()

struct ast_module * AST_MODULE_SELF_SYM ( void  )

Definition at line 355 of file app_controlplayback.c.

◆ controlplayback_exec()

static int controlplayback_exec ( struct ast_channel chan,
const char *  data 
)
static

Definition at line 203 of file app_controlplayback.c.

204{
205 int res = 0;
206 int skipms = 0;
207 long offsetms = 0;
208 char offsetbuf[20];
209 char stopkeybuf[2];
210 char *tmp;
211 struct ast_flags opts = { 0, };
212 char *opt_args[OPT_ARG_ARRAY_LEN];
214 AST_APP_ARG(filename);
215 AST_APP_ARG(skip);
216 AST_APP_ARG(fwd);
217 AST_APP_ARG(rev);
219 AST_APP_ARG(pause);
220 AST_APP_ARG(restart);
222 );
223
224 if (ast_strlen_zero(data)) {
225 ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
226 return -1;
227 }
228
229 tmp = ast_strdupa(data);
231
232 if (args.argc < 1) {
233 ast_log(LOG_WARNING, "ControlPlayback requires an argument (filename)\n");
234 return -1;
235 }
236
237 skipms = args.skip ? (atoi(args.skip) ? atoi(args.skip) : 3000) : 3000;
238
239 if (!args.fwd || !is_on_phonepad(*args.fwd)) {
240 char *digit = "#";
241 if (!is_argument(args.rev, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
242 args.fwd = digit;
243 else
244 args.fwd = NULL;
245 }
246 if (!args.rev || !is_on_phonepad(*args.rev)) {
247 char *digit = "*";
248 if (!is_argument(args.fwd, *digit) && !is_argument(args.stop, *digit) && !is_argument(args.pause, *digit) && !is_argument(args.restart, *digit))
249 args.rev = digit;
250 else
251 args.rev = NULL;
252 }
253 ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
254 if (args.stop && !is_on_phonepad(*args.stop))
255 args.stop = NULL;
256 if (args.pause && !is_on_phonepad(*args.pause))
257 args.pause = NULL;
258 if (args.restart && !is_on_phonepad(*args.restart))
259 args.restart = NULL;
260
261 if (args.options) {
262 ast_app_parse_options(cpb_opts, &opts, opt_args, args.options);
263 if (ast_test_flag(&opts, OPT_OFFSET))
264 offsetms = atol(opt_args[OPT_ARG_OFFSET]);
265 }
266
267 res = ast_control_streamfile(chan, args.filename, args.fwd, args.rev, args.stop, args.pause, args.restart, skipms, &offsetms);
268
269 /* If we stopped on one of our stop keys, return 0 */
270 if (res > 0 && args.stop && strchr(args.stop, res)) {
271 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "USERSTOPPED");
272 snprintf(stopkeybuf, sizeof(stopkeybuf), "%c", res);
273 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTOPKEY", stopkeybuf);
274 res = 0;
275 } else if (res > 0 && res == AST_CONTROL_STREAM_STOP) {
276 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "REMOTESTOPPED");
277 res = 0;
278 } else {
279 if (res < 0) {
280 res = 0;
281 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "ERROR");
282 } else
283 pbx_builtin_setvar_helper(chan, "CPLAYBACKSTATUS", "SUCCESS");
284 }
285
286 snprintf(offsetbuf, sizeof(offsetbuf), "%ld", offsetms);
287 pbx_builtin_setvar_helper(chan, "CPLAYBACKOFFSET", offsetbuf);
288
289 return res;
290}
char digit
static const struct ast_app_option cpb_opts[128]
static int is_on_phonepad(char key)
static int is_argument(const char *haystack, int needle)
unsigned int stop
Definition app_sla.c:342
static int skipms
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition astmm.h:298
#define ast_log
Definition astobj2.c:42
#define AST_APP_ARG(name)
Define an application argument.
int ast_control_streamfile(struct ast_channel *chan, const char *file, const char *fwd, const char *rev, const char *stop, const char *pause, const char *restart, int skipms, long *offsetms)
Stream a file with fast forward, pause, reverse, restart.
Definition main/app.c:1465
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
int ast_app_parse_options(const struct ast_app_option *options, struct ast_flags *flags, char **args, char *optstr)
Parses a string containing application options and sets flags/arguments.
Definition main/app.c:3066
@ AST_CONTROL_STREAM_STOP
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_WARNING
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
static struct @519 args
#define NULL
Definition resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
Structure used to handle boolean flags.
Definition utils.h:220
static struct test_options options
#define ast_test_flag(p, flag)
Definition utils.h:64

References args, AST_APP_ARG, ast_app_parse_options(), AST_CONTROL_STREAM_STOP, 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, digit, is_argument(), is_on_phonepad(), LOG_WARNING, NULL, OPT_ARG_ARRAY_LEN, OPT_ARG_OFFSET, OPT_OFFSET, options, pbx_builtin_setvar_helper(), skipms, and stop.

Referenced by load_module().

◆ controlplayback_manager()

static int controlplayback_manager ( struct mansession s,
const struct message m 
)
static

Definition at line 292 of file app_controlplayback.c.

293{
294 const char *channel_name = astman_get_header(m, "Channel");
295 const char *control_type = astman_get_header(m, "Control");
296 struct ast_channel *chan;
297
298 if (ast_strlen_zero(channel_name)) {
299 astman_send_error(s, m, "Channel not specified");
300 return 0;
301 }
302
303 if (ast_strlen_zero(control_type)) {
304 astman_send_error(s, m, "Control not specified");
305 return 0;
306 }
307
308 chan = ast_channel_get_by_name(channel_name);
309 if (!chan) {
310 astman_send_error(s, m, "No such channel");
311 return 0;
312 }
313
314 if (!strcasecmp(control_type, "stop")) {
316 } else if (!strcasecmp(control_type, "forward")) {
318 } else if (!strcasecmp(control_type, "reverse")) {
320 } else if (!strcasecmp(control_type, "pause")) {
322 } else if (!strcasecmp(control_type, "restart")) {
324 } else {
325 astman_send_error(s, m, "Unknown control type");
326 chan = ast_channel_unref(chan);
327 return 0;
328 }
329
330 chan = ast_channel_unref(chan);
331 astman_send_ack(s, m, NULL);
332 return 0;
333}
int ast_queue_control(struct ast_channel *chan, enum ast_control_frame_type control)
Queue a control frame without payload.
Definition channel.c:1288
struct ast_channel * ast_channel_get_by_name(const char *search)
Find a channel by name or uniqueid.
Definition channel.c:1416
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3018
void astman_send_error(struct mansession *s, const struct message *m, char *error)
Send error in manager transaction.
Definition manager.c:1982
void astman_send_ack(struct mansession *s, const struct message *m, char *msg)
Send ack in manager transaction.
Definition manager.c:2014
const char * astman_get_header(const struct message *m, char *var)
Get header from manager transaction.
Definition manager.c:1643
@ AST_CONTROL_STREAM_RESTART
@ AST_CONTROL_STREAM_SUSPEND
@ AST_CONTROL_STREAM_REVERSE
@ AST_CONTROL_STREAM_FORWARD
Main Channel structure associated with a channel.

References ast_channel_get_by_name(), ast_channel_unref, AST_CONTROL_STREAM_FORWARD, AST_CONTROL_STREAM_RESTART, AST_CONTROL_STREAM_REVERSE, AST_CONTROL_STREAM_STOP, AST_CONTROL_STREAM_SUSPEND, ast_queue_control(), ast_strlen_zero(), astman_get_header(), astman_send_ack(), astman_send_error(), and NULL.

Referenced by load_module().

◆ is_argument()

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

Definition at line 192 of file app_controlplayback.c.

193{
194 if (ast_strlen_zero(haystack))
195 return 0;
196
197 if (strchr(haystack, needle))
198 return -1;
199
200 return 0;
201}

References ast_strlen_zero().

Referenced by controlplayback_exec().

◆ is_on_phonepad()

static int is_on_phonepad ( char  key)
static

Definition at line 187 of file app_controlplayback.c.

188{
189 return key == 35 || key == 42 || (key >= 48 && key <= 57);
190}

Referenced by controlplayback_exec().

◆ load_module()

static int load_module ( void  )
static

Definition at line 345 of file app_controlplayback.c.

346{
347 int res = 0;
348
351
352 return res;
353}
static const char app[]
static int controlplayback_exec(struct ast_channel *chan, const char *data)
static int controlplayback_manager(struct mansession *s, const struct message *m)
#define ast_manager_register_xml(action, authority, func)
Register a manager callback using XML documentation to describe the manager.
Definition manager.h:192
#define EVENT_FLAG_CALL
Definition manager.h:76
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition module.h:640

References app, ast_manager_register_xml, ast_register_application_xml, controlplayback_exec(), controlplayback_manager(), and EVENT_FLAG_CALL.

◆ unload_module()

static int unload_module ( void  )
static

Definition at line 335 of file app_controlplayback.c.

336{
337 int res = 0;
338
340 res |= ast_manager_unregister("ControlPlayback");
341
342 return res;
343}
int ast_manager_unregister(const char *action)
Unregister a registered manager command.
Definition manager.c:7698
int ast_unregister_application(const char *app)
Unregister an application.
Definition pbx_app.c:392

References app, ast_manager_unregister(), and ast_unregister_application().

Variable Documentation

◆ __mod_info

struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .description = "Control Playback Application" , .key = ASTERISK_GPL_KEY , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .load_pri = AST_MODPRI_DEFAULT, .support_level = AST_MODULE_SUPPORT_CORE, }
static

Definition at line 355 of file app_controlplayback.c.

◆ app

const char app[] = "ControlPlayback"
static

Definition at line 170 of file app_controlplayback.c.

Referenced by load_module(), and unload_module().

◆ ast_module_info

const struct ast_module_info* ast_module_info = &__mod_info
static

Definition at line 355 of file app_controlplayback.c.

◆ cpb_opts

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

Definition at line 185 of file app_controlplayback.c.

Referenced by controlplayback_exec().