update comment to match the state of the code
[asterisk-bristuff.git] / apps / app_echo.c
blob14f7c6d650daa04701044b14f024cd3208b610d4
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
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.
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.
19 /*! \file
21 * \brief Echo application -- play back what you hear to evaluate latency
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <unistd.h>
35 #include <string.h>
37 #include "asterisk/lock.h"
38 #include "asterisk/file.h"
39 #include "asterisk/logger.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
44 static char *app = "Echo";
46 static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
48 static char *descrip =
49 " Echo(): This application will echo any audio, video, or DTMF frames read from\n"
50 "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
51 "application will exit.\n";
54 static int echo_exec(struct ast_channel *chan, void *data)
56 int res = -1;
57 int format;
58 struct ast_module_user *u;
60 u = ast_module_user_add(chan);
62 format = ast_best_codec(chan->nativeformats);
63 ast_set_write_format(chan, format);
64 ast_set_read_format(chan, format);
66 while (ast_waitfor(chan, -1) > -1) {
67 struct ast_frame *f = ast_read(chan);
68 if (!f)
69 break;
70 f->delivery.tv_sec = 0;
71 f->delivery.tv_usec = 0;
72 if (ast_write(chan, f)) {
73 ast_frfree(f);
74 goto end;
76 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
77 res = 0;
78 ast_frfree(f);
79 goto end;
81 ast_frfree(f);
83 end:
84 ast_module_user_remove(u);
85 return res;
88 static int unload_module(void)
90 int res;
92 res = ast_unregister_application(app);
94 ast_module_user_hangup_all();
96 return res;
99 static int load_module(void)
101 return ast_register_application(app, echo_exec, synopsis, descrip);
104 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");