make app_queue 1.2 jump compliant (issue #5580)
[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  * \ingroup applications
24  */
25
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <unistd.h>
29 #include <string.h>
30
31 #include "asterisk.h"
32
33 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
34
35 #include "asterisk/lock.h"
36 #include "asterisk/file.h"
37 #include "asterisk/logger.h"
38 #include "asterisk/channel.h"
39 #include "asterisk/pbx.h"
40 #include "asterisk/module.h"
41
42 static char *tdesc = "Simple Echo Application";
43
44 static char *app = "Echo";
45
46 static char *synopsis = "Echo audio read back to the user";
47
48 static char *descrip = 
49 "  Echo():  Echo audio read from channel back to the channel. \n"
50 "User can exit the application by either pressing the '#' key, \n"
51 "or hanging up.\n";
52
53 STANDARD_LOCAL_USER;
54
55 LOCAL_USER_DECL;
56
57 static int echo_exec(struct ast_channel *chan, void *data)
58 {
59         int res=-1;
60         struct localuser *u;
61         struct ast_frame *f;
62         LOCAL_USER_ADD(u);
63         ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
64         ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
65         /* Do our thing here */
66         while(ast_waitfor(chan, -1) > -1) {
67                 f = ast_read(chan);
68                 if (!f)
69                         break;
70                 f->delivery.tv_sec = 0;
71                 f->delivery.tv_usec = 0;
72                 if (f->frametype == AST_FRAME_VOICE) {
73                         if (ast_write(chan, f)) 
74                                 break;
75                 } else if (f->frametype == AST_FRAME_VIDEO) {
76                         if (ast_write(chan, f)) 
77                                 break;
78                 } else if (f->frametype == AST_FRAME_DTMF) {
79                         if (f->subclass == '#') {
80                                 res = 0;
81                                 break;
82                         } else
83                                 if (ast_write(chan, f))
84                                         break;
85                 }
86                 ast_frfree(f);
87         }
88         LOCAL_USER_REMOVE(u);
89         return res;
90 }
91
92 int unload_module(void)
93 {
94         int res;
95
96         res = ast_unregister_application(app);
97
98         STANDARD_HANGUP_LOCALUSERS;
99
100         return res;
101 }
102
103 int load_module(void)
104 {
105         return ast_register_application(app, echo_exec, synopsis, descrip);
106 }
107
108 char *description(void)
109 {
110         return tdesc;
111 }
112
113 int usecount(void)
114 {
115         int res;
116         STANDARD_USECOUNT(res);
117         return res;
118 }
119
120 char *key()
121 {
122         return ASTERISK_GPL_KEY;
123 }