app_queue: Added initialization for "context" parameter
[asterisk/asterisk.git] / apps / app_echo.c
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_REGISTER_FILE()
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;
61         int fir_sent = 0;
62
63         while (ast_waitfor(chan, -1) > -1) {
64                 struct ast_frame *f = ast_read(chan);
65                 if (!f) {
66                         break;
67                 }
68                 f->delivery.tv_sec = 0;
69                 f->delivery.tv_usec = 0;
70                 if (f->frametype == AST_FRAME_CONTROL
71                         && f->subclass.integer == AST_CONTROL_VIDUPDATE) {
72                         if (ast_write(chan, f) < 0) {
73                                 ast_frfree(f);
74                                 goto end;
75                         }
76                         fir_sent = 1;
77                 }
78                 if (!fir_sent && f->frametype == AST_FRAME_VIDEO) {
79                         struct ast_frame frame = {
80                                 .frametype = AST_FRAME_CONTROL,
81                                 .subclass.integer = AST_CONTROL_VIDUPDATE,
82                         };
83                         ast_write(chan, &frame);
84                         fir_sent = 1;
85                 }
86                 if (f->frametype != AST_FRAME_CONTROL
87                         && f->frametype != AST_FRAME_MODEM
88                         && f->frametype != AST_FRAME_NULL
89                         && ast_write(chan, f)) {
90                         ast_frfree(f);
91                         goto end;
92                 }
93                 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass.integer == '#')) {
94                         res = 0;
95                         ast_frfree(f);
96                         goto end;
97                 }
98                 ast_frfree(f);
99         }
100 end:
101         return res;
102 }
103
104 static int unload_module(void)
105 {
106         return ast_unregister_application(app);
107 }
108
109 static int load_module(void)
110 {
111         return ast_register_application_xml(app, echo_exec);
112 }
113
114 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");