Debian Codegraph @

apps/app_echo.c

raw symbols SCIP
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2005, Digium, Inc.
5 *
6 * Mark Spencer <[email protected]>
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 <[email protected]>
24 *
25 * \ingroup applications
26 */
27
28 /*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32 #include "asterisk.h"
33
34 #include "asterisk/file.h"
35 #include "asterisk/module.h"
36 #include "asterisk/channel.h"
37
38 /*** DOCUMENTATION
39 <application name="Echo" language="en_US">
40 <since>
41 <version>0.1.2</version>
42 </since>
43 <synopsis>
44 Echo media, DTMF back to the calling party
45 </synopsis>
46 <syntax />
47 <description>
48 <para>Echos back any media or DTMF frames read from the calling
49 channel back to itself. This will not echo CONTROL, MODEM, or NULL
50 frames. Note: If '#' detected application exits.</para>
51 <para>This application does not automatically answer and should be
52 preceded by an application such as Answer() or Progress().</para>
53 </description>
54 </application>
55 ***/
56
57 static const char app[] = "Echo";
58
59 static int echo_exec(struct ast_channel *chan, const char *data)
60 {
61 int res = -1;
62 int fir_sent = 0;
63
64 while (ast_waitfor(chan, -1) > -1) {
65 struct ast_frame *f = ast_read(chan);
66 if (!f) {
67 break;
68 }
69 f->delivery.tv_sec = 0;
70 f->delivery.tv_usec = 0;
71 if (f->frametype == AST_FRAME_CONTROL
72 && f->subclass.integer == AST_CONTROL_VIDUPDATE
73 && !fir_sent) {
74 if (ast_write(chan, f) < 0) {
75 ast_frfree(f);
76 goto end;
77 }
78 fir_sent = 1;
79 }
80 if (!fir_sent && f->frametype == AST_FRAME_VIDEO) {
81 struct ast_frame frame = {
82 .frametype = AST_FRAME_CONTROL,
83 .subclass.integer = AST_CONTROL_VIDUPDATE,
84 };
85 ast_write(chan, &frame);
86 fir_sent = 1;
87 }
88 if (f->frametype != AST_FRAME_CONTROL
89 && f->frametype != AST_FRAME_MODEM
90 && f->frametype != AST_FRAME_NULL
91 && ast_write(chan, f)) {
92 ast_frfree(f);
93 goto end;
94 }
95 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
96 res = 0;
97 ast_frfree(f);
98 goto end;
99 }
100 ast_frfree(f);
101 }
102 end:
103 return res;
104 }
105
106 static int unload_module(void)
107 {
108 return ast_unregister_application(app);
109 }
110
111 static int load_module(void)
112 {
113 return ast_register_application_xml(app, echo_exec);
114 }
115
116 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");