Thu Jul 9 13:40:18 2009

Asterisk developer's documentation


app_echo.c

Go to the documentation of this file.
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: 103249 $")
00031 
00032 #include "asterisk/file.h"
00033 #include "asterisk/module.h"
00034 #include "asterisk/channel.h"
00035 
00036 static char *app = "Echo";
00037 
00038 static char *synopsis = "Echo audio, video, or DTMF back to the calling party";
00039 
00040 static char *descrip =
00041 "  Echo(): This application will echo any audio, video, or DTMF frames read from\n"
00042 "the calling channel back to itself. If the DTMF digit '#' is received, the\n"
00043 "application will exit.\n";
00044 
00045 
00046 static int echo_exec(struct ast_channel *chan, void *data)
00047 {
00048    int res = -1;
00049    int format;
00050 
00051    format = ast_best_codec(chan->nativeformats);
00052    ast_set_write_format(chan, format);
00053    ast_set_read_format(chan, format);
00054 
00055    while (ast_waitfor(chan, -1) > -1) {
00056       struct ast_frame *f = ast_read(chan);
00057       if (!f)
00058          break;
00059       f->delivery.tv_sec = 0;
00060       f->delivery.tv_usec = 0;
00061       if (ast_write(chan, f)) {
00062          ast_frfree(f);
00063          goto end;
00064       }
00065       if ((f->frametype == AST_FRAME_DTMF) && (f->subclass == '#')) {
00066          res = 0;
00067          ast_frfree(f);
00068          goto end;
00069       }
00070       ast_frfree(f);
00071    }
00072 end:
00073    return res;
00074 }
00075 
00076 static int unload_module(void)
00077 {
00078    return ast_unregister_application(app);
00079 }
00080 
00081 static int load_module(void)
00082 {
00083    return ast_register_application(app, echo_exec, synopsis, descrip);
00084 }
00085 
00086 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Simple Echo Application");

Generated on Thu Jul 9 13:40:18 2009 for Asterisk - the Open Source PBX by  doxygen 1.4.7