reflect addition/removal of dynamic queue members in queue_log, so that people using...
[asterisk-bristuff.git] / apps / app_echo.c
blob4b2c940562c167a6b7bc21adc4318f443a302193
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 switch (f->frametype) {
73 case AST_FRAME_DTMF:
74 if (f->subclass == '#') {
75 res = 0;
76 ast_frfree(f);
77 goto end;
79 /* fall through */
80 default:
81 if (ast_write(chan, f)) {
82 ast_frfree(f);
83 goto end;
86 ast_frfree(f);
88 end:
89 ast_module_user_remove(u);
90 return res;
93 static int unload_module(void)
95 int res;
97 res = ast_unregister_application(app);
99 ast_module_user_hangup_all();
101 return res;
104 static int load_module(void)
106 return ast_register_application(app, echo_exec, synopsis, descrip);
109 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");