00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2005, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! \file 00020 * 00021 * \brief Echo application -- play back what you hear to evaluate latency 00022 * 00023 * \author Mark Spencer <markster@digium.com> 00024 * 00025 * \ingroup applications 00026 */ 00027 00028 #include "asterisk.h" 00029 00030 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 249952 $") 00031 00032 #include "asterisk/file.h" 00033 #include "asterisk/module.h" 00034 #include "asterisk/channel.h" 00035 00036 /*** DOCUMENTATION 00037 <application name="Echo" language="en_US"> 00038 <synopsis> 00039 Echo audio, video, DTMF back to the calling party 00040 </synopsis> 00041 <syntax /> 00042 <description> 00043 <para>Echos back any audio, video or DTMF frames read from the calling 00044 channel back to itself. Note: If '#' detected application exits</para> 00045 </description> 00046 </application> 00047 ***/ 00048 00049 static char *app = "Echo"; 00050 00051 static int echo_exec(struct ast_channel *chan, void *data) 00052 { 00053 int res = -1; 00054 int format; 00055 00056 format = ast_best_codec(chan->nativeformats); 00057 ast_set_write_format(chan, format); 00058 ast_set_read_format(chan, format); 00059 00060 while (ast_waitfor(chan, -1) > -1) { 00061 struct ast_frame *f = ast_read(chan); 00062 if (!f) { 00063 break; 00064 } 00065 f->delivery.tv_sec = 0; 00066 f->delivery.tv_usec = 0; 00067 if (ast_write(chan, f)) { 00068 ast_frfree(f); 00069 goto end; 00070 } 00071 if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) { 00072 res = 0; 00073 ast_frfree(f); 00074 goto end; 00075 } 00076 ast_frfree(f); 00077 } 00078 end: 00079 return res; 00080 } 00081 00082 static int unload_module(void) 00083 { 00084 return ast_unregister_application(app); 00085 } 00086 00087 static int load_module(void) 00088 { 00089 return ast_register_application_xml(app, echo_exec); 00090 } 00091 00092 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");