Add SIP/RTP video support, video enable app_echo, start on RTCP
[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 #include <pthread.h>
26
27
28 static char *tdesc = "Simple Echo Application";
29
30 static char *app = "Echo";
31
32 static char *synopsis = "Echo audio read back to the user";
33
34 static char *descrip = 
35 "  Echo():  Echo audio read from channel back to the channel. Returns 0\n"
36 "if the user exits with the '#' key, or -1 if the user hangs up.\n";
37
38 STANDARD_LOCAL_USER;
39
40 LOCAL_USER_DECL;
41
42 static int echo_exec(struct ast_channel *chan, void *data)
43 {
44         int res=-1;
45         struct localuser *u;
46         struct ast_frame *f;
47         LOCAL_USER_ADD(u);
48         ast_set_write_format(chan, ast_best_codec(chan->nativeformats));
49         ast_set_read_format(chan, ast_best_codec(chan->nativeformats));
50         /* Do our thing here */
51         while(ast_waitfor(chan, -1) > -1) {
52                 f = ast_read(chan);
53                 if (!f)
54                         break;
55                 if (f->frametype == AST_FRAME_VOICE) {
56                         if (ast_write(chan, f)) 
57                                 break;
58                 } else if (f->frametype == AST_FRAME_VIDEO) {
59                         if (ast_write(chan, f)) 
60                                 break;
61                 } else if (f->frametype == AST_FRAME_DTMF) {
62                         if (f->subclass == '#') {
63                                 res = 0;
64                                 break;
65                         } else
66                                 if (ast_write(chan, f))
67                                         break;
68                 }
69                 ast_frfree(f);
70         }
71         LOCAL_USER_REMOVE(u);
72         return res;
73 }
74
75 int unload_module(void)
76 {
77         STANDARD_HANGUP_LOCALUSERS;
78         return ast_unregister_application(app);
79 }
80
81 int load_module(void)
82 {
83         return ast_register_application(app, echo_exec, synopsis, descrip);
84 }
85
86 char *description(void)
87 {
88         return tdesc;
89 }
90
91 int usecount(void)
92 {
93         int res;
94         STANDARD_USECOUNT(res);
95         return res;
96 }
97
98 char *key()
99 {
100         return ASTERISK_GPL_KEY;
101 }