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