Wed Jan 8 2020 09:49:39

Asterisk developer's documentation


app_echo.c
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@digium.com>
7  *
8  * See http://www.asterisk.org for more information about
9  * the Asterisk project. Please do not directly contact
10  * any of the maintainers of this project for assistance;
11  * the project provides a web site, mailing lists and IRC
12  * channels for your use.
13  *
14  * This program is free software, distributed under the terms of
15  * the GNU General Public License Version 2. See the LICENSE file
16  * at the top of the source tree.
17  */
18 
19 /*! \file
20  *
21  * \brief Echo application -- play back what you hear to evaluate latency
22  *
23  * \author Mark Spencer <markster@digium.com>
24  *
25  * \ingroup applications
26  */
27 
28 /*** MODULEINFO
29  <support_level>core</support_level>
30  ***/
31 
32 #include "asterisk.h"
33 
34 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 360033 $")
35 
36 #include "asterisk/file.h"
37 #include "asterisk/module.h"
38 #include "asterisk/channel.h"
39 
40 /*** DOCUMENTATION
41  <application name="Echo" language="en_US">
42  <synopsis>
43  Echo media, DTMF back to the calling party
44  </synopsis>
45  <syntax />
46  <description>
47  <para>Echos back any media or DTMF frames read from the calling
48  channel back to itself. This will not echo CONTROL, MODEM, or NULL
49  frames. Note: If '#' detected application exits.</para>
50  <para>This application does not automatically answer and should be
51  preceeded by an application such as Answer() or Progress().</para>
52  </description>
53  </application>
54  ***/
55 
56 static const char app[] = "Echo";
57 
58 static int echo_exec(struct ast_channel *chan, const char *data)
59 {
60  int res = -1;
62 
63  format = ast_best_codec(chan->nativeformats);
64  ast_set_write_format(chan, format);
65  ast_set_read_format(chan, format);
66 
67  while (ast_waitfor(chan, -1) > -1) {
68  struct ast_frame *f = ast_read(chan);
69  if (!f) {
70  break;
71  }
72  f->delivery.tv_sec = 0;
73  f->delivery.tv_usec = 0;
75  && f->frametype != AST_FRAME_MODEM
76  && f->frametype != AST_FRAME_NULL
77  && ast_write(chan, f)) {
78  ast_frfree(f);
79  goto end;
80  }
81  if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
82  res = 0;
83  ast_frfree(f);
84  goto end;
85  }
86  ast_frfree(f);
87  }
88 end:
89  return res;
90 }
91 
92 static int unload_module(void)
93 {
94  return ast_unregister_application(app);
95 }
96 
97 static int load_module(void)
98 {
100 }
101 
102 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");
union ast_frame_subclass subclass
Definition: frame.h:146
Main Channel structure associated with a channel.
Definition: channel.h:742
static int echo_exec(struct ast_channel *chan, const char *data)
Definition: app_echo.c:58
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk main include file. File version handling, generic pbx functions.
#define AST_FRAME_DTMF
Definition: frame.h:128
struct ast_frame * ast_read(struct ast_channel *chan)
Reads a frame.
Definition: channel.c:4383
format_t ast_best_codec(format_t fmts)
Pick the best audio codec.
Definition: channel.c:1062
format_t nativeformats
Definition: channel.h:852
int ast_unregister_application(const char *app)
Unregister an application.
Definition: pbx.c:7705
int ast_set_write_format(struct ast_channel *chan, format_t format)
Sets write format on channel chan Set write format for channel to whichever component of &quot;format&quot; is ...
Definition: channel.c:5307
int ast_set_read_format(struct ast_channel *chan, format_t format)
Sets read format on channel chan Set read format for channel to whichever component of &quot;format&quot; is be...
Definition: channel.c:5301
General Asterisk PBX channel definitions.
static const char app[]
Definition: app_echo.c:56
static int unload_module(void)
Definition: app_echo.c:92
int64_t format_t
Definition: frame_defs.h:32
static struct ast_format f[]
Definition: format_g726.c:181
int ast_write(struct ast_channel *chan, struct ast_frame *frame)
Write a frame to a channel This function writes the given frame to the indicated channel.
Definition: channel.c:4916
struct timeval delivery
Definition: frame.h:162
int ast_waitfor(struct ast_channel *chan, int ms)
Wait for input on a channel.
Definition: channel.c:3539
Data structure associated with a single frame of data.
Definition: frame.h:142
enum ast_frame_type frametype
Definition: frame.h:144
#define ast_frfree(fr)
Definition: frame.h:583
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
static snd_pcm_format_t format
Definition: chan_alsa.c:93
static int load_module(void)
Definition: app_echo.c:97
#define ast_register_application_xml(app, execute)
Register an application using XML documentation.
Definition: module.h:437
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180