Remove pthread.h from source. We should be using asterisk/lock.h everywhere instead...
[asterisk/asterisk.git] / apps / app_echo.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Echo application -- play back what you hear to evaluate latency
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <asterisk/lock.h>
15 #include <asterisk/file.h>
16 #include <asterisk/logger.h>
17 #include <asterisk/channel.h>
18 #include <asterisk/pbx.h>
19 #include <asterisk/module.h>
20 #include <stdlib.h>
21 #include <unistd.h>
22 #include <string.h>
23 #include <stdlib.h>
24
25 static char *tdesc = "Simple Echo Application";
26
27 static char *app = "Echo";
28
29 static char *synopsis = "Echo audio read back to the user";
30
31 static char *descrip = 
32 "  Echo():  Echo audio read from channel back to the channel. Returns 0\n"
33 "if the user exits with the '#' key, or -1 if the user hangs up.\n";
34
35 STANDARD_LOCAL_USER;
36
37 LOCAL_USER_DECL;
38
39 static int echo_exec(struct ast_channel *chan, void *data)
40 {
41         int res=-1;
42         struct localuser *u;
43         struct ast_frame *f;
44         LOCAL_USER_ADD(u);
45         ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
46         ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
47         /* Do our thing here */
48         while(ast_waitfor(chan, -1) > -1) {
49                 f = ast_read(chan);
50                 if (!f)
51                         break;
52                 f->delivery.tv_sec = 0;
53                 f->delivery.tv_usec = 0;
54                 if (f->frametype == AST_FRAME_VOICE) {
55                         if (ast_write(chan, f)) 
56                                 break;
57                 } else if (f->frametype == AST_FRAME_VIDEO) {
58                         if (ast_write(chan, f)) 
59                                 break;
60                 } else if (f->frametype == AST_FRAME_DTMF) {
61                         if (f->subclass == '#') {
62                                 res = 0;
63                                 break;
64                         } else
65                                 if (ast_write(chan, f))
66                                         break;
67                 }
68                 ast_frfree(f);
69         }
70         LOCAL_USER_REMOVE(u);
71         return res;
72 }
73
74 int unload_module(void)
75 {
76         STANDARD_HANGUP_LOCALUSERS;
77         return ast_unregister_application(app);
78 }
79
80 int load_module(void)
81 {
82         return ast_register_application(app, echo_exec, synopsis, descrip);
83 }
84
85 char *description(void)
86 {
87         return tdesc;
88 }
89
90 int usecount(void)
91 {
92         int res;
93         STANDARD_USECOUNT(res);
94         return res;
95 }
96
97 char *key()
98 {
99         return ASTERISK_GPL_KEY;
100 }